3 * Provide things related to namespaces
8 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
10 if( defined( 'MEDIAWIKI' ) ) {
14 * Definitions of the NS_ constants are in Defines.php
17 $wgCanonicalNamespaceNames = array(
19 NS_SPECIAL
=> 'Special',
22 NS_USER_TALK
=> 'User_talk',
23 NS_PROJECT
=> 'Project',
24 NS_PROJECT_TALK
=> 'Project_talk',
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',
32 NS_HELP_TALK
=> 'Help_talk',
33 NS_CATEGORY
=> 'Category',
34 NS_CATEGORY_TALK
=> 'Category_talk',
37 if( is_array( $wgExtraNamespaces ) ) {
38 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames +
$wgExtraNamespaces;
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.
47 * These are synonyms for the names given in the language file
48 * Users and translators should not change them
55 * Check if the given namespace might be moved
58 function isMovable( $index ) {
59 if ( $index < NS_MAIN ||
$index == NS_IMAGE ||
$index == NS_CATEGORY
) {
66 * Check if the given namespace is not a talk page
69 function isMain( $index ) {
70 return ! Namespace::isTalk( $index );
74 * Check if the give namespace is a talk page
77 function isTalk( $index ) {
78 return ($index > 0) // Special namespaces are negative
79 && ($index %
2); // Talk namespaces are odd-numbered
83 * Get the talk namespace corresponding to the given index
85 function getTalk( $index ) {
86 if ( Namespace::isTalk( $index ) ) {
94 function getSubject( $index ) {
95 if ( Namespace::isTalk( $index ) ) {
103 * Returns the canonical (English Wikipedia) name for a given index
105 function getCanonicalName( $index ) {
106 global $wgCanonicalNamespaceNames;
107 return $wgCanonicalNamespaceNames[$index];
111 * Returns the index for a given canonical name, or NULL
112 * The input *must* be converted to lower case first
114 function getCanonicalIndex( $name ) {
115 global $wgCanonicalNamespaceNames;
116 static $xNamespaces = false;
117 if ( $xNamespaces === false ) {
118 $xNamespaces = array();
119 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
120 $xNamespaces[strtolower($text)] = $i;
123 if ( array_key_exists( $name, $xNamespaces ) ) {
124 return $xNamespaces[$name];