MediaWiki master
MediaWiki\Title\TitleParser Class Reference

A title parser service for MediaWiki. More...

Public Member Functions

 __construct (Language $language, InterwikiLookup $interwikiLookup, NamespaceInfo $nsInfo, $localInterwikis)
 
 makeTitleValueSafe ( $namespace, $text, $fragment='', $interwiki='')
 Given a namespace and title, return a TitleValue if valid, or null if invalid.
 
 overrideCreateMalformedTitleExceptionCallback (callable $callback)
 
 parseTitle ( $text, $defaultNamespace=NS_MAIN)
 Parses the given text and constructs a TitleValue.
 
 splitTitleString ( $text, $defaultNamespace=NS_MAIN)
 Validates, 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.
 

Detailed Description

A title parser 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.

See also
https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue
Since
1.23

Definition at line 43 of file TitleParser.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Title\TitleParser::__construct ( Language $language,
InterwikiLookup $interwikiLookup,
NamespaceInfo $nsInfo,
$localInterwikis )
Parameters
Language$languageThe language object to use for localizing namespace names, capitalization, etc.
InterwikiLookup$interwikiLookup
NamespaceInfo$nsInfo
string[] | string$localInterwikis

Definition at line 67 of file TitleParser.php.

Member Function Documentation

◆ getTitleInvalidRegex()

static MediaWiki\Title\TitleParser::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.

Since
1.44
Returns
string Regex string

Definition at line 423 of file TitleParser.php.

References MediaWiki\Title\Title\legalChars().

Referenced by MediaWiki\Title\MediaWikiTitleCodec\getTitleInvalidRegex(), and MediaWiki\Title\TitleParser\splitTitleString().

◆ makeTitleValueSafe()

MediaWiki\Title\TitleParser::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

Definition at line 138 of file TitleParser.php.

References MediaWiki\Title\TitleParser\splitTitleString().

◆ overrideCreateMalformedTitleExceptionCallback()

MediaWiki\Title\TitleParser::overrideCreateMalformedTitleExceptionCallback ( callable $callback)
Access: internal
Parameters
callable$callback

Definition at line 93 of file TitleParser.php.

◆ parseTitle()

MediaWiki\Title\TitleParser::parseTitle ( $text,
$defaultNamespace = NS_MAIN )

Parses the given text and constructs a TitleValue.

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

Definition at line 111 of file TitleParser.php.

References MediaWiki\Title\TitleParser\splitTitleString().

◆ splitTitleString()

MediaWiki\Title\TitleParser::splitTitleString ( $text,
$defaultNamespace = NS_MAIN )

Validates, normalizes and splits a title string.

This is the "source of truth" for title validity.

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
Access: internal
Exceptions
MalformedTitleExceptionIf $text is not a valid title string.
Returns
array A map with the fields 'interwiki', 'fragment', 'namespace', and 'dbkey'.

Definition at line 183 of file TitleParser.php.

References $matches, MediaWiki\Title\TitleValue\assertValidSpec(), MediaWiki\Title\TitleParser\getTitleInvalidRegex(), MediaWiki\Title\Title\newMainPage(), NS_MAIN, NS_SPECIAL, NS_TALK, NS_USER, NS_USER_TALK, and MediaWiki\Message\Message\numParam().

Referenced by MediaWiki\Title\TitleParser\makeTitleValueSafe(), and MediaWiki\Title\TitleParser\parseTitle().


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