Add RELEASE-NOTES for 33269, fix another one.
[mediawiki.git] / includes / Namespace.php
blobaf1641aaa24e97416021d8e13ee19a5c47f3b1fc
1 <?php
2 /**
3 * Provide things related to namespaces
4 */
6 /**
7 * Definitions of the NS_ constants are in Defines.php
8 * @private
9 */
10 $wgCanonicalNamespaceNames = array(
11 NS_MEDIA => 'Media',
12 NS_SPECIAL => 'Special',
13 NS_TALK => 'Talk',
14 NS_USER => 'User',
15 NS_USER_TALK => 'User_talk',
16 NS_PROJECT => 'Project',
17 NS_PROJECT_TALK => 'Project_talk',
18 NS_IMAGE => 'Image',
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',
24 NS_HELP => 'Help',
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;
34 /**
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
45 class MWNamespace {
47 /**
48 * Can pages in the given namespace be moved?
50 * @param int $index Namespace index
51 * @return bool
53 public static function isMovable( $index ) {
54 return !( $index < NS_MAIN || $index == NS_IMAGE || $index == NS_CATEGORY );
57 /**
58 * Is the given namespace is a subject (non-talk) namespace?
60 * @param int $index Namespace index
61 * @return bool
63 public static function isMain( $index ) {
64 return !self::isTalk( $index );
67 /**
68 * Is the given namespace a talk namespace?
70 * @param int $index Namespace index
71 * @return bool
73 public static function isTalk( $index ) {
74 return $index > NS_MAIN
75 && $index % 2;
78 /**
79 * Get the talk namespace index for a given namespace
81 * @param int $index Namespace index
82 * @return int
84 public static function getTalk( $index ) {
85 return self::isTalk( $index )
86 ? $index
87 : $index + 1;
90 /**
91 * Get the subject namespace index for a given namespace
93 * @param int $index Namespace index
94 * @return int
96 public static function getSubject( $index ) {
97 return self::isTalk( $index )
98 ? $index - 1
99 : $index;
103 * Returns the canonical (English Wikipedia) name for a given index
105 * @param int $index Namespace index
106 * @return string
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
118 * @return int
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];
131 } else {
132 return NULL;
137 * Can this namespace ever have a talk namespace?
139 * @param $index Namespace index
140 * @return bool
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
151 * @return bool
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?
161 * @param int $index
162 * @return bool
164 public static function isWatchable( $index ) {
165 return $index >= NS_MAIN;