Merge "Replace "Bug37714" by "T39714""
[lhc/web/wiklou.git] / includes / title / TitleValue.php
index 77c1953..698bc4f 100644 (file)
@@ -1,6 +1,6 @@
 <?php
 /**
- * Representation of a page title within %MediaWiki.
+ * Representation of a page title within MediaWiki.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * http://www.gnu.org/copyleft/gpl.html
  *
  * @file
- * @license GPL 2+
  * @author Daniel Kinzler
  */
 use MediaWiki\Linker\LinkTarget;
 use Wikimedia\Assert\Assert;
+use Wikimedia\Assert\ParameterTypeException;
 
 /**
- * Represents a page (or page fragment) title within %MediaWiki.
+ * 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.
@@ -59,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.
         *
@@ -77,10 +87,18 @@ 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',
@@ -150,7 +168,7 @@ class TitleValue implements LinkTarget {
         * @return string
         */
        public function getText() {
-               return str_replace( '_', ' ', $this->getDBkey() );
+               return str_replace( '_', ' ', $this->dbkey );
        }
 
        /**