BUG#1402 Make link color of tab subject page link on talk page indicate whether artic...
[lhc/web/wiklou.git] / includes / Namespace.php
1 <?php
2 /**
3 * Provide things related to namespaces
4 * @package MediaWiki
5 */
6
7 /**
8 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
9 */
10 if( defined( 'MEDIAWIKI' ) ) {
11
12
13 /**
14 * Definitions of the NS_ constants are in Defines.php
15 * @private
16 */
17 $wgCanonicalNamespaceNames = array(
18 NS_MEDIA => 'Media',
19 NS_SPECIAL => 'Special',
20 NS_TALK => 'Talk',
21 NS_USER => 'User',
22 NS_USER_TALK => 'User_talk',
23 NS_PROJECT => 'Project',
24 NS_PROJECT_TALK => 'Project_talk',
25 NS_IMAGE => 'Image',
26 NS_IMAGE_TALK => 'Image_talk',
27 NS_MEDIAWIKI => 'MediaWiki',
28 NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
29 NS_TEMPLATE => 'Template',
30 NS_TEMPLATE_TALK => 'Template_talk',
31 NS_HELP => 'Help',
32 NS_HELP_TALK => 'Help_talk',
33 NS_CATEGORY => 'Category',
34 NS_CATEGORY_TALK => 'Category_talk',
35
36 NS_THREAD => 'Thread' // Reserved for Forum-like
37 );
38
39 if( defined( 'MEDIAWIKI' ) && is_array( $wgExtraNamespaces ) ) {
40 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
41 }
42
43 /**
44 * This is a utility class with only static functions
45 * for dealing with namespaces that encodes all the
46 * "magic" behaviors of them based on index. The textual
47 * names of the namespaces are handled by Language.php.
48 *
49 * These are synonyms for the names given in the language file
50 * Users and translators should not change them
51 *
52 * @package MediaWiki
53 */
54 class Namespace {
55
56 /**#@+
57 * These functions are deprecated
58 * @deprecated
59 */
60 function getSpecial() { return NS_SPECIAL; }
61 function getUser() { return NS_USER; }
62 function getWikipedia() { return NS_PROJECT; }
63 function getImage() { return NS_IMAGE; }
64 function getMedia() { return NS_MEDIA; }
65 function getCategory() { return NS_CATEGORY; }
66 /**#@-*/
67
68 /**
69 * Check if the given namespace might be moved
70 * @return bool
71 */
72 function isMovable( $index ) {
73 if ( $index < NS_MAIN || $index == NS_IMAGE || $index == NS_CATEGORY ) {
74 return false;
75 }
76 return true;
77 }
78
79 /**
80 * Check if the give namespace is a talk page
81 * @return bool
82 */
83 function isTalk( $index ) {
84 global $wgExtraNamespaces;
85 return ( $index == NS_TALK || $index == NS_USER_TALK ||
86 $index == NS_PROJECT_TALK || $index == NS_IMAGE_TALK ||
87 $index == NS_MEDIAWIKI_TALK || $index == NS_TEMPLATE_TALK ||
88 $index == NS_HELP_TALK || $index == NS_CATEGORY_TALK
89 || ( (isset($wgExtraNamespaces) && $index % 2) )
90 );
91
92 }
93
94 /**
95 * Get the talk namespace corresponding to the given index
96 */
97 function getTalk( $index ) {
98 if ( Namespace::isTalk( $index ) ) {
99 return $index;
100 } else {
101 # FIXME
102 return $index + 1;
103 }
104 }
105
106 function getSubject( $index ) {
107 if ( Namespace::isTalk( $index ) ) {
108 return $index - 1;
109 } else {
110 return $index;
111 }
112 }
113
114 /**
115 * Returns the canonical (English Wikipedia) name for a given index
116 */
117 function &getCanonicalName( $index ) {
118 global $wgCanonicalNamespaceNames;
119 return $wgCanonicalNamespaceNames[$index];
120 }
121
122 /**
123 * Returns the index for a given canonical name, or NULL
124 * The input *must* be converted to lower case first
125 */
126 function &getCanonicalIndex( $name ) {
127 global $wgCanonicalNamespaceNames;
128 static $xNamespaces = false;
129 if ( $xNamespaces === false ) {
130 $xNamespaces = array();
131 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
132 $xNamespaces[strtolower($text)] = $i;
133 }
134 }
135 if ( array_key_exists( $name, $xNamespaces ) ) {
136 return $xNamespaces[$name];
137 } else {
138 return NULL;
139 }
140 }
141 }
142
143 }
144 ?>