MediaWiki master
MediaWiki\Title\TitleFormatter Class Reference

A title formatter service for MediaWiki. More...

Collaboration diagram for MediaWiki\Title\TitleFormatter:

Public Member Functions

 __construct (Language $language, GenderCache $genderCache, NamespaceInfo $nsInfo)
 
 formatTitle ( $namespace, $text, $fragment='', $interwiki='')
 Returns the title formatted for display.
 
 getFullText ( $title)
 Returns the title formatted for display, with namespace and fragment.
 
 getNamespaceName ( $namespace, $text)
 Returns the name of the namespace for the given title.
 
 getPrefixedDBkey ( $target)
 Return the title in prefixed database key form, with interwiki and namespace.
 
 getPrefixedText ( $title)
 Returns the title formatted for display, including the namespace name.
 
 getText ( $title)
 Returns the title text formatted for display, without namespace or fragment.
 

Protected Attributes

GenderCache $genderCache
 
Language $language
 
NamespaceInfo $nsInfo
 

Detailed Description

A title formatter service for MediaWiki.

This is designed to encapsulate knowledge about conventions for the title forms to be used in the database, in urls, in wikitext, etc.

Note
Normalization and validation is applied while parsing, not when formatting. It's possible to construct a TitleValue with an invalid title, and use TitleFormatter 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 46 of file TitleFormatter.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Title\TitleFormatter::__construct ( Language $language,
GenderCache $genderCache,
NamespaceInfo $nsInfo )
Parameters
Language$languageThe language object to use for localizing namespace names, capitalization, etc.
GenderCache$genderCacheThe gender cache for generating gendered namespace names
NamespaceInfo$nsInfo

Definition at line 57 of file TitleFormatter.php.

References MediaWiki\Title\TitleFormatter\$genderCache, MediaWiki\Title\TitleFormatter\$language, and MediaWiki\Title\TitleFormatter\$nsInfo.

Member Function Documentation

◆ formatTitle()

MediaWiki\Title\TitleFormatter::formatTitle ( $namespace,
$text,
$fragment = '',
$interwiki = '' )

Returns the title formatted for display.

By default, this includes the namespace but not the fragment.

Note
Normalization is applied if $title is not in TitleValue::TITLE_FORM.
Parameters
int | false$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 prefix (may be empty).
Exceptions
InvalidArgumentExceptionIf the namespace is invalid
Returns
string

Definition at line 82 of file TitleFormatter.php.

References MediaWiki\Title\TitleFormatter\getNamespaceName(), and NS_SPECIAL.

Referenced by MediaWiki\Title\TitleFormatter\getFullText(), MediaWiki\Title\TitleFormatter\getPrefixedDBkey(), and MediaWiki\Title\TitleFormatter\getPrefixedText().

◆ getFullText()

MediaWiki\Title\TitleFormatter::getFullText ( $title)

Returns the title formatted for display, with namespace and fragment.

Parameters
LinkTarget | PageReference$titleThe title to format
Returns
string

Definition at line 191 of file TitleFormatter.php.

References MediaWiki\Title\TitleFormatter\formatTitle().

◆ getNamespaceName()

MediaWiki\Title\TitleFormatter::getNamespaceName ( $namespace,
$text )

Returns the name of the namespace for the given title.

Note
This must take into account gender sensitive namespace names.
Parameters
int$namespace
string$text
Exceptions
InvalidArgumentExceptionIf the namespace is invalid
Returns
string Namespace name with underscores (not spaces), e.g. 'User_talk'

Definition at line 221 of file TitleFormatter.php.

Referenced by MediaWiki\Title\TitleFormatter\formatTitle().

◆ getPrefixedDBkey()

MediaWiki\Title\TitleFormatter::getPrefixedDBkey ( $target)

Return the title in prefixed database key form, with interwiki and namespace.

Since
1.27
Parameters
LinkTarget | PageReference$target
Returns
string

Definition at line 165 of file TitleFormatter.php.

References MediaWiki\Title\TitleFormatter\formatTitle().

◆ getPrefixedText()

MediaWiki\Title\TitleFormatter::getPrefixedText ( $title)

Returns the title formatted for display, including the namespace name.

Parameters
LinkTarget | PageReference$titleThe title to format
Returns
string

Definition at line 134 of file TitleFormatter.php.

References MediaWiki\Title\TitleFormatter\formatTitle().

◆ getText()

MediaWiki\Title\TitleFormatter::getText ( $title)

Returns the title text formatted for display, without namespace or fragment.

Parameters
LinkTarget | PageReference$titleThe title to format
Returns
string

Definition at line 116 of file TitleFormatter.php.

Member Data Documentation

◆ $genderCache

GenderCache MediaWiki\Title\TitleFormatter::$genderCache
protected

Definition at line 48 of file TitleFormatter.php.

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

◆ $language

Language MediaWiki\Title\TitleFormatter::$language
protected

Definition at line 47 of file TitleFormatter.php.

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

◆ $nsInfo

NamespaceInfo MediaWiki\Title\TitleFormatter::$nsInfo
protected

Definition at line 49 of file TitleFormatter.php.

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


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