mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CategoryTree
synced 2024-11-27 09:43:06 +00:00
Use LinkRenderer instead of manually building links
Use LinkRenderer instead of manually re-implementing parts of it and manually building the <a> tags to create links. Aside from technical debt cleanup, this will cause "stub" and "mw- redirect" classes to get added to the <categorytree> output. Bug: T25771 Change-Id: I1c644ef364818c4202dc0e30602d557dbec46010
This commit is contained in:
parent
48ddabd046
commit
1c779bee3a
|
@ -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' );
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue