wgNamespaceIds in JavaScript didn't include canonical namespaces. Adding them to...
authorKrinkle <krinkle@users.mediawiki.org>
Tue, 14 Jun 2011 22:49:38 +0000 (22:49 +0000)
committerKrinkle <krinkle@users.mediawiki.org>
Tue, 14 Jun 2011 22:49:38 +0000 (22:49 +0000)
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
includes/resourceloader/ResourceLoaderStartUpModule.php

index 6dfd970..82b59a2 100644 (file)
@@ -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.
index dc3dbdf..83c57f9 100644 (file)
@@ -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,