/**
* Additional namespaces. If the namespaces defined in Language.php and
* Namespace.php are insufficient, you can create new ones here, for example,
- * to import Help files in other languages.
+ * to import Help files in other languages. You can also override the namespace
+ * names of existing namespaces. Extensions developers should use
+ * $wgCanonicalNamespaceNames.
+ *
* PLEASE NOTE: Once you delete a namespace, the pages in that namespace will
* no longer be accessible. If you rename it, then you can access them through
* the new namespace name.
NS_CATEGORY_TALK => 'Category_talk',
);
-if( isset( $wgExtraNamespaces ) && is_array( $wgExtraNamespaces ) ) {
+/// @todo UGLY UGLY
+if( is_array( $wgExtraNamespaces ) ) {
$wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
}
* Returns whether the specified namespace exists
*/
public static function exists( $index ) {
- global $wgCanonicalNamespaceNames;
- return isset( $wgCanonicalNamespaceNames[$index] );
+ $nslist = self::getCanonicalNamespaces();
+ return isset( $nslist[$index] );
}
/**
- * Returns the canonical (English Wikipedia) name for a given index
+ * Returns array of all defined namespaces with their canonical
+ * (English) names.
+ *
+ * @return \array
+ * @since 1.17
+ */
+ public static function getCanonicalNamespaces() {
+ static $namespaces = null;
+ if ( $namespaces === null ) {
+ global $wgExtraNamespaces, $wgCanonicalNamespaceNames;
+ if ( is_array( $wgExtraNamespaces ) ) {
+ $namespaces = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
+ }
+ $namespaces[NS_MAIN] = '';
+ var_dump( $namespaces );
+ }
+ return $namespaces;
+ }
+
+ /**
+ * Returns the canonical (English) name for a given index
*
* @param $index Int: namespace index
* @return string or false if no canonical definition.
*/
public static function getCanonicalName( $index ) {
- global $wgCanonicalNamespaceNames;
- if( isset( $wgCanonicalNamespaceNames[$index] ) ) {
- return $wgCanonicalNamespaceNames[$index];
+ $nslist = self::getCanonicalNamespaces();
+ if( isset( $nslist[$index] ) ) {
+ return $nslist[$index];
} else {
return false;
}
* @return int
*/
public static function getCanonicalIndex( $name ) {
- global $wgCanonicalNamespaceNames;
static $xNamespaces = false;
if ( $xNamespaces === false ) {
$xNamespaces = array();
- foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
+ foreach ( self::getCanonicalNamespaces() as $i => $text ) {
$xNamespaces[strtolower($text)] = $i;
}
}
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 ) {
+ foreach ( array_keys( self::getCanonicalNamespaces() ) as $ns ) {
if ( $ns > 0 ) {
$mValidNamespaces[] = $ns;
}
*/
function getNamespaces() {
if ( is_null( $this->namespaceNames ) ) {
- global $wgExtraNamespaces, $wgMetaNamespace, $wgMetaNamespaceTalk;
+ global $wgMetaNamespace, $wgMetaNamespaceTalk;
$this->namespaceNames = self::$dataCache->getItem( $this->mCode, 'namespaceNames' );
- if ( $wgExtraNamespaces ) {
- $this->namespaceNames = $wgExtraNamespaces + $this->namespaceNames;
- }
+ $validNamespaces = MWNamespace::getCanonicalNamespaces();
+
+ $this->namespaceNames = $validNamespaces + $this->namespaceNames;
$this->namespaceNames[NS_PROJECT] = $wgMetaNamespace;
if ( $wgMetaNamespaceTalk ) {
}
# Sometimes a language will be localised but not actually exist on this wiki.
- global $wgCanonicalNamespaceNames;
- $validNamespaces = array_keys($wgCanonicalNamespaceNames);
- $validNamespaces[] = NS_MAIN;
foreach( $this->namespaceNames as $key => $text ) {
- if ( ! in_array( $key, $validNamespaces ) ) {
- unset( $this->namespaceNames[$key] );
- }
+ if ( !isset( $validNamespaces[$key] ) ) {
+ unset( $this->namespaceNames[$key] );
+ }
}
# The above mixing may leave namespaces out of canonical order.