From efe4524e50e7d902142a7f7615397c6a0012d609 Mon Sep 17 00:00:00 2001 From: =?utf8?q?=C3=86var=20Arnfj=C3=B6r=C3=B0=20Bjarmason?= Date: Sat, 18 Jun 2005 04:06:54 +0000 Subject: [PATCH] * (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() --- languages/Language.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) 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; } -- 2.20.1