X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ftitle%2FTitleValue.php;h=7c370f1ae56d29e4e347be1f4a9e43da725288de;hb=100bebdbfa8baa2b945874e2b11281898660dcc1;hp=a0a7b1defd4cc8c852249f39ef0737b351cd6879;hpb=88db1539087a62ba94d7d8105355543fff0e2d07;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/title/TitleValue.php b/includes/title/TitleValue.php index a0a7b1defd..7c370f1ae5 100644 --- a/includes/title/TitleValue.php +++ b/includes/title/TitleValue.php @@ -21,6 +21,7 @@ * @license GPL 2+ * @author Daniel Kinzler */ +use MediaWiki\Linker\LinkTarget; use Wikimedia\Assert\Assert; /** @@ -29,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 */ @@ -51,6 +49,11 @@ class TitleValue implements LinkTarget { */ protected $fragment; + /** + * @var string + */ + protected $interwiki; + /** * Constructs a TitleValue. * @@ -64,21 +67,25 @@ 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' ); + Assert::parameter( !preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ), '$dbkey', + "invalid DB key '$dbkey'" ); Assert::parameter( $dbkey !== '', '$dbkey', 'should not be empty' ); $this->namespace = $namespace; $this->dbkey = $dbkey; $this->fragment = $fragment; + $this->interwiki = $interwiki; } /** @@ -88,6 +95,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 */ @@ -137,7 +153,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; } /** @@ -154,6 +195,10 @@ class TitleValue implements LinkTarget { $name .= '#' . $this->fragment; } + if ( $this->interwiki !== '' ) { + $name = $this->interwiki . ':' . $name; + } + return $name; } }