MediaWiki REL1_28
MWNamespace Class Reference

This is a utility class with only static functions for dealing with namespaces that encodes all the "magic" behaviors of them based on index. More...

Static Public Member Functions

static canTalk ( $index)
 Can this namespace ever have a talk namespace?
 
static equals ( $ns1, $ns2)
 Returns whether the specified namespaces are the same namespace.
 
static exists ( $index)
 Returns whether the specified namespace exists.
 
static getAssociated ( $index)
 Get the associated namespace.
 
static getCanonicalIndex ( $name)
 Returns the index for a given canonical name, or NULL The input must be converted to lower case first.
 
static getCanonicalName ( $index)
 Returns the canonical (English) name for a given index.
 
static getCanonicalNamespaces ( $rebuild=false)
 Returns array of all defined namespaces with their canonical (English) names.
 
static getContentNamespaces ()
 Get a list of all namespace indices which are considered to contain content.
 
static getNamespaceContentModel ( $index)
 Get the default content model for a namespace This does not mean that all pages in that namespace have the model.
 
static getRestrictionLevels ( $index, User $user=null)
 Determine which restriction levels it makes sense to use in a namespace, optionally filtered by a user's rights.
 
static getSubject ( $index)
 Get the subject namespace index for a given namespace Special namespaces (NS_MEDIA, NS_SPECIAL) are always the subject.
 
static getSubjectNamespaces ()
 List all namespace indices which are considered subject, aka not a talk or special namespace.
 
static getTalk ( $index)
 Get the talk namespace index for a given namespace.
 
static getTalkNamespaces ()
 List all namespace indices which are considered talks, aka not a subject or special namespace.
 
static getValidNamespaces ()
 Returns an array of the namespaces (by integer id) that exist on the wiki.
 
static hasGenderDistinction ( $index)
 Does the namespace (potentially) have different aliases for different genders.
 
static hasSubpages ( $index)
 Does the namespace allow subpages?
 
static isCapitalized ( $index)
 Is the namespace first-letter capitalized?
 
static isContent ( $index)
 Does this namespace contain content, for the purposes of calculating statistics, etc?
 
static isMovable ( $index)
 Can pages in the given namespace be moved?
 
static isNonincludable ( $index)
 It is not possible to use pages from this namespace as template?
 
static isSubject ( $index)
 Is the given namespace is a subject (non-talk) namespace?
 
static isTalk ( $index)
 Is the given namespace a talk namespace?
 
static isWatchable ( $index)
 Can pages in a namespace be watched?
 
static subjectEquals ( $ns1, $ns2)
 Returns whether the specified namespaces share the same subject.
 
static wantSignatures ( $index)
 Might pages in this namespace require the use of the Signature button on the edit toolbar?
 

Static Private Member Functions

static isMethodValidFor ( $index, $method)
 Throw an exception when trying to get the subject or talk page for a given namespace where it does not make sense.
 

Static Private Attributes

static $alwaysCapitalizedNamespaces = [ NS_SPECIAL, NS_USER, NS_MEDIAWIKI ]
 These namespaces should always be first-letter capitalized, now and forevermore.
 

Detailed Description

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

Definition at line 33 of file MWNamespace.php.

Member Function Documentation

◆ canTalk()

static MWNamespace::canTalk (   $index)
static

Can this namespace ever have a talk namespace?

Parameters
int$indexNamespace index
Returns
bool

Definition at line 287 of file MWNamespace.php.

References NS_MAIN.

◆ equals()

static MWNamespace::equals (   $ns1,
  $ns2 
)
static

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.
Parameters
int$ns1The first namespace index
int$ns2The second namespace index
Returns
bool
Since
1.19

Definition at line 180 of file MWNamespace.php.

◆ exists()

static MWNamespace::exists (   $index)
static

Returns whether the specified namespace exists.

Parameters
int$index
Returns
bool
Since
1.19

Definition at line 161 of file MWNamespace.php.

◆ getAssociated()

static MWNamespace::getAssociated (   $index)
static

Get the associated namespace.

For talk namespaces, returns the subject (non-talk) namespace For subject (non-talk) namespaces, returns the talk namespace

Parameters
int$indexNamespace index
Returns
int|null If no associated namespace could be found

Definition at line 141 of file MWNamespace.php.

◆ getCanonicalIndex()

static MWNamespace::getCanonicalIndex (   $name)
static

Returns the index for a given canonical name, or NULL The input must be converted to lower case first.

Parameters
string$nameNamespace name
Returns
int

Definition at line 245 of file MWNamespace.php.

References $name, and as.

◆ getCanonicalName()

static MWNamespace::getCanonicalName (   $index)
static

Returns the canonical (English) name for a given index.

Parameters
int$indexNamespace index
Returns
string|bool If no canonical definition.

Definition at line 229 of file MWNamespace.php.

◆ getCanonicalNamespaces()

static MWNamespace::getCanonicalNamespaces (   $rebuild = false)
static

Returns array of all defined namespaces with their canonical (English) names.

Parameters
bool$rebuildRebuild namespace list (default = false). Used for testing.
Returns
array
Since
1.17

Definition at line 208 of file MWNamespace.php.

References $namespaces, $wgCanonicalNamespaceNames, $wgExtraNamespaces, ExtensionRegistry\getInstance(), global, and NS_MAIN.

◆ getContentNamespaces()

static MWNamespace::getContentNamespaces ( )
static

Get a list of all namespace indices which are considered to contain content.

Returns
array Array of namespace indices

Definition at line 340 of file MWNamespace.php.

References $wgContentNamespaces, global, and NS_MAIN.

◆ getNamespaceContentModel()

static MWNamespace::getNamespaceContentModel (   $index)
static

Get the default content model for a namespace This does not mean that all pages in that namespace have the model.

Since
1.21
Parameters
int$indexIndex to check
Returns
null|string Default model name for the given namespace, if set

Definition at line 436 of file MWNamespace.php.

References $wgNamespaceContentModels, and global.

◆ getRestrictionLevels()

static MWNamespace::getRestrictionLevels (   $index,
User  $user = null 
)
static

Determine which restriction levels it makes sense to use in a namespace, optionally filtered by a user's rights.

Since
1.23
Parameters
int$indexIndex to check
User$userUser to check
Returns
array

Definition at line 452 of file MWNamespace.php.

References $user, $wgNamespaceProtection, $wgRestrictionLevels, array(), as, global, and use.

◆ getSubject()

static MWNamespace::getSubject (   $index)
static

Get the subject namespace index for a given namespace Special namespaces (NS_MEDIA, NS_SPECIAL) are always the subject.

Parameters
int$indexNamespace index
Returns
int

Definition at line 122 of file MWNamespace.php.

References NS_MAIN.

◆ getSubjectNamespaces()

static MWNamespace::getSubjectNamespaces ( )
static

List all namespace indices which are considered subject, aka not a talk or special namespace.

See also MWNamespace::isSubject

Returns
array Array of namespace indices

Definition at line 358 of file MWNamespace.php.

References getValidNamespaces().

◆ getTalk()

static MWNamespace::getTalk (   $index)
static

Get the talk namespace index for a given namespace.

Parameters
int$indexNamespace index
Returns
int

Definition at line 108 of file MWNamespace.php.

◆ getTalkNamespaces()

static MWNamespace::getTalkNamespaces ( )
static

List all namespace indices which are considered talks, aka not a subject or special namespace.

See also MWNamespace::isTalk

Returns
array Array of namespace indices

Definition at line 371 of file MWNamespace.php.

References getValidNamespaces().

◆ getValidNamespaces()

static MWNamespace::getValidNamespaces ( )
static

Returns an array of the namespaces (by integer id) that exist on the wiki.

Used primarily by the api in help documentation.

Returns
array

Definition at line 265 of file MWNamespace.php.

References as.

Referenced by getSubjectNamespaces(), and getTalkNamespaces().

◆ hasGenderDistinction()

static MWNamespace::hasGenderDistinction (   $index)
static

Does the namespace (potentially) have different aliases for different genders.

Not all languages make a distinction here.

Since
1.18
Parameters
int$indexIndex to check
Returns
bool

Definition at line 412 of file MWNamespace.php.

References NS_USER, and NS_USER_TALK.

◆ hasSubpages()

static MWNamespace::hasSubpages (   $index)
static

Does the namespace allow subpages?

Parameters
int$indexIndex to check
Returns
bool

Definition at line 331 of file MWNamespace.php.

References $wgNamespacesWithSubpages, and global.

◆ isCapitalized()

static MWNamespace::isCapitalized (   $index)
static

Is the namespace first-letter capitalized?

Parameters
int$indexIndex to check
Returns
bool

Definition at line 384 of file MWNamespace.php.

References $wgCapitalLinkOverrides, $wgCapitalLinks, global, NS_FILE, and NS_MEDIA.

◆ isContent()

static MWNamespace::isContent (   $index)
static

Does this namespace contain content, for the purposes of calculating statistics, etc?

Parameters
int$indexIndex to check
Returns
bool

Definition at line 298 of file MWNamespace.php.

References $wgContentNamespaces, global, and NS_MAIN.

Referenced by MediaWiki\Linker\LinkRenderer\getLinkClasses().

◆ isMethodValidFor()

static MWNamespace::isMethodValidFor (   $index,
  $method 
)
staticprivate

Throw an exception when trying to get the subject or talk page for a given namespace where it does not make sense.

Special namespaces are defined in includes/Defines.php and have a value below 0 (ex: NS_SPECIAL = -1 , NS_MEDIA = -2)

Parameters
int$index
string$method
Exceptions
MWException
Returns
bool

Definition at line 54 of file MWNamespace.php.

References NS_MAIN.

◆ isMovable()

namespace are movable Hooks may change this value to override the return value of MWNamespace::isMovable (   $index)
static

Can pages in the given namespace be moved?

Parameters
int$indexNamespace index
Returns
bool

Definition at line 67 of file MWNamespace.php.

References $wgAllowImageMoving, global, NS_FILE, and NS_MAIN.

◆ isNonincludable()

static MWNamespace::isNonincludable (   $index)
static

It is not possible to use pages from this namespace as template?

Since
1.20
Parameters
int$indexIndex to check
Returns
bool

Definition at line 423 of file MWNamespace.php.

References $wgNonincludableNamespaces, and global.

◆ isSubject()

static MWNamespace::isSubject (   $index)
static

Is the given namespace is a subject (non-talk) namespace?

Parameters
int$indexNamespace index
Returns
bool
Since
1.19

Definition at line 87 of file MWNamespace.php.

◆ isTalk()

static MWNamespace::isTalk (   $index)
static

Is the given namespace a talk namespace?

Parameters
int$indexNamespace index
Returns
bool

Definition at line 97 of file MWNamespace.php.

References NS_MAIN.

◆ isWatchable()

static MWNamespace::isWatchable (   $index)
static

Can pages in a namespace be watched?

Parameters
int$index
Returns
bool

Definition at line 321 of file MWNamespace.php.

References NS_MAIN.

◆ subjectEquals()

static MWNamespace::subjectEquals (   $ns1,
  $ns2 
)
static

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.

Parameters
int$ns1The first namespace index
int$ns2The second namespace index
Returns
bool
Since
1.19

Definition at line 195 of file MWNamespace.php.

◆ wantSignatures()

static MWNamespace::wantSignatures (   $index)
static

Might pages in this namespace require the use of the Signature button on the edit toolbar?

Parameters
int$indexIndex to check
Returns
bool

Definition at line 310 of file MWNamespace.php.

References $wgExtraSignatureNamespaces, and global.

Member Data Documentation

◆ $alwaysCapitalizedNamespaces

MWNamespace::$alwaysCapitalizedNamespaces = [ NS_SPECIAL, NS_USER, NS_MEDIAWIKI ]
staticprivate

These namespaces should always be first-letter capitalized, now and forevermore.

Historically, they could've probably been lowercased too, but some things are just too ingrained now. :)

Definition at line 40 of file MWNamespace.php.


The documentation for this class was generated from the following files: