From: Ævar Arnfjörð Bjarmason Date: Sat, 18 Jun 2005 04:06:54 +0000 (+0000) Subject: * (bug 2287) Added input checking to getNsText() X-Git-Tag: 1.5.0beta1~169 X-Git-Url: http://git.cyclocoop.org/data/%24self?a=commitdiff_plain;h=efe4524e50e7d902142a7f7615397c6a0012d609;p=lhc%2Fweb%2Fwiklou.git * (bug 2287) Added input checking to getNsText() * Rewrote getNsText() and getNsIndex() so that they don't need to be redeclared by child classes * Documented getNsText() and getNsIndex() --- diff --git a/languages/Language.php b/languages/Language.php index 0a5b6a3e39..9bc502715f 100644 --- a/languages/Language.php +++ b/languages/Language.php @@ -2231,12 +2231,13 @@ class Language { * * * @param int $index the array key of the namespace to return - * @return string + * @return mixed, string if the namespace value exists, otherwise false */ function getNsText( $index ) { - global $wgNamespaceNamesEn; - return $wgNamespaceNamesEn[$index]; + $ns = $this->getNamespaces(); + return isset( $ns[$index] ) ? $ns[$index] : false; } + /** * A convenience function that returns the same thing as * getNsText() except with '_' changed to ' ', useful for @@ -2250,16 +2251,17 @@ class Language { } /** - * Get a namespace key by value + * Get a namespace key by value, case insensetive. * * @param string $text * @return mixed An integer if $text is a valid value otherwise false */ function getNsIndex( $text ) { - global $wgNamespaceNamesEn; - - foreach ( $wgNamespaceNamesEn as $i => $n ) { - if ( 0 == strcasecmp( $n, $text ) ) { return $i; } + $ns = $this->getNamespaces(); + + foreach ( $ns as $i => $n ) { + if ( strcasecmp( $n, $text ) == 0) + return $i; } return false; }