00001 <?php
00002
# This is a utility class with only static functions
00003
# for dealing with namespaces that encodes all the
00004
# "magic" behaviors of them based on index. The textual
00005
# names of the namespaces are handled by Language.php.
00006
00007
# Virtual namespaces; these don't appear in the page database:
00008 define(
"NS_MEDIA", -2);
00009 define(
"NS_SPECIAL", -1);
00010
00011
# Real namespaces:
00012 define(
"NS_MAIN", 0);
00013 define(
"NS_TALK", 1);
00014 define(
"NS_USER", 2);
00015 define(
"NS_USER_TALK", 3);
00016 define(
"NS_WP", 4);
00017 define(
"NS_WIKIPEDIA", 4);
00018 define(
"NS_WP_TALK", 5);
00019 define(
"NS_WIKIPEDIA_TALK", 5);
00020 define(
"NS_IMAGE", 6);
00021 define(
"NS_IMAGE_TALK", 7);
00022 define(
"NS_MEDIAWIKI", 8);
00023 define(
"NS_MEDIAWIKI_TALK", 9);
00024 define(
"NS_TEMPLATE", 10);
00025 define(
"NS_TEMPLATE_TALK", 11);
00026 define(
"NS_HELP", 12);
00027 define(
"NS_HELP_TALK", 13);
00028 define(
"NS_CATEGORY", 14);
00029 define(
"NS_CATEGORY_TALK", 15);
00030
00031
# These are synonyms for the names given in the language file
00032
# Users and translators should not change them
00033 $wgCanonicalNamespaceNames = array(
00034 NS_MEDIA =>
"Media",
00035 NS_SPECIAL =>
"Special",
00036 NS_TALK =>
"Talk",
00037 NS_USER =>
"User",
00038 NS_USER_TALK =>
"User_talk",
00039 NS_WIKIPEDIA =>
"Project",
00040 NS_WIKIPEDIA_TALK =>
"Project_talk",
00041 NS_IMAGE =>
"Image",
00042 NS_IMAGE_TALK =>
"Image_talk",
00043 NS_MEDIAWIKI =>
"MediaWiki",
00044 NS_MEDIAWIKI_TALK =>
"MediaWiki_talk",
00045 NS_TEMPLATE =>
"Template",
00046 NS_TEMPLATE_TALK =>
"Template_talk",
00047 NS_HELP =>
"Help",
00048 NS_HELP_TALK =>
"Help_talk",
00049 NS_CATEGORY =>
"Category",
00050 NS_CATEGORY_TALK =>
"Category_talk"
00051 );
00052
00053 class Namespace {
00054
00055
00056 function
getSpecial() {
return NS_SPECIAL; }
00057 function
getUser() {
return NS_USER; }
00058 function
getWikipedia() {
return NS_WP; }
00059 function
getImage() {
return NS_IMAGE; }
00060 function
getMedia() {
return NS_MEDIA; }
00061 function
getCategory() {
return NS_CATEGORY; }
00062
00063 function
isMovable( $index )
00064 {
00065
if ( $index <
NS_MAIN || $index ==
NS_IMAGE || $index ==
NS_CATEGORY ) {
00066
return false;
00067 }
00068
return true;
00069 }
00070
00071 function
isTalk( $index )
00072 {
00073
if (
NS_TALK == $index ||
NS_USER_TALK == $index ||
NS_WP_TALK
00074 == $index ||
NS_IMAGE_TALK == $index ||
NS_MEDIAWIKI_TALK == $index ||
00075
NS_TEMPLATE_TALK == $index ||
NS_HELP_TALK == $index ||
00076
NS_CATEGORY_TALK == $index ) {
00077
return true;
00078 }
00079
return false;
00080 }
00081
00082
# Get the talk namespace corresponding to the given index
00083
#
00084 function
getTalk( $index )
00085 {
00086
if (
Namespace::isTalk( $index ) ) {
00087
return $index;
00088 }
else {
00089
# FIXME
00090
return $index + 1;
00091 }
00092 }
00093
00094 function
getSubject( $index )
00095 {
00096
if (
Namespace::isTalk( $index ) ) {
00097
return $index - 1;
00098 }
else {
00099
return $index;
00100 }
00101 }
00102
00103
# Returns the canonical (English Wikipedia) name for a given index
00104 function &
getCanonicalName( $index )
00105 {
00106 global
$wgCanonicalNamespaceNames;
00107
return $wgCanonicalNamespaceNames[$index];
00108 }
00109
00110
# Returns the index for a given canonical name, or NULL
00111
# The input *must* be converted to lower case first
00112 function &
getCanonicalIndex( $name )
00113 {
00114 global
$wgCanonicalNamespaceNames;
00115
static $xNamespaces =
false;
00116
if ( $xNamespaces ===
false ) {
00117 $xNamespaces = array();
00118 foreach ( $wgCanonicalNamespaceNames as $i => $text ) {
00119 $xNamespaces[strtolower($text)] =
$i;
00120 }
00121 }
00122
if ( array_key_exists( $
name, $xNamespaces ) ) {
00123
return $xNamespaces[$name];
00124 }
else {
00125
return NULL;
00126 }
00127 }
00128 }
00129
00130 ?>