bug 9982. Encapsulate wgCanonicalNamespaceNames. Patch by Scott Colcord, with updates
authorChad Horohoe <demon@users.mediawiki.org>
Fri, 16 Oct 2009 04:06:30 +0000 (04:06 +0000)
committerChad Horohoe <demon@users.mediawiki.org>
Fri, 16 Oct 2009 04:06:30 +0000 (04:06 +0000)
CREDITS
includes/Namespace.php
includes/Skin.php
includes/SkinTemplate.php
includes/Title.php

diff --git a/CREDITS b/CREDITS
index c859870..f242963 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -104,6 +104,7 @@ following names for their contribution to the product.
 * Robert Treat
 * RockMFR
 * ST47
+* Scott Colcord
 * Simon Walker
 * Stefano Codari
 * Str4nd
index f9c2311..a9601b4 100644 (file)
@@ -107,6 +107,15 @@ class MWNamespace {
                        ? $index - 1
                        : $index;
        }
+       
+       /**
+        * Returns whether the specified namespace exists
+        */
+       public static function exists( $index ) {
+               global $wgCanonicalNamespaceNames;
+               return isset( $wgCanonicalNamespaceNames[$index] );
+       }
+
 
        /**
         * Returns the canonical (English Wikipedia) name for a given index
index 4a92159..a0c3311 100644 (file)
@@ -357,7 +357,7 @@ class Skin extends Linker {
                }
                global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension;
                global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
-               global $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
+               global $wgOut, $wgArticle;
                global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
                global $wgUseAjax, $wgAjaxWatch;
                global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
@@ -365,7 +365,7 @@ class Skin extends Linker {
                global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
 
                $ns = $wgTitle->getNamespace();
-               $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
+               $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
                $separatorTransTable = $wgContLang->separatorTransformTable();
                $separatorTransTable = $separatorTransTable ? $separatorTransTable : array();
                $compactSeparatorTransTable = array(
index 90cf2ba..50024c2 100644 (file)
@@ -134,7 +134,7 @@ class SkinTemplate extends Skin {
                global $wgMaxCredits, $wgShowCreditsIfMax;
                global $wgPageShowWatchingUsers;
                global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
-               global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames;
+               global $wgArticlePath, $wgScriptPath, $wgServer;
 
                wfProfileIn( __METHOD__ );
 
@@ -226,8 +226,8 @@ class SkinTemplate extends Skin {
                $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
                $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
 
-               $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
-                                       $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
+               $nsname = MWNamespace::exists( $this->mTitle->getNamespace() ) ?
+                                       MWNamespace::getCanonicalName( $this->mTitle->getNamespace() ) :
                                        $this->mTitle->getNsText();
 
                $tpl->set( 'nscanonical', $nsname );
index 134ad28..422a50b 100644 (file)
@@ -546,7 +546,7 @@ class Title {
         * @return \type{\string} Namespace text
         */
        public function getNsText() {
-               global $wgContLang, $wgCanonicalNamespaceNames;
+               global $wgContLang;
 
                if ( '' != $this->mInterwiki ) {
                        // This probably shouldn't even happen. ohh man, oh yuck.
@@ -555,8 +555,8 @@ class Title {
                        //
                        // Use the canonical namespaces if possible to try to
                        // resolve a foreign namespace.
-                       if( isset( $wgCanonicalNamespaceNames[$this->mNamespace] ) ) {
-                               return $wgCanonicalNamespaceNames[$this->mNamespace];
+                       if( MWNamespace::exists( $this->mNamespace ) ) {
+                               return MWNamespace::getCanonicalName( $this->mNamespace );
                        }
                }
                return $wgContLang->getNsText( $this->mNamespace );
@@ -3616,13 +3616,13 @@ class Title {
         * @return \type{\string} XML 'id' name
         */
        public function getNamespaceKey( $prepend = 'nstab-' ) {
-               global $wgContLang, $wgCanonicalNamespaceNames;
+               global $wgContLang;
                // Gets the subject namespace if this title
                $namespace = MWNamespace::getSubject( $this->getNamespace() );
                // Checks if cononical namespace name exists for namespace
-               if ( isset( $wgCanonicalNamespaceNames[$namespace] ) ) {
+               if ( MWNamespace::exists( $this->getNamespace() ) ) {
                        // Uses canonical namespace name
-                       $namespaceKey = $wgCanonicalNamespaceNames[$namespace];
+                       $namespaceKey = MWNamespace::getCanonicalName( $namespace );
                } else {
                        // Uses text of namespace
                        $namespaceKey = $this->getSubjectNsText();