89 'CanonicalNamespaceNames',
90 'CapitalLinkOverrides',
94 'ExtraSignatureNamespaces',
95 'NamespaceContentModels',
96 'NamespacesWithSubpages',
97 'NonincludableNamespaces',
106 $this->options = $options;
107 $this->hookRunner =
new HookRunner( $hookContainer );
124 throw new MWException(
"$method does not make any sense for given namespace $index" );
142 || ctype_digit( $index )
144 || ( $index[0] ===
'-' && ctype_digit( substr( $index, 1 ) ) )
146 throw new InvalidArgumentException(
147 "$method called with non-integer (" . gettype( $index ) .
") namespace '$index'"
151 return intval( $index );
161 $extensionRegistry = ExtensionRegistry::getInstance();
162 $extNamespaces = $extensionRegistry->getAttribute(
'ImmovableNamespaces' );
164 $result = $index >=
NS_MAIN && !in_array( $index, $extNamespaces );
169 $this->hookRunner->onNamespaceIsMovable( $index, $result );
181 return !$this->
isTalk( $index );
209 return $this->
isTalk( $index )
224 if ( $target->getText() ===
'' ) {
225 throw new MWException(
'Can\'t determine talk page associated with relative section link' );
228 if ( $target->getInterwiki() !==
'' ) {
229 throw new MWException(
'Can\'t determine talk page associated with interwiki link' );
232 if ( $this->
isTalk( $target->getNamespace() ) ) {
237 return new TitleValue( $this->
getTalk( $target->getNamespace() ), $target->getDBkey() );
271 $index = $this->makeValidNamespace( $index, __METHOD__ );
273 # Handle special namespaces
278 return $this->isTalk( $index )
288 if ( $this->isSubject( $target->getNamespace() ) ) {
291 return new TitleValue( $this->getSubject( $target->getNamespace() ), $target->getDBkey() );
304 $this->isMethodValidFor( $index, __METHOD__ );
306 if ( $this->isSubject( $index ) ) {
307 return $this->getTalk( $index );
309 return $this->getSubject( $index );
319 if ( $target->getText() ===
'' ) {
320 throw new MWException(
'Can\'t determine talk page associated with relative section link' );
323 if ( $target->getInterwiki() !==
'' ) {
324 throw new MWException(
'Can\'t determine talk page associated with interwiki link' );
328 $this->getAssociated( $target->getNamespace() ), $target->getDBkey() );
339 $nslist = $this->getCanonicalNamespaces();
340 return isset( $nslist[$index] );
371 return $this->getSubject( $ns1 ) == $this->getSubject( $ns2 );
381 if ( $this->canonicalNamespaces ===
null ) {
382 $this->canonicalNamespaces =
383 [
NS_MAIN =>
'' ] + $this->options->get(
'CanonicalNamespaceNames' );
384 $this->canonicalNamespaces +=
385 ExtensionRegistry::getInstance()->getAttribute(
'ExtensionNamespaces' );
386 if ( is_array( $this->options->get(
'ExtraNamespaces' ) ) ) {
387 $this->canonicalNamespaces += $this->options->get(
'ExtraNamespaces' );
389 $this->hookRunner->onCanonicalNamespaces( $this->canonicalNamespaces );
391 return $this->canonicalNamespaces;
401 $nslist = $this->getCanonicalNamespaces();
402 return $nslist[$index] ??
false;
413 if ( $this->namespaceIndexes ===
false ) {
414 $this->namespaceIndexes = [];
415 foreach ( $this->getCanonicalNamespaces() as $i => $text ) {
416 $this->namespaceIndexes[strtolower( $text )] = $i;
419 if ( array_key_exists( $name, $this->namespaceIndexes ) ) {
420 return $this->namespaceIndexes[$name];
432 if ( $this->validNamespaces ===
null ) {
433 $this->validNamespaces = [];
434 foreach ( array_keys( $this->getCanonicalNamespaces() ) as $ns ) {
436 $this->validNamespaces[] = $ns;
440 sort( $this->validNamespaces, SORT_NUMERIC );
443 return $this->validNamespaces;
464 return $index ==
NS_MAIN || in_array( $index, $this->options->get(
'ContentNamespaces' ) );
475 return $this->isTalk( $index ) ||
476 in_array( $index, $this->options->get(
'ExtraSignatureNamespaces' ) );
497 return !empty( $this->options->get(
'NamespacesWithSubpages' )[$index] );
505 $contentNamespaces = $this->options->get(
'ContentNamespaces' );
506 if ( !is_array( $contentNamespaces ) || $contentNamespaces === [] ) {
508 } elseif ( !in_array(
NS_MAIN, $contentNamespaces ) ) {
510 return array_merge( [
NS_MAIN ], $contentNamespaces );
512 return $contentNamespaces;
524 $this->getValidNamespaces(),
525 [ $this,
'isSubject' ]
537 $this->getValidNamespaces(),
553 $index = $this->getSubject( $index );
556 if ( in_array( $index, $this->alwaysCapitalizedNamespaces ) ) {
559 $overrides = $this->options->get(
'CapitalLinkOverrides' );
560 if ( isset( $overrides[$index] ) ) {
562 return $overrides[$index];
565 return $this->options->get(
'CapitalLinks' );
586 $namespaces = $this->options->get(
'NonincludableNamespaces' );
587 return $namespaces && in_array( $index, $namespaces );
601 return $this->options->get(
'NamespaceContentModels' )[$index] ??
null;
618 return MediaWikiServices::getInstance()
619 ->getPermissionManager()
620 ->getNamespaceRestrictionLevels( $index, $user );
633 $this->isMethodValidFor( $index, __METHOD__ );
637 } elseif ( $index ==
NS_FILE ) {
652 return array_keys( self::CANONICAL_NAMES );
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that a deprecated feature was used.
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
This is a utility class for dealing with namespaces that encodes all the "magic" behaviors of them ba...
getAssociatedPage(LinkTarget $target)
hasGenderDistinction( $index)
Does the namespace (potentially) have different aliases for different genders.
__construct(ServiceOptions $options, HookContainer $hookContainer)
equals( $ns1, $ns2)
Returns whether the specified namespaces are the same namespace.
wantSignatures( $index)
Might pages in this namespace require the use of the Signature button on the edit toolbar?
getNamespaceContentModel( $index)
Get the default content model for a namespace This does not mean that all pages in that namespace hav...
subjectEquals( $ns1, $ns2)
Returns whether the specified namespaces share the same subject.
isCapitalized( $index)
Is the namespace first-letter capitalized?
getCanonicalName( $index)
Returns the canonical (English) name for a given index.
getContentNamespaces()
Get a list of all namespace indices which are considered to contain content.
string[] null $canonicalNamespaces
Canonical namespaces cache.
isNonincludable( $index)
It is not possible to use pages from this namespace as template?
getTalkNamespaces()
List all namespace indices which are considered talks, aka not a subject or special namespace.
getRestrictionLevels( $index, User $user=null)
Determine which restriction levels it makes sense to use in a namespace, optionally filtered by a use...
makeValidNamespace( $index, $method)
Throw if given index isn't an integer or integer-like string and so can't be a valid namespace.
hasTalkNamespace( $index)
Does this namespace ever have a talk namespace?
isSubject( $index)
Is the given namespace is a subject (non-talk) namespace?
$alwaysCapitalizedNamespaces
These namespaces should always be first-letter capitalized, now and forevermore.
getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
static getCommonNamespaces()
Retrieve the indexes for the namespaces defined by core.
exists( $index)
Returns whether the specified namespace exists.
isContent( $index)
Does this namespace contain content, for the purposes of calculating statistics, etc?
getSubjectPage(LinkTarget $target)
isMethodValidFor( $index, $method)
Throw an exception when trying to get the subject or talk page for a given namespace where it does no...
int[] null $validNamespaces
Valid namespaces cache.
getCanonicalNamespaces()
Returns array of all defined namespaces with their canonical (English) names.
const CANONICAL_NAMES
Definitions of the NS_ constants are in Defines.php.
getSubject( $index)
Get the subject namespace index for a given namespace Special namespaces (NS_MEDIA,...
hasSubpages( $index)
Does the namespace allow subpages? Note that this refers to structured handling of subpages,...
array false $namespaceIndexes
Canonical namespaces index cache.
canHaveTalkPage(LinkTarget $target)
Can the title have a corresponding talk page?
isWatchable( $index)
Can pages in a namespace be watched?
getTalk( $index)
Get the talk namespace index for a given namespace.
getSubjectNamespaces()
List all namespace indices which are considered subject, aka not a talk or special namespace.
isMovable( $index)
Can pages in the given namespace be moved?
getCategoryLinkType( $index)
Returns the link type to be used for categories.
getAssociated( $index)
Get the associated namespace.
getTalkPage(LinkTarget $target)
Get a LinkTarget referring to the talk page of $target.
const CONSTRUCTOR_OPTIONS
isTalk( $index)
Is the given namespace a talk namespace?
getCanonicalIndex( $name)
Returns the index for a given canonical name, or NULL The input must be converted to lower case first...
Represents a page (or page fragment) title within MediaWiki.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...