From 1c779bee3a76c4454db0d30aee43509d2816d521 Mon Sep 17 00:00:00 2001 From: Kunal Mehta Date: Mon, 30 May 2016 03:01:38 -0700 Subject: [PATCH] Use LinkRenderer instead of manually building links Use LinkRenderer instead of manually re-implementing parts of it and manually building the tags to create links. Aside from technical debt cleanup, this will cause "stub" and "mw- redirect" classes to get added to the output. Bug: T25771 Change-Id: I1c644ef364818c4202dc0e30602d557dbec46010 --- includes/CategoryTree.php | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/includes/CategoryTree.php b/includes/CategoryTree.php index 125a6cea..ef3f3ca2 100644 --- a/includes/CategoryTree.php +++ b/includes/CategoryTree.php @@ -21,7 +21,7 @@ * @ingroup Extensions * @author Daniel Kinzler, brightbyte.de */ - +use MediaWiki\Linker\LinkRenderer; use MediaWiki\MediaWikiServices; /** @@ -30,6 +30,10 @@ use MediaWiki\MediaWikiServices; */ class CategoryTree { public $mOptions = []; + + /** + * @var LinkRenderer + */ private $linkRenderer; /** @@ -313,13 +317,6 @@ class CategoryTree { return $s; } - /** - * @return string - */ - private function getOptionsAsUrlParameters() { - return http_build_query( $this->mOptions ); - } - /** * Custom tag implementation. This is called by CategoryTreeHooks::parserHook, which is used to * load CategoryTreeFunctions.php on demand. @@ -501,10 +498,7 @@ class CategoryTree { $res = $dbr->select( 'categorylinks', - [ - 'page_namespace' => NS_CATEGORY, - 'page_title' => 'cl_to', - ], + [ 'cl_to' ], [ 'cl_from' => $title->getArticleID() ], __METHOD__, [ @@ -518,19 +512,19 @@ class CategoryTree { $s = ''; foreach ( $res as $row ) { - $t = Title::newFromRow( $row ); - - $label = $t->getText(); - - $wikiLink = $special->getLocalURL( 'target=' . $t->getPartialURL() . - '&' . $this->getOptionsAsUrlParameters() ); + $t = Title::makeTitle( NS_CATEGORY, $row->cl_to ); if ( $s !== '' ) { $s .= wfMessage( 'pipe-separator' )->escaped(); } $s .= Xml::openElement( 'span', [ 'class' => 'CategoryTreeItem' ] ); - $s .= Xml::element( 'a', [ 'class' => 'CategoryTreeLabel', 'href' => $wikiLink ], $label ); + $s .= $this->linkRenderer->makeLink( + $special, + $t->getText(), + [ 'class' => 'CategoryTreeLabel' ], + [ 'target' => $t->getPartialURL() ] + $this->mOptions + ); $s .= Xml::closeElement( 'span' ); }