Merge "Use LinkTarget in TitleValue only methods"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Wed, 3 Feb 2016 13:36:59 +0000 (13:36 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Wed, 3 Feb 2016 13:36:59 +0000 (13:36 +0000)
1  2 
includes/Title.php

diff --combined includes/Title.php
@@@ -236,17 -236,28 +236,28 @@@ class Title implements LinkTarget 
         * @return Title
         */
        public static function newFromTitleValue( TitleValue $titleValue ) {
+               return self::newFromLinkTarget( $titleValue );
+       }
+       /**
+        * Create a new Title from a LinkTarget
+        *
+        * @param LinkTarget $linkTarget Assumed to be safe.
+        *
+        * @return Title
+        */
+       public static function newFromLinkTarget( LinkTarget $linkTarget ) {
                return self::makeTitle(
-                       $titleValue->getNamespace(),
-                       $titleValue->getText(),
-                       $titleValue->getFragment() );
+                       $linkTarget->getNamespace(),
+                       $linkTarget->getText(),
+                       $linkTarget->getFragment() );
        }
  
        /**
         * Create a new Title from text, such as what one would find in a link. De-
         * codes any HTML entities in the text.
         *
 -       * @param string|null $text The link text; spaces, prefixes, and an
 +       * @param string|int|null $text The link text; spaces, prefixes, and an
         *   initial ':' indicating the main namespace are accepted.
         * @param int $defaultNamespace The namespace to use if none is specified
         *   by a prefix.  If you want to force a specific namespace even if
                if ( is_object( $text ) ) {
                        throw new InvalidArgumentException( '$text must be a string.' );
                }
 -              if ( $text !== null && !is_string( $text ) ) {
 +              // DWIM: Integers can be passed in here when page titles are used as array keys.
 +              if ( $text !== null && !is_string( $text ) && !is_int( $text ) ) {
                        wfDebugLog( 'T76305', wfGetAllCallers( 5 ) );
                        return null;
                }
                }
  
                try {
 -                      return Title::newFromTextThrow( $text, $defaultNamespace );
 +                      return Title::newFromTextThrow( strval( $text ), $defaultNamespace );
                } catch ( MalformedTitleException $ex ) {
                        return null;
                }