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