r57800 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r57799‎ | r57800 | r57801 >
Date:04:06, 16 October 2009
Author:demon
Status:ok
Tags:
Comment:
bug 9982. Encapsulate wgCanonicalNamespaceNames. Patch by Scott Colcord, with updates
Modified paths:
  • /trunk/phase3/CREDITS (modified) (history)
  • /trunk/phase3/includes/Namespace.php (modified) (history)
  • /trunk/phase3/includes/Skin.php (modified) (history)
  • /trunk/phase3/includes/SkinTemplate.php (modified) (history)
  • /trunk/phase3/includes/Title.php (modified) (history)

Diff [purge]

Index: trunk/phase3/CREDITS
@@ -104,6 +104,7 @@
105105 * Robert Treat
106106 * RockMFR
107107 * ST47
 108+* Scott Colcord
108109 * Simon Walker
109110 * Stefano Codari
110111 * Str4nd
Index: trunk/phase3/includes/Title.php
@@ -546,7 +546,7 @@
547547 * @return \type{\string} Namespace text
548548 */
549549 public function getNsText() {
550 - global $wgContLang, $wgCanonicalNamespaceNames;
 550+ global $wgContLang;
551551
552552 if ( '' != $this->mInterwiki ) {
553553 // This probably shouldn't even happen. ohh man, oh yuck.
@@ -555,8 +555,8 @@
556556 //
557557 // Use the canonical namespaces if possible to try to
558558 // resolve a foreign namespace.
559 - if( isset( $wgCanonicalNamespaceNames[$this->mNamespace] ) ) {
560 - return $wgCanonicalNamespaceNames[$this->mNamespace];
 559+ if( MWNamespace::exists( $this->mNamespace ) ) {
 560+ return MWNamespace::getCanonicalName( $this->mNamespace );
561561 }
562562 }
563563 return $wgContLang->getNsText( $this->mNamespace );
@@ -3616,13 +3616,13 @@
36173617 * @return \type{\string} XML 'id' name
36183618 */
36193619 public function getNamespaceKey( $prepend = 'nstab-' ) {
3620 - global $wgContLang, $wgCanonicalNamespaceNames;
 3620+ global $wgContLang;
36213621 // Gets the subject namespace if this title
36223622 $namespace = MWNamespace::getSubject( $this->getNamespace() );
36233623 // Checks if cononical namespace name exists for namespace
3624 - if ( isset( $wgCanonicalNamespaceNames[$namespace] ) ) {
 3624+ if ( MWNamespace::exists( $this->getNamespace() ) ) {
36253625 // Uses canonical namespace name
3626 - $namespaceKey = $wgCanonicalNamespaceNames[$namespace];
 3626+ $namespaceKey = MWNamespace::getCanonicalName( $namespace );
36273627 } else {
36283628 // Uses text of namespace
36293629 $namespaceKey = $this->getSubjectNsText();
Index: trunk/phase3/includes/Namespace.php
@@ -107,7 +107,16 @@
108108 ? $index - 1
109109 : $index;
110110 }
 111+
 112+ /**
 113+ * Returns whether the specified namespace exists
 114+ */
 115+ public static function exists( $index ) {
 116+ global $wgCanonicalNamespaceNames;
 117+ return isset( $wgCanonicalNamespaceNames[$index] );
 118+ }
111119
 120+
112121 /**
113122 * Returns the canonical (English Wikipedia) name for a given index
114123 *
Index: trunk/phase3/includes/SkinTemplate.php
@@ -134,7 +134,7 @@
135135 global $wgMaxCredits, $wgShowCreditsIfMax;
136136 global $wgPageShowWatchingUsers;
137137 global $wgUseTrackbacks, $wgUseSiteJs, $wgDebugComments;
138 - global $wgArticlePath, $wgScriptPath, $wgServer, $wgCanonicalNamespaceNames;
 138+ global $wgArticlePath, $wgScriptPath, $wgServer;
139139
140140 wfProfileIn( __METHOD__ );
141141
@@ -226,8 +226,8 @@
227227 $tpl->set( 'pageclass', $this->getPageClasses( $this->mTitle ) );
228228 $tpl->set( 'skinnameclass', ( 'skin-' . Sanitizer::escapeClass( $this->getSkinName() ) ) );
229229
230 - $nsname = isset( $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] ) ?
231 - $wgCanonicalNamespaceNames[ $this->mTitle->getNamespace() ] :
 230+ $nsname = MWNamespace::exists( $this->mTitle->getNamespace() ) ?
 231+ MWNamespace::getCanonicalName( $this->mTitle->getNamespace() ) :
232232 $this->mTitle->getNsText();
233233
234234 $tpl->set( 'nscanonical', $nsname );
Index: trunk/phase3/includes/Skin.php
@@ -357,7 +357,7 @@
358358 }
359359 global $wgScript, $wgTitle, $wgStylePath, $wgUser, $wgScriptExtension;
360360 global $wgArticlePath, $wgScriptPath, $wgServer, $wgContLang, $wgLang;
361 - global $wgCanonicalNamespaceNames, $wgOut, $wgArticle;
 361+ global $wgOut, $wgArticle;
362362 global $wgBreakFrames, $wgRequest, $wgVariantArticlePath, $wgActionPaths;
363363 global $wgUseAjax, $wgAjaxWatch;
364364 global $wgVersion, $wgEnableAPI, $wgEnableWriteAPI;
@@ -365,7 +365,7 @@
366366 global $wgMWSuggestTemplate, $wgDBname, $wgEnableMWSuggest;
367367
368368 $ns = $wgTitle->getNamespace();
369 - $nsname = isset( $wgCanonicalNamespaceNames[ $ns ] ) ? $wgCanonicalNamespaceNames[ $ns ] : $wgTitle->getNsText();
 369+ $nsname = MWNamespace::exists( $ns ) ? MWNamespace::getCanonicalName( $ns ) : $wgTitle->getNsText();
370370 $separatorTransTable = $wgContLang->separatorTransformTable();
371371 $separatorTransTable = $separatorTransTable ? $separatorTransTable : array();
372372 $compactSeparatorTransTable = array(

Status & tagging log