MediaWiki  master
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...

Collaboration diagram for MWNamespace:

Static Public Member Functions

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

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. More...
 

Static Private Attributes

static $alwaysCapitalizedNamespaces = [ NS_SPECIAL, NS_USER, NS_MEDIAWIKI ]
 These namespaces should always be first-letter capitalized, now and forevermore. More...
 
static string[] null $canonicalNamespaces = null
 Canonical namespaces cache. More...
 
static array false $namespaceIndexes = false
 Canonical namespaces index cache. More...
 
static int[] null $validNamespaces = null
 Valid namespaces cache. More...
 

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 32 of file MWNamespace.php.

Member Function Documentation

static MWNamespace::canTalk (   $index)
static

Does this namespace ever have a talk namespace?

Deprecated:
since 1.30, use hasTalkNamespace() instead.
Parameters
int$indexNamespace index
Returns
bool True if this namespace either is or has a corresponding talk namespace.

Definition at line 312 of file MWNamespace.php.

Referenced by ChangesFeed\buildItems(), and MWNamespaceTest\testCanTalk().

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 201 of file MWNamespace.php.

Referenced by Title\inNamespace(), and MWNamespaceTest\testEquals().

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 162 of file MWNamespace.php.

Referenced by ChangesListSpecialPage\buildQuery(), ContribsPager\getNamespaceCond(), MWNamespaceTest\testGetAssociated(), MWNamespaceTest\testGetAssociatedExceptionsForNsMedia(), and MWNamespaceTest\testGetAssociatedExceptionsForNsSpecial().

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 271 of file MWNamespace.php.

References $name, and as.

Referenced by Language\getNsIndex().

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. Deprecated since 1.31, use self::clearCaches() instead.
Returns
array
Since
1.17

Definition at line 230 of file MWNamespace.php.

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

Referenced by NamespaceConflictChecker\checkAll(), ResourceLoaderStartUpModule\getConfigSettings(), and Language\getNamespaces().

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 473 of file MWNamespace.php.

References global.

Referenced by ApiQuerySiteinfo\appendNamespaces(), and ContentHandler\getDefaultModelFor().

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 489 of file MWNamespace.php.

References $user, $wgNamespaceProtection, array(), as, User\getGroupsWithPermission(), global, and use.

Referenced by EditPage\addPageProtectionWarningHeaders(), SkinTemplate\buildContentNavigationUrls(), ProtectionForm\buildSelector(), ProtectionForm\execute(), ProtectionForm\loadData(), and EditPage\showTextbox1().

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 143 of file MWNamespace.php.

References NS_MAIN.

Referenced by Title\getNamespaceKey(), Title\getSubjectNsText(), Title\getSubjectPage(), ApiQueryInfo\getTSIDs(), MovePage\move(), MediaWiki\Widget\Search\SearchFormWidget\powerSearchBox(), SkinTemplate\tabAction(), MWNamespaceTest\testGetSubject(), and SpecialEditWatchlist\watchTitles().

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 395 of file MWNamespace.php.

Referenced by MWNamespaceTest\testGetSubjectNamespaces().

static MWNamespace::getTalk (   $index)
static
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 408 of file MWNamespace.php.

Referenced by MWNamespaceTest\testGetTalkNamespaces().

static MWNamespace::getValidNamespaces ( )
static
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 449 of file MWNamespace.php.

References NS_USER_TALK.

Referenced by GenderCache\doLinkBatch(), GenderCache\doTitlesArray(), MediaWikiTitleCodec\getNamespaceName(), ApiPageSet\initFromQueryResult(), ApiPageSet\processTitlesArray(), ApiQueryAllPages\run(), and MWNamespaceTest\testHasGenderDistinction().

static MWNamespace::hasTalkNamespace (   $index)
static

Does this namespace ever have a talk namespace?

Since
1.30
Parameters
int$indexNamespace ID
Returns
bool True if this namespace either is or has a corresponding talk namespace.

Definition at line 324 of file MWNamespace.php.

References NS_MAIN.

Referenced by Title\canHaveTalkPage(), and MWNamespaceTest\testHasTalkNamespace().

static MWNamespace::isCapitalized (   $index)
static
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 335 of file MWNamespace.php.

References $wgContentNamespaces, global, and NS_MAIN.

Referenced by ApiQuerySiteinfo\appendNamespaces(), MediaWiki\Linker\LinkRenderer\getLinkClasses(), and Title\isContentPage().

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 62 of file MWNamespace.php.

References NS_MAIN.

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 88 of file MWNamespace.php.

References $wgAllowImageMoving, global, NS_FILE, NS_MAIN, and Hooks\run().

Referenced by Title\checkActionPermissions(), Title\isMovable(), MovePageForm\showForm(), and MWNamespaceTest\testIsMovable().

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 460 of file MWNamespace.php.

References global.

Referenced by ApiQuerySiteinfo\appendNamespaces(), Parser\braceSubstitution(), and MWNamespaceTest\testIsNonincludable().

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 108 of file MWNamespace.php.

Referenced by NamespaceConflictChecker\getDestinationTitle(), NamespaceConflictChecker\getTargetList(), and GenerateSitemap\guessPriority().

static MWNamespace::isTalk (   $index)
static

Is the given namespace a talk namespace?

Parameters
int$indexNamespace index
Returns
bool

Definition at line 118 of file MWNamespace.php.

References NS_MAIN.

Referenced by MediaWikiTestCase\getDefaultWikitextNS(), ApiQueryInfo\getTSIDs(), SpecialEditWatchlist\getWatchlistInfo(), Title\isTalkPage(), and DumpNotalkFilter\pass().

static MWNamespace::isWatchable (   $index)
static

Can pages in a namespace be watched?

Parameters
int$index
Returns
bool

Definition at line 358 of file MWNamespace.php.

References NS_MAIN.

Referenced by Title\isWatchable().

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 216 of file MWNamespace.php.

Referenced by MWNamespaceTest\assertDifferentSubject(), MWNamespaceTest\assertSameSubject(), and Title\hasSubjectNamespace().

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 347 of file MWNamespace.php.

References global.

Referenced by EditPage\getEditToolbar().

Member Data Documentation

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 39 of file MWNamespace.php.

string [] null MWNamespace::$canonicalNamespaces = null
staticprivate

Canonical namespaces cache.

Definition at line 42 of file MWNamespace.php.

array false MWNamespace::$namespaceIndexes = false
staticprivate

Canonical namespaces index cache.

Definition at line 45 of file MWNamespace.php.

int [] null MWNamespace::$validNamespaces = null
staticprivate

Valid namespaces cache.

Definition at line 48 of file MWNamespace.php.


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