91 'CanonicalNamespaceNames',
92 'CapitalLinkOverrides',
96 'ExtraSignatureNamespaces',
97 'NamespaceContentModels',
98 'NamespacesWithSubpages',
99 'NonincludableNamespaces',
108 $this->options = $options;
109 $this->hookRunner =
new HookRunner( $hookContainer );
126 throw new MWException(
"$method does not make any sense for given namespace $index" );
144 || ctype_digit( $index )
146 || ( $index[0] ===
'-' && ctype_digit( substr( $index, 1 ) ) )
148 throw new InvalidArgumentException(
149 "$method called with non-integer (" . gettype( $index ) .
") namespace '$index'"
153 return intval( $index );
163 if ( !$this->options->get(
'AllowImageMoving' ) ) {
164 wfDeprecatedMsg(
'Setting $wgAllowImageMoving to false was deprecated in MediaWiki 1.35',
165 '1.35',
false,
false );
168 $extensionRegistry = ExtensionRegistry::getInstance();
169 $extNamespaces = $extensionRegistry->getAttribute(
'ImmovableNamespaces' );
172 ( $index !=
NS_FILE || $this->options->get(
'AllowImageMoving' ) ) &&
173 !in_array( $index, $extNamespaces );
178 $this->hookRunner->onNamespaceIsMovable( $index, $result );
190 return !$this->
isTalk( $index );
218 return $this->
isTalk( $index )
233 if ( $target->getText() ===
'' ) {
234 throw new MWException(
'Can\'t determine talk page associated with relative section link' );
237 if ( $target->getInterwiki() !==
'' ) {
238 throw new MWException(
'Can\'t determine talk page associated with interwiki link' );
241 if ( $this->
isTalk( $target->getNamespace() ) ) {
246 return new TitleValue( $this->
getTalk( $target->getNamespace() ), $target->getDBkey() );
280 $index = $this->makeValidNamespace( $index, __METHOD__ );
282 # Handle special namespaces
287 return $this->isTalk( $index )
297 if ( $this->isSubject( $target->getNamespace() ) ) {
300 return new TitleValue( $this->getSubject( $target->getNamespace() ), $target->getDBkey() );
313 $this->isMethodValidFor( $index, __METHOD__ );
315 if ( $this->isSubject( $index ) ) {
316 return $this->getTalk( $index );
318 return $this->getSubject( $index );
328 if ( $target->getText() ===
'' ) {
329 throw new MWException(
'Can\'t determine talk page associated with relative section link' );
332 if ( $target->getInterwiki() !==
'' ) {
333 throw new MWException(
'Can\'t determine talk page associated with interwiki link' );
337 $this->getAssociated( $target->getNamespace() ), $target->getDBkey() );
348 $nslist = $this->getCanonicalNamespaces();
349 return isset( $nslist[$index] );
380 return $this->getSubject( $ns1 ) == $this->getSubject( $ns2 );
390 if ( $this->canonicalNamespaces ===
null ) {
391 $this->canonicalNamespaces =
392 [
NS_MAIN =>
'' ] + $this->options->get(
'CanonicalNamespaceNames' );
393 $this->canonicalNamespaces +=
394 ExtensionRegistry::getInstance()->getAttribute(
'ExtensionNamespaces' );
395 if ( is_array( $this->options->get(
'ExtraNamespaces' ) ) ) {
396 $this->canonicalNamespaces += $this->options->get(
'ExtraNamespaces' );
398 $this->hookRunner->onCanonicalNamespaces( $this->canonicalNamespaces );
400 return $this->canonicalNamespaces;
410 $nslist = $this->getCanonicalNamespaces();
411 return $nslist[$index] ??
false;
422 if ( $this->namespaceIndexes ===
false ) {
423 $this->namespaceIndexes = [];
424 foreach ( $this->getCanonicalNamespaces() as $i => $text ) {
425 $this->namespaceIndexes[strtolower( $text )] = $i;
428 if ( array_key_exists( $name, $this->namespaceIndexes ) ) {
429 return $this->namespaceIndexes[$name];
441 if ( $this->validNamespaces ===
null ) {
442 $this->validNamespaces = [];
443 foreach ( array_keys( $this->getCanonicalNamespaces() ) as $ns ) {
445 $this->validNamespaces[] = $ns;
449 sort( $this->validNamespaces, SORT_NUMERIC );
452 return $this->validNamespaces;
473 return $index ==
NS_MAIN || in_array( $index, $this->options->get(
'ContentNamespaces' ) );
484 return $this->isTalk( $index ) ||
485 in_array( $index, $this->options->get(
'ExtraSignatureNamespaces' ) );
505 return !empty( $this->options->get(
'NamespacesWithSubpages' )[$index] );
513 $contentNamespaces = $this->options->get(
'ContentNamespaces' );
514 if ( !is_array( $contentNamespaces ) || $contentNamespaces === [] ) {
516 } elseif ( !in_array(
NS_MAIN, $contentNamespaces ) ) {
518 return array_merge( [
NS_MAIN ], $contentNamespaces );
520 return $contentNamespaces;
532 $this->getValidNamespaces(),
533 [ $this,
'isSubject' ]
545 $this->getValidNamespaces(),
561 $index = $this->getSubject( $index );
564 if ( in_array( $index, $this->alwaysCapitalizedNamespaces ) ) {
567 $overrides = $this->options->get(
'CapitalLinkOverrides' );
568 if ( isset( $overrides[$index] ) ) {
570 return $overrides[$index];
573 return $this->options->get(
'CapitalLinks' );
594 $namespaces = $this->options->get(
'NonincludableNamespaces' );
595 return $namespaces && in_array( $index, $namespaces );
609 return $this->options->get(
'NamespaceContentModels' )[$index] ??
null;
625 return MediaWikiServices::getInstance()
626 ->getPermissionManager()
627 ->getNamespaceRestrictionLevels( $index, $user );
640 $this->isMethodValidFor( $index, __METHOD__ );
644 } elseif ( $index ==
NS_FILE ) {
659 return array_keys( self::CANONICAL_NAMES );
wfDeprecatedMsg( $msg, $version=false, $component=false, $callerOffset=2)
Log a deprecation warning with arbitrary message text.
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?
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,...