debugging code accidentally left in
[mediawiki.git] / includes / Namespace.php
blobebb2bce6b3c0e43c538bbc1e1d184afad42a2923
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
44 class Namespace {
46 /**
47 * Check if the given namespace might be moved
48 * @return bool
50 static function isMovable( $index ) {
51 return !( $index < NS_MAIN || $index == NS_IMAGE || $index == NS_CATEGORY );
54 /**
55 * Check if the given namespace is not a talk page
56 * @return bool
58 static function isMain( $index ) {
59 return ! Namespace::isTalk( $index );
62 /**
63 * Check if the give namespace is a talk page
64 * @return bool
66 static function isTalk( $index ) {
67 return ($index > NS_MAIN) // Special namespaces are negative
68 && ($index % 2); // Talk namespaces are odd-numbered
71 /**
72 * Get the talk namespace corresponding to the given index
74 static function getTalk( $index ) {
75 if ( Namespace::isTalk( $index ) ) {
76 return $index;
77 } else {
78 # FIXME
79 return $index + 1;
83 static function getSubject( $index ) {
84 if ( Namespace::isTalk( $index ) ) {
85 return $index - 1;
86 } else {
87 return $index;
91 /**
92 * Returns the canonical (English Wikipedia) name for a given index
94 static function getCanonicalName( $index ) {
95 global $wgCanonicalNamespaceNames;
96 return $wgCanonicalNamespaceNames[$index];
99 /**
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];
114 } else {
115 return NULL;
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
132 * @return bool
134 public static function isContent( $index ) {
135 global $wgContentNamespaces;
136 return $index == NS_MAIN || in_array( $index, $wgContentNamespaces );
140 * Can pages in a namespace be watched?
142 * @param int $index
143 * @return bool
145 public static function isWatchable( $index ) {
146 return $index >= NS_MAIN;