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