Index: trunk/phase3/includes/Namespace.php |
— | — | @@ -28,7 +28,8 @@ |
29 | 29 | NS_CATEGORY_TALK => 'Category_talk', |
30 | 30 | ); |
31 | 31 | |
32 | | -if( isset( $wgExtraNamespaces ) && is_array( $wgExtraNamespaces ) ) { |
| 32 | +/// @todo UGLY UGLY |
| 33 | +if( is_array( $wgExtraNamespaces ) ) { |
33 | 34 | $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces; |
34 | 35 | } |
35 | 36 | |
— | — | @@ -112,21 +113,41 @@ |
113 | 114 | * Returns whether the specified namespace exists |
114 | 115 | */ |
115 | 116 | public static function exists( $index ) { |
116 | | - global $wgCanonicalNamespaceNames; |
117 | | - return isset( $wgCanonicalNamespaceNames[$index] ); |
| 117 | + $nslist = self::getCanonicalNamespaces(); |
| 118 | + return isset( $nslist[$index] ); |
118 | 119 | } |
119 | 120 | |
120 | 121 | |
121 | 122 | /** |
122 | | - * Returns the canonical (English Wikipedia) name for a given index |
| 123 | + * Returns array of all defined namespaces with their canonical |
| 124 | + * (English) names. |
123 | 125 | * |
| 126 | + * @return \array |
| 127 | + * @since 1.17 |
| 128 | + */ |
| 129 | + public static function getCanonicalNamespaces() { |
| 130 | + static $namespaces = null; |
| 131 | + if ( $namespaces === null ) { |
| 132 | + global $wgExtraNamespaces, $wgCanonicalNamespaceNames; |
| 133 | + if ( is_array( $wgExtraNamespaces ) ) { |
| 134 | + $namespaces = $wgCanonicalNamespaceNames + $wgExtraNamespaces; |
| 135 | + } |
| 136 | + $namespaces[NS_MAIN] = ''; |
| 137 | + var_dump( $namespaces ); |
| 138 | + } |
| 139 | + return $namespaces; |
| 140 | + } |
| 141 | + |
| 142 | + /** |
| 143 | + * Returns the canonical (English) name for a given index |
| 144 | + * |
124 | 145 | * @param $index Int: namespace index |
125 | 146 | * @return string or false if no canonical definition. |
126 | 147 | */ |
127 | 148 | public static function getCanonicalName( $index ) { |
128 | | - global $wgCanonicalNamespaceNames; |
129 | | - if( isset( $wgCanonicalNamespaceNames[$index] ) ) { |
130 | | - return $wgCanonicalNamespaceNames[$index]; |
| 149 | + $nslist = self::getCanonicalNamespaces(); |
| 150 | + if( isset( $nslist[$index] ) ) { |
| 151 | + return $nslist[$index]; |
131 | 152 | } else { |
132 | 153 | return false; |
133 | 154 | } |
— | — | @@ -140,11 +161,10 @@ |
141 | 162 | * @return int |
142 | 163 | */ |
143 | 164 | public static function getCanonicalIndex( $name ) { |
144 | | - global $wgCanonicalNamespaceNames; |
145 | 165 | static $xNamespaces = false; |
146 | 166 | if ( $xNamespaces === false ) { |
147 | 167 | $xNamespaces = array(); |
148 | | - foreach ( $wgCanonicalNamespaceNames as $i => $text ) { |
| 168 | + foreach ( self::getCanonicalNamespaces() as $i => $text ) { |
149 | 169 | $xNamespaces[strtolower($text)] = $i; |
150 | 170 | } |
151 | 171 | } |
— | — | @@ -164,9 +184,7 @@ |
165 | 185 | static $mValidNamespaces = null; |
166 | 186 | |
167 | 187 | if ( is_null( $mValidNamespaces ) ) { |
168 | | - global $wgCanonicalNamespaceNames; |
169 | | - $mValidNamespaces = array( NS_MAIN ); // Doesn't appear in $wgCanonicalNamespaceNames for some reason |
170 | | - foreach ( array_keys( $wgCanonicalNamespaceNames ) as $ns ) { |
| 188 | + foreach ( array_keys( self::getCanonicalNamespaces() ) as $ns ) { |
171 | 189 | if ( $ns > 0 ) { |
172 | 190 | $mValidNamespaces[] = $ns; |
173 | 191 | } |
Index: trunk/phase3/includes/DefaultSettings.php |
— | — | @@ -2295,7 +2295,10 @@ |
2296 | 2296 | /** |
2297 | 2297 | * Additional namespaces. If the namespaces defined in Language.php and |
2298 | 2298 | * Namespace.php are insufficient, you can create new ones here, for example, |
2299 | | - * to import Help files in other languages. |
| 2299 | + * to import Help files in other languages. You can also override the namespace |
| 2300 | + * names of existing namespaces. Extensions developers should use |
| 2301 | + * $wgCanonicalNamespaceNames. |
| 2302 | + * |
2300 | 2303 | * PLEASE NOTE: Once you delete a namespace, the pages in that namespace will |
2301 | 2304 | * no longer be accessible. If you rename it, then you can access them through |
2302 | 2305 | * the new namespace name. |
Index: trunk/phase3/languages/Language.php |
— | — | @@ -241,13 +241,13 @@ |
242 | 242 | */ |
243 | 243 | function getNamespaces() { |
244 | 244 | if ( is_null( $this->namespaceNames ) ) { |
245 | | - global $wgExtraNamespaces, $wgMetaNamespace, $wgMetaNamespaceTalk; |
| 245 | + global $wgMetaNamespace, $wgMetaNamespaceTalk; |
246 | 246 | |
247 | 247 | $this->namespaceNames = self::$dataCache->getItem( $this->mCode, 'namespaceNames' ); |
248 | | - if ( $wgExtraNamespaces ) { |
249 | | - $this->namespaceNames = $wgExtraNamespaces + $this->namespaceNames; |
250 | | - } |
| 248 | + $validNamespaces = MWNamespace::getCanonicalNamespaces(); |
251 | 249 | |
| 250 | + $this->namespaceNames = $validNamespaces + $this->namespaceNames; |
| 251 | + |
252 | 252 | $this->namespaceNames[NS_PROJECT] = $wgMetaNamespace; |
253 | 253 | if ( $wgMetaNamespaceTalk ) { |
254 | 254 | $this->namespaceNames[NS_PROJECT_TALK] = $wgMetaNamespaceTalk; |
— | — | @@ -258,13 +258,10 @@ |
259 | 259 | } |
260 | 260 | |
261 | 261 | # Sometimes a language will be localised but not actually exist on this wiki. |
262 | | - global $wgCanonicalNamespaceNames; |
263 | | - $validNamespaces = array_keys($wgCanonicalNamespaceNames); |
264 | | - $validNamespaces[] = NS_MAIN; |
265 | 262 | foreach( $this->namespaceNames as $key => $text ) { |
266 | | - if ( ! in_array( $key, $validNamespaces ) ) { |
267 | | - unset( $this->namespaceNames[$key] ); |
268 | | - } |
| 263 | + if ( !isset( $validNamespaces[$key] ) ) { |
| 264 | + unset( $this->namespaceNames[$key] ); |
| 265 | + } |
269 | 266 | } |
270 | 267 | |
271 | 268 | # The above mixing may leave namespaces out of canonical order. |