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