MediaWiki REL1_34
MediaWikiTitleCodec Class Reference

A codec for MediaWiki page titles. More...

Inheritance diagram for MediaWikiTitleCodec:
Collaboration diagram for MediaWikiTitleCodec:

Public Member Functions

 __construct (Language $language, GenderCache $genderCache, $localInterwikis=[], InterwikiLookup $interwikiLookup=null, NamespaceInfo $nsInfo=null)
 
 formatTitle ( $namespace, $text, $fragment='', $interwiki='')
 
 getFullText (LinkTarget $title)
 
 getNamespaceName ( $namespace, $text)
 
 getPrefixedDBkey (LinkTarget $target)
 
 getPrefixedText (LinkTarget $title)
 
 getText (LinkTarget $title)
 
 makeTitleValueSafe ( $namespace, $text, $fragment='', $interwiki='')
 Given a namespace and title, return a TitleValue if valid, or null if invalid.
 
 parseTitle ( $text, $defaultNamespace=NS_MAIN)
 Parses the given text and constructs a TitleValue.
 
 splitTitleString ( $text, $defaultNamespace=NS_MAIN)
 Normalizes and splits a title string.
 

Static Public Member Functions

static getTitleInvalidRegex ()
 Returns a simple regex that will match on characters and sequences invalid in titles.
 

Protected Attributes

GenderCache $genderCache
 
InterwikiLookup $interwikiLookup
 
Language $language
 
string[] $localInterwikis
 
NamespaceInfo $nsInfo
 

Detailed Description

A codec for MediaWiki page titles.

Note
Normalization and validation is applied while parsing, not when formatting. It's possible to construct a TitleValue with an invalid title, and use MediaWikiTitleCodec to generate an (invalid) title string from it. TitleValues should be constructed only via parseTitle() or from a (semi)trusted source, such as the database.
See also
https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue
Since
1.23

Definition at line 38 of file MediaWikiTitleCodec.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWikiTitleCodec::__construct ( Language  $language,
GenderCache  $genderCache,
  $localInterwikis = [],
InterwikiLookup  $interwikiLookup = null,
NamespaceInfo  $nsInfo = null 
)
Parameters
Language$languageThe language object to use for localizing namespace names, capitalization, etc.
GenderCache$genderCacheThe gender cache for generating gendered namespace names
string[] | string$localInterwikis
InterwikiLookup | null$interwikiLookup
NamespaceInfo | null$nsInfo

Definition at line 72 of file MediaWikiTitleCodec.php.

References wfDeprecated().

Member Function Documentation

◆ formatTitle()

MediaWikiTitleCodec::formatTitle (   $namespace,
  $text,
  $fragment = '',
  $interwiki = '' 
)
See also
TitleFormatter::formatTitle()
Parameters
int | bool$namespaceThe namespace ID (or false, if the namespace should be ignored)
string$textThe page title. Should be valid. Only minimal normalization is applied. Underscores will be replaced.
string$fragmentThe fragment name (may be empty).
string$interwikiThe interwiki name (may be empty).
Exceptions
InvalidArgumentExceptionIf the namespace is invalid
Returns
string

Implements TitleFormatter.

Definition at line 130 of file MediaWikiTitleCodec.php.

References getNamespaceName(), and NS_SPECIAL.

Referenced by getFullText(), getPrefixedDBkey(), and getPrefixedText().

◆ getFullText()

MediaWikiTitleCodec::getFullText ( LinkTarget  $title)
See also
TitleFormatter::getText()
Parameters
LinkTarget$title
Returns
string

Implements TitleFormatter.

Definition at line 277 of file MediaWikiTitleCodec.php.

References $title, and formatTitle().

◆ getNamespaceName()

MediaWikiTitleCodec::getNamespaceName (   $namespace,
  $text 
)
See also
TitleFormatter::getNamespaceName()
Parameters
int$namespace
string$text
Exceptions
InvalidArgumentExceptionIf the namespace is invalid
Returns
string Namespace name with underscores (not spaces)

Implements TitleFormatter.

Definition at line 100 of file MediaWikiTitleCodec.php.

Referenced by formatTitle().

◆ getPrefixedDBkey()

MediaWikiTitleCodec::getPrefixedDBkey ( LinkTarget  $target)
Since
1.27
See also
TitleFormatter::getPrefixedDBkey()
Parameters
LinkTarget$target
Returns
string

Implements TitleFormatter.

Definition at line 261 of file MediaWikiTitleCodec.php.

References formatTitle(), MediaWiki\Linker\LinkTarget\getDBkey(), MediaWiki\Linker\LinkTarget\getInterwiki(), and MediaWiki\Linker\LinkTarget\getNamespace().

◆ getPrefixedText()

MediaWikiTitleCodec::getPrefixedText ( LinkTarget  $title)
See also
TitleFormatter::getText()
Parameters
LinkTarget$title
Returns
string PhanUndeclaredProperty

Implements TitleFormatter.

Definition at line 242 of file MediaWikiTitleCodec.php.

References $title, and formatTitle().

◆ getText()

MediaWikiTitleCodec::getText ( LinkTarget  $title)
See also
TitleFormatter::getText()
Parameters
LinkTarget$title
Returns
string $title->getText()

Implements TitleFormatter.

Definition at line 230 of file MediaWikiTitleCodec.php.

References $title.

◆ getTitleInvalidRegex()

static MediaWikiTitleCodec::getTitleInvalidRegex ( )
static

Returns a simple regex that will match on characters and sequences invalid in titles.

Note that this doesn't pick up many things that could be wrong with titles, but that replacing this regex with something valid will make many titles valid. Previously Title::getTitleInvalidRegex()

Returns
string Regex string
Since
1.25

Definition at line 512 of file MediaWikiTitleCodec.php.

Referenced by MediaWiki\Languages\LanguageNameUtils\isValidCode().

◆ makeTitleValueSafe()

MediaWikiTitleCodec::makeTitleValueSafe (   $namespace,
  $text,
  $fragment = '',
  $interwiki = '' 
)

Given a namespace and title, return a TitleValue if valid, or null if invalid.

Parameters
int$namespace
string$text
string$fragment
string$interwiki
Returns
TitleValue|null

Implements TitleParser.

Definition at line 199 of file MediaWikiTitleCodec.php.

References splitTitleString().

◆ parseTitle()

MediaWikiTitleCodec::parseTitle (   $text,
  $defaultNamespace = NS_MAIN 
)

Parses the given text and constructs a TitleValue.

Parameters
string$textThe text to parse
int$defaultNamespaceNamespace to assume per default (usually NS_MAIN)
Exceptions
MalformedTitleException
Returns
TitleValue

Implements TitleParser.

Definition at line 166 of file MediaWikiTitleCodec.php.

References NS_MAIN, and splitTitleString().

◆ splitTitleString()

MediaWikiTitleCodec::splitTitleString (   $text,
  $defaultNamespace = NS_MAIN 
)

Normalizes and splits a title string.

This function removes illegal characters, splits off the interwiki and namespace prefixes, sets the other forms, and canonicalizes everything.

Todo:
this method is only exposed as a temporary measure to ease refactoring. It was copied with minimal changes from Title::secureAndSplit().
Todo:
This method should be split up and an appropriate interface defined for use by the Title class.
Parameters
string$text
int$defaultNamespace
Exceptions
MalformedTitleExceptionIf $text is not a valid title string.
Returns
array A map with the fields 'interwiki', 'fragment', 'namespace', 'user_case_dbkey', and 'dbkey'.

Definition at line 306 of file MediaWikiTitleCodec.php.

References $matches, NS_MAIN, NS_SPECIAL, NS_TALK, NS_USER, NS_USER_TALK, and Message\numParam().

Referenced by makeTitleValueSafe(), and parseTitle().

Member Data Documentation

◆ $genderCache

GenderCache MediaWikiTitleCodec::$genderCache
protected

Definition at line 47 of file MediaWikiTitleCodec.php.

◆ $interwikiLookup

InterwikiLookup MediaWikiTitleCodec::$interwikiLookup
protected

Definition at line 57 of file MediaWikiTitleCodec.php.

◆ $language

Language MediaWikiTitleCodec::$language
protected

Definition at line 42 of file MediaWikiTitleCodec.php.

◆ $localInterwikis

string [] MediaWikiTitleCodec::$localInterwikis
protected

Definition at line 52 of file MediaWikiTitleCodec.php.

◆ $nsInfo

NamespaceInfo MediaWikiTitleCodec::$nsInfo
protected

Definition at line 62 of file MediaWikiTitleCodec.php.


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