Reserved namespace 100 and 101 for forum-like's thread pages
[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 NS_THREAD_TALK => 'Thread_talk' // Reserved for Forum-like
38 );
39
40 if( defined( 'MEDIAWIKI' ) && is_array( $wgExtraNamespaces ) ) {
41 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames + $wgExtraNamespaces;
42 }
43
44 /**
45 * This is a utility class with only static functions
46 * for dealing with namespaces that encodes all the
47 * "magic" behaviors of them based on index. The textual
48 * names of the namespaces are handled by Language.php.
49 *
50 * These are synonyms for the names given in the language file
51 * Users and translators should not change them
52 *
53 * @package MediaWiki
54 */
55 class Namespace {
56
57 /**#@+
58 * These functions are deprecated
59 * @deprecated
60 */
61 function getSpecial() { return NS_SPECIAL; }
62 function getUser() { return NS_USER; }
63 function getWikipedia() { return NS_PROJECT; }
64 function getImage() { return NS_IMAGE; }
65 function getMedia() { return NS_MEDIA; }
66 function getCategory() { return NS_CATEGORY; }
67 /**#@-*/
68
69 /**
70 * Check if the given namespace might be moved
71 * @return bool
72 */
73 function isMovable( $index ) {
74 if ( $index < NS_MAIN || $index == NS_IMAGE || $index == NS_CATEGORY ) {
75 return false;
76 }
77 return true;
78 }
79
80 /**
81 * Check if the give namespace is a talk page
82 * @return bool
83 */
84 function isTalk( $index ) {
85 global $wgExtraNamespaces;
86 return ( $index == NS_TALK || $index == NS_USER_TALK ||
87 $index == NS_PROJECT_TALK || $index == NS_IMAGE_TALK ||
88 $index == NS_MEDIAWIKI_TALK || $index == NS_TEMPLATE_TALK ||
89 $index == NS_HELP_TALK || $index == NS_CATEGORY_TALK
90 || ( (isset($wgExtraNamespaces) && $index % 2) )
91 );
92
93 }
94
95 /**
96 * Get the talk namespace corresponding to the given index
97 */
98 function getTalk( $index ) {
99 if ( Namespace::isTalk( $index ) ) {
100 return $index;
101 } else {
102 # FIXME
103 return $index + 1;
104 }
105 }
106
107 function getSubject( $index ) {
108 if ( Namespace::isTalk( $index ) ) {
109 return $index - 1;
110 } else {
111 return $index;
112 }
113 }
114
115 /**
116 * Returns the canonical (English Wikipedia) name for a given index
117 */
118 function &getCanonicalName( $index ) {
119 global $wgCanonicalNamespaceNames;
120 return $wgCanonicalNamespaceNames[$index];
121 }
122
123 /**
124 * Returns the index for a given canonical name, or NULL
125 * The input *must* be converted to lower case first
126 */
127 function &getCanonicalIndex( $name ) {
128 global $wgCanonicalNamespaceNames;
129 static $xNamespaces = false;
130 if ( $xNamespaces === false ) {
131 $xNamespaces = array();
132 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
133 $xNamespaces[strtolower($text)] = $i;
134 }
135 }
136 if ( array_key_exists( $name, $xNamespaces ) ) {
137 return $xNamespaces[$name];
138 } else {
139 return NULL;
140 }
141 }
142 }
143
144 }
145 ?>