Category namespaces
[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 define("NS_CATEGORY", 14);
29 define("NS_CATEGORY_TALK", 15);
30
31 # These are synonyms for the names given in the language file
32 # Users and translators should not change them
33 /* private */ $wgCanonicalNamespaceNames = array(
34 NS_MEDIA => "Media",
35 NS_SPECIAL => "Special",
36 NS_TALK => "Talk",
37 NS_USER => "User",
38 NS_USER_TALK => "User_talk",
39 NS_WIKIPEDIA => "Project",
40 NS_WIKIPEDIA_TALK => "Project_talk",
41 NS_IMAGE => "Image",
42 NS_IMAGE_TALK => "Image_talk",
43 NS_MEDIAWIKI => "MediaWiki",
44 NS_MEDIAWIKI_TALK => "MediaWiki_talk",
45 NS_TEMPLATE => "Template",
46 NS_TEMPLATE_TALK => "Template_talk",
47 NS_HELP => "Help",
48 NS_HELP_TALK => "Help_talk",
49 NS_CATEGORY => "Category",
50 NS_CATEGORY_TALK => "Category_talk"
51 );
52
53 class Namespace {
54
55 /* These functions are deprecated */
56 function getSpecial() { return NS_SPECIAL; }
57 function getUser() { return NS_USER; }
58 function getWikipedia() { return NS_WP; }
59 function getImage() { return NS_IMAGE; }
60 function getMedia() { return NS_MEDIA; }
61
62 function isMovable( $index )
63 {
64 if ( $index < NS_MAIN || $index == NS_IMAGE ) {
65 return false;
66 }
67 return true;
68 }
69
70 function isTalk( $index )
71 {
72 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 ) {
73 return true;
74 }
75 return false;
76 }
77
78 # Get the talk namespace corresponding to the given index
79 #
80 function getTalk( $index )
81 {
82 if ( Namespace::isTalk( $index ) ) {
83 return $index;
84 } else {
85 # FIXME
86 return $index + 1;
87 }
88 }
89
90 function getSubject( $index )
91 {
92 if ( Namespace::isTalk( $index ) ) {
93 return $index - 1;
94 } else {
95 return $index;
96 }
97 }
98
99 # Returns the canonical (English Wikipedia) name for a given index
100 function &getCanonicalName( $index )
101 {
102 global $wgCanonicalNamespaceNames;
103 return $wgCanonicalNamespaceNames[$index];
104 }
105
106 # Returns the index for a given canonical name, or NULL
107 # The input *must* be converted to lower case first
108 function &getCanonicalIndex( $name )
109 {
110 global $wgCanonicalNamespaceNames;
111 static $xNamespaces = false;
112 if ( $xNamespaces === false ) {
113 $xNamespaces = array();
114 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
115 $xNamespaces[strtolower($text)] = $i;
116 }
117 }
118 if ( array_key_exists( $name, $xNamespaces ) ) {
119 return $xNamespaces[$name];
120 } else {
121 return NULL;
122 }
123 }
124 }
125
126 ?>