From ab66a4427ae32f56397d8913bcc15642240c4c1e Mon Sep 17 00:00:00 2001 From: addshore Date: Wed, 27 Jan 2016 12:34:49 +0100 Subject: [PATCH] Use LinkTarget in TitleValue only methods Change-Id: Iee4b183ae54457d0c6cd3473f9fed3207742b54f --- includes/Title.php | 17 ++++++++++++++--- includes/title/MediaWikiPageLinkRenderer.php | 20 ++++++++++++-------- includes/title/MediaWikiTitleCodec.php | 12 ++++++------ includes/title/PageLinkRenderer.php | 12 ++++++------ includes/title/TitleFormatter.php | 12 ++++++------ 5 files changed, 44 insertions(+), 29 deletions(-) diff --git a/includes/Title.php b/includes/Title.php index f2a33e2ecc..fdd773b033 100644 --- a/includes/Title.php +++ b/includes/Title.php @@ -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() ); } /** diff --git a/includes/title/MediaWikiPageLinkRenderer.php b/includes/title/MediaWikiPageLinkRenderer.php index 27574fa4a0..07060b2f79 100644 --- a/includes/title/MediaWikiPageLinkRenderer.php +++ b/includes/title/MediaWikiPageLinkRenderer.php @@ -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 ); } diff --git a/includes/title/MediaWikiTitleCodec.php b/includes/title/MediaWikiTitleCodec.php index c49786521a..1de4247887 100644 --- a/includes/title/MediaWikiTitleCodec.php +++ b/includes/title/MediaWikiTitleCodec.php @@ -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() ); } diff --git a/includes/title/PageLinkRenderer.php b/includes/title/PageLinkRenderer.php index ca91f58331..2ca5707058 100644 --- a/includes/title/PageLinkRenderer.php +++ b/includes/title/PageLinkRenderer.php @@ -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 ); } diff --git a/includes/title/TitleFormatter.php b/includes/title/TitleFormatter.php index aad83769c8..4edc5db5ab 100644 --- a/includes/title/TitleFormatter.php +++ b/includes/title/TitleFormatter.php @@ -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. -- 2.20.1