/** * @param ResourceLoaderContext $context * @return array */ protected function getConfigSettings($context) { $hash = $context->getHash(); if (isset($this->configVars[$hash])) { return $this->configVars[$hash]; } global $wgContLang; $mainPage = Title::newMainPage(); /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = array(); foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) { $namespaceIds[$wgContLang->lc($name)] = $index; if (!MWNamespace::isCapitalized($index)) { $caseSensitiveNamespaces[] = $index; } } $conf = $this->getConfig(); // Build list of variables $vars = array('wgLoadScript' => wfScript('load'), 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $conf->get('StylePath'), 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $conf->get('ArticlePath'), 'wgScriptPath' => $conf->get('ScriptPath'), 'wgScriptExtension' => '.php', 'wgScript' => wfScript(), 'wgSearchType' => $conf->get('SearchType'), 'wgVariantArticlePath' => $conf->get('VariantArticlePath'), 'wgActionPaths' => (object) $conf->get('ActionPaths'), 'wgServer' => $conf->get('Server'), 'wgServerName' => $conf->get('ServerName'), 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgTranslateNumerals' => $conf->get('TranslateNumerals'), 'wgVersion' => $conf->get('Version'), 'wgEnableAPI' => $conf->get('EnableAPI'), 'wgEnableWriteAPI' => $conf->get('EnableWriteAPI'), 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $conf->get('Sitename'), 'wgDBname' => $conf->get('DBname'), 'wgExtraSignatureNamespaces' => $conf->get('ExtraSignatureNamespaces'), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $conf->get('ExtensionAssetsPath'), 'wgCookiePrefix' => $conf->get('CookiePrefix'), 'wgCookieDomain' => $conf->get('CookieDomain'), 'wgCookiePath' => $conf->get('CookiePath'), 'wgCookieExpiration' => $conf->get('CookieExpiration'), 'wgResourceLoaderMaxQueryLength' => $conf->get('ResourceLoaderMaxQueryLength'), 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgResourceLoaderStorageVersion' => $conf->get('ResourceLoaderStorageVersion'), 'wgResourceLoaderStorageEnabled' => $conf->get('ResourceLoaderStorageEnabled'), 'wgResourceLoaderLegacyModules' => self::getLegacyModules(), 'wgForeignUploadTargets' => $conf->get('ForeignUploadTargets'), 'wgEnableUploads' => $conf->get('EnableUploads')); Hooks::run('ResourceLoaderGetConfigVars', array(&$vars)); $this->configVars[$hash] = $vars; return $this->configVars[$hash]; }
/** * @param ResourceLoaderContext $context * @return array */ protected function getConfig($context) { $hash = $context->getHash(); if (isset($this->configVars[$hash])) { return $this->configVars[$hash]; } global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgVersion, $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath, $wgCookiePrefix, $wgResourceLoaderMaxQueryLength, $wgResourceLoaderStorageEnabled, $wgResourceLoaderStorageVersion, $wgSearchType; $mainPage = Title::newMainPage(); /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = array(); foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) { $namespaceIds[$wgContLang->lc($name)] = $index; if (!MWNamespace::isCapitalized($index)) { $caseSensitiveNamespaces[] = $index; } } // Build list of variables $vars = array('wgLoadScript' => $wgLoadScript, 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $wgStylePath, 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScriptExtension' => $wgScriptExtension, 'wgScript' => $wgScript, 'wgSearchType' => $wgSearchType, 'wgVariantArticlePath' => $wgVariantArticlePath, 'wgActionPaths' => (object) $wgActionPaths, 'wgServer' => $wgServer, 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgVersion' => $wgVersion, 'wgEnableAPI' => $wgEnableAPI, 'wgEnableWriteAPI' => $wgEnableWriteAPI, 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgContentNamespaces' => MWNamespace::getContentNamespaces(), 'wgSiteName' => $wgSitename, 'wgFileExtensions' => array_values(array_unique($wgFileExtensions)), 'wgDBname' => $wgDBname, 'wgFileCanRotate' => BitmapHandler::canRotate(), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $wgExtensionAssetsPath, 'wgCookiePrefix' => $wgCookiePrefix, 'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength, 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass(Title::legalChars()), 'wgResourceLoaderStorageVersion' => $wgResourceLoaderStorageVersion, 'wgResourceLoaderStorageEnabled' => $wgResourceLoaderStorageEnabled); wfRunHooks('ResourceLoaderGetConfigVars', array(&$vars)); $this->configVars[$hash] = $vars; return $this->configVars[$hash]; }
/** * @param $context ResourceLoaderContext * @return array */ protected function getConfig($context) { global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgUseAjax, $wgVersion, $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgEnableMWSuggest, $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath, $wgCookiePrefix, $wgResourceLoaderMaxQueryLength; $mainPage = Title::newMainPage(); /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = array(); foreach (MWNamespace::getCanonicalNamespaces() as $index => $name) { $namespaceIds[$wgContLang->lc($name)] = $index; if (!MWNamespace::isCapitalized($index)) { $caseSensitiveNamespaces[] = $index; } } // Build list of variables $vars = array('wgLoadScript' => $wgLoadScript, 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $wgStylePath, 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScriptExtension' => $wgScriptExtension, 'wgScript' => $wgScript, 'wgVariantArticlePath' => $wgVariantArticlePath, 'wgActionPaths' => (object) $wgActionPaths, 'wgServer' => $wgServer, 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgVersion' => $wgVersion, 'wgEnableAPI' => $wgEnableAPI, 'wgEnableWriteAPI' => $wgEnableWriteAPI, 'wgDefaultDateFormat' => $wgContLang->getDefaultDateFormat(), 'wgMonthNames' => $wgContLang->getMonthNamesArray(), 'wgMonthNamesShort' => $wgContLang->getMonthAbbreviationsArray(), 'wgMainPageTitle' => $mainPage ? $mainPage->getPrefixedText() : null, 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgSiteName' => $wgSitename, 'wgFileExtensions' => array_values($wgFileExtensions), 'wgDBname' => $wgDBname, 'wgFileCanRotate' => BitmapHandler::canRotate(), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $wgExtensionAssetsPath, 'wgCookiePrefix' => $wgCookiePrefix, 'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength, 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgSassParams' => SassUtil::getSassSettings()); if ($wgUseAjax && $wgEnableMWSuggest) { $vars['wgMWSuggestTemplate'] = SearchEngine::getMWSuggestTemplate(); } wfRunHooks('ResourceLoaderGetConfigVars', array(&$vars)); return $vars; }
public function tearDown() { global $wgContLang; // Reset namespace cache MWNamespace::getCanonicalNamespaces(true); $wgContLang->resetNamespaces(); parent::tearDown(); }
/** * @todo Document * @param $fix Boolean: whether or not to fix broken entries * @param $suffix String: suffix to append to renamed articles * * @return bool */ private function checkAll($fix, $suffix = '') { global $wgContLang, $wgNamespaceAliases, $wgCapitalLinks; $spaces = array(); // List interwikis first, so they'll be overridden // by any conflicting local namespaces. foreach ($this->getInterwikiList() as $prefix) { $name = $wgContLang->ucfirst($prefix); $spaces[$name] = 0; } // Now pull in all canonical and alias namespaces... foreach (MWNamespace::getCanonicalNamespaces() as $ns => $name) { // This includes $wgExtraNamespaces if ($name !== '') { $spaces[$name] = $ns; } } foreach ($wgContLang->getNamespaces() as $ns => $name) { if ($name !== '') { $spaces[$name] = $ns; } } foreach ($wgNamespaceAliases as $name => $ns) { $spaces[$name] = $ns; } foreach ($wgContLang->getNamespaceAliases() as $name => $ns) { $spaces[$name] = $ns; } // We'll need to check for lowercase keys as well, // since we're doing case-sensitive searches in the db. foreach ($spaces as $name => $ns) { $moreNames = array(); $moreNames[] = $wgContLang->uc($name); $moreNames[] = $wgContLang->ucfirst($wgContLang->lc($name)); $moreNames[] = $wgContLang->ucwords($name); $moreNames[] = $wgContLang->ucwords($wgContLang->lc($name)); $moreNames[] = $wgContLang->ucwordbreaks($name); $moreNames[] = $wgContLang->ucwordbreaks($wgContLang->lc($name)); if (!$wgCapitalLinks) { foreach ($moreNames as $altName) { $moreNames[] = $wgContLang->lcfirst($altName); } $moreNames[] = $wgContLang->lcfirst($name); } foreach (array_unique($moreNames) as $altName) { if ($altName !== $name) { $spaces[$altName] = $ns; } } } ksort($spaces); asort($spaces); $ok = true; foreach ($spaces as $name => $ns) { $ok = $this->checkNamespace($ns, $name, $fix, $suffix) && $ok; } return $ok; }
function tearDown() { global $wgContLang; MWNamespace::getCanonicalNamespaces(true); # reset namespace cache $wgContLang->resetNamespaces(); # reset namespace cache parent::tearDown(); }
protected function tearDown() { global $wgContLang; // Reset namespace cache MWNamespace::getCanonicalNamespaces(true); $wgContLang->resetNamespaces(); // And LinkCache MediaWikiServices::getInstance()->resetServiceForTesting('LinkCache'); parent::tearDown(); }
protected function tearDown() { global $wgContLang; // Reset namespace cache MWNamespace::getCanonicalNamespaces(true); $wgContLang->resetNamespaces(); // And LinkCache LinkCache::destroySingleton(); parent::tearDown(); }
function iaclfCanonicalNsText($index) { static $ns; if (!$ns) { $ns = MWNamespace::getCanonicalNamespaces(); foreach ($ns as &$v) { $v = str_replace('_', ' ', $v); } $ns[0] = 'Main'; } return isset($ns[$index]) ? $ns[$index] : NULL; }
public function teardown() { global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang; unset($wgExtraNamespaces[12312]); unset($wgExtraNamespaces[12313]); unset($wgNamespaceContentModels[12312]); unset($wgContentHandlers["testing"]); MWNamespace::getCanonicalNamespaces(true); # reset namespace cache $wgContLang->resetNamespaces(); # reset namespace cache parent::teardown(); }
protected function tearDown() { global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang; parent::tearDown(); unset($wgExtraNamespaces[12312]); unset($wgExtraNamespaces[12313]); unset($wgNamespaceContentModels[12312]); unset($wgContentHandlers['DUMMY']); MWNamespace::getCanonicalNamespaces(true); # reset namespace cache $wgContLang->resetNamespaces(); # reset namespace cache }
protected function setUp() { global $wgExtraNamespaces, $wgNamespaceContentModels, $wgContentHandlers, $wgContLang; parent::setUp(); $this->setMwGlobals(['wgExtraNamespaces' => $wgExtraNamespaces, 'wgNamespaceContentModels' => $wgNamespaceContentModels, 'wgContentHandlers' => $wgContentHandlers, 'wgContLang' => $wgContLang]); $wgExtraNamespaces[12312] = 'Dummy'; $wgExtraNamespaces[12313] = 'Dummy_talk'; $wgNamespaceContentModels[12312] = "testing"; $wgContentHandlers["testing"] = 'DummyContentHandlerForTesting'; MWNamespace::getCanonicalNamespaces(true); # reset namespace cache $wgContLang->resetNamespaces(); # reset namespace cache }
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' => [], 'wgExtraNamespaces' => [self::NS_NONCAP => 'NonCap'], 'wgCapitalLinkOverrides' => [self::NS_NONCAP => false]]); $this->originalHandlers = TestingAccessWrapper::newFromClass('Hooks')->handlers; TestingAccessWrapper::newFromClass('Hooks')->handlers = []; // Clear caches so that our new namespace appears MWNamespace::getCanonicalNamespaces(true); Language::factory('en')->resetNamespaces(); SpecialPageFactory::resetList(); }
/** * @param OutputPage $oOut * @param Skin $oSkin * @return boolean */ public function onBeforePageDisplay(&$oOut, &$oSkin) { $oTitle = $oSkin->getTitle(); $aNamespaces = MWNamespace::getCanonicalNamespaces(); $iCurrentNs = $oTitle->getNamespace(); if ($oTitle->isTalkPage()) { $iCurrentNs--; } if (!isset($aNamespaces[$iCurrentNs])) { return true; } $oStyleSheetTitle = Title::newFromText($aNamespaces[$iCurrentNs] . '_css', NS_MEDIAWIKI); if ($oStyleSheetTitle->exists()) { $oOut->addStyle($oStyleSheetTitle->getLocalUrl(array('action' => 'raw', 'ctype' => 'text/css'))); } return true; }
public static function getNamespaceName($title) { $page_ns = MWNamespace::getCanonicalNamespaces(); $page_ns = $page_ns[$title->getNamespace()]; // NS text if ($page_ns == "") { $page_ns = "Main"; } return $page_ns; }
protected function tearDown() { MWNamespace::getCanonicalNamespaces(true); # reset namespace cache parent::tearDown(); }
/** * Translate namespace from localized to the canonical form. * * @param $param - Page title */ function translateNamespace($param) { list($dbKey, $namespace) = $this->getKeyNS($param); if ($namespace == 0) { return $dbKey; } else { $canonicalNamespaces = MWNamespace::getCanonicalNamespaces(); return $canonicalNamespaces[$namespace] . ":" . $dbKey; } }
/** * @return array */ function getNamespaces() { if (is_null($this->namespaceNames)) { global $wgMetaNamespace, $wgMetaNamespaceTalk, $wgExtraNamespaces; $this->namespaceNames = self::$dataCache->getItem($this->mCode, 'namespaceNames'); $validNamespaces = MWNamespace::getCanonicalNamespaces(); $this->namespaceNames = $wgExtraNamespaces + $this->namespaceNames + $validNamespaces; $this->namespaceNames[NS_PROJECT] = $wgMetaNamespace; if ($wgMetaNamespaceTalk) { $this->namespaceNames[NS_PROJECT_TALK] = $wgMetaNamespaceTalk; } else { $talk = $this->namespaceNames[NS_PROJECT_TALK]; $this->namespaceNames[NS_PROJECT_TALK] = $this->fixVariableInNamespace($talk); } # Sometimes a language will be localised but not actually exist on this wiki. foreach ($this->namespaceNames as $key => $text) { if (!isset($validNamespaces[$key])) { unset($this->namespaceNames[$key]); } } # The above mixing may leave namespaces out of canonical order. # Re-order by namespace ID number... ksort($this->namespaceNames); } return $this->namespaceNames; }
/** * @param $context ResourceLoaderContext * @return array */ protected function getConfig( $context ) { global $wgLoadScript, $wgScript, $wgStylePath, $wgScriptExtension, $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgVariantArticlePath, $wgActionPaths, $wgVersion, $wgEnableAPI, $wgEnableWriteAPI, $wgDBname, $wgSitename, $wgFileExtensions, $wgExtensionAssetsPath, $wgCookiePrefix, $wgResourceLoaderMaxQueryLength; $mainPage = Title::newMainPage(); /** * Namespace related preparation * - wgNamespaceIds: Key-value pairs of all localized, canonical and aliases for namespaces. * - wgCaseSensitiveNamespaces: Array of namespaces that are case-sensitive. */ $namespaceIds = $wgContLang->getNamespaceIds(); $caseSensitiveNamespaces = array(); foreach ( MWNamespace::getCanonicalNamespaces() as $index => $name ) { $namespaceIds[$wgContLang->lc( $name )] = $index; if ( !MWNamespace::isCapitalized( $index ) ) { $caseSensitiveNamespaces[] = $index; } } // Build list of variables $vars = array( 'wgLoadScript' => $wgLoadScript, 'debug' => $context->getDebug(), 'skin' => $context->getSkin(), 'stylepath' => $wgStylePath, 'wgUrlProtocols' => wfUrlProtocols(), 'wgArticlePath' => $wgArticlePath, 'wgScriptPath' => $wgScriptPath, 'wgScriptExtension' => $wgScriptExtension, 'wgScript' => $wgScript, 'wgVariantArticlePath' => $wgVariantArticlePath, // Force object to avoid "empty" associative array from // becoming [] instead of {} in JS (bug 34604) 'wgActionPaths' => (object)$wgActionPaths, 'wgServer' => $wgServer, 'wgUserLanguage' => $context->getLanguage(), 'wgContentLanguage' => $wgContLang->getCode(), 'wgVersion' => $wgVersion, 'wgEnableAPI' => $wgEnableAPI, 'wgEnableWriteAPI' => $wgEnableWriteAPI, 'wgMainPageTitle' => $mainPage->getPrefixedText(), 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), 'wgNamespaceIds' => $namespaceIds, 'wgSiteName' => $wgSitename, 'wgFileExtensions' => array_values( array_unique( $wgFileExtensions ) ), 'wgDBname' => $wgDBname, // This sucks, it is only needed on Special:Upload, but I could // not find a way to add vars only for a certain module 'wgFileCanRotate' => BitmapHandler::canRotate(), 'wgAvailableSkins' => Skin::getSkinNames(), 'wgExtensionAssetsPath' => $wgExtensionAssetsPath, // MediaWiki sets cookies to have this prefix by default 'wgCookiePrefix' => $wgCookiePrefix, 'wgResourceLoaderMaxQueryLength' => $wgResourceLoaderMaxQueryLength, 'wgCaseSensitiveNamespaces' => $caseSensitiveNamespaces, 'wgLegalTitleChars' => Title::convertByteClassToUnicodeClass( Title::legalChars() ), ); wfRunHooks( 'ResourceLoaderGetConfigVars', array( &$vars ) ); return $vars; }
protected function doPagelinksUpdate() { if ($this->db->tableExists('pagelinks', __METHOD__)) { $this->output("...already have pagelinks table.\n"); return; } $this->output("Converting links and brokenlinks tables to pagelinks... "); $this->applyPatch('patch-pagelinks.sql'); $this->output("done.\n"); global $wgContLang; foreach (MWNamespace::getCanonicalNamespaces() as $ns => $name) { if ($ns == 0) { continue; } $this->output("Cleaning up broken links for namespace {$ns}... "); $pagelinks = $this->db->tableName('pagelinks'); $name = $wgContLang->getNsText($ns); $prefix = $this->db->strencode($name); $likeprefix = str_replace('_', '\\_', $prefix); $sql = "UPDATE {$pagelinks}\n\t\t\t\t\t SET pl_namespace={$ns},\n\t\t\t\t\t\t pl_title=TRIM(LEADING '{$prefix}:' FROM pl_title)\n\t\t\t\t\t WHERE pl_namespace=0\n\t\t\t\t\t AND pl_title LIKE '{$likeprefix}:%'"; $this->db->query($sql, __METHOD__); $this->output("done.\n"); } }
protected function tearDown() { global $wgNamespaceAliases, $wgContLang; $wgNamespaceAliases['Image'] = $this->savedWeirdGlobals['image_alias']; $wgNamespaceAliases['Image_talk'] = $this->savedWeirdGlobals['image_talk_alias']; MWTidy::destroySingleton(); // Restore backends RepoGroup::destroySingleton(); FileBackendGroup::destroySingleton(); // Remove temporary pages from the link cache LinkCache::singleton()->clear(); // Restore message cache (temporary pages and $wgUseDatabaseMessages) MessageCache::destroyInstance(); parent::tearDown(); MWNamespace::getCanonicalNamespaces(true); # reset namespace cache $wgContLang->resetNamespaces(); # reset namespace cache }
/** * Check all namespaces * * @param array $options Associative array of validated command-line options * * @return bool */ private function checkAll($options) { global $wgContLang, $wgNamespaceAliases, $wgCapitalLinks; $spaces = array(); // List interwikis first, so they'll be overridden // by any conflicting local namespaces. foreach ($this->getInterwikiList() as $prefix) { $name = $wgContLang->ucfirst($prefix); $spaces[$name] = 0; } // Now pull in all canonical and alias namespaces... foreach (MWNamespace::getCanonicalNamespaces() as $ns => $name) { // This includes $wgExtraNamespaces if ($name !== '') { $spaces[$name] = $ns; } } foreach ($wgContLang->getNamespaces() as $ns => $name) { if ($name !== '') { $spaces[$name] = $ns; } } foreach ($wgNamespaceAliases as $name => $ns) { $spaces[$name] = $ns; } foreach ($wgContLang->getNamespaceAliases() as $name => $ns) { $spaces[$name] = $ns; } // We'll need to check for lowercase keys as well, // since we're doing case-sensitive searches in the db. foreach ($spaces as $name => $ns) { $moreNames = array(); $moreNames[] = $wgContLang->uc($name); $moreNames[] = $wgContLang->ucfirst($wgContLang->lc($name)); $moreNames[] = $wgContLang->ucwords($name); $moreNames[] = $wgContLang->ucwords($wgContLang->lc($name)); $moreNames[] = $wgContLang->ucwordbreaks($name); $moreNames[] = $wgContLang->ucwordbreaks($wgContLang->lc($name)); if (!$wgCapitalLinks) { foreach ($moreNames as $altName) { $moreNames[] = $wgContLang->lcfirst($altName); } $moreNames[] = $wgContLang->lcfirst($name); } foreach (array_unique($moreNames) as $altName) { if ($altName !== $name) { $spaces[$altName] = $ns; } } } // Sort by namespace index, and if there are two with the same index, // break the tie by sorting by name $origSpaces = $spaces; uksort($spaces, function ($a, $b) use($origSpaces) { if ($origSpaces[$a] < $origSpaces[$b]) { return -1; } elseif ($origSpaces[$a] > $origSpaces[$b]) { return 1; } elseif ($a < $b) { return -1; } elseif ($a > $b) { return 1; } else { return 0; } }); $ok = true; foreach ($spaces as $name => $ns) { $ok = $this->checkNamespace($ns, $name, $options) && $ok; } $this->output("{$this->totalPages} pages to fix, " . "{$this->resolvablePages} were resolvable.\n\n"); foreach ($spaces as $name => $ns) { if ($ns != 0) { /* Fix up link destinations for non-interwiki links only. * * For example if a page has [[Foo:Bar]] and then a Foo namespace * is introduced, pagelinks needs to be updated to have * page_namespace = NS_FOO. * * If instead an interwiki prefix was introduced called "Foo", * the link should instead be moved to the iwlinks table. If a new * language is introduced called "Foo", or if there is a pagelink * [[fr:Bar]] when interlanguage magic links are turned on, the * link would have to be moved to the langlinks table. Let's put * those cases in the too-hard basket for now. The consequences are * not especially severe. * @fixme Handle interwiki links, and pagelinks to Category:, File: * which probably need reparsing. */ $this->checkLinkTable('pagelinks', 'pl', $ns, $name, $options); $this->checkLinkTable('templatelinks', 'tl', $ns, $name, $options); // The redirect table has interwiki links randomly mixed in, we // need to filter those out. For example [[w:Foo:Bar]] would // have rd_interwiki=w and rd_namespace=0, which would match the // query for a conflicting namespace "Foo" if filtering wasn't done. $this->checkLinkTable('redirect', 'rd', $ns, $name, $options, array('rd_interwiki' => null)); $this->checkLinkTable('redirect', 'rd', $ns, $name, $options, array('rd_interwiki' => '')); } } $this->output("{$this->totalLinks} links to fix, " . "{$this->resolvableLinks} were resolvable.\n"); return $ok; }
/** * Check all namespaces * * @param array $options Associative array of validated command-line options * * @return bool */ private function checkAll($options) { global $wgContLang, $wgNamespaceAliases, $wgCapitalLinks; $spaces = array(); // List interwikis first, so they'll be overridden // by any conflicting local namespaces. foreach ($this->getInterwikiList() as $prefix) { $name = $wgContLang->ucfirst($prefix); $spaces[$name] = 0; } // Now pull in all canonical and alias namespaces... foreach (MWNamespace::getCanonicalNamespaces() as $ns => $name) { // This includes $wgExtraNamespaces if ($name !== '') { $spaces[$name] = $ns; } } foreach ($wgContLang->getNamespaces() as $ns => $name) { if ($name !== '') { $spaces[$name] = $ns; } } foreach ($wgNamespaceAliases as $name => $ns) { $spaces[$name] = $ns; } foreach ($wgContLang->getNamespaceAliases() as $name => $ns) { $spaces[$name] = $ns; } // We'll need to check for lowercase keys as well, // since we're doing case-sensitive searches in the db. foreach ($spaces as $name => $ns) { $moreNames = array(); $moreNames[] = $wgContLang->uc($name); $moreNames[] = $wgContLang->ucfirst($wgContLang->lc($name)); $moreNames[] = $wgContLang->ucwords($name); $moreNames[] = $wgContLang->ucwords($wgContLang->lc($name)); $moreNames[] = $wgContLang->ucwordbreaks($name); $moreNames[] = $wgContLang->ucwordbreaks($wgContLang->lc($name)); if (!$wgCapitalLinks) { foreach ($moreNames as $altName) { $moreNames[] = $wgContLang->lcfirst($altName); } $moreNames[] = $wgContLang->lcfirst($name); } foreach (array_unique($moreNames) as $altName) { if ($altName !== $name) { $spaces[$altName] = $ns; } } } // Sort by namespace index, and if there are two with the same index, // break the tie by sorting by name $origSpaces = $spaces; uksort($spaces, function ($a, $b) use($origSpaces) { if ($origSpaces[$a] < $origSpaces[$b]) { return -1; } elseif ($origSpaces[$a] > $origSpaces[$b]) { return 1; } elseif ($a < $b) { return -1; } elseif ($a > $b) { return 1; } else { return 0; } }); $ok = true; foreach ($spaces as $name => $ns) { $ok = $this->checkNamespace($ns, $name, $options) && $ok; } $this->output("{$this->totalPages} pages to fix, " . "{$this->resolvableCount} were resolvable.\n"); return $ok; }
private function appendNamespaceSetup(&$setup, &$teardown) { // Add a namespace shadowing a interwiki link, to test // proper precedence when resolving links. (bug 51680) $setup['wgExtraNamespaces'] = [100 => 'MemoryAlpha', 101 => 'MemoryAlpha_talk']; // Changing wgExtraNamespaces invalidates caches in MWNamespace and // any live Language object, both on setup and teardown $reset = function () { MWNamespace::getCanonicalNamespaces(true); $GLOBALS['wgContLang']->resetNamespaces(); }; $setup[] = $reset; $teardown[] = $reset; }