3 * Provide things related to namespaces
8 * Definitions of the NS_ constants are in Defines.php
11 $wgCanonicalNamespaceNames = array(
13 NS_SPECIAL
=> 'Special',
16 NS_USER_TALK
=> 'User_talk',
17 NS_PROJECT
=> 'Project',
18 NS_PROJECT_TALK
=> 'Project_talk',
20 NS_IMAGE_TALK
=> 'Image_talk',
21 NS_MEDIAWIKI
=> 'MediaWiki',
22 NS_MEDIAWIKI_TALK
=> 'MediaWiki_talk',
23 NS_TEMPLATE
=> 'Template',
24 NS_TEMPLATE_TALK
=> 'Template_talk',
26 NS_HELP_TALK
=> 'Help_talk',
27 NS_CATEGORY
=> 'Category',
28 NS_CATEGORY_TALK
=> 'Category_talk',
31 if( is_array( $wgExtraNamespaces ) ) {
32 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames +
$wgExtraNamespaces;
36 * This is a utility class with only static functions
37 * for dealing with namespaces that encodes all the
38 * "magic" behaviors of them based on index. The textual
39 * names of the namespaces are handled by Language.php.
41 * These are synonyms for the names given in the language file
42 * Users and translators should not change them
49 * Check if the given namespace might be moved
52 function isMovable( $index ) {
53 return !( $index < NS_MAIN ||
$index == NS_IMAGE ||
$index == NS_CATEGORY
);
57 * Check if the given namespace is not a talk page
60 function isMain( $index ) {
61 return ! Namespace::isTalk( $index );
65 * Check if the give namespace is a talk page
68 function isTalk( $index ) {
69 return ($index > NS_MAIN
) // Special namespaces are negative
70 && ($index %
2); // Talk namespaces are odd-numbered
74 * Get the talk namespace corresponding to the given index
76 function getTalk( $index ) {
77 if ( Namespace::isTalk( $index ) ) {
85 function getSubject( $index ) {
86 if ( Namespace::isTalk( $index ) ) {
94 * Returns the canonical (English Wikipedia) name for a given index
96 function getCanonicalName( $index ) {
97 global $wgCanonicalNamespaceNames;
98 return $wgCanonicalNamespaceNames[$index];
102 * Returns the index for a given canonical name, or NULL
103 * The input *must* be converted to lower case first
105 function getCanonicalIndex( $name ) {
106 global $wgCanonicalNamespaceNames;
107 static $xNamespaces = false;
108 if ( $xNamespaces === false ) {
109 $xNamespaces = array();
110 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
111 $xNamespaces[strtolower($text)] = $i;
114 if ( array_key_exists( $name, $xNamespaces ) ) {
115 return $xNamespaces[$name];
122 * Can this namespace ever have a talk namespace?
123 * @param $index Namespace index
125 function canTalk( $index ) {
126 return( $index >= NS_MAIN
);