From b3621a2826992c8df009b90dfbc1fb59ef4a55c2 Mon Sep 17 00:00:00 2001 From: Krinkle Date: Tue, 14 Jun 2011 22:49:38 +0000 Subject: [PATCH] wgNamespaceIds in JavaScript didn't include canonical namespaces. Adding them to it, in a similar way that Language->getNamespaceIds does it for the localized namespaces and the namespace aliases. Fixes bug in mw.Title constructor when .setNamespace() is used with a canonical namespace on a non-English content-language wiki. Example: On a German wiki "var foo = new mw.Title('bar').setNamespace('file')" will throw an Error, as wgNamespaceIds only contains localized namespaces + namespace aliases, not canonical ones (in contrary to the assumption that has been made in various places). (bug 25375) Add canonical namespaces to JavaScript "wgNamespaceIds" --- RELEASE-NOTES-1.19 | 1 + .../resourceloader/ResourceLoaderStartUpModule.php | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/RELEASE-NOTES-1.19 b/RELEASE-NOTES-1.19 index 6dfd970e2e..82b59a2280 100644 --- a/RELEASE-NOTES-1.19 +++ b/RELEASE-NOTES-1.19 @@ -91,6 +91,7 @@ production. as lastTabIndex(). * (bug 29332) Warn if user requests mediawiki-announce subscription but does not enter an e-mail address. +* (bug 25375) Add canonical namespaces to JavaScript "wgNamespaceIds" === API changes in 1.19 === * BREAKING CHANGE: action=watch now requires POST and token. diff --git a/includes/resourceloader/ResourceLoaderStartUpModule.php b/includes/resourceloader/ResourceLoaderStartUpModule.php index dc3dbdfda9..83c57f98b8 100644 --- a/includes/resourceloader/ResourceLoaderStartUpModule.php +++ b/includes/resourceloader/ResourceLoaderStartUpModule.php @@ -55,6 +55,14 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { ); $mainPage = Title::newMainPage(); + // Build wgNamespaceIds + // A complete key-value pair object mapping localized, canonical and aliases for namespaces + // to their numerical ids (case insensitive and with underscores) + $namespaceIds = $wgContLang->getNamespaceIds(); + foreach( MWNamespace::getCanonicalNamespaces() as $index => $name ) { + $nsIds[$wgContLang->lc( $name )] = $index; + } + // Build list of variables $vars = array( 'wgLoadScript' => $wgLoadScript, @@ -81,7 +89,7 @@ class ResourceLoaderStartUpModule extends ResourceLoaderModule { 'wgDigitTransformTable' => $compactDigitTransTable, 'wgMainPageTitle' => $mainPage ? $mainPage->getPrefixedText() : null, 'wgFormattedNamespaces' => $wgContLang->getFormattedNamespaces(), - 'wgNamespaceIds' => $wgContLang->getNamespaceIds(), + 'wgNamespaceIds' => $namespaceIds, 'wgSiteName' => $wgSitename, 'wgFileExtensions' => array_values( $wgFileExtensions ), 'wgDBname' => $wgDBname, -- 2.20.1