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( is_array( $wgExtraNamespaces ) ) { 00032 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces; 00033 } 00034 00046 class MWNamespace { 00047 00054 public static function isMovable( $index ) { 00055 global $wgAllowImageMoving; 00056 return !( $index < NS_MAIN || ($index == NS_FILE && !$wgAllowImageMoving) || $index == NS_CATEGORY ); 00057 } 00058 00065 public static function isMain( $index ) { 00066 return !self::isTalk( $index ); 00067 } 00068 00075 public static function isTalk( $index ) { 00076 return $index > NS_MAIN 00077 && $index % 2; 00078 } 00079 00086 public static function getTalk( $index ) { 00087 return self::isTalk( $index ) 00088 ? $index 00089 : $index + 1; 00090 } 00091 00098 public static function getSubject( $index ) { 00099 return self::isTalk( $index ) 00100 ? $index - 1 00101 : $index; 00102 } 00103 00110 public static function getCanonicalName( $index ) { 00111 global $wgCanonicalNamespaceNames; 00112 if( isset( $wgCanonicalNamespaceNames[$index] ) ) { 00113 return $wgCanonicalNamespaceNames[$index]; 00114 } else { 00115 return false; 00116 } 00117 } 00118 00126 public static function getCanonicalIndex( $name ) { 00127 global $wgCanonicalNamespaceNames; 00128 static $xNamespaces = false; 00129 if ( $xNamespaces === false ) { 00130 $xNamespaces = array(); 00131 foreach ( $wgCanonicalNamespaceNames as $i => $text ) { 00132 $xNamespaces[strtolower($text)] = $i; 00133 } 00134 } 00135 if ( array_key_exists( $name, $xNamespaces ) ) { 00136 return $xNamespaces[$name]; 00137 } else { 00138 return NULL; 00139 } 00140 } 00141 00148 public static function canTalk( $index ) { 00149 return $index >= NS_MAIN; 00150 } 00151 00159 public static function isContent( $index ) { 00160 global $wgContentNamespaces; 00161 return $index == NS_MAIN || in_array( $index, $wgContentNamespaces ); 00162 } 00163 00170 public static function isWatchable( $index ) { 00171 return $index >= NS_MAIN; 00172 } 00173 00180 public static function hasSubpages( $index ) { 00181 global $wgNamespacesWithSubpages; 00182 return !empty( $wgNamespacesWithSubpages[$index] ); 00183 } 00184 00185 }