Use LinkTarget in TitleValue only methods
authoraddshore <addshorewiki@gmail.com>
Wed, 27 Jan 2016 11:34:49 +0000 (12:34 +0100)
committeraddshore <addshorewiki@gmail.com>
Fri, 29 Jan 2016 11:51:52 +0000 (12:51 +0100)
Change-Id: Iee4b183ae54457d0c6cd3473f9fed3207742b54f

includes/Title.php
includes/title/MediaWikiPageLinkRenderer.php
includes/title/MediaWikiTitleCodec.php
includes/title/PageLinkRenderer.php
includes/title/TitleFormatter.php

index f2a33e2..fdd773b 100644 (file)
@@ -236,10 +236,21 @@ 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() );
        }
 
        /**
index 27574fa..07060b2 100644 (file)
@@ -62,12 +62,12 @@ class MediaWikiPageLinkRenderer implements PageLinkRenderer {
        /**
         * Returns the (partial) URL for the given page (including any section identifier).
         *
-        * @param TitleValue $page The link's target
+        * @param LinkTarget $page The link's target
         * @param array $params Any additional URL parameters.
         *
         * @return string
         */
-       public function getPageUrl( TitleValue $page, $params = array() ) {
+       public function getPageUrl( LinkTarget $page, $params = array() ) {
                // TODO: move the code from Linker::linkUrl here!
                // The below is just a rough estimation!
 
@@ -93,20 +93,24 @@ class MediaWikiPageLinkRenderer implements PageLinkRenderer {
        /**
         * Returns an HTML link to the given page, using the given surface text.
         *
-        * @param TitleValue $page The link's target
+        * @param LinkTarget $linkTarget The link's target
         * @param string $text The link's surface text (will be derived from $page if not given).
         *
         * @return string
         */
-       public function renderHtmlLink( TitleValue $page, $text = null ) {
+       public function renderHtmlLink( LinkTarget $linkTarget, $text = null ) {
                if ( $text === null ) {
-                       $text = $this->formatter->getFullText( $page );
+                       $text = $this->formatter->getFullText( $linkTarget );
                }
 
                // TODO: move the logic implemented by Linker here,
                // using $this->formatter and $this->baseUrl, and
                // re-implement Linker to use a HtmlPageLinkRenderer.
-               $title = Title::newFromTitleValue( $page );
+               if ( $linkTarget instanceof Title ) {
+                       $title = $linkTarget;
+               } else {
+                       $title = Title::newFromLinkTarget( $linkTarget );
+               }
                $link = Linker::link( $title, htmlspecialchars( $text ) );
 
                return $link;
@@ -115,12 +119,12 @@ class MediaWikiPageLinkRenderer implements PageLinkRenderer {
        /**
         * Returns a wikitext link to the given page, using the given surface text.
         *
-        * @param TitleValue $page The link's target
+        * @param LinkTarget $page The link's target
         * @param string $text The link's surface text (will be derived from $page if not given).
         *
         * @return string
         */
-       public function renderWikitextLink( TitleValue $page, $text = null ) {
+       public function renderWikitextLink( LinkTarget $page, $text = null ) {
                if ( $text === null ) {
                        $text = $this->formatter->getFullText( $page );
                }
index c497865..1de4247 100644 (file)
@@ -151,33 +151,33 @@ class MediaWikiTitleCodec implements TitleFormatter, TitleParser {
        /**
         * @see TitleFormatter::getText()
         *
-        * @param TitleValue $title
+        * @param LinkTarget $title
         *
         * @return string $title->getText()
         */
-       public function getText( TitleValue $title ) {
+       public function getText( LinkTarget $title ) {
                return $this->formatTitle( false, $title->getText(), '' );
        }
 
        /**
         * @see TitleFormatter::getText()
         *
-        * @param TitleValue $title
+        * @param LinkTarget $title
         *
         * @return string
         */
-       public function getPrefixedText( TitleValue $title ) {
+       public function getPrefixedText( LinkTarget $title ) {
                return $this->formatTitle( $title->getNamespace(), $title->getText(), '' );
        }
 
        /**
         * @see TitleFormatter::getText()
         *
-        * @param TitleValue $title
+        * @param LinkTarget $title
         *
         * @return string
         */
-       public function getFullText( TitleValue $title ) {
+       public function getFullText( LinkTarget $title ) {
                return $this->formatTitle( $title->getNamespace(), $title->getText(), $title->getFragment() );
        }
 
index ca91f58..2ca5707 100644 (file)
@@ -37,32 +37,32 @@ interface PageLinkRenderer {
         *
         * @todo expand this to cover the functionality of Linker::linkUrl
         *
-        * @param TitleValue $page The link's target
+        * @param LinkTarget $page The link's target
         * @param array $params Any additional URL parameters.
         *
         * @return string
         */
-       public function getPageUrl( TitleValue $page, $params = array() );
+       public function getPageUrl( LinkTarget $page, $params = array() );
 
        /**
         * Returns an HTML link to the given page, using the given surface text.
         *
         * @todo expand this to cover the functionality of Linker::link
         *
-        * @param TitleValue $page The link's target
+        * @param LinkTarget $page The link's target
         * @param string $text The link's surface text (will be derived from $page if not given).
         *
         * @return string
         */
-       public function renderHtmlLink( TitleValue $page, $text = null );
+       public function renderHtmlLink( LinkTarget $page, $text = null );
 
        /**
         * Returns a wikitext link to the given page, using the given surface text.
         *
-        * @param TitleValue $page The link's target
+        * @param LinkTarget $page The link's target
         * @param string $text The link's surface text (will be derived from $page if not given).
         *
         * @return string
         */
-       public function renderWikitextLink( TitleValue $page, $text = null );
+       public function renderWikitextLink( LinkTarget $page, $text = null );
 }
index aad8376..4edc5db 100644 (file)
@@ -51,29 +51,29 @@ interface TitleFormatter {
         *
         * @note Only minimal normalization is applied. Consider using TitleValue::getText() directly.
         *
-        * @param TitleValue $title The title to format
+        * @param LinkTarget $title The title to format
         *
         * @return string
         */
-       public function getText( TitleValue $title );
+       public function getText( LinkTarget $title );
 
        /**
         * Returns the title formatted for display, including the namespace name.
         *
-        * @param TitleValue $title The title to format
+        * @param LinkTarget $title The title to format
         *
         * @return string
         */
-       public function getPrefixedText( TitleValue $title );
+       public function getPrefixedText( LinkTarget $title );
 
        /**
         * Returns the title formatted for display, with namespace and fragment.
         *
-        * @param TitleValue $title The title to format
+        * @param LinkTarget $title The title to format
         *
         * @return string
         */
-       public function getFullText( TitleValue $title );
+       public function getFullText( LinkTarget $title );
 
        /**
         * Returns the name of the namespace for the given title.