00001 <?php
00011 $wgCanonicalNamespaceNames = array(
00012 NS_MEDIA => 'Media',
00013 NS_SPECIAL => 'Special',
00014 NS_TALK => 'Talk',
00015 NS_USER => 'User',
00016 NS_USER_TALK => 'User_talk',
00017 NS_PROJECT => 'Project',
00018 NS_PROJECT_TALK => 'Project_talk',
00019 NS_FILE => 'File',
00020 NS_FILE_TALK => 'File_talk',
00021 NS_MEDIAWIKI => 'MediaWiki',
00022 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
00023 NS_TEMPLATE => 'Template',
00024 NS_TEMPLATE_TALK => 'Template_talk',
00025 NS_HELP => 'Help',
00026 NS_HELP_TALK => 'Help_talk',
00027 NS_CATEGORY => 'Category',
00028 NS_CATEGORY_TALK => 'Category_talk',
00029 );
00030
00031 if( isset( $wgExtraNamespaces ) && is_array( $wgExtraNamespaces ) ) {
00032 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
00033 }
00034
00046 class MWNamespace {
00047
00053 private static $alwaysCapitalizedNamespaces = array( NS_SPECIAL, NS_USER, NS_MEDIAWIKI );
00054
00061 public static function isMovable( $index ) {
00062 global $wgAllowImageMoving;
00063 return !( $index < NS_MAIN || ($index == NS_FILE && !$wgAllowImageMoving) || $index == NS_CATEGORY );
00064 }
00065
00072 public static function isMain( $index ) {
00073 return !self::isTalk( $index );
00074 }
00075
00082 public static function isTalk( $index ) {
00083 return $index > NS_MAIN
00084 && $index % 2;
00085 }
00086
00093 public static function getTalk( $index ) {
00094 return self::isTalk( $index )
00095 ? $index
00096 : $index + 1;
00097 }
00098
00105 public static function getSubject( $index ) {
00106 return self::isTalk( $index )
00107 ? $index - 1
00108 : $index;
00109 }
00110
00114 public static function exists( $index ) {
00115 global $wgCanonicalNamespaceNames;
00116 return isset( $wgCanonicalNamespaceNames[$index] );
00117 }
00118
00119
00126 public static function getCanonicalName( $index ) {
00127 global $wgCanonicalNamespaceNames;
00128 if( isset( $wgCanonicalNamespaceNames[$index] ) ) {
00129 return $wgCanonicalNamespaceNames[$index];
00130 } else {
00131 return false;
00132 }
00133 }
00134
00142 public static function getCanonicalIndex( $name ) {
00143 global $wgCanonicalNamespaceNames;
00144 static $xNamespaces = false;
00145 if ( $xNamespaces === false ) {
00146 $xNamespaces = array();
00147 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
00148 $xNamespaces[strtolower($text)] = $i;
00149 }
00150 }
00151 if ( array_key_exists( $name, $xNamespaces ) ) {
00152 return $xNamespaces[$name];
00153 } else {
00154 return null;
00155 }
00156 }
00157
00164 public static function canTalk( $index ) {
00165 return $index >= NS_MAIN;
00166 }
00167
00175 public static function isContent( $index ) {
00176 global $wgContentNamespaces;
00177 return $index == NS_MAIN || in_array( $index, $wgContentNamespaces );
00178 }
00179
00186 public static function isWatchable( $index ) {
00187 return $index >= NS_MAIN;
00188 }
00189
00196 public static function hasSubpages( $index ) {
00197 global $wgNamespacesWithSubpages;
00198 return !empty( $wgNamespacesWithSubpages[$index] );
00199 }
00200
00207 public static function isCapitalized( $index ) {
00208 global $wgCapitalLinks, $wgCapitalLinkOverrides;
00209
00210 $index = $index === NS_MEDIA ? NS_FILE : $index;
00211
00212
00213 $index = self::getSubject( $index );
00214
00215
00216 if ( in_array( $index, self::$alwaysCapitalizedNamespaces ) ) {
00217 return true;
00218 }
00219 if ( isset( $wgCapitalLinkOverrides[ $index ] ) ) {
00220
00221 return $wgCapitalLinkOverrides[ $index ];
00222 }
00223
00224 return $wgCapitalLinks;
00225 }
00226 }