X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Ftitle%2FTitleValue.php;h=722e5ef91d2760302af04d8aa3fb568aac8691a7;hb=4d6828ef7835b7c5c5e903637fcba4bf5c487e1b;hp=3e133006d087fb4b62fc737a202f05d91c789b19;hpb=3f59cb9f3a53ad28f8a95fe299c5de6abd24b453;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/title/TitleValue.php b/includes/title/TitleValue.php index 3e133006d0..722e5ef91d 100644 --- a/includes/title/TitleValue.php +++ b/includes/title/TitleValue.php @@ -22,6 +22,7 @@ */ use MediaWiki\Linker\LinkTarget; use Wikimedia\Assert\Assert; +use Wikimedia\Assert\ParameterTypeException; /** * Represents a page (or page fragment) title within MediaWiki. @@ -58,6 +59,16 @@ class TitleValue implements LinkTarget { */ protected $interwiki; + /** + * Text form including namespace/interwiki, initialised on demand + * + * Only public to share cache with TitleFormatter + * + * @private + * @var string + */ + public $prefixedText = null; + /** * Constructs a TitleValue. * @@ -76,15 +87,24 @@ class TitleValue implements LinkTarget { * @throws InvalidArgumentException */ 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' ); + if ( !is_int( $namespace ) ) { + throw new ParameterTypeException( '$namespace', 'int' ); + } + if ( !is_string( $dbkey ) ) { + throw new ParameterTypeException( '$dbkey', 'string' ); + } + if ( !is_string( $fragment ) ) { + throw new ParameterTypeException( '$fragment', 'string' ); + } + if ( !is_string( $interwiki ) ) { + throw new ParameterTypeException( '$interwiki', 'string' ); + } // Sanity check, no full validation or normalization applied here! Assert::parameter( !preg_match( '/^_|[ \r\n\t]|_$/', $dbkey ), '$dbkey', "invalid DB key '$dbkey'" ); - Assert::parameter( $dbkey !== '', '$dbkey', 'should not be empty' ); + Assert::parameter( $dbkey !== '' || ( $fragment !== '' && $namespace === NS_MAIN ), + '$dbkey', 'should not be empty unless namespace is main and fragment is non-empty' ); $this->namespace = $namespace; $this->dbkey = $dbkey; @@ -149,7 +169,7 @@ class TitleValue implements LinkTarget { * @return string */ public function getText() { - return str_replace( '_', ' ', $this->getDBkey() ); + return str_replace( '_', ' ', $this->dbkey ); } /**