MediaWiki REL1_36
TitleValue Class Reference

Represents a page (or page fragment) title within MediaWiki. More...

Inheritance diagram for TitleValue:
Collaboration diagram for TitleValue:

Public Member Functions

 __construct ( $namespace, $title, $fragment='', $interwiki='')
 Constructs a TitleValue.
 
 __toString ()
 Returns a string representation of the title, for logging.
 
 createFragmentTarget ( $fragment)
 Creates a new TitleValue for a different fragment of the same page.
 
 getDBkey ()
 Returns the title's DB key, as supplied to the constructor, without namespace prefix or fragment.
 
 getFragment ()
 
 getInterwiki ()
 Returns the interwiki part.
 
 getNamespace ()
 
 getText ()
 Returns the title in text form, without namespace prefix or fragment.
 
 hasFragment ()
 
 inNamespace ( $ns)
 
 isExternal ()
 Whether it has an interwiki part.
 
 isSameLinkAs (LinkTarget $other)
 

Static Public Member Functions

static assertValidSpec ( $namespace, $title, $fragment='', $interwiki='')
 Asserts that the given parameters could be used to construct a TitleValue object.
 
static newFromPage (PageIdentity $page)
 Constructs a TitleValue from a local PageIdentity.
 
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.
 

Protected Attributes

string $dbkey
 
string $fragment
 
string $interwiki
 
int $namespace
 

Detailed Description

Represents a page (or page fragment) title within MediaWiki.

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.

@newable

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

Definition at line 40 of file TitleValue.php.

Constructor & Destructor Documentation

◆ __construct()

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

Constructs 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 149 of file TitleValue.php.

References $title.

Member Function Documentation

◆ __toString()

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 305 of file TitleValue.php.

◆ assertValidSpec()

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

Asserts 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 171 of file TitleValue.php.

References $title, and NS_MAIN.

◆ createFragmentTarget()

TitleValue::createFragmentTarget (   $fragment)

Creates a new TitleValue for a different fragment of the same page.

Since
1.27
Parameters
string$fragmentThe fragment name, or "" for the entire page.
Returns
TitleValue

Implements MediaWiki\Linker\LinkTarget.

Definition at line 268 of file TitleValue.php.

◆ getDBkey()

TitleValue::getDBkey ( )

Returns the title's DB key, as supplied to the constructor, without namespace prefix or fragment.

Since
1.23
Returns
string

Implements MediaWiki\Linker\LinkTarget.

Definition at line 240 of file TitleValue.php.

◆ getFragment()

TitleValue::getFragment ( )
Since
1.23
Returns
string

Implements MediaWiki\Linker\LinkTarget.

Definition at line 221 of file TitleValue.php.

◆ getInterwiki()

TitleValue::getInterwiki ( )

Returns the interwiki part.

Since
1.27
Returns
string

Implements MediaWiki\Linker\LinkTarget.

Definition at line 293 of file TitleValue.php.

◆ getNamespace()

TitleValue::getNamespace ( )
Since
1.23
Returns
int

Implements MediaWiki\Linker\LinkTarget.

Definition at line 204 of file TitleValue.php.

◆ getText()

TitleValue::getText ( )

Returns the title in text form, without namespace prefix or fragment.

Since
1.23

This is computed from the DB key by replacing any underscores with spaces.

Note
To get a title string that includes the namespace and/or fragment, use a TitleFormatter.
Returns
string

Implements MediaWiki\Linker\LinkTarget.

Definition at line 256 of file TitleValue.php.

◆ hasFragment()

TitleValue::hasFragment ( )
Since
1.27
Returns
bool

Implements MediaWiki\Linker\LinkTarget.

Definition at line 229 of file TitleValue.php.

◆ inNamespace()

TitleValue::inNamespace (   $ns)
Since
1.27
Parameters
int$ns
Returns
bool

Implements MediaWiki\Linker\LinkTarget.

Definition at line 213 of file TitleValue.php.

◆ isExternal()

TitleValue::isExternal ( )

Whether it has an interwiki part.

Since
1.27
Returns
bool

Implements MediaWiki\Linker\LinkTarget.

Definition at line 283 of file TitleValue.php.

◆ isSameLinkAs()

TitleValue::isSameLinkAs ( LinkTarget  $other)

◆ newFromPage()

static TitleValue::newFromPage ( PageIdentity  $page)
static

Constructs a TitleValue from a local PageIdentity.

Note
PageIdentities from another wiki are not supported, this method will throw if $page->getWikiId() doesn't return false.
Since
1.36
Parameters
PageIdentity$page
Exceptions
InvalidArgumentExceptionif $page does not belong to the local wiki.
Returns
TitleValue

Definition at line 119 of file TitleValue.php.

◆ tryNew()

static 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 94 of file TitleValue.php.

References $title.

Member Data Documentation

◆ $dbkey

string TitleValue::$dbkey
protected
Deprecated:
in 1.31. This class is immutable. Use the getter for access.

Definition at line 52 of file TitleValue.php.

◆ $fragment

string TitleValue::$fragment
protected
Deprecated:
in 1.31. This class is immutable. Use the getter for access.

Definition at line 58 of file TitleValue.php.

◆ $interwiki

string TitleValue::$interwiki
protected
Deprecated:
in 1.31. This class is immutable. Use the getter for access.

Definition at line 64 of file TitleValue.php.

◆ $namespace

int TitleValue::$namespace
protected
Deprecated:
in 1.31. This class is immutable. Use the getter for access.

Definition at line 46 of file TitleValue.php.

◆ $prefixedText

string TitleValue::$prefixedText = null

Text form including namespace/interwiki, initialised on demand.

Only public to share cache with TitleFormatter

Access: internal

Definition at line 74 of file TitleValue.php.


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