3 * Provide things related to namespaces
8 * Definitions of the NS_ constants are in Defines.php
11 $wgCanonicalNamespaceNames = array(
13 NS_SPECIAL
=> 'Special',
16 NS_USER_TALK
=> 'User_talk',
17 NS_PROJECT
=> 'Project',
18 NS_PROJECT_TALK
=> 'Project_talk',
20 NS_FILE_TALK
=> 'File_talk',
21 NS_MEDIAWIKI
=> 'MediaWiki',
22 NS_MEDIAWIKI_TALK
=> 'MediaWiki_talk',
23 NS_TEMPLATE
=> 'Template',
24 NS_TEMPLATE_TALK
=> 'Template_talk',
26 NS_HELP_TALK
=> 'Help_talk',
27 NS_CATEGORY
=> 'Category',
28 NS_CATEGORY_TALK
=> 'Category_talk',
31 if( is_array( $wgExtraNamespaces ) ) {
32 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames +
$wgExtraNamespaces;
36 * This is a utility class with only static functions
37 * for dealing with namespaces that encodes all the
38 * "magic" behaviors of them based on index. The textual
39 * names of the namespaces are handled by Language.php.
41 * These are synonyms for the names given in the language file
42 * Users and translators should not change them
49 * These namespaces should always be first-letter capitalized, now and
50 * forevermore. Historically, they could've probably been lowercased too,
51 * but some things are just too ingrained now. :)
53 private static $alwaysCapitalizedNamespaces = array( NS_SPECIAL
, NS_MEDIAWIKI
);
56 * Can pages in the given namespace be moved?
58 * @param $index Int: namespace index
61 public static function isMovable( $index ) {
62 global $wgAllowImageMoving;
63 return !( $index < NS_MAIN ||
($index == NS_FILE
&& !$wgAllowImageMoving) ||
$index == NS_CATEGORY
);
67 * Is the given namespace is a subject (non-talk) namespace?
69 * @param $index Int: namespace index
72 public static function isMain( $index ) {
73 return !self
::isTalk( $index );
77 * Is the given namespace a talk namespace?
79 * @param $index Int: namespace index
82 public static function isTalk( $index ) {
83 return $index > NS_MAIN
88 * Get the talk namespace index for a given namespace
90 * @param $index Int: namespace index
93 public static function getTalk( $index ) {
94 return self
::isTalk( $index )
100 * Get the subject namespace index for a given namespace
102 * @param $index Int: Namespace index
105 public static function getSubject( $index ) {
106 return self
::isTalk( $index )
112 * Returns the canonical (English Wikipedia) name for a given index
114 * @param $index Int: namespace index
115 * @return string or false if no canonical definition.
117 public static function getCanonicalName( $index ) {
118 global $wgCanonicalNamespaceNames;
119 if( isset( $wgCanonicalNamespaceNames[$index] ) ) {
120 return $wgCanonicalNamespaceNames[$index];
127 * Returns the index for a given canonical name, or NULL
128 * The input *must* be converted to lower case first
130 * @param $name String: namespace name
133 public static function getCanonicalIndex( $name ) {
134 global $wgCanonicalNamespaceNames;
135 static $xNamespaces = false;
136 if ( $xNamespaces === false ) {
137 $xNamespaces = array();
138 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
139 $xNamespaces[strtolower($text)] = $i;
142 if ( array_key_exists( $name, $xNamespaces ) ) {
143 return $xNamespaces[$name];
150 * Can this namespace ever have a talk namespace?
152 * @param $index Int: namespace index
155 public static function canTalk( $index ) {
156 return $index >= NS_MAIN
;
160 * Does this namespace contain content, for the purposes of calculating
163 * @param $index Int: index to check
166 public static function isContent( $index ) {
167 global $wgContentNamespaces;
168 return $index == NS_MAIN ||
in_array( $index, $wgContentNamespaces );
172 * Can pages in a namespace be watched?
177 public static function isWatchable( $index ) {
178 return $index >= NS_MAIN
;
182 * Does the namespace allow subpages?
184 * @param $index int Index to check
187 public static function hasSubpages( $index ) {
188 global $wgNamespacesWithSubpages;
189 return !empty( $wgNamespacesWithSubpages[$index] );
193 * Is the namespace first-letter capitalized?
195 * @param $index int Index to check
198 public static function isCapitalized( $index ) {
199 global $wgCapitalLinks, $wgCapitalLinkOverrides;
200 // Turn NS_MEDIA into NS_FILE
201 $index = $index === NS_MEDIA ? NS_FILE
: $index;
203 // Make sure to get the subject of our namespace
204 $index = self
::getSubject( $index );
206 // Some namespaces are special and should always be upper case
207 if ( in_array( $index, self
::$alwaysCapitalizedNamespaces ) ) {
210 if ( isset( $wgCapitalLinkOverrides[ $index ] ) ) {
211 // $wgCapitalLinkOverrides is explicitly set
212 return $wgCapitalLinkOverrides[ $index ];
214 // Default to the global setting
215 return $wgCapitalLinks;