2 if ( ! defined( 'MEDIAWIKI' ) )
5 * Provide things related to namespaces
10 * Definitions of the NS_ constants are in Defines.php
13 $wgCanonicalNamespaceNames = array(
15 NS_SPECIAL
=> 'Special',
18 NS_USER_TALK
=> 'User_talk',
19 NS_PROJECT
=> 'Project',
20 NS_PROJECT_TALK
=> 'Project_talk',
22 NS_IMAGE_TALK
=> 'Image_talk',
23 NS_MEDIAWIKI
=> 'MediaWiki',
24 NS_MEDIAWIKI_TALK
=> 'MediaWiki_talk',
25 NS_TEMPLATE
=> 'Template',
26 NS_TEMPLATE_TALK
=> 'Template_talk',
28 NS_HELP_TALK
=> 'Help_talk',
29 NS_CATEGORY
=> 'Category',
30 NS_CATEGORY_TALK
=> 'Category_talk',
33 if( is_array( $wgExtraNamespaces ) ) {
34 $wgCanonicalNamespaceNames = $wgCanonicalNamespaceNames +
$wgExtraNamespaces;
38 * This is a utility class with only static functions
39 * for dealing with namespaces that encodes all the
40 * "magic" behaviors of them based on index. The textual
41 * names of the namespaces are handled by Language.php.
43 * These are synonyms for the names given in the language file
44 * Users and translators should not change them
51 * Check if the given namespace might be moved
54 function isMovable( $index ) {
55 return !( $index < NS_MAIN ||
$index == NS_IMAGE ||
$index == NS_CATEGORY
);
59 * Check if the given namespace is not a talk page
62 function isMain( $index ) {
63 return ! Namespace::isTalk( $index );
67 * Check if the give namespace is a talk page
70 function isTalk( $index ) {
71 return ($index > NS_MAIN
) // Special namespaces are negative
72 && ($index %
2); // Talk namespaces are odd-numbered
76 * Get the talk namespace corresponding to the given index
78 function getTalk( $index ) {
79 if ( Namespace::isTalk( $index ) ) {
87 function getSubject( $index ) {
88 if ( Namespace::isTalk( $index ) ) {
96 * Returns the canonical (English Wikipedia) name for a given index
98 function getCanonicalName( $index ) {
99 global $wgCanonicalNamespaceNames;
100 return $wgCanonicalNamespaceNames[$index];
104 * Returns the index for a given canonical name, or NULL
105 * The input *must* be converted to lower case first
107 function getCanonicalIndex( $name ) {
108 global $wgCanonicalNamespaceNames;
109 static $xNamespaces = false;
110 if ( $xNamespaces === false ) {
111 $xNamespaces = array();
112 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
113 $xNamespaces[strtolower($text)] = $i;
116 if ( array_key_exists( $name, $xNamespaces ) ) {
117 return $xNamespaces[$name];