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