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