3 * Provide things related to namespaces
7 * Definitions of the NS_ constants are in Defines.php
10 $wgCanonicalNamespaceNames = array(
12 NS_SPECIAL
=> 'Special',
15 NS_USER_TALK
=> 'User_talk',
16 NS_PROJECT
=> 'Project',
17 NS_PROJECT_TALK
=> 'Project_talk',
19 NS_IMAGE_TALK
=> 'Image_talk',
20 NS_MEDIAWIKI
=> 'MediaWiki',
21 NS_MEDIAWIKI_TALK
=> 'MediaWiki_talk',
22 NS_TEMPLATE
=> 'Template',
23 NS_TEMPLATE_TALK
=> 'Template_talk',
25 NS_HELP_TALK
=> 'Help_talk',
26 NS_CATEGORY
=> 'Category',
27 NS_CATEGORY_TALK
=> 'Category_talk',
30 if( is_array( $wgExtraNamespaces ) ) {
31 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames +
$wgExtraNamespaces;
35 * This is a utility class with only static functions
36 * for dealing with namespaces that encodes all the
37 * "magic" behaviors of them based on index. The textual
38 * names of the namespaces are handled by Language.php.
40 * These are synonyms for the names given in the language file
41 * Users and translators should not change them
48 * Can pages in the given namespace be moved?
50 * @param int $index Namespace index
53 public static function isMovable( $index ) {
54 return !( $index < NS_MAIN ||
$index == NS_IMAGE ||
$index == NS_CATEGORY
);
58 * Is the given namespace is a subject (non-talk) namespace?
60 * @param int $index Namespace index
63 public static function isMain( $index ) {
64 return !self
::isTalk( $index );
68 * Is the given namespace a talk namespace?
70 * @param int $index Namespace index
73 public static function isTalk( $index ) {
74 return $index > NS_MAIN
79 * Get the talk namespace index for a given namespace
81 * @param int $index Namespace index
84 public static function getTalk( $index ) {
85 return self
::isTalk( $index )
91 * Get the subject namespace index for a given namespace
93 * @param int $index Namespace index
96 public static function getSubject( $index ) {
97 return self
::isTalk( $index )
103 * Returns the canonical (English Wikipedia) name for a given index
105 * @param int $index Namespace index
108 public static function getCanonicalName( $index ) {
109 global $wgCanonicalNamespaceNames;
110 return $wgCanonicalNamespaceNames[$index];
114 * Returns the index for a given canonical name, or NULL
115 * The input *must* be converted to lower case first
117 * @param string $name Namespace name
120 public static function getCanonicalIndex( $name ) {
121 global $wgCanonicalNamespaceNames;
122 static $xNamespaces = false;
123 if ( $xNamespaces === false ) {
124 $xNamespaces = array();
125 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
126 $xNamespaces[strtolower($text)] = $i;
129 if ( array_key_exists( $name, $xNamespaces ) ) {
130 return $xNamespaces[$name];
137 * Can this namespace ever have a talk namespace?
139 * @param $index Namespace index
142 public static function canTalk( $index ) {
143 return $index >= NS_MAIN
;
147 * Does this namespace contain content, for the purposes
148 * of calculating statistics, etc?
150 * @param $index Index to check
153 public static function isContent( $index ) {
154 global $wgContentNamespaces;
155 return $index == NS_MAIN ||
in_array( $index, $wgContentNamespaces );
159 * Can pages in a namespace be watched?
164 public static function isWatchable( $index ) {
165 return $index >= NS_MAIN
;