X-Git-Url: http://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ftitle%2FTitleValue.php;h=597bf2f4ee18e7cd4ab79335856a238725b5a350;hb=956967415397d64f7c67259f190e8122a0b32506;hp=c23d6989f43bb2244188154a5fe10fd85aaea8c2;hpb=7a0574a6a33ca7863dd4fcabe1fd17dfa7c8cb6e;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/title/TitleValue.php b/includes/title/TitleValue.php index c23d6989f4..597bf2f4ee 100644 --- a/includes/title/TitleValue.php +++ b/includes/title/TitleValue.php @@ -30,9 +30,6 @@ use Wikimedia\Assert\Assert; * @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. * - * @note TitleValue represents the title of a local page (or fragment of a page). - * It does not represent a link, and does not support interwiki prefixes etc. - * * @see https://www.mediawiki.org/wiki/Requests_for_comment/TitleValue * @since 1.23 */ @@ -52,6 +49,11 @@ class TitleValue implements LinkTarget { */ protected $fragment; + /** + * @var string + */ + protected $interwiki; + /** * Constructs a TitleValue. * @@ -65,13 +67,15 @@ class TitleValue implements LinkTarget { * @param string $dbkey The page title in valid DBkey form. No normalization is applied. * @param string $fragment The fragment title. Use '' to represent the whole page. * No validation or normalization is applied. + * @param string $interwiki The interwiki component * * @throws InvalidArgumentException */ - public function __construct( $namespace, $dbkey, $fragment = '' ) { + public function __construct( $namespace, $dbkey, $fragment = '', $interwiki = '' ) { Assert::parameterType( 'integer', $namespace, '$namespace' ); Assert::parameterType( 'string', $dbkey, '$dbkey' ); Assert::parameterType( 'string', $fragment, '$fragment' ); + Assert::parameterType( 'string', $interwiki, '$interwiki' ); // Sanity check, no full validation or normalization applied here! Assert::parameter( !preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ), '$dbkey', 'invalid DB key' ); @@ -80,6 +84,7 @@ class TitleValue implements LinkTarget { $this->namespace = $namespace; $this->dbkey = $dbkey; $this->fragment = $fragment; + $this->interwiki = $interwiki; } /** @@ -89,6 +94,15 @@ class TitleValue implements LinkTarget { return $this->namespace; } + /** + * @since 1.27 + * @param int $ns + * @return bool + */ + public function inNamespace( $ns ) { + return $this->namespace == $ns; + } + /** * @return string */ @@ -138,7 +152,32 @@ class TitleValue implements LinkTarget { * @return TitleValue */ public function createFragmentTarget( $fragment ) { - return new TitleValue( $this->namespace, $this->dbkey, $fragment ); + return new TitleValue( + $this->namespace, + $this->dbkey, + $fragment, + $this->interwiki + ); + } + + /** + * Whether it has an interwiki part + * + * @since 1.27 + * @return bool + */ + public function isExternal() { + return $this->interwiki !== ''; + } + + /** + * Returns the interwiki part + * + * @since 1.27 + * @return string + */ + public function getInterwiki() { + return $this->interwiki; } /** @@ -155,6 +194,10 @@ class TitleValue implements LinkTarget { $name .= '#' . $this->fragment; } + if ( $this->interwiki !== '' ) { + $name = $this->interwiki . ':' . $name; + } + return $name; } }