MediaWiki master
MediaWiki\Title\NamespaceInfo Class Reference

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

Public Member Functions

 __construct (ServiceOptions $options, HookContainer $hookContainer, array $extensionNamespaces, array $extensionImmovableNamespaces)
 
 canHaveTalkPage (LinkTarget $target)
 Can the title have a corresponding talk page?
 
 equals ( $ns1, $ns2)
 Returns whether the specified namespaces are the same namespace.
 
 exists ( $index)
 Returns whether the specified namespace exists.
 
 getAssociated ( $index)
 Get the associated namespace.
 
 getAssociatedPage (LinkTarget $target)
 
 getCanonicalIndex ( $name)
 Returns the index for a given canonical name, or NULL The input must be converted to lower case first.
 
 getCanonicalName ( $index)
 Returns the canonical (English) name for a given index.
 
 getCanonicalNamespaces ()
 Returns array of all defined namespaces with their canonical (English) names.
 
 getCategoryLinkType ( $index)
 Returns the link type to be used for categories.
 
 getContentNamespaces ()
 Get a list of all namespace indices which are considered to contain content.
 
 getNamespaceContentModel ( $index)
 Get the default content model for a namespace This does not mean that all pages in that namespace have the model.
 
 getSubject ( $index)
 Get the subject namespace index for a given namespace Special namespaces (NS_MEDIA, NS_SPECIAL) are always the subject.
 
 getSubjectNamespaces ()
 List all namespace indices which are considered subject, aka not a talk or special namespace.
 
 getSubjectPage (LinkTarget $target)
 
 getTalk ( $index)
 Get the talk namespace index for a given namespace.
 
 getTalkNamespaces ()
 List all namespace indices which are considered talks, aka not a subject or special namespace.
 
 getTalkPage (LinkTarget $target)
 Get a LinkTarget referring to the talk page of $target.
 
 getValidNamespaces ()
 Returns an array of the namespaces (by integer id) that exist on the wiki.
 
 hasGenderDistinction ( $index)
 Does the namespace (potentially) have different aliases for different genders.
 
 hasSubpages ( $index)
 Does the namespace allow subpages? Note that this refers to structured handling of subpages, and does not include SpecialPage subpage parameters.
 
 hasTalkNamespace ( $index)
 Does this namespace ever have a talk namespace?
 
 isCapitalized ( $index)
 Is the namespace first-letter capitalized?
 
 isContent ( $index)
 Does this namespace contain content, for the purposes of calculating statistics, etc?
 
 isMovable ( $index)
 Can pages in the given namespace be moved?
 
 isNonincludable ( $index)
 It is not possible to use pages from this namespace as template?
 
 isSubject ( $index)
 Is the given namespace is a subject (non-talk) namespace?
 
 isTalk ( $index)
 Is the given namespace a talk namespace?
 
 isWatchable ( $index)
 Can pages in a namespace be watched?
 
 subjectEquals ( $ns1, $ns2)
 Returns whether the specified namespaces share the same subject.
 
 wantSignatures ( $index)
 Might pages in this namespace require the use of the Signature button on the edit toolbar?
 

Static Public Member Functions

static getCommonNamespaces ()
 Retrieve the indexes for the namespaces defined by core.
 

Public Attributes

const CANONICAL_NAMES
 Definitions of the NS_ constants are in Defines.php.
 
const CONSTRUCTOR_OPTIONS
 

Detailed Description

This is a utility class 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.

Since
1.34

Definition at line 39 of file NamespaceInfo.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Title\NamespaceInfo::__construct ( ServiceOptions $options,
HookContainer $hookContainer,
array $extensionNamespaces,
array $extensionImmovableNamespaces )
Parameters
ServiceOptions$options
HookContainer$hookContainer
array$extensionNamespaces
array$extensionImmovableNamespaces

Definition at line 114 of file NamespaceInfo.php.

References MediaWiki\Config\ServiceOptions\assertRequiredOptions().

Member Function Documentation

◆ canHaveTalkPage()

MediaWiki\Title\NamespaceInfo::canHaveTalkPage ( LinkTarget $target)

Can the title have a corresponding talk page?

False for relative section-only links (with getText() === ''), interwiki links (with getInterwiki() !== ''), and pages in NS_SPECIAL.

See also
getTalkPage
Parameters
LinkTarget$target
Returns
bool True if this title either is a talk page or can have a talk page associated.

Definition at line 265 of file NamespaceInfo.php.

References MediaWiki\Linker\LinkTarget\getNamespace(), MediaWiki\Linker\LinkTarget\getText(), MediaWiki\Linker\LinkTarget\isExternal(), and NS_MAIN.

◆ equals()

MediaWiki\Title\NamespaceInfo::equals ( $ns1,
$ns2 )

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

Definition at line 364 of file NamespaceInfo.php.

◆ exists()

MediaWiki\Title\NamespaceInfo::exists ( $index)

Returns whether the specified namespace exists.

Parameters
int$index
Returns
bool

Definition at line 346 of file NamespaceInfo.php.

Referenced by MediaWiki\Title\NamespaceImportTitleFactory\__construct().

◆ getAssociated()

MediaWiki\Title\NamespaceInfo::getAssociated ( $index)

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
Exceptions
MWExceptionif called on a namespace that has no talk pages (e.g., NS_SPECIAL)

Definition at line 311 of file NamespaceInfo.php.

◆ getAssociatedPage()

MediaWiki\Title\NamespaceInfo::getAssociatedPage ( LinkTarget $target)
Parameters
LinkTarget$target
Returns
LinkTarget Talk page for $target if it's a subject page, subject page if it's a talk page
Exceptions
MWExceptionif $target's namespace doesn't have talk pages (e.g., NS_SPECIAL)

Definition at line 326 of file NamespaceInfo.php.

◆ getCanonicalIndex()

MediaWiki\Title\NamespaceInfo::getCanonicalIndex ( $name)

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|null

Definition at line 419 of file NamespaceInfo.php.

◆ getCanonicalName()

MediaWiki\Title\NamespaceInfo::getCanonicalName ( $index)

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

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

Definition at line 407 of file NamespaceInfo.php.

◆ getCanonicalNamespaces()

MediaWiki\Title\NamespaceInfo::getCanonicalNamespaces ( )

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

Returns
string[]

Definition at line 388 of file NamespaceInfo.php.

References NS_MAIN.

◆ getCategoryLinkType()

MediaWiki\Title\NamespaceInfo::getCategoryLinkType ( $index)

Returns the link type to be used for categories.

This determines which section of a category page titles in the namespace will appear within.

Parameters
int$indexNamespace index
Returns
string One of 'subcat', 'file', 'page'

Definition at line 621 of file NamespaceInfo.php.

References NS_CATEGORY, and NS_FILE.

◆ getCommonNamespaces()

static MediaWiki\Title\NamespaceInfo::getCommonNamespaces ( )
static

Retrieve the indexes for the namespaces defined by core.

Since
1.34
Returns
int[]

Definition at line 640 of file NamespaceInfo.php.

◆ getContentNamespaces()

MediaWiki\Title\NamespaceInfo::getContentNamespaces ( )

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

Returns
int[] Array of namespace indices

Definition at line 512 of file NamespaceInfo.php.

References NS_MAIN.

Referenced by MediaWiki\Specials\SpecialRandomPage\__construct().

◆ getNamespaceContentModel()

MediaWiki\Title\NamespaceInfo::getNamespaceContentModel ( $index)

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

Note
To determine the default model for a new page's main slot, or any slot in general, use SlotRoleHandler::getDefaultModel() together with SlotRoleRegistry::getRoleHandler().
Parameters
int$indexIndex to check
Returns
null|string Default model name for the given namespace, if set

Definition at line 608 of file NamespaceInfo.php.

◆ getSubject()

MediaWiki\Title\NamespaceInfo::getSubject ( $index)

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 278 of file NamespaceInfo.php.

References NS_MAIN.

◆ getSubjectNamespaces()

MediaWiki\Title\NamespaceInfo::getSubjectNamespaces ( )

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

See also NamespaceInfo::isSubject

Returns
int[] Array of namespace indices

Definition at line 530 of file NamespaceInfo.php.

◆ getSubjectPage()

MediaWiki\Title\NamespaceInfo::getSubjectPage ( LinkTarget $target)
Parameters
LinkTarget$target
Returns
LinkTarget Subject page for $target

Definition at line 295 of file NamespaceInfo.php.

◆ getTalk()

MediaWiki\Title\NamespaceInfo::getTalk ( $index)

Get the talk namespace index for a given namespace.

Parameters
int$indexNamespace index
Returns
int
Exceptions
MWExceptionif the given namespace doesn't have an associated talk namespace (e.g. NS_SPECIAL).

Definition at line 219 of file NamespaceInfo.php.

References MediaWiki\Title\NamespaceInfo\isTalk().

◆ getTalkNamespaces()

MediaWiki\Title\NamespaceInfo::getTalkNamespaces ( )

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

See also NamespaceInfo::isTalk

Returns
int[] Array of namespace indices

Definition at line 543 of file NamespaceInfo.php.

◆ getTalkPage()

MediaWiki\Title\NamespaceInfo::getTalkPage ( LinkTarget $target)

Get a LinkTarget referring to the talk page of $target.

See also
canHaveTalkPage
Parameters
LinkTarget$target
Returns
LinkTarget Talk page for $target
Exceptions
MWExceptionif $target doesn't have talk pages, e.g. because it's in NS_SPECIAL, because it's a relative section-only link, or it's an interwiki link.

Definition at line 237 of file NamespaceInfo.php.

◆ getValidNamespaces()

MediaWiki\Title\NamespaceInfo::getValidNamespaces ( )

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

Used primarily by the API in help documentation. The array is sorted numerically and omits negative namespaces.

Returns
array

Definition at line 438 of file NamespaceInfo.php.

◆ hasGenderDistinction()

MediaWiki\Title\NamespaceInfo::hasGenderDistinction ( $index)

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

Not all languages make a distinction here.

Parameters
int$indexIndex to check
Returns
bool

Definition at line 583 of file NamespaceInfo.php.

References NS_USER, and NS_USER_TALK.

◆ hasSubpages()

MediaWiki\Title\NamespaceInfo::hasSubpages ( $index)

Does the namespace allow subpages? Note that this refers to structured handling of subpages, and does not include SpecialPage subpage parameters.

Parameters
int$indexIndex to check
Returns
bool

Definition at line 504 of file NamespaceInfo.php.

Referenced by MediaWiki\Title\SubpageImportTitleFactory\__construct().

◆ hasTalkNamespace()

MediaWiki\Title\NamespaceInfo::hasTalkNamespace ( $index)

Does this namespace ever have a talk namespace?

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

Definition at line 459 of file NamespaceInfo.php.

References NS_MAIN.

◆ isCapitalized()

MediaWiki\Title\NamespaceInfo::isCapitalized ( $index)

Is the namespace first-letter capitalized?

Parameters
int$indexIndex to check
Returns
bool

Definition at line 556 of file NamespaceInfo.php.

References NS_FILE, and NS_MEDIA.

◆ isContent()

MediaWiki\Title\NamespaceInfo::isContent ( $index)

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

Parameters
int$indexIndex to check
Returns
bool

Definition at line 470 of file NamespaceInfo.php.

References NS_MAIN.

◆ isMovable()

MediaWiki\Title\NamespaceInfo::isMovable ( $index)

Can pages in the given namespace be moved?

Parameters
int$indexNamespace index
Returns
bool

Definition at line 177 of file NamespaceInfo.php.

References NS_MAIN.

◆ isNonincludable()

MediaWiki\Title\NamespaceInfo::isNonincludable ( $index)

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

Parameters
int$indexIndex to check
Returns
bool

Definition at line 593 of file NamespaceInfo.php.

◆ isSubject()

MediaWiki\Title\NamespaceInfo::isSubject ( $index)

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

Parameters
int$indexNamespace index
Returns
bool

Definition at line 194 of file NamespaceInfo.php.

References MediaWiki\Title\NamespaceInfo\isTalk().

◆ isTalk()

MediaWiki\Title\NamespaceInfo::isTalk ( $index)

Is the given namespace a talk namespace?

Parameters
int$indexNamespace index
Returns
bool

Definition at line 204 of file NamespaceInfo.php.

References NS_MAIN.

Referenced by MediaWiki\Title\NamespaceInfo\getTalk(), and MediaWiki\Title\NamespaceInfo\isSubject().

◆ isWatchable()

MediaWiki\Title\NamespaceInfo::isWatchable ( $index)

Can pages in a namespace be watched?

Parameters
int$index
Returns
bool

Definition at line 493 of file NamespaceInfo.php.

References NS_MAIN.

◆ subjectEquals()

MediaWiki\Title\NamespaceInfo::subjectEquals ( $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.

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

Definition at line 378 of file NamespaceInfo.php.

◆ wantSignatures()

MediaWiki\Title\NamespaceInfo::wantSignatures ( $index)

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 482 of file NamespaceInfo.php.

Member Data Documentation

◆ CANONICAL_NAMES

const MediaWiki\Title\NamespaceInfo::CANONICAL_NAMES
Initial value:
= [
NS_MEDIA => 'Media',
NS_SPECIAL => 'Special',
NS_MAIN => '',
NS_TALK => 'Talk',
NS_USER => 'User',
NS_USER_TALK => 'User_talk',
NS_PROJECT => 'Project',
NS_PROJECT_TALK => 'Project_talk',
NS_FILE => 'File',
NS_FILE_TALK => 'File_talk',
NS_MEDIAWIKI => 'MediaWiki',
NS_MEDIAWIKI_TALK => 'MediaWiki_talk',
NS_TEMPLATE => 'Template',
NS_TEMPLATE_TALK => 'Template_talk',
NS_HELP => 'Help',
NS_HELP_TALK => 'Help_talk',
NS_CATEGORY => 'Category',
NS_CATEGORY_TALK => 'Category_talk',
]
const NS_HELP
Definition Defines.php:76
const NS_USER
Definition Defines.php:66
const NS_FILE
Definition Defines.php:70
const NS_MEDIAWIKI_TALK
Definition Defines.php:73
const NS_MAIN
Definition Defines.php:64
const NS_PROJECT_TALK
Definition Defines.php:69
const NS_MEDIAWIKI
Definition Defines.php:72
const NS_TEMPLATE
Definition Defines.php:74
const NS_SPECIAL
Definition Defines.php:53
const NS_FILE_TALK
Definition Defines.php:71
const NS_HELP_TALK
Definition Defines.php:77
const NS_CATEGORY_TALK
Definition Defines.php:79
const NS_MEDIA
Definition Defines.php:52
const NS_TALK
Definition Defines.php:65
const NS_USER_TALK
Definition Defines.php:67
const NS_PROJECT
Definition Defines.php:68
const NS_CATEGORY
Definition Defines.php:78
const NS_TEMPLATE_TALK
Definition Defines.php:75

Definitions of the NS_ constants are in Defines.php.

Access: internal

Definition at line 72 of file NamespaceInfo.php.

◆ CONSTRUCTOR_OPTIONS

const MediaWiki\Title\NamespaceInfo::CONSTRUCTOR_OPTIONS
Initial value:
= [
]
const ContentNamespaces
Name constant for the ContentNamespaces setting, for use with Config::get()
const CapitalLinks
Name constant for the CapitalLinks setting, for use with Config::get()
const ExtraSignatureNamespaces
Name constant for the ExtraSignatureNamespaces setting, for use with Config::get()
const NamespaceContentModels
Name constant for the NamespaceContentModels setting, for use with Config::get()
const NamespacesWithSubpages
Name constant for the NamespacesWithSubpages setting, for use with Config::get()
const ExtraNamespaces
Name constant for the ExtraNamespaces setting, for use with Config::get()
const CanonicalNamespaceNames
Name constant for the CanonicalNamespaceNames setting, for use with Config::get()
const NonincludableNamespaces
Name constant for the NonincludableNamespaces setting, for use with Config::get()
const CapitalLinkOverrides
Name constant for the CapitalLinkOverrides setting, for use with Config::get()
Access: internal
For use by ServiceWiring

Definition at line 96 of file NamespaceInfo.php.


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