本文整理汇总了PHP中MediaWiki\MediaWikiServices类的典型用法代码示例。如果您正苦于以下问题:PHP MediaWikiServices类的具体用法?PHP MediaWikiServices怎么用?PHP MediaWikiServices使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MediaWikiServices类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: run
/**
* @param ApiPageSet $resultPageSet
*/
private function run($resultPageSet = null)
{
$params = $this->extractRequestParams();
$search = $params['search'];
$limit = $params['limit'];
$namespaces = $params['namespace'];
$offset = $params['offset'];
$searchEngine = MediaWikiServices::getInstance()->newSearchEngine();
$searchEngine->setLimitOffset($limit + 1, $offset);
$searchEngine->setNamespaces($namespaces);
$titles = $searchEngine->extractTitles($searchEngine->completionSearchWithVariants($search));
if ($resultPageSet) {
$resultPageSet->setRedirectMergePolicy(function (array $current, array $new) {
if (!isset($current['index']) || $new['index'] < $current['index']) {
$current['index'] = $new['index'];
}
return $current;
});
if (count($titles) > $limit) {
$this->setContinueEnumParameter('offset', $offset + $params['limit']);
array_pop($titles);
}
$resultPageSet->populateFromTitles($titles);
foreach ($titles as $index => $title) {
$resultPageSet->setGeneratorData($title, ['index' => $index + $offset + 1]);
}
} else {
$result = $this->getResult();
$count = 0;
foreach ($titles as $title) {
if (++$count > $limit) {
$this->setContinueEnumParameter('offset', $offset + $params['limit']);
break;
}
$vals = ['ns' => intval($title->getNamespace()), 'title' => $title->getPrefixedText()];
if ($title->isSpecialPage()) {
$vals['special'] = true;
} else {
$vals['pageid'] = intval($title->getArticleID());
}
$fit = $result->addValue(['query', $this->getModuleName()], null, $vals);
if (!$fit) {
$this->setContinueEnumParameter('offset', $offset + $count - 1);
break;
}
}
$result->addIndexedTagName(['query', $this->getModuleName()], $this->getModulePrefix());
}
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:52,代码来源:ApiQueryPrefixSearch.php
示例17: execute
/**
* Do the actual work. All child classes will need to implement this
*/
public function execute()
{
$file = $this->getArg(0);
if ($file === 'php://output' || $file === 'php://stdout') {
$this->mQuiet = true;
}
$handle = fopen($file, 'w');
if (!$handle) {
$this->error("Failed to open {$file} for writing.\n", 1);
}
$exporter = new SiteExporter($handle);
$siteLookup = \MediaWiki\MediaWikiServices::getInstance()->getSiteLookup();
$exporter->exportSites($siteLookup->getSites());
fclose($handle);
$this->output("Exported sites to " . realpath($file) . ".\n");
}
开发者ID:claudinec,项目名称:galan-wiki,代码行数:19,代码来源:exportSites.php
示例18: execute
function execute()
{
if ($this->hasOption('tpl-time')) {
$this->templateTimestamp = wfTimestamp(TS_MW, strtotime($this->getOption('tpl-time')));
Hooks::register('BeforeParserFetchTemplateAndtitle', [$this, 'onFetchTemplate']);
}
$this->clearLinkCache = $this->hasOption('reset-linkcache');
// Set as a member variable to avoid function calls when we're timing the parse
$this->linkCache = MediaWikiServices::getInstance()->getLinkCache();
$title = Title::newFromText($this->getArg());
if (!$title) {
$this->error("Invalid title");
exit(1);
}
if ($this->hasOption('page-time')) {
$pageTimestamp = wfTimestamp(TS_MW, strtotime($this->getOption('page-time')));
$id = $this->getRevIdForTime($title, $pageTimestamp);
if (!$id) {
$this->error("The page did not exist at that time");
exit(1);
}
$revision = Revision::newFromId($id);
} else {
$revision = Revision::newFromTitle($title);
}
if (!$revision) {
$this->error("Unable to load revision, incorrect title?");
exit(1);
}
$warmup = $this->getOption('warmup', 1);
for ($i = 0; $i < $warmup; $i++) {
$this->runParser($revision);
}
$loops = $this->getOption('loops', 1);
if ($loops < 1) {
$this->error('Invalid number of loops specified', true);
}
$startUsage = getrusage();
$startTime = microtime(true);
for ($i = 0; $i < $loops; $i++) {
$this->runParser($revision);
}
$endUsage = getrusage();
$endTime = microtime(true);
printf("CPU time = %.3f s, wall clock time = %.3f s\n", ($endUsage['ru_utime.tv_sec'] + $endUsage['ru_utime.tv_usec'] * 1.0E-6 - $startUsage['ru_utime.tv_sec'] - $startUsage['ru_utime.tv_usec'] * 1.0E-6) / $loops, ($endTime - $startTime) / $loops);
}
开发者ID:paladox,项目名称:mediawiki,代码行数:46,代码来源:benchmarkParse.php
示例19: resetGlobalInstance
/**
* Creates a new instance of MediaWikiServices and sets it as the global default
* instance. getInstance() will return a different MediaWikiServices object
* after every call to resetGlobalInstance().
*
* @since 1.28
*
* @warning This should not be used during normal operation. It is intended for use
* when the configuration has changed significantly since bootstrap time, e.g.
* during the installation process or during testing.
*
* @warning Calling resetGlobalInstance() may leave the application in an inconsistent
* state. Calling this is only safe under the ASSUMPTION that NO REFERENCE to
* any of the services managed by MediaWikiServices exist. If any service objects
* managed by the old MediaWikiServices instance remain in use, they may INTERFERE
* with the operation of the services managed by the new MediaWikiServices.
* Operating with a mix of services created by the old and the new
* MediaWikiServices instance may lead to INCONSISTENCIES and even DATA LOSS!
* Any class implementing LAZY LOADING is especially prone to this problem,
* since instances would typically retain a reference to a storage layer service.
*
* @see forceGlobalInstance()
* @see resetGlobalInstance()
* @see resetBetweenTest()
*
* @param Config|null $bootstrapConfig The Config object to be registered as the
* 'BootstrapConfig' service. This has to contain at least the information
* needed to set up the 'ConfigFactory' service. If not given, the bootstrap
* config of the old instance of MediaWikiServices will be re-used. If there
* was no previous instance, a new GlobalVarConfig object will be used to
* bootstrap the services.
*
* @param string $quick Set this to "quick" to allow expensive resources to be re-used.
* See SalvageableService for details.
*
* @throws MWException If called after MW_SERVICE_BOOTSTRAP_COMPLETE has been defined in
* Setup.php (unless MW_PHPUNIT_TEST or MEDIAWIKI_INSTALL or RUN_MAINTENANCE_IF_MAIN
* is defined).
*/
public static function resetGlobalInstance(Config $bootstrapConfig = null, $quick = '')
{
if (self::$instance === null) {
// no global instance yet, nothing to reset
return;
}
self::failIfResetNotAllowed(__METHOD__);
if ($bootstrapConfig === null) {
$bootstrapConfig = self::$instance->getBootstrapConfig();
}
$oldInstance = self::$instance;
self::$instance = self::newInstance($bootstrapConfig, 'load');
self::$instance->importWiring($oldInstance, ['BootstrapConfig']);
if ($quick === 'quick') {
self::$instance->salvage($oldInstance);
} else {
$oldInstance->destroy();
}
}
开发者ID:paladox,项目名称:mediawiki,代码行数:58,代码来源:MediaWikiServices.php
示例20: testGetLinkClasses
public function testGetLinkClasses()
{
$wanCache = ObjectCache::getMainWANInstance();
$titleFormatter = MediaWikiServices::getInstance()->getTitleFormatter();
$linkCache = new LinkCache($titleFormatter, $wanCache);
$foobarTitle = new TitleValue(NS_MAIN, 'FooBar');
$redirectTitle = new TitleValue(NS_MAIN, 'Redirect');
$userTitle = new TitleValue(NS_USER, 'Someuser');
$linkCache->addGoodLinkObj(1, $foobarTitle, 10, 0);
$linkCache->addGoodLinkObj(2, $redirectTitle, 10, 1);
$linkCache->addGoodLinkObj(3, $userTitle, 10, 0);
$linkRenderer = new LinkRenderer($titleFormatter, $linkCache);
$linkRenderer->setStubThreshold(0);
$this->assertEquals('', $linkRenderer->getLinkClasses($foobarTitle));
$linkRenderer->setStubThreshold(20);
$this->assertEquals('stub', $linkRenderer->getLinkClasses($foobarTitle));
$linkRenderer->setStubThreshold(0);
$this->assertEquals('mw-redirect', $linkRenderer->getLinkClasses($redirectTitle));
$linkRenderer->setStubThreshold(20);
$this->assertEquals('', $linkRenderer->getLinkClasses($userTitle));
}
开发者ID:paladox,项目名称:mediawiki,代码行数:21,代码来源:LinkRendererTest.php
注:本文中的MediaWiki\MediaWikiServices类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论