25use Wikimedia\Assert\Assert;
26use Wikimedia\Assert\ParameterAssertionException;
27use Wikimedia\Assert\ParameterTypeException;
94 public static function tryNew( $namespace,
$title, $fragment =
'', $interwiki =
'' ) {
96 throw new ParameterTypeException(
'$namespace',
'int' );
101 }
catch ( ParameterAssertionException $ex ) {
120 if ( $page->getWikiId() ) {
124 throw new InvalidArgumentException(
'Not a local PageIdentity: ' . $page );
127 return new TitleValue( $page->getNamespace(), $page->getDBkey() );
150 self::assertValidSpec( $namespace,
$title, $fragment, $interwiki );
152 $this->
namespace = $namespace;
153 $this->dbkey = strtr(
$title,
' ',
'_' );
154 $this->fragment = $fragment;
155 $this->interwiki = $interwiki;
172 if ( !is_int( $namespace ) ) {
173 throw new ParameterTypeException(
'$namespace',
'int' );
175 if ( !is_string(
$title ) ) {
176 throw new ParameterTypeException(
'$title',
'string' );
178 if ( !is_string( $fragment ) ) {
179 throw new ParameterTypeException(
'$fragment',
'string' );
181 if ( !is_string( $interwiki ) ) {
182 throw new ParameterTypeException(
'$interwiki',
'string' );
185 Assert::parameter( !preg_match(
'/^[_ ]|[\r\n\t]|[_ ]$/',
$title ),
'$title',
186 "invalid name '$title'" );
196 'should not be empty unless namespace is main'
205 return $this->namespace;
214 return $this->
namespace == $ns;
222 return $this->fragment;
230 return $this->fragment !==
'';
257 return str_replace(
'_',
' ', $this->dbkey );
284 return $this->interwiki !==
'';
294 return $this->interwiki;
306 $name = $this->namespace .
':' . $this->dbkey;
308 if ( $this->fragment !==
'' ) {
309 $name .=
'#' . $this->fragment;
312 if ( $this->interwiki !==
'' ) {
313 $name = $this->interwiki .
':' . $name;
326 return ( $other->
getInterwiki() === $this->getInterwiki() )
327 && ( $other->
getDBkey() === $this->getDBkey() )
329 && ( $other->
getFragment() === $this->getFragment() );
if(ini_get('mbstring.func_overload')) if(!defined('MW_ENTRY_POINT'))
Pre-config setup: Before loading LocalSettings.php.
Represents a page (or page fragment) title within MediaWiki.
isExternal()
Whether it has an interwiki part.
__construct( $namespace, $title, $fragment='', $interwiki='')
Constructs a TitleValue.
getInterwiki()
Returns the interwiki part.
static assertValidSpec( $namespace, $title, $fragment='', $interwiki='')
Asserts that the given parameters could be used to construct a TitleValue object.
string $prefixedText
Text form including namespace/interwiki, initialised on demand.
getText()
Returns the title in text form, without namespace prefix or fragment.
createFragmentTarget( $fragment)
Creates a new TitleValue for a different fragment of the same page.
isSameLinkAs(LinkTarget $other)
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.
getDBkey()
Returns the title's DB key, as supplied to the constructor, without namespace prefix or fragment.
__toString()
Returns a string representation of the title, for logging.
Interface for objects (potentially) representing an editable wiki page.