MediaWiki master
MediaWiki\Title\TitleValue Class Reference

Represents the target of a wiki link. More...

Inherits MediaWiki\Linker\LinkTarget.

Collaboration diagram for MediaWiki\Title\TitleValue:

Public Member Functions

 __construct ( $namespace, $title, $fragment='', $interwiki='')
 Construct a TitleValue.
 
 __toString ()
 Returns a string representation of the title, for logging.
 
 createFragmentTarget (string $fragment)
 Create a new LinkTarget with a different fragment on the same page.
 
 getDBkey ()
 Get the main part of the link target, in canonical database form.
 
 getFragment ()
 Get the link fragment in text form (i.e.
 
 getInterwiki ()
 The interwiki component of this LinkTarget.
 
 getNamespace ()
 Get the namespace index.
 
- Public Member Functions inherited from MediaWiki\Linker\LinkTarget
 getText ()
 Get the main part of the link target, in text form.
 
 hasFragment ()
 Whether the link target has a fragment.
 
 inNamespace (int $ns)
 Convenience function to check if the target is in a given namespace.
 
 isExternal ()
 Whether this LinkTarget has an interwiki component.
 
 isSameLinkAs (ParsoidLinkTarget $other)
 Check whether the given LinkTarget refers to the same target as this LinkTarget.
 

Static Public Member Functions

static assertValidSpec ( $namespace, $title, $fragment='', $interwiki='')
 Assert that the given parameters could be used to construct a TitleValue object.
 
static castPageToLinkTarget (?PageReference $page)
 Casts a PageReference to a LinkTarget.
 
static newFromLinkTarget (ParsoidLinkTarget $linkTarget)
 Create a TitleValue from a LinkTarget.
 
static newFromPage (PageReference $page)
 Create a TitleValue from a local PageReference.
 
static tryNew ( $namespace, $title, $fragment='', $interwiki='')
 Constructs a TitleValue, or returns null if the parameters are not valid.
 

Public Attributes

string $prefixedText = null
 Text form including namespace/interwiki, initialised on demand.
 

Detailed Description

Represents the target of a wiki link.

Note
In contrast to Title, this is designed to be a plain value object. That is, it is immutable, does not use global state, and causes no side effects.
Stability: newable
See also
https://www.mediawiki.org/wiki/Manual:Modeling_pages
Since
1.23

Definition at line 46 of file TitleValue.php.

Constructor & Destructor Documentation

◆ __construct()

MediaWiki\Title\TitleValue::__construct ( $namespace,
$title,
$fragment = '',
$interwiki = '' )

Construct a TitleValue.

Note
TitleValue expects a valid namespace and name; typically, a TitleValue is constructed either from a database entry, or by a TitleParser. For constructing a TitleValue from user input or external sources, use a TitleParser.
Stability: stable
to call
Parameters
int$namespaceThe namespace ID. This is not validated.
string$titleThe page title in either DBkey or text form. No normalization is applied beyond underscore/space conversion.
string$fragmentThe fragment title. Use '' to represent the whole page. No validation or normalization is applied.
string$interwikiThe interwiki component. No validation or normalization is applied.
Exceptions
InvalidArgumentException

Definition at line 168 of file TitleValue.php.

Member Function Documentation

◆ __toString()

MediaWiki\Title\TitleValue::__toString ( )

Returns a string representation of the title, for logging.

This is purely informative and must not be used programmatically. Use the appropriate TitleFormatter to generate the correct string representation for a given use.

Since
1.23
Returns
string

Implements MediaWiki\Linker\LinkTarget.

Definition at line 252 of file TitleValue.php.

◆ assertValidSpec()

static MediaWiki\Title\TitleValue::assertValidSpec ( $namespace,
$title,
$fragment = '',
$interwiki = '' )
static

Assert that the given parameters could be used to construct a TitleValue object.

Performs basic syntax and consistency checks. Does not perform full validation, use TitleParser::makeTitleValueSafe() for that.

Parameters
int$namespace
string$title
string$fragment
string$interwiki
Exceptions
InvalidArgumentExceptionif the combination of parameters is not valid for constructing a TitleValue.

Definition at line 190 of file TitleValue.php.

References NS_MAIN.

Referenced by MediaWiki\Title\MediaWikiTitleCodec\splitTitleString().

◆ castPageToLinkTarget()

static MediaWiki\Title\TitleValue::castPageToLinkTarget ( ?PageReference $page)
static

Casts a PageReference to a LinkTarget.

If $page is null, null is returned. If $page is also an instance of LinkTarget, $page is returned unchanged.

See also
newFromPage()
Since
1.37
Parameters
PageReference | null$page
Returns
LinkTarget|null

Definition at line 143 of file TitleValue.php.

◆ createFragmentTarget()

MediaWiki\Title\TitleValue::createFragmentTarget ( string $fragment)

Create a new LinkTarget with a different fragment on the same page.

It is expected that the same type of object will be returned, but the only requirement is that it is a LinkTarget.

Since
1.27
Parameters
string$fragmentThe fragment override, or "" to remove it.
Returns
LinkTarget

Implements MediaWiki\Linker\LinkTarget.

Definition at line 231 of file TitleValue.php.

◆ getDBkey()

MediaWiki\Title\TitleValue::getDBkey ( )

Get the main part of the link target, in canonical database form.

The main part is the link target without namespace prefix or hash fragment. The database form means that spaces become underscores, this is also used for URLs.

Since
1.27
Returns
string

Implements MediaWiki\Linker\LinkTarget.

Definition at line 227 of file TitleValue.php.

◆ getFragment()

MediaWiki\Title\TitleValue::getFragment ( )

Get the link fragment in text form (i.e.

the bit after the hash #).

Since
1.27
Returns
string link fragment

Implements MediaWiki\Linker\LinkTarget.

Definition at line 223 of file TitleValue.php.

◆ getInterwiki()

MediaWiki\Title\TitleValue::getInterwiki ( )

The interwiki component of this LinkTarget.

Since
1.27
Returns
string

Implements MediaWiki\Linker\LinkTarget.

Definition at line 240 of file TitleValue.php.

◆ getNamespace()

MediaWiki\Title\TitleValue::getNamespace ( )

Get the namespace index.

Since
1.27
Returns
int Namespace index

Implements MediaWiki\Linker\LinkTarget.

Definition at line 219 of file TitleValue.php.

◆ newFromLinkTarget()

static MediaWiki\Title\TitleValue::newFromLinkTarget ( ParsoidLinkTarget $linkTarget)
static

Create a TitleValue from a LinkTarget.

Parameters
ParsoidLinkTarget$linkTarget
Returns
TitleValue
Since
1.42

Definition at line 120 of file TitleValue.php.

◆ newFromPage()

static MediaWiki\Title\TitleValue::newFromPage ( PageReference $page)
static

Create a TitleValue from a local PageReference.

Note
The PageReference may belong to another wiki. In that case, the resulting TitleValue is also logically bound to that other wiki. No attempt is made to map the PageReference wiki ID to an interwiki prefix for the TitleValue.
Since
1.36
Parameters
PageReference$page
Returns
TitleValue

Definition at line 110 of file TitleValue.php.

◆ tryNew()

static MediaWiki\Title\TitleValue::tryNew ( $namespace,
$title,
$fragment = '',
$interwiki = '' )
static

Constructs a TitleValue, or returns null if the parameters are not valid.

Note
This does not perform any normalization, and only basic validation. For full normalization and validation, use TitleParser::makeTitleValueSafe().
Parameters
int$namespaceThe namespace ID. This is not validated.
string$titleThe page title in either DBkey or text form. No normalization is applied beyond underscore/space conversion.
string$fragmentThe fragment title. Use '' to represent the whole page. No validation or normalization is applied.
string$interwikiThe interwiki component. No validation or normalization is applied.
Returns
TitleValue|null
Exceptions
InvalidArgumentException

Definition at line 87 of file TitleValue.php.

Member Data Documentation

◆ $prefixedText

string MediaWiki\Title\TitleValue::$prefixedText = null

Text form including namespace/interwiki, initialised on demand.

Only public to share cache with TitleFormatter

Access: internal

Definition at line 69 of file TitleValue.php.


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