MediaWiki  1.23.13
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? 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 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 isMain ( $index)
 
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 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 = array( NS_SPECIAL, NS_USER, NS_MEDIAWIKI )
 These namespaces should always be first-letter capitalized, now and forevermore. 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 33 of file Namespace.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 293 of file Namespace.php.

References NS_MAIN.

Referenced by ChangesFeed\buildItems(), and Title\canTalk().

◆ 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 190 of file Namespace.php.

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

◆ exists()

static MWNamespace::exists (   $index)
static

Returns whether the specified namespace exists.

Parameters
$index
Returns
bool
Since
1.19

Definition at line 171 of file Namespace.php.

References getCanonicalNamespaces().

Referenced by Linker\getInvalidTitleDescription(), OutputPage\getJSVars(), Title\getNamespaceKey(), Title\getNsText(), Title\makeTitleSafe(), and TitleCleanup\moveInconsistentPage().

◆ 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 or null if no associated namespace could be found

Definition at line 151 of file Namespace.php.

References getSubject(), getTalk(), and isMethodValidFor().

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

◆ 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 253 of file Namespace.php.

References $name, array(), and as.

Referenced by Language\getNsIndex().

◆ getCanonicalName()

static MWNamespace::getCanonicalName (   $index)
static

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

Parameters
int$indexnamespace index
Returns
string or false if no canonical definition.

Definition at line 237 of file Namespace.php.

References getCanonicalNamespaces().

Referenced by MWNamespaceTest\__call(), RevisionStorageTest\createPage(), SpecialListGroupRights\execute(), Linker\formatLinksInCommentCallback(), SpecialStatistics\getGroupStats(), OutputPage\getJSVars(), Title\getNamespaceKey(), Title\getNsText(), and Title\moveSubpages().

◆ getCanonicalNamespaces()

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

◆ getContentNamespaces()

◆ 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 430 of file Namespace.php.

References global.

Referenced by ContentHandler\getDefaultModelFor().

◆ 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 446 of file Namespace.php.

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

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

◆ 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 132 of file Namespace.php.

References isTalk(), and NS_MAIN.

Referenced by WatchedItem\addWatch(), getAssociated(), Title\getNamespaceKey(), Title\getSubjectNsText(), Title\getSubjectPage(), ApiQueryInfo\getTSIDs(), isCapitalized(), Title\moveTo(), SpecialSearch\powerSearchBox(), WatchedItem\removeWatch(), subjectEquals(), SkinTemplate\tabAction(), MWNamespaceTest\testGetSubject(), SpecialEditWatchlist\unwatchTitles(), and SpecialEditWatchlist\watchTitles().

◆ 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 of namespace indices

Definition at line 352 of file Namespace.php.

References getValidNamespaces().

Referenced by MWNamespaceTest\testGetSubjectNamespaces().

◆ getTalk()

◆ 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 of namespace indices

Definition at line 365 of file Namespace.php.

References getValidNamespaces().

Referenced by MWNamespaceTest\testGetTalkNamespaces().

◆ 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
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 273 of file Namespace.php.

References as.

Referenced by SpecialTrackingCategories\execute(), MediaWikiTestCase\getDefaultWikitextNS(), getSubjectNamespaces(), getTalkNamespaces(), and SpecialListGroupRights\outputNamespaceProtectionInfo().

◆ 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 406 of file Namespace.php.

References NS_USER, and NS_USER_TALK.

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

◆ hasSubpages()

◆ isCapitalized()

static MWNamespace::isCapitalized (   $index)
static

Is the namespace first-letter capitalized?

Parameters
int$indexIndex to check
Returns
bool

Definition at line 378 of file Namespace.php.

References getSubject(), global, NS_FILE, and NS_MEDIA.

Referenced by FileRepo\__construct(), UploadForm\addUploadJS(), Title\capitalize(), ResourceLoaderStartUpModule\getConfig(), FileRepo\getNameFromTitle(), XmlDumpWriter\namespaces(), and MWNamespaceTest\testIsCapitalizedHardcodedAssertions().

◆ 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 304 of file Namespace.php.

References global, and NS_MAIN.

Referenced by Title\isContentPage().

◆ isMain()

static MWNamespace::isMain (   $index)
static
See also
self::isSubject
Deprecated:
Please use the more consistently named isSubject (since 1.19)
Returns
bool

Definition at line 96 of file Namespace.php.

References isSubject(), and wfDeprecated().

◆ 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
$index
$method
Exceptions
MWException
Returns
bool

Definition at line 54 of file Namespace.php.

References NS_MAIN.

Referenced by getAssociated(), and getTalk().

◆ 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 Namespace.php.

References array(), global, NS_CATEGORY, NS_FILE, NS_MAIN, and wfRunHooks().

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

◆ 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 417 of file Namespace.php.

References global.

Referenced by MWNamespaceTest\testIsNonincludable().

◆ 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 Namespace.php.

References isTalk().

Referenced by isMain().

◆ isTalk()

static MWNamespace::isTalk (   $index)
static

Is the given namespace a talk namespace?

Parameters
int$indexnamespace index
Returns
bool
Examples
/src/tests/phpunit/MediaWikiTestCase.php.

Definition at line 107 of file Namespace.php.

References NS_MAIN.

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

◆ isWatchable()

static MWNamespace::isWatchable (   $index)
static

Can pages in a namespace be watched?

Parameters
$indexInt
Returns
bool

Definition at line 315 of file Namespace.php.

References NS_MAIN.

Referenced by Title\isWatchable().

◆ 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 205 of file Namespace.php.

References getSubject().

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

Member Data Documentation

◆ $alwaysCapitalizedNamespaces

MWNamespace::$alwaysCapitalizedNamespaces = array( 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 Namespace.php.


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