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
47 * Check if the given namespace might be moved
50 static function isMovable( $index ) {
51 return !( $index < NS_MAIN ||
$index == NS_IMAGE ||
$index == NS_CATEGORY
);
55 * Check if the given namespace is not a talk page
58 static function isMain( $index ) {
59 return ! Namespace::isTalk( $index );
63 * Check if the give namespace is a talk page
66 static function isTalk( $index ) {
67 return ($index > NS_MAIN
) // Special namespaces are negative
68 && ($index %
2); // Talk namespaces are odd-numbered
72 * Get the talk namespace corresponding to the given index
74 static function getTalk( $index ) {
75 if ( Namespace::isTalk( $index ) ) {
83 static function getSubject( $index ) {
84 if ( Namespace::isTalk( $index ) ) {
92 * Returns the canonical (English Wikipedia) name for a given index
94 static function getCanonicalName( $index ) {
95 global $wgCanonicalNamespaceNames;
96 return $wgCanonicalNamespaceNames[$index];
100 * Returns the index for a given canonical name, or NULL
101 * The input *must* be converted to lower case first
103 static function getCanonicalIndex( $name ) {
104 global $wgCanonicalNamespaceNames;
105 static $xNamespaces = false;
106 if ( $xNamespaces === false ) {
107 $xNamespaces = array();
108 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
109 $xNamespaces[strtolower($text)] = $i;
112 if ( array_key_exists( $name, $xNamespaces ) ) {
113 return $xNamespaces[$name];
120 * Can this namespace ever have a talk namespace?
121 * @param $index Namespace index
123 static function canTalk( $index ) {
124 return( $index >= NS_MAIN
);
128 * Does this namespace contain content, for the purposes
129 * of calculating statistics, etc?
131 * @param $index Index to check
134 public static function isContent( $index ) {
135 global $wgContentNamespaces;
136 return $index == NS_MAIN ||
in_array( $index, $wgContentNamespaces );