Custom namespaces:
[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_PROJECT => 'Project',
22 NS_PROJECT_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 if(isset($wgExtraNamespaces)) {
36 $wgCanonicalNamespaceNames=$wgCanonicalNamespaceNames+$wgExtraNamespaces;
37 }
38
39 class Namespace {
40
41 /* These functions are deprecated */
42 function getSpecial() { return NS_SPECIAL; }
43 function getUser() { return NS_USER; }
44 function getWikipedia() { return NS_PROJECT; }
45 function getImage() { return NS_IMAGE; }
46 function getMedia() { return NS_MEDIA; }
47 function getCategory() { return NS_CATEGORY; }
48
49 function isMovable( $index )
50 {
51 if ( $index < NS_MAIN || $index == NS_IMAGE || $index == NS_CATEGORY ) {
52 return false;
53 }
54 return true;
55 }
56
57 function isTalk( $index )
58 {
59 global $wgExtraNamespaces;
60 return ( $index == NS_TALK || $index == NS_USER_TALK ||
61 $index == NS_PROJECT_TALK || $index == NS_IMAGE_TALK ||
62 $index == NS_MEDIAWIKI_TALK || $index == NS_TEMPLATE_TALK ||
63 $index == NS_HELP_TALK || $index == NS_CATEGORY_TALK
64 || ( (isset($wgExtraNamespaces) && $index % 2) )
65 );
66
67 }
68
69 # Get the talk namespace corresponding to the given index
70 #
71 function getTalk( $index )
72 {
73 if ( Namespace::isTalk( $index ) ) {
74 return $index;
75 } else {
76 # FIXME
77 return $index + 1;
78 }
79 }
80
81 function getSubject( $index )
82 {
83 if ( Namespace::isTalk( $index ) ) {
84 return $index - 1;
85 } else {
86 return $index;
87 }
88 }
89
90 # Returns the canonical (English Wikipedia) name for a given index
91 function &getCanonicalName( $index )
92 {
93 global $wgCanonicalNamespaceNames;
94 return $wgCanonicalNamespaceNames[$index];
95 }
96
97 # Returns the index for a given canonical name, or NULL
98 # The input *must* be converted to lower case first
99 function &getCanonicalIndex( $name )
100 {
101 global $wgCanonicalNamespaceNames;
102 static $xNamespaces = false;
103 if ( $xNamespaces === false ) {
104 $xNamespaces = array();
105 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
106 $xNamespaces[strtolower($text)] = $i;
107 }
108 }
109 if ( array_key_exists( $name, $xNamespaces ) ) {
110 return $xNamespaces[$name];
111 } else {
112 return NULL;
113 }
114 }
115 }
116
117 }
118 ?>