当前位置: 首页>>代码示例>>PHP>>正文


PHP MediaWiki\MediaWikiServices类代码示例

本文整理汇总了PHP中MediaWiki\MediaWikiServices的典型用法代码示例。如果您正苦于以下问题:PHP MediaWikiServices类的具体用法?PHP MediaWikiServices怎么用?PHP MediaWikiServices使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MediaWikiServices类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: write

 /**
  * @param array $updates Array of arrays each containing two keys, 'primaryKey'
  *  and 'changes'. primaryKey must contain a map of column names to values
  *  sufficient to uniquely identify the row changes must contain a map of column
  *  names to update values to apply to the row.
  */
 public function write(array $updates)
 {
     $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
     $ticket = $lbFactory->getEmptyTransactionTicket(__METHOD__);
     foreach ($updates as $update) {
         $this->db->update($this->table, $update['changes'], $update['primaryKey'], __METHOD__);
     }
     $lbFactory->commitAndWaitForReplication(__METHOD__, $ticket);
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:15,代码来源:BatchRowWriter.php

示例2: provideSearchOptionsTests

 public static function provideSearchOptionsTests()
 {
     $defaultNS = MediaWikiServices::getInstance()->getSearchEngineConfig()->defaultNamespaces();
     $EMPTY_REQUEST = [];
     $NO_USER_PREF = null;
     return [[$EMPTY_REQUEST, $NO_USER_PREF, 'default', $defaultNS, 'Bug 33270: No request nor user preferences should give default profile'], [['ns5' => 1], $NO_USER_PREF, 'advanced', [5], 'Web request with specific NS should override user preference'], [$EMPTY_REQUEST, ['searchNs2' => 1, 'searchNs14' => 1] + array_fill_keys(array_map(function ($ns) {
         return "searchNs{$ns}";
     }, $defaultNS), 0), 'advanced', [2, 14], 'Bug 33583: search with no option should honor User search preferences' . ' and have all other namespace disabled']];
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:9,代码来源:SpecialSearchTest.php

示例3: execute

 /**
  * Do the import.
  */
 public function execute()
 {
     $file = $this->getArg(0);
     $siteStore = \MediaWiki\MediaWikiServices::getInstance()->getSiteStore();
     $importer = new SiteImporter($siteStore);
     $importer->setExceptionCallback([$this, 'reportException']);
     $importer->importFromFile($file);
     $this->output("Done.\n");
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:12,代码来源:importSites.php

示例4: testStuff

 public function testStuff()
 {
     $user = self::$users[__CLASS__]->getUser();
     $page = WikiPage::factory(Title::newFromText('UTPage'));
     $user->addWatch($page->getTitle());
     $result = $this->doApiRequestWithToken(['action' => 'setnotificationtimestamp', 'timestamp' => '20160101020202', 'pageids' => $page->getId()], null, $user);
     $this->assertEquals(['batchcomplete' => true, 'setnotificationtimestamp' => [['ns' => 0, 'title' => 'UTPage', 'notificationtimestamp' => '2016-01-01T02:02:02Z']]], $result[0]);
     $watchedItemStore = MediaWikiServices::getInstance()->getWatchedItemStore();
     $this->assertEquals($watchedItemStore->getNotificationTimestampsBatch($user, [$page->getTitle()]), [['UTPage' => '20160101020202']]);
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:10,代码来源:ApiSetNotificationTimestampIntegrationTest.php

示例5: __construct

 public function __construct()
 {
     // We use a try/catch because we don't want to fail here
     // if $wgObjectCaches is not configured properly for APC setup
     try {
         $this->cache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
     } catch (MWException $e) {
         $this->cache = new EmptyBagOStuff();
     }
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:10,代码来源:ExtensionRegistry.php

示例6: testGetNotificationTimestamp_falseOnNotAllowed

 public function testGetNotificationTimestamp_falseOnNotAllowed()
 {
     $user = $this->getUser();
     $title = Title::newFromText('WatchedItemIntegrationTestPage');
     WatchedItem::fromUserTitle($user, $title)->addWatch();
     MediaWikiServices::getInstance()->getWatchedItemStore()->resetNotificationTimestamp($user, $title);
     $this->assertEquals(null, WatchedItem::fromUserTitle($user, $title)->getNotificationTimestamp());
     $user->mRights = [];
     $this->assertFalse(WatchedItem::fromUserTitle($user, $title)->getNotificationTimestamp());
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:10,代码来源:WatchedItemIntegrationTest.php

示例7: tearDown

 protected function tearDown()
 {
     global $wgContLang;
     // Reset namespace cache
     MWNamespace::getCanonicalNamespaces(true);
     $wgContLang->resetNamespaces();
     // And LinkCache
     MediaWikiServices::getInstance()->resetServiceForTesting('LinkCache');
     parent::tearDown();
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:10,代码来源:ContentHandlerTest.php

示例8: newInstance

 /**
  * Returns the global SiteStore instance. This is a relict of the first implementation
  * of SiteStore, and is kept around for compatibility.
  *
  * @note This does not return an instance of SiteSQLStore!
  *
  * @since 1.21
  * @deprecated 1.27 use MediaWikiServices::getSiteStore() or MediaWikiServices::getSiteLookup()
  *             instead.
  *
  * @param null $sitesTable IGNORED
  * @param null $cache IGNORED
  *
  * @return SiteStore
  */
 public static function newInstance($sitesTable = null, BagOStuff $cache = null)
 {
     if ($sitesTable !== null) {
         throw new InvalidArgumentException(__METHOD__ . ': $sitesTable parameter is unused and must be null');
     }
     // NOTE: we silently ignore $cache for now, since some existing callers
     // specify it. If we break compatibility with them, we could just as
     // well just remove this class.
     return \MediaWiki\MediaWikiServices::getInstance()->getSiteStore();
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:25,代码来源:SiteSQLStore.php

示例9: applyDefaultConfig

 /**
  * @param array $lbConf Config for LBFactory::__construct()
  * @param Config $mainConfig Main config object from MediaWikiServices
  * @return array
  */
 public static function applyDefaultConfig(array $lbConf, Config $mainConfig)
 {
     global $wgCommandLineMode;
     $lbConf += ['localDomain' => new DatabaseDomain($mainConfig->get('DBname'), null, $mainConfig->get('DBprefix')), 'profiler' => Profiler::instance(), 'trxProfiler' => Profiler::instance()->getTransactionProfiler(), 'replLogger' => LoggerFactory::getInstance('DBReplication'), 'queryLogger' => LoggerFactory::getInstance('DBQuery'), 'connLogger' => LoggerFactory::getInstance('DBConnection'), 'perfLogger' => LoggerFactory::getInstance('DBPerformance'), 'errorLogger' => [MWExceptionHandler::class, 'logException'], 'cliMode' => $wgCommandLineMode, 'hostname' => wfHostname(), 'readOnlyReason' => wfConfiguredReadOnlyReason()];
     if ($lbConf['class'] === 'LBFactorySimple') {
         if (isset($lbConf['servers'])) {
             // Server array is already explicitly configured; leave alone
         } elseif (is_array($mainConfig->get('DBservers'))) {
             foreach ($mainConfig->get('DBservers') as $i => $server) {
                 if ($server['type'] === 'sqlite') {
                     $server += ['dbDirectory' => $mainConfig->get('SQLiteDataDir')];
                 } elseif ($server['type'] === 'postgres') {
                     $server += ['port' => $mainConfig->get('DBport')];
                 }
                 $lbConf['servers'][$i] = $server + ['schema' => $mainConfig->get('DBmwschema'), 'tablePrefix' => $mainConfig->get('DBprefix'), 'flags' => DBO_DEFAULT, 'sqlMode' => $mainConfig->get('SQLMode'), 'utf8Mode' => $mainConfig->get('DBmysql5')];
             }
         } else {
             $flags = DBO_DEFAULT;
             $flags |= $mainConfig->get('DebugDumpSql') ? DBO_DEBUG : 0;
             $flags |= $mainConfig->get('DBssl') ? DBO_SSL : 0;
             $flags |= $mainConfig->get('DBcompress') ? DBO_COMPRESS : 0;
             $server = ['host' => $mainConfig->get('DBserver'), 'user' => $mainConfig->get('DBuser'), 'password' => $mainConfig->get('DBpassword'), 'dbname' => $mainConfig->get('DBname'), 'schema' => $mainConfig->get('DBmwschema'), 'tablePrefix' => $mainConfig->get('DBprefix'), 'type' => $mainConfig->get('DBtype'), 'load' => 1, 'flags' => $flags, 'sqlMode' => $mainConfig->get('SQLMode'), 'utf8Mode' => $mainConfig->get('DBmysql5')];
             if ($server['type'] === 'sqlite') {
                 $server['dbDirectory'] = $mainConfig->get('SQLiteDataDir');
             } elseif ($server['type'] === 'postgres') {
                 $server['port'] = $mainConfig->get('DBport');
             }
             $lbConf['servers'] = [$server];
         }
         if (!isset($lbConf['externalClusters'])) {
             $lbConf['externalClusters'] = $mainConfig->get('ExternalServers');
         }
     } elseif ($lbConf['class'] === 'LBFactoryMulti') {
         if (isset($lbConf['serverTemplate'])) {
             $lbConf['serverTemplate']['schema'] = $mainConfig->get('DBmwschema');
             $lbConf['serverTemplate']['sqlMode'] = $mainConfig->get('SQLMode');
             $lbConf['serverTemplate']['utf8Mode'] = $mainConfig->get('DBmysql5');
         }
     }
     // Use APC/memcached style caching, but avoids loops with CACHE_DB (T141804)
     $sCache = MediaWikiServices::getInstance()->getLocalServerObjectCache();
     if ($sCache->getQoS($sCache::ATTR_EMULATION) > $sCache::QOS_EMULATION_SQL) {
         $lbConf['srvCache'] = $sCache;
     }
     $cCache = ObjectCache::getLocalClusterInstance();
     if ($cCache->getQoS($cCache::ATTR_EMULATION) > $cCache::QOS_EMULATION_SQL) {
         $lbConf['memCache'] = $cCache;
     }
     $wCache = MediaWikiServices::getInstance()->getMainWANObjectCache();
     if ($wCache->getQoS($wCache::ATTR_EMULATION) > $wCache::QOS_EMULATION_SQL) {
         $lbConf['wanCache'] = $wCache;
     }
     return $lbConf;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:59,代码来源:MWLBFactory.php

示例10: doUpdates

 /**
  * Driver function that handles updating assessment data in database
  * @param Title $titleObj Title object of the subject page
  * @param array $assessmentData Data for all assessments compiled
  */
 public static function doUpdates($titleObj, $assessmentData)
 {
     global $wgUpdateRowsPerQuery;
     $factory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
     $ticket = $factory->getEmptyTransactionTicket(__METHOD__);
     $pageId = $titleObj->getArticleID();
     $revisionId = $titleObj->getLatestRevID();
     // Compile a list of projects to find out which ones to be deleted afterwards
     $projects = array();
     foreach ($assessmentData as $parserData) {
         // For each project, get the corresponding ID from page_assessments_projects table
         $projectId = self::getProjectId($parserData[0]);
         if ($projectId === false) {
             $projectId = self::insertProject($parserData[0]);
         }
         $projects[$parserData[0]] = $projectId;
     }
     $projectsInDb = self::getAllProjects($pageId, self::READ_LATEST);
     $toInsert = array_diff($projects, $projectsInDb);
     $toDelete = array_diff($projectsInDb, $projects);
     $toUpdate = array_intersect($projects, $projectsInDb);
     $i = 0;
     // Add and update records to the database
     foreach ($assessmentData as $parserData) {
         $projectId = $projects[$parserData[0]];
         if ($projectId) {
             $class = $parserData[1];
             $importance = $parserData[2];
             $values = array('pa_page_id' => $pageId, 'pa_project_id' => $projectId, 'pa_class' => $class, 'pa_importance' => $importance, 'pa_page_revision' => $revisionId);
             if (in_array($projectId, $toInsert)) {
                 self::insertRecord($values);
             } elseif (in_array($projectId, $toUpdate)) {
                 self::updateRecord($values);
             }
             // Check for database lag if there's a huge number of assessments
             if ($i > 0 && $i % $wgUpdateRowsPerQuery == 0) {
                 $factory->commitAndWaitForReplication(__METHOD__, $ticket);
             }
             $i++;
         }
     }
     // Delete records from the database
     foreach ($toDelete as $project) {
         $values = array('pa_page_id' => $pageId, 'pa_project_id' => $project);
         self::deleteRecord($values);
         // Check for database lag if there's a huge number of deleted assessments
         if ($i > 0 && $i % $wgUpdateRowsPerQuery == 0) {
             $factory->commitAndWaitForReplication(__METHOD__, $ticket);
         }
         $i++;
     }
     return;
 }
开发者ID:wikimedia,项目名称:mediawiki-extensions-PageAssessments,代码行数:58,代码来源:PageAssessmentsBody.php

示例11: __construct

 /**
  * Changeslist constructor
  *
  * @param Skin|IContextSource $obj
  */
 public function __construct($obj)
 {
     if ($obj instanceof IContextSource) {
         $this->setContext($obj);
         $this->skin = $obj->getSkin();
     } else {
         $this->setContext($obj->getContext());
         $this->skin = $obj;
     }
     $this->preCacheMessages();
     $this->watchMsgCache = new HashBagOStuff(['maxKeys' => 50]);
     $this->linkRenderer = MediaWikiServices::getInstance()->getLinkRenderer();
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:18,代码来源:ChangesList.php

示例12: initFromTitle

 /**
  * Initialize from a Title and if possible initializes a corresponding
  * Revision and File.
  *
  * @param Title $title
  */
 protected function initFromTitle($title)
 {
     $this->mTitle = $title;
     if (!is_null($this->mTitle)) {
         $id = false;
         Hooks::run('SearchResultInitFromTitle', [$title, &$id]);
         $this->mRevision = Revision::newFromTitle($this->mTitle, $id, Revision::READ_NORMAL);
         if ($this->mTitle->getNamespace() === NS_FILE) {
             $this->mImage = wfFindFile($this->mTitle);
         }
     }
     $this->searchEngine = MediaWikiServices::getInstance()->newSearchEngine();
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:19,代码来源:SearchResult.php

示例13: setUp

 protected function setUp()
 {
     parent::setUp();
     if (!$this->isWikitextNS(NS_MAIN)) {
         $this->markTestSkipped('Main namespace does not support wikitext.');
     }
     // Avoid special pages from extensions interferring with the tests
     $this->setMwGlobals(['wgSpecialPages' => [], 'wgHooks' => []]);
     $this->search = MediaWikiServices::getInstance()->newSearchEngine();
     $this->search->setNamespaces([]);
     $this->originalHandlers = TestingAccessWrapper::newFromClass('Hooks')->handlers;
     TestingAccessWrapper::newFromClass('Hooks')->handlers = [];
     SpecialPageFactory::resetList();
 }
开发者ID:claudinec,项目名称:galan-wiki,代码行数:14,代码来源:SearchEnginePrefixTest.php

示例14: run

 public function run()
 {
     $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
     $lb = $lbFactory->getMainLB();
     $dbw = $lb->getConnection(DB_MASTER);
     $this->ticket = $lbFactory->getEmptyTransactionTicket(__METHOD__);
     $page = WikiPage::newFromID($this->params['pageId'], WikiPage::READ_LATEST);
     if (!$page) {
         $this->setLastError("Could not find page #{$this->params['pageId']}");
         return false;
         // deleted?
     }
     // Use a named lock so that jobs for this page see each others' changes
     $lockKey = "CategoryMembershipUpdates:{$page->getId()}";
     $scopedLock = $dbw->getScopedLockAndFlush($lockKey, __METHOD__, 3);
     if (!$scopedLock) {
         $this->setLastError("Could not acquire lock '{$lockKey}'");
         return false;
     }
     $dbr = $lb->getConnection(DB_REPLICA, ['recentchanges']);
     // Wait till the replica DB is caught up so that jobs for this page see each others' changes
     if (!$lb->safeWaitForMasterPos($dbr)) {
         $this->setLastError("Timed out while waiting for replica DB to catch up");
         return false;
     }
     // Clear any stale REPEATABLE-READ snapshot
     $dbr->flushSnapshot(__METHOD__);
     $cutoffUnix = wfTimestamp(TS_UNIX, $this->params['revTimestamp']);
     // Using ENQUEUE_FUDGE_SEC handles jobs inserted out of revision order due to the delay
     // between COMMIT and actual enqueueing of the CategoryMembershipChangeJob job.
     $cutoffUnix -= self::ENQUEUE_FUDGE_SEC;
     // Get the newest revision that has a SRC_CATEGORIZE row...
     $row = $dbr->selectRow(['revision', 'recentchanges'], ['rev_timestamp', 'rev_id'], ['rev_page' => $page->getId(), 'rev_timestamp >= ' . $dbr->addQuotes($dbr->timestamp($cutoffUnix))], __METHOD__, ['ORDER BY' => 'rev_timestamp DESC, rev_id DESC'], ['recentchanges' => ['INNER JOIN', ['rc_this_oldid = rev_id', 'rc_source' => RecentChange::SRC_CATEGORIZE, 'rc_cur_id = rev_page', 'rc_timestamp >= rev_timestamp']]]);
     // Only consider revisions newer than any such revision
     if ($row) {
         $cutoffUnix = wfTimestamp(TS_UNIX, $row->rev_timestamp);
         $lastRevId = (int) $row->rev_id;
     } else {
         $lastRevId = 0;
     }
     // Find revisions to this page made around and after this revision which lack category
     // notifications in recent changes. This lets jobs pick up were the last one left off.
     $encCutoff = $dbr->addQuotes($dbr->timestamp($cutoffUnix));
     $res = $dbr->select('revision', Revision::selectFields(), ['rev_page' => $page->getId(), "rev_timestamp > {$encCutoff}" . " OR (rev_timestamp = {$encCutoff} AND rev_id > {$lastRevId})"], __METHOD__, ['ORDER BY' => 'rev_timestamp ASC, rev_id ASC']);
     // Apply all category updates in revision timestamp order
     foreach ($res as $row) {
         $this->notifyUpdatesForRevision($lbFactory, $page, Revision::newFromRow($row));
     }
     return true;
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:50,代码来源:CategoryMembershipChangeJob.php

示例15: rollbackMasterChangesAndLog

 /**
  * If there are any open database transactions, roll them back and log
  * the stack trace of the exception that should have been caught so the
  * transaction could be aborted properly.
  *
  * @since 1.23
  * @param Exception|Throwable $e
  */
 public static function rollbackMasterChangesAndLog($e)
 {
     $services = MediaWikiServices::getInstance();
     if ($services->isServiceDisabled('DBLoadBalancerFactory')) {
         return;
         // T147599
     }
     $lbFactory = $services->getDBLoadBalancerFactory();
     if ($lbFactory->hasMasterChanges()) {
         $logger = LoggerFactory::getInstance('Bug56269');
         $logger->warning('Exception thrown with an uncommited database transaction: ' . self::getLogMessage($e), self::getLogContext($e));
     }
     $lbFactory->rollbackMasterChanges(__METHOD__);
 }
开发者ID:paladox,项目名称:mediawiki,代码行数:22,代码来源:MWExceptionHandler.php


注:本文中的MediaWiki\MediaWikiServices类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。