Moved MAG_XXXX constants to MagicWord.php, changed canonical name for NS 4 to "MetaNa...
[lhc/web/wiklou.git] / includes / Namespace.php
1 <?php
2 # This is a utility class with only static functions
3 # for dealing with namespaces that encodes all the
4 # "magic" behaviors of them based on index. The textual
5 # names of the namespaces are handled by Language.php.
6
7 # Virtual namespaces; these don't appear in the page database:
8 define("NS_MEDIA", -2);
9 define("NS_SPECIAL", -1);
10
11 # Real namespaces:
12 define("NS_MAIN", 0);
13 define("NS_TALK", 1);
14 define("NS_USER", 2);
15 define("NS_USER_TALK", 3);
16 define("NS_WP", 4);
17 define("NS_WIKIPEDIA", 4);
18 define("NS_WP_TALK", 5);
19 define("NS_WIKIPEDIA_TALK", 5);
20 define("NS_IMAGE", 6);
21 define("NS_IMAGE_TALK", 7);
22 define("NS_MEDIAWIKI", 8);
23 define("NS_MEDIAWIKI_TALK", 9);
24 define("NS_TEMPLATE", 10);
25 define("NS_TEMPLATE_TALK", 11);
26 define("NS_HELP", 12);
27 define("NS_HELP_TALK", 13);
28
29 # These are synonyms for the names given in the language file
30 # Users and translators should not change them
31 /* private */ $wgCanonicalNamespaceNames = array(
32 NS_MEDIA => "Media",
33 NS_SPECIAL => "Special",
34 NS_TALK => "Talk",
35 NS_USER => "User",
36 NS_USER_TALK => "User_talk",
37 NS_WIKIPEDIA => "MetaNamespace",
38 NS_WIKIPEDIA_TALK => "MetaNamespace_talk",
39 NS_IMAGE => "Image",
40 NS_IMAGE_TALK => "Image_talk",
41 NS_MEDIAWIKI => "MediaWiki",
42 NS_MEDIAWIKI_TALK => "MediaWiki_talk",
43 NS_TEMPLATE => "Template",
44 NS_TEMPLATE_TALK => "Template_talk",
45 NS_HELP => "Help",
46 NS_HELP_TALK => "Help_talk"
47 );
48
49 class Namespace {
50
51 /* These functions are deprecated */
52 function getSpecial() { return NS_SPECIAL; }
53 function getUser() { return NS_USER; }
54 function getWikipedia() { return NS_WP; }
55 function getImage() { return NS_IMAGE; }
56 function getMedia() { return NS_MEDIA; }
57
58 function isMovable( $index )
59 {
60 if ( $index < NS_MAIN || $index == NS_IMAGE ) {
61 return false;
62 }
63 return true;
64 }
65
66 function isTalk( $index )
67 {
68 if ( NS_TALK == $index || NS_USER_TALK == $index || NS_WP_TALK == $index || NS_IMAGE_TALK == $index || NS_MEDIAWIKI_TALK == $index || NS_TEMPLATE_TALK == $index || NS_HELP_TALK == $index ) {
69 return true;
70 }
71 return false;
72 }
73
74 # Get the talk namespace corresponding to the given index
75 #
76 function getTalk( $index )
77 {
78 if ( Namespace::isTalk( $index ) ) {
79 return $index;
80 } else {
81 # FIXME
82 return $index + 1;
83 }
84 }
85
86 function getSubject( $index )
87 {
88 if ( Namespace::isTalk( $index ) ) {
89 return $index - 1;
90 } else {
91 return $index;
92 }
93 }
94
95 # Returns the canonical (English Wikipedia) name for a given index
96 function &getCanonicalName( $index )
97 {
98 global $wgCanonicalNamespaceNames;
99 return $wgCanonicalNamespaceNames[$index];
100 }
101
102 # Returns the index for a given canonical name, or NULL
103 # The input *must* be converted to lower case first
104 function &getCanonicalIndex( $name )
105 {
106 global $wgCanonicalNamespaceNames;
107 static $xNamespaces = false;
108 if ( $xNamespaces === false ) {
109 $xNamespaces = array();
110 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
111 $xNamespaces[strtolower($text)] = $i;
112 }
113 }
114 if ( array_key_exists( $name, $xNamespaces ) ) {
115 return $xNamespaces[$name];
116 } else {
117 return NULL;
118 }
119 }
120 }
121
122 ?>