r21363 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r21362‎ | r21363 | r21364 >
Date:10:03, 19 April 2007
Author:vyznev
Status:old
Tags:
Comment:
make ->getNsIndex() check canonical namespace names too, remove now redundant explicit check from Title.php; as far as I can tell this shouldn't break anything, and arguably it'll fix some currently broken code. introduce new function getLocalNsIndex() to provide the old functionality, should anyone actually need it.
Modified paths:
  • /trunk/phase3/includes/Title.php (modified) (history)
  • /trunk/phase3/languages/Language.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/Title.php
@@ -1645,12 +1645,7 @@
16461646 $m = array();
16471647 if ( preg_match( "/^(.+?)_*:_*(.*)$/S", $dbkey, $m ) ) {
16481648 $p = $m[1];
1649 - $lowerNs = $wgContLang->lc( $p );
1650 - if ( $ns = Namespace::getCanonicalIndex( $lowerNs ) ) {
1651 - # Canonical namespace
1652 - $dbkey = $m[2];
1653 - $this->mNamespace = $ns;
1654 - } elseif ( $ns = $wgContLang->getNsIndex( $lowerNs )) {
 1649+ if ( $ns = $wgContLang->getNsIndex( $p )) {
16551650 # Ordinary namespace
16561651 $dbkey = $m[2];
16571652 $this->mNamespace = $ns;
Index: trunk/phase3/languages/Language.php
@@ -228,15 +228,33 @@
229229 }
230230
231231 /**
232 - * Get a namespace key by value, case insensetive.
 232+ * Get a namespace key by value, case insensitive.
 233+ * Only matches namespace names for the current language, not the
 234+ * canonical ones defined in Namespace.php.
233235 *
234236 * @param string $text
235237 * @return mixed An integer if $text is a valid value otherwise false
236238 */
 239+ function getLocalNsIndex( $text ) {
 240+ $this->load();
 241+ $lctext = $this->lc($text);
 242+ if( ( $ns = $this->mNamespaceIds[$lctext] ) !== null ) return $ns;
 243+ return false;
 244+ }
 245+
 246+ /**
 247+ * Get a namespace key by value, case insensitive. Canonical namespace
 248+ * names override custom ones defined for the current language.
 249+ *
 250+ * @param string $text
 251+ * @return mixed An integer if $text is a valid value otherwise false
 252+ */
237253 function getNsIndex( $text ) {
238254 $this->load();
239255 $lctext = $this->lc($text);
240 - return isset( $this->mNamespaceIds[$lctext] ) ? $this->mNamespaceIds[$lctext] : false;
 256+ if( ( $ns = Namespace::getCanonicalIndex( $lctext ) ) !== null ) return $ns;
 257+ if( ( $ns = $this->mNamespaceIds[$lctext] ) !== null ) return $ns;
 258+ return false;
241259 }
242260
243261 /**

Follow-up revisions

RevisionCommit summaryAuthorDate
r21376Revert r21363; triggers PHP notices due to failed lookups for interwiki prefixesbrion13:40, 19 April 2007
r21387reapply r21363, hopefully without stupid notices this timevyznev18:47, 19 April 2007