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