2004-02-18 02:15:00 +00:00
|
|
|
<?php
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2012-05-12 20:33:02 +00:00
|
|
|
* Provide things related to namespaces.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @file
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2005-08-02 13:35:19 +00:00
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* This is a utility class with only static functions
|
|
|
|
|
* for dealing with namespaces that encodes all the
|
|
|
|
|
* "magic" behaviors of them based on index. The textual
|
|
|
|
|
* names of the namespaces are handled by Language.php.
|
|
|
|
|
*
|
|
|
|
|
* These are synonyms for the names given in the language file
|
|
|
|
|
* Users and translators should not change them
|
2004-09-03 23:00:01 +00:00
|
|
|
*
|
|
|
|
|
*/
|
2008-03-21 23:13:34 +00:00
|
|
|
class MWNamespace {
|
2003-04-14 23:10:40 +00:00
|
|
|
|
2009-10-09 12:52:16 +00:00
|
|
|
/**
|
2010-02-05 04:25:30 +00:00
|
|
|
* These namespaces should always be first-letter capitalized, now and
|
|
|
|
|
* forevermore. Historically, they could've probably been lowercased too,
|
2009-10-09 12:52:16 +00:00
|
|
|
* but some things are just too ingrained now. :)
|
|
|
|
|
*/
|
2009-12-15 04:20:17 +00:00
|
|
|
private static $alwaysCapitalizedNamespaces = array( NS_SPECIAL, NS_USER, NS_MEDIAWIKI );
|
2009-10-09 12:52:16 +00:00
|
|
|
|
2011-02-21 22:17:06 +00:00
|
|
|
/**
|
2011-02-23 19:56:33 +00:00
|
|
|
* Throw an exception when trying to get the subject or talk page
|
|
|
|
|
* for a given namespace where it does not make sense.
|
2011-08-20 12:47:17 +00:00
|
|
|
* Special namespaces are defined in includes/Defines.php and have
|
2011-02-21 22:17:06 +00:00
|
|
|
* a value below 0 (ex: NS_SPECIAL = -1 , NS_MEDIA = -2)
|
|
|
|
|
*
|
2011-05-21 19:07:24 +00:00
|
|
|
* @param $index
|
|
|
|
|
* @param $method
|
|
|
|
|
*
|
2012-10-07 23:35:26 +00:00
|
|
|
* @throws MWException
|
2012-02-09 17:41:50 +00:00
|
|
|
* @return bool
|
2011-02-21 22:17:06 +00:00
|
|
|
*/
|
|
|
|
|
private static function isMethodValidFor( $index, $method ) {
|
2011-12-16 10:58:20 +00:00
|
|
|
if ( $index < NS_MAIN ) {
|
2011-02-23 19:56:33 +00:00
|
|
|
throw new MWException( "$method does not make any sense for given namespace $index" );
|
2011-02-21 22:17:06 +00:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2007-08-14 01:14:42 +00:00
|
|
|
* Can pages in the given namespace be moved?
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index namespace index
|
2004-09-02 23:28:24 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-08-14 01:14:42 +00:00
|
|
|
public static function isMovable( $index ) {
|
2008-07-10 21:53:14 +00:00
|
|
|
global $wgAllowImageMoving;
|
2012-05-10 10:19:56 +00:00
|
|
|
|
2013-02-03 20:05:24 +00:00
|
|
|
$result = !( $index < NS_MAIN || ( $index == NS_FILE && !$wgAllowImageMoving ) || $index == NS_CATEGORY );
|
2012-05-10 10:19:56 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @since 1.20
|
|
|
|
|
*/
|
|
|
|
|
wfRunHooks( 'NamespaceIsMovable', array( $index, &$result ) );
|
|
|
|
|
|
|
|
|
|
return $result;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2005-11-03 01:29:02 +00:00
|
|
|
/**
|
2007-08-14 01:14:42 +00:00
|
|
|
* Is the given namespace is a subject (non-talk) namespace?
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index namespace index
|
2005-11-03 01:29:02 +00:00
|
|
|
* @return bool
|
2011-11-22 13:34:55 +00:00
|
|
|
* @since 1.19
|
2005-11-03 01:29:02 +00:00
|
|
|
*/
|
2011-11-22 13:34:55 +00:00
|
|
|
public static function isSubject( $index ) {
|
2007-08-14 01:14:42 +00:00
|
|
|
return !self::isTalk( $index );
|
2005-11-03 01:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-22 13:34:55 +00:00
|
|
|
/**
|
|
|
|
|
* @see self::isSubject
|
|
|
|
|
* @deprecated Please use the more consistently named isSubject (since 1.19)
|
2012-02-09 21:35:05 +00:00
|
|
|
* @return bool
|
2011-11-22 13:34:55 +00:00
|
|
|
*/
|
|
|
|
|
public static function isMain( $index ) {
|
2011-12-13 19:51:03 +00:00
|
|
|
wfDeprecated( __METHOD__, '1.19' );
|
2011-11-22 13:34:55 +00:00
|
|
|
return self::isSubject( $index );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2007-08-14 01:14:42 +00:00
|
|
|
* Is the given namespace a talk namespace?
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index namespace index
|
2004-09-02 23:28:24 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2007-08-14 01:14:42 +00:00
|
|
|
public static function isTalk( $index ) {
|
|
|
|
|
return $index > NS_MAIN
|
|
|
|
|
&& $index % 2;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2007-08-14 01:14:42 +00:00
|
|
|
* Get the talk namespace index for a given namespace
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index namespace index
|
2007-08-14 01:14:42 +00:00
|
|
|
* @return int
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2007-08-14 01:14:42 +00:00
|
|
|
public static function getTalk( $index ) {
|
2011-02-21 22:17:06 +00:00
|
|
|
self::isMethodValidFor( $index, __METHOD__ );
|
2007-08-14 01:14:42 +00:00
|
|
|
return self::isTalk( $index )
|
|
|
|
|
? $index
|
|
|
|
|
: $index + 1;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
|
|
|
|
|
2007-08-14 01:14:42 +00:00
|
|
|
/**
|
|
|
|
|
* Get the subject namespace index for a given namespace
|
2011-02-21 22:17:06 +00:00
|
|
|
* Special namespaces (NS_MEDIA, NS_SPECIAL) are always the subject.
|
2007-08-14 01:14:42 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index Namespace index
|
2007-08-14 01:14:42 +00:00
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public static function getSubject( $index ) {
|
2011-02-21 22:17:06 +00:00
|
|
|
# Handle special namespaces
|
2011-12-16 10:58:20 +00:00
|
|
|
if ( $index < NS_MAIN ) {
|
2011-02-21 22:17:06 +00:00
|
|
|
return $index;
|
|
|
|
|
}
|
|
|
|
|
|
2007-08-14 01:14:42 +00:00
|
|
|
return self::isTalk( $index )
|
|
|
|
|
? $index - 1
|
|
|
|
|
: $index;
|
2003-04-14 23:10:40 +00:00
|
|
|
}
|
2010-02-05 04:25:30 +00:00
|
|
|
|
2011-02-21 22:17:06 +00:00
|
|
|
/**
|
|
|
|
|
* Get the associated namespace.
|
|
|
|
|
* For talk namespaces, returns the subject (non-talk) namespace
|
|
|
|
|
* For subject (non-talk) namespaces, returns the talk namespace
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index namespace index
|
2011-02-21 22:17:06 +00:00
|
|
|
* @return int or null if no associated namespace could be found
|
|
|
|
|
*/
|
|
|
|
|
public static function getAssociated( $index ) {
|
|
|
|
|
self::isMethodValidFor( $index, __METHOD__ );
|
|
|
|
|
|
2011-12-16 10:58:20 +00:00
|
|
|
if ( self::isSubject( $index ) ) {
|
2011-02-21 22:17:06 +00:00
|
|
|
return self::getTalk( $index );
|
2011-12-16 10:58:20 +00:00
|
|
|
} elseif ( self::isTalk( $index ) ) {
|
2011-02-21 22:17:06 +00:00
|
|
|
return self::getSubject( $index );
|
|
|
|
|
} else {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-16 04:06:30 +00:00
|
|
|
/**
|
|
|
|
|
* Returns whether the specified namespace exists
|
2011-05-21 19:07:24 +00:00
|
|
|
*
|
|
|
|
|
* @param $index
|
2011-12-15 01:02:25 +00:00
|
|
|
*
|
2011-05-21 19:07:24 +00:00
|
|
|
* @return bool
|
2011-11-22 13:34:55 +00:00
|
|
|
* @since 1.19
|
2009-10-16 04:06:30 +00:00
|
|
|
*/
|
|
|
|
|
public static function exists( $index ) {
|
2010-08-20 10:25:10 +00:00
|
|
|
$nslist = self::getCanonicalNamespaces();
|
|
|
|
|
return isset( $nslist[$index] );
|
2009-10-16 04:06:30 +00:00
|
|
|
}
|
|
|
|
|
|
2011-11-22 13:34:55 +00:00
|
|
|
/**
|
|
|
|
|
* Returns whether the specified namespaces are the same namespace
|
|
|
|
|
*
|
|
|
|
|
* @note It's possible that in the future we may start using something
|
|
|
|
|
* other than just namespace indexes. Under that circumstance making use
|
|
|
|
|
* of this function rather than directly doing comparison will make
|
|
|
|
|
* sure that code will not potentially break.
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $ns1 The first namespace index
|
2013-03-13 07:42:41 +00:00
|
|
|
* @param int $ns2 The second namespace index
|
2011-11-22 13:34:55 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
public static function equals( $ns1, $ns2 ) {
|
|
|
|
|
return $ns1 == $ns2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether the specified namespaces share the same subject.
|
|
|
|
|
* eg: NS_USER and NS_USER wil return true, as well
|
|
|
|
|
* NS_USER and NS_USER_TALK will return true.
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $ns1 The first namespace index
|
2013-03-13 07:42:41 +00:00
|
|
|
* @param int $ns2 The second namespace index
|
2011-11-22 13:34:55 +00:00
|
|
|
*
|
|
|
|
|
* @return bool
|
|
|
|
|
* @since 1.19
|
|
|
|
|
*/
|
|
|
|
|
public static function subjectEquals( $ns1, $ns2 ) {
|
|
|
|
|
return self::getSubject( $ns1 ) == self::getSubject( $ns2 );
|
|
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
2010-08-20 10:25:10 +00:00
|
|
|
* Returns array of all defined namespaces with their canonical
|
|
|
|
|
* (English) names.
|
|
|
|
|
*
|
2012-04-26 10:08:21 +00:00
|
|
|
* @param bool $rebuild rebuild namespace list (default = false). Used for testing.
|
|
|
|
|
*
|
2012-02-13 16:35:59 +00:00
|
|
|
* @return array
|
2010-08-20 10:25:10 +00:00
|
|
|
* @since 1.17
|
|
|
|
|
*/
|
2012-04-26 10:08:21 +00:00
|
|
|
public static function getCanonicalNamespaces( $rebuild = false ) {
|
2010-08-20 10:25:10 +00:00
|
|
|
static $namespaces = null;
|
2012-04-26 10:08:21 +00:00
|
|
|
if ( $namespaces === null || $rebuild ) {
|
2010-08-20 10:25:10 +00:00
|
|
|
global $wgExtraNamespaces, $wgCanonicalNamespaceNames;
|
2011-01-21 03:48:00 +00:00
|
|
|
$namespaces = array( NS_MAIN => '' ) + $wgCanonicalNamespaceNames;
|
2010-08-20 10:25:10 +00:00
|
|
|
if ( is_array( $wgExtraNamespaces ) ) {
|
2011-01-21 03:48:00 +00:00
|
|
|
$namespaces += $wgExtraNamespaces;
|
2010-08-20 10:25:10 +00:00
|
|
|
}
|
2010-08-24 19:58:55 +00:00
|
|
|
wfRunHooks( 'CanonicalNamespaces', array( &$namespaces ) );
|
2010-08-20 10:25:10 +00:00
|
|
|
}
|
|
|
|
|
return $namespaces;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns the canonical (English) name for a given index
|
2007-08-14 01:14:42 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index namespace index
|
2008-12-16 23:57:21 +00:00
|
|
|
* @return string or false if no canonical definition.
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2007-08-14 01:14:42 +00:00
|
|
|
public static function getCanonicalName( $index ) {
|
2010-08-20 10:25:10 +00:00
|
|
|
$nslist = self::getCanonicalNamespaces();
|
2011-12-16 10:58:20 +00:00
|
|
|
if ( isset( $nslist[$index] ) ) {
|
2010-08-20 10:25:10 +00:00
|
|
|
return $nslist[$index];
|
2008-12-16 23:57:21 +00:00
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2004-04-05 10:38:40 +00:00
|
|
|
}
|
|
|
|
|
|
2004-09-02 23:28:24 +00:00
|
|
|
/**
|
|
|
|
|
* Returns the index for a given canonical name, or NULL
|
|
|
|
|
* The input *must* be converted to lower case first
|
2007-08-14 01:14:42 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param string $name namespace name
|
2007-08-14 01:14:42 +00:00
|
|
|
* @return int
|
2004-09-02 23:28:24 +00:00
|
|
|
*/
|
2007-08-14 01:14:42 +00:00
|
|
|
public static function getCanonicalIndex( $name ) {
|
2004-04-05 10:38:40 +00:00
|
|
|
static $xNamespaces = false;
|
|
|
|
|
if ( $xNamespaces === false ) {
|
|
|
|
|
$xNamespaces = array();
|
2010-08-20 10:25:10 +00:00
|
|
|
foreach ( self::getCanonicalNamespaces() as $i => $text ) {
|
2011-12-16 10:58:20 +00:00
|
|
|
$xNamespaces[strtolower( $text )] = $i;
|
2004-04-05 10:38:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if ( array_key_exists( $name, $xNamespaces ) ) {
|
|
|
|
|
return $xNamespaces[$name];
|
|
|
|
|
} else {
|
2009-12-11 21:07:27 +00:00
|
|
|
return null;
|
2004-04-05 10:38:40 +00:00
|
|
|
}
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-07-25 22:29:05 +00:00
|
|
|
/**
|
|
|
|
|
* Returns an array of the namespaces (by integer id) that exist on the
|
|
|
|
|
* wiki. Used primarily by the api in help documentation.
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
public static function getValidNamespaces() {
|
|
|
|
|
static $mValidNamespaces = null;
|
|
|
|
|
|
|
|
|
|
if ( is_null( $mValidNamespaces ) ) {
|
2010-08-20 10:25:10 +00:00
|
|
|
foreach ( array_keys( self::getCanonicalNamespaces() ) as $ns ) {
|
2010-08-23 08:46:13 +00:00
|
|
|
if ( $ns >= 0 ) {
|
2010-07-25 22:29:05 +00:00
|
|
|
$mValidNamespaces[] = $ns;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $mValidNamespaces;
|
|
|
|
|
}
|
|
|
|
|
|
2006-04-12 15:38:17 +00:00
|
|
|
/**
|
|
|
|
|
* Can this namespace ever have a talk namespace?
|
2007-08-14 01:14:42 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index namespace index
|
2007-08-14 01:14:42 +00:00
|
|
|
* @return bool
|
2006-04-12 15:38:17 +00:00
|
|
|
*/
|
2013-02-03 20:05:24 +00:00
|
|
|
public static function canTalk( $index ) {
|
2010-02-05 04:25:30 +00:00
|
|
|
return $index >= NS_MAIN;
|
2013-02-03 20:05:24 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-01-08 15:32:58 +00:00
|
|
|
/**
|
2008-05-23 22:00:14 +00:00
|
|
|
* Does this namespace contain content, for the purposes of calculating
|
|
|
|
|
* statistics, etc?
|
2007-01-08 15:32:58 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index index to check
|
2007-01-08 15:32:58 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function isContent( $index ) {
|
|
|
|
|
global $wgContentNamespaces;
|
|
|
|
|
return $index == NS_MAIN || in_array( $index, $wgContentNamespaces );
|
2007-07-05 18:20:46 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2007-07-05 18:20:46 +00:00
|
|
|
/**
|
|
|
|
|
* Can pages in a namespace be watched?
|
|
|
|
|
*
|
2008-05-21 18:18:58 +00:00
|
|
|
* @param $index Int
|
2007-07-05 18:20:46 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function isWatchable( $index ) {
|
|
|
|
|
return $index >= NS_MAIN;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2008-05-23 22:00:14 +00:00
|
|
|
/**
|
|
|
|
|
* Does the namespace allow subpages?
|
|
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index Index to check
|
2008-05-23 22:00:14 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function hasSubpages( $index ) {
|
|
|
|
|
global $wgNamespacesWithSubpages;
|
|
|
|
|
return !empty( $wgNamespacesWithSubpages[$index] );
|
|
|
|
|
}
|
2010-02-05 04:25:30 +00:00
|
|
|
|
2010-12-22 14:16:25 +00:00
|
|
|
/**
|
|
|
|
|
* Get a list of all namespace indices which are considered to contain content
|
|
|
|
|
* @return array of namespace indices
|
|
|
|
|
*/
|
|
|
|
|
public static function getContentNamespaces() {
|
|
|
|
|
global $wgContentNamespaces;
|
2011-12-16 10:58:20 +00:00
|
|
|
if ( !is_array( $wgContentNamespaces ) || $wgContentNamespaces === array() ) {
|
2010-12-22 14:16:25 +00:00
|
|
|
return NS_MAIN;
|
|
|
|
|
} elseif ( !in_array( NS_MAIN, $wgContentNamespaces ) ) {
|
|
|
|
|
// always force NS_MAIN to be part of array (to match the algorithm used by isContent)
|
|
|
|
|
return array_merge( array( NS_MAIN ), $wgContentNamespaces );
|
|
|
|
|
} else {
|
|
|
|
|
return $wgContentNamespaces;
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-06-26 14:45:06 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List all namespace indices which are considered subject, aka not a talk
|
|
|
|
|
* or special namespace. See also MWNamespace::isSubject
|
|
|
|
|
*
|
|
|
|
|
* @return array of namespace indices
|
|
|
|
|
*/
|
|
|
|
|
public static function getSubjectNamespaces() {
|
|
|
|
|
return array_filter(
|
|
|
|
|
MWNamespace::getValidNamespaces(),
|
|
|
|
|
'MWNamespace::isSubject'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* List all namespace indices which are considered talks, aka not a subject
|
|
|
|
|
* or special namespace. See also MWNamespace::isTalk
|
|
|
|
|
*
|
|
|
|
|
* @return array of namespace indices
|
|
|
|
|
*/
|
|
|
|
|
public static function getTalkNamespaces() {
|
|
|
|
|
return array_filter(
|
|
|
|
|
MWNamespace::getValidNamespaces(),
|
|
|
|
|
'MWNamespace::isTalk'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2009-10-09 12:52:16 +00:00
|
|
|
/**
|
|
|
|
|
* Is the namespace first-letter capitalized?
|
2010-02-05 04:25:30 +00:00
|
|
|
*
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index Index to check
|
2009-10-09 12:52:16 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function isCapitalized( $index ) {
|
|
|
|
|
global $wgCapitalLinks, $wgCapitalLinkOverrides;
|
|
|
|
|
// Turn NS_MEDIA into NS_FILE
|
|
|
|
|
$index = $index === NS_MEDIA ? NS_FILE : $index;
|
2010-02-05 04:25:30 +00:00
|
|
|
|
2009-10-09 12:52:16 +00:00
|
|
|
// Make sure to get the subject of our namespace
|
|
|
|
|
$index = self::getSubject( $index );
|
2010-02-05 04:25:30 +00:00
|
|
|
|
2009-10-09 12:52:16 +00:00
|
|
|
// Some namespaces are special and should always be upper case
|
|
|
|
|
if ( in_array( $index, self::$alwaysCapitalizedNamespaces ) ) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if ( isset( $wgCapitalLinkOverrides[ $index ] ) ) {
|
|
|
|
|
// $wgCapitalLinkOverrides is explicitly set
|
|
|
|
|
return $wgCapitalLinkOverrides[ $index ];
|
|
|
|
|
}
|
|
|
|
|
// Default to the global setting
|
|
|
|
|
return $wgCapitalLinks;
|
|
|
|
|
}
|
2011-02-12 20:40:40 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Does the namespace (potentially) have different aliases for different
|
|
|
|
|
* genders. Not all languages make a distinction here.
|
|
|
|
|
*
|
|
|
|
|
* @since 1.18
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index Index to check
|
2011-02-12 20:40:40 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
|
|
|
|
public static function hasGenderDistinction( $index ) {
|
|
|
|
|
return $index == NS_USER || $index == NS_USER_TALK;
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-05 08:22:28 +00:00
|
|
|
/**
|
|
|
|
|
* It is not possible to use pages from this namespace as template?
|
|
|
|
|
*
|
|
|
|
|
* @since 1.20
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index Index to check
|
2012-05-05 08:22:28 +00:00
|
|
|
* @return bool
|
|
|
|
|
*/
|
2012-05-11 17:52:34 +00:00
|
|
|
public static function isNonincludable( $index ) {
|
2012-05-05 08:22:28 +00:00
|
|
|
global $wgNonincludableNamespaces;
|
|
|
|
|
return $wgNonincludableNamespaces && in_array( $index, $wgNonincludableNamespaces );
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-13 20:05:15 +00:00
|
|
|
/**
|
|
|
|
|
* Get the default content model for a namespace
|
|
|
|
|
* This does not mean that all pages in that namespace have the model
|
|
|
|
|
*
|
|
|
|
|
* @since 1.21
|
2013-03-11 17:15:01 +00:00
|
|
|
* @param int $index Index to check
|
2012-12-13 20:05:15 +00:00
|
|
|
* @return null|string default model name for the given namespace, if set
|
|
|
|
|
*/
|
|
|
|
|
public static function getNamespaceContentModel( $index ) {
|
|
|
|
|
global $wgNamespaceContentModels;
|
|
|
|
|
return isset( $wgNamespaceContentModels[$index] )
|
|
|
|
|
? $wgNamespaceContentModels[$index]
|
|
|
|
|
: null;
|
|
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
}
|