Merge "Move wgContLang from config to injectable"
[lhc/web/wiklou.git] / includes / Title.php
index ec17ef5..7887890 100644 (file)
@@ -21,6 +21,7 @@
  *
  * @file
  */
+use MediaWiki\Linker\LinkTarget;
 
 /**
  * Represents a title within MediaWiki.
@@ -248,10 +249,16 @@ class Title implements LinkTarget {
         * @return Title
         */
        public static function newFromLinkTarget( LinkTarget $linkTarget ) {
+               if ( $linkTarget instanceof Title ) {
+                       // Special case if it's already a Title object
+                       return $linkTarget;
+               }
                return self::makeTitle(
                        $linkTarget->getNamespace(),
                        $linkTarget->getText(),
-                       $linkTarget->getFragment() );
+                       $linkTarget->getFragment(),
+                       $linkTarget->getInterwiki()
+               );
        }
 
        /**
@@ -268,13 +275,9 @@ class Title implements LinkTarget {
         * @return Title|null Title or null on an error.
         */
        public static function newFromText( $text, $defaultNamespace = NS_MAIN ) {
-               if ( is_object( $text ) ) {
-                       throw new InvalidArgumentException( '$text must be a string.' );
-               }
                // 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;
+                       throw new InvalidArgumentException( '$text must be a string.' );
                }
                if ( $text === null ) {
                        return null;
@@ -572,40 +575,6 @@ class Title implements LinkTarget {
                return $title;
        }
 
-       /**
-        * Extract a redirect destination from a string and return the
-        * Title, or null if the text doesn't contain a valid redirect
-        * This will recurse down $wgMaxRedirects times or until a non-redirect target is hit
-        * in order to provide (hopefully) the Title of the final destination instead of another redirect
-        *
-        * @param string $text Text with possible redirect
-        * @return Title
-        * @deprecated since 1.21, use Content::getUltimateRedirectTarget instead.
-        */
-       public static function newFromRedirectRecurse( $text ) {
-               ContentHandler::deprecated( __METHOD__, '1.21' );
-
-               $content = ContentHandler::makeContent( $text, null, CONTENT_MODEL_WIKITEXT );
-               return $content->getUltimateRedirectTarget();
-       }
-
-       /**
-        * Extract a redirect destination from a string and return an
-        * array of Titles, or null if the text doesn't contain a valid redirect
-        * The last element in the array is the final destination after all redirects
-        * have been resolved (up to $wgMaxRedirects times)
-        *
-        * @param string $text Text with possible redirect
-        * @return Title[] Array of Titles, with the destination last
-        * @deprecated since 1.21, use Content::getRedirectChain instead.
-        */
-       public static function newFromRedirectArray( $text ) {
-               ContentHandler::deprecated( __METHOD__, '1.21' );
-
-               $content = ContentHandler::makeContent( $text, null, CONTENT_MODEL_WIKITEXT );
-               return $content->getRedirectChain();
-       }
-
        /**
         * Get the prefixed DB key associated with an ID
         *
@@ -904,7 +873,9 @@ class Title implements LinkTarget {
                                $this->mTitleValue = new TitleValue(
                                        $this->getNamespace(),
                                        $this->getDBkey(),
-                                       $this->getFragment() );
+                                       $this->getFragment(),
+                                       $this->getInterwiki()
+                               );
                        } catch ( InvalidArgumentException $ex ) {
                                wfDebug( __METHOD__ . ': Can\'t create a TitleValue for [[' .
                                        $this->getPrefixedText() . ']]: ' . $ex->getMessage() . "\n" );
@@ -1410,7 +1381,8 @@ class Title implements LinkTarget {
         * specified fragment before setting, so it assumes you're passing it with
         * an initial "#".
         *
-        * Deprecated for public use, use Title::makeTitle() with fragment parameter.
+        * Deprecated for public use, use Title::makeTitle() with fragment parameter,
+        * or Title::createFragmentTarget().
         * Still in active use privately.
         *
         * @private
@@ -1420,6 +1392,23 @@ class Title implements LinkTarget {
                $this->mFragment = strtr( substr( $fragment, 1 ), '_', ' ' );
        }
 
+       /**
+        * Creates a new Title for a different fragment of the same page.
+        *
+        * @since 1.27
+        * @param string $fragment
+        * @return Title
+        */
+       public function createFragmentTarget( $fragment ) {
+               return self::makeTitle(
+                       $this->getNamespace(),
+                       $this->getText(),
+                       $fragment,
+                       $this->getInterwiki()
+               );
+
+       }
+
        /**
         * Prefix some arbitrary text with the namespace or interwiki prefix
         * of this object