MediaWiki  1.23.2
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=array())
 
 formatTitle ( $namespace, $text, $fragment='')
 
 getFullText (TitleValue $title)
 
 getNamespaceName ( $namespace, $text)
 
 getPrefixedText (TitleValue $title)
 
 getText (TitleValue $title)
 
 parseTitle ( $text, $defaultNamespace)
 Parses the given text and constructs a TitleValue. More...
 
 splitTitleString ( $text, $defaultNamespace=NS_MAIN)
 Normalizes and splits a title string. More...
 

Protected Attributes

GenderCache $genderCache
 
Language $language
 
string[] $localInterwikis
 

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

Definition at line 35 of file MediaWikiTitleCodec.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWikiTitleCodec::__construct ( Language  $language,
GenderCache  $genderCache,
  $localInterwikis = array() 
)
Parameters
Language$languagethe language object to use for localizing namespace names.
GenderCache$genderCachethe gender cache for generating gendered namespace names
string[] | string$localInterwikis

Definition at line 54 of file MediaWikiTitleCodec.php.

References $genderCache, $language, $localInterwikis, and array().

Member Function Documentation

◆ formatTitle()

MediaWikiTitleCodec::formatTitle (   $namespace,
  $text,
  $fragment = '' 
)
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).
Exceptions
InvalidArgumentExceptionif the namespace is invalid
Returns
string

Implements TitleFormatter.

Definition at line 98 of file MediaWikiTitleCodec.php.

References getNamespaceName().

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

◆ getFullText()

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

Implements TitleFormatter.

Definition at line 174 of file MediaWikiTitleCodec.php.

References $title, formatTitle(), and TitleValue\getNamespace().

◆ getNamespaceName()

MediaWikiTitleCodec::getNamespaceName (   $namespace,
  $text 
)
See also
TitleFormatter::getNamespaceName()
Parameters
int$namespace
string$text
Exceptions
InvalidArgumentExceptionif the namespace is invalid
Returns
String

Implements TitleFormatter.

Definition at line 69 of file MediaWikiTitleCodec.php.

References $name, and MWNamespace\hasGenderDistinction().

Referenced by formatTitle().

◆ getPrefixedText()

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

Implements TitleFormatter.

Definition at line 163 of file MediaWikiTitleCodec.php.

References $title, formatTitle(), and TitleValue\getNamespace().

◆ getText()

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

Implements TitleFormatter.

Definition at line 152 of file MediaWikiTitleCodec.php.

References formatTitle(), and TitleValue\getText().

◆ parseTitle()

MediaWikiTitleCodec::parseTitle (   $text,
  $defaultNamespace 
)

Parses the given text and constructs a TitleValue.

Normalization is applied according to the rules appropriate for the form specified by $form.

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

Implements TitleParser.

Definition at line 126 of file MediaWikiTitleCodec.php.

References 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 mapp with the fields 'interwiki', 'fragment', 'namespace', 'user_case_dbkey', and 'dbkey'.

Definition at line 198 of file MediaWikiTitleCodec.php.

References array(), as, Title\capitalize(), Title\getTitleInvalidRegex(), Interwiki\isValidInterwiki(), NS_MAIN, NS_SPECIAL, NS_TALK, NS_USER, NS_USER_TALK, processing, IP\sanitizeIP(), and UTF8_REPLACEMENT.

Referenced by parseTitle().

Member Data Documentation

◆ $genderCache

GenderCache MediaWikiTitleCodec::$genderCache
protected

Definition at line 43 of file MediaWikiTitleCodec.php.

Referenced by __construct().

◆ $language

Language MediaWikiTitleCodec::$language
protected

Definition at line 39 of file MediaWikiTitleCodec.php.

Referenced by __construct().

◆ $localInterwikis

string [] MediaWikiTitleCodec::$localInterwikis
protected

Definition at line 47 of file MediaWikiTitleCodec.php.

Referenced by __construct().


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