3 * Provide things related to namespaces
7 * This is not a valid entry point, perform no further processing unless MEDIAWIKI is defined
9 if( defined( 'MEDIAWIKI' ) ) {
13 * Definitions of the NS_ constants are in Defines.php
16 $wgCanonicalNamespaceNames = array(
18 NS_SPECIAL
=> 'Special',
21 NS_USER_TALK
=> 'User_talk',
22 NS_PROJECT
=> 'Project',
23 NS_PROJECT_TALK
=> 'Project_talk',
25 NS_IMAGE_TALK
=> 'Image_talk',
26 NS_MEDIAWIKI
=> 'MediaWiki',
27 NS_MEDIAWIKI_TALK
=> 'MediaWiki_talk',
28 NS_TEMPLATE
=> 'Template',
29 NS_TEMPLATE_TALK
=> 'Template_talk',
31 NS_HELP_TALK
=> 'Help_talk',
32 NS_CATEGORY
=> 'Category',
33 NS_CATEGORY_TALK
=> 'Category_talk'
36 if(isset($wgExtraNamespaces)) {
37 $wgCanonicalNamespaceNames=$wgCanonicalNamespaceNames+
$wgExtraNamespaces;
41 * This is a utility class with only static functions
42 * for dealing with namespaces that encodes all the
43 * "magic" behaviors of them based on index. The textual
44 * names of the namespaces are handled by Language.php.
46 * These are synonyms for the names given in the language file
47 * Users and translators should not change them
52 * These functions are deprecated
55 function getSpecial() { return NS_SPECIAL
; }
56 function getUser() { return NS_USER
; }
57 function getWikipedia() { return NS_PROJECT
; }
58 function getImage() { return NS_IMAGE
; }
59 function getMedia() { return NS_MEDIA
; }
60 function getCategory() { return NS_CATEGORY
; }
64 * Check if the given namespace might be moved
67 function isMovable( $index ) {
68 if ( $index < NS_MAIN ||
$index == NS_IMAGE ||
$index == NS_CATEGORY
) {
75 * Check if the give namespace is a talk page
78 function isTalk( $index ) {
79 global $wgExtraNamespaces;
80 return ( $index == NS_TALK ||
$index == NS_USER_TALK ||
81 $index == NS_PROJECT_TALK ||
$index == NS_IMAGE_TALK ||
82 $index == NS_MEDIAWIKI_TALK ||
$index == NS_TEMPLATE_TALK ||
83 $index == NS_HELP_TALK ||
$index == NS_CATEGORY_TALK
84 ||
( (isset($wgExtraNamespaces) && $index %
2) )
90 * Get the talk namespace corresponding to the given index
92 function getTalk( $index ) {
93 if ( Namespace::isTalk( $index ) ) {
101 function getSubject( $index ) {
102 if ( Namespace::isTalk( $index ) ) {
110 * Returns the canonical (English Wikipedia) name for a given index
112 function &getCanonicalName( $index ) {
113 global $wgCanonicalNamespaceNames;
114 return $wgCanonicalNamespaceNames[$index];
118 * Returns the index for a given canonical name, or NULL
119 * The input *must* be converted to lower case first
121 function &getCanonicalIndex( $name ) {
122 global $wgCanonicalNamespaceNames;
123 static $xNamespaces = false;
124 if ( $xNamespaces === false ) {
125 $xNamespaces = array();
126 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
127 $xNamespaces[strtolower($text)] = $i;
130 if ( array_key_exists( $name, $xNamespaces ) ) {
131 return $xNamespaces[$name];