From 5833c105d0801c60ef6124abef032139dfd38a5a Mon Sep 17 00:00:00 2001 From: Platonides Date: Sun, 25 Jul 2010 22:29:05 +0000 Subject: [PATCH] Move getValidNamespaces() to Namespace.php --- includes/Namespace.php | 21 +++++++++++++++++++++ includes/api/ApiBase.php | 22 ++++------------------ 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/includes/Namespace.php b/includes/Namespace.php index e8e7523fc2..a6e599d3c0 100644 --- a/includes/Namespace.php +++ b/includes/Namespace.php @@ -155,6 +155,27 @@ class MWNamespace { } } + /** + * Returns an array of the namespaces (by integer id) that exist on the + * wiki. Used primarily by the api in help documentation. + * @return array + */ + public static function getValidNamespaces() { + static $mValidNamespaces = null; + + if ( is_null( $mValidNamespaces ) ) { + global $wgCanonicalNamespaceNames; + $mValidNamespaces = array( NS_MAIN ); // Doesn't appear in $wgCanonicalNamespaceNames for some reason + foreach ( array_keys( $wgCanonicalNamespaceNames ) as $ns ) { + if ( $ns > 0 ) { + $mValidNamespaces[] = $ns; + } + } + } + + return $mValidNamespaces; + } + /** * Can this namespace ever have a talk namespace? * diff --git a/includes/api/ApiBase.php b/includes/api/ApiBase.php index 09c9f45bf4..397f9e4718 100644 --- a/includes/api/ApiBase.php +++ b/includes/api/ApiBase.php @@ -329,7 +329,7 @@ abstract class ApiBase { switch ( $type ) { case 'namespace': // Special handling because namespaces are type-limited, yet they are not given - $desc .= $paramPrefix . $prompt . implode( ', ', ApiBase::getValidNamespaces() ); + $desc .= $paramPrefix . $prompt . implode( ', ', MWNamespace::getValidNamespaces() ); break; case 'limit': $desc .= $paramPrefix . "No more than {$paramSettings[self :: PARAM_MAX]} ({$paramSettings[self::PARAM_MAX2]} for bots) allowed"; @@ -524,24 +524,10 @@ abstract class ApiBase { } /** - * Returns an array of the namespaces (by integer id) that exist on the - * wiki. Used primarily in help documentation. - * @return array + * @deprecated use MWNamespace::getValidNamespaces() */ public static function getValidNamespaces() { - static $mValidNamespaces = null; - - if ( is_null( $mValidNamespaces ) ) { - global $wgCanonicalNamespaceNames; - $mValidNamespaces = array( NS_MAIN ); // Doesn't appear in $wgCanonicalNamespaceNames for some reason - foreach ( array_keys( $wgCanonicalNamespaceNames ) as $ns ) { - if ( $ns > 0 ) { - $mValidNamespaces[] = $ns; - } - } - } - - return $mValidNamespaces; + return MWNamespace::getValidNamespaces(); } /** @@ -649,7 +635,7 @@ abstract class ApiBase { $value = $this->getMain()->getRequest()->getVal( $encParamName, $default ); if ( isset( $value ) && $type == 'namespace' ) { - $type = ApiBase::getValidNamespaces(); + $type = MWNamespace::getValidNamespaces(); } } -- 2.20.1