Legoktm has uploaded a new change for review.
https://gerrit.wikimedia.org/r/291702
Change subject: Use LinkRenderer instead of manually building links
......................................................................
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
---
M CategoryTreeFunctions.php
1 file changed, 20 insertions(+), 23 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CategoryTree
refs/changes/02/291702/1
diff --git a/CategoryTreeFunctions.php b/CategoryTreeFunctions.php
index 3ffcaf4..f2bb791 100644
--- a/CategoryTreeFunctions.php
+++ b/CategoryTreeFunctions.php
@@ -9,6 +9,8 @@
* @copyright © 2006-2007 Daniel Kinzler
* @license GNU General Public Licence 2.0 or later
*/
+use MediaWiki\Linker\LinkRenderer;
+use MediaWiki\MediaWikiServices;
if ( !defined( 'MEDIAWIKI' ) ) {
echo( "This file is part of an extension to the MediaWiki software and
cannot be used standalone.\n" );
@@ -18,6 +20,11 @@
class CategoryTree {
public $mIsAjaxRequest = false;
public $mOptions = array();
+
+ /**
+ * @var LinkRenderer
+ */
+ private $linkRenderer;
/**
* @param $options array
@@ -58,6 +65,8 @@
$this->mOptions['mode'] = CT_MODE_ALL;
}
}
+
+ $this->linkRenderer =
MediaWikiServices::getInstance()->getLinkRenderer();
}
/**
@@ -470,10 +479,7 @@
$res = $dbr->select(
'categorylinks',
- array(
- 'page_namespace' => NS_CATEGORY,
- 'page_title' => 'cl_to',
- ),
+ array( 'cl_to' ),
array( 'cl_from' => $title->getArticleID() ),
__METHOD__,
array(
@@ -487,20 +493,19 @@
$s = '';
foreach ( $res as $row ) {
- $t = Title::newFromRow( $row );
-
- $label = htmlspecialchars( $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', array( 'class' =>
'CategoryTreeItem' ) );
- $s .= Xml::openElement( 'a', array( 'class' =>
'CategoryTreeLabel', 'href' => $wikiLink ) )
- . $label . Xml::closeElement( 'a' );
+ $s .= $this->linkRenderer->makeLink(
+ $special,
+ $t->getText(),
+ array( 'class' => 'CategoryTreeLabel' ),
+ array( 'target' => $t->getPartialURL() ) +
$this->mOptions
+ );
$s .= Xml::closeElement( 'span' );
$s .= "\n\t\t";
@@ -556,19 +561,12 @@
# when showing only categories, omit namespace in label unless
we explicitely defined the configuration setting
# patch contributed by Manuel Schneider
<[email protected]>, Bug 8011
if ( $hideprefix ) {
- $label = htmlspecialchars( $title->getText() );
+ $label = $title->getText();
} else {
- $label = htmlspecialchars( $title->getPrefixedText() );
+ $label = $title->getPrefixedText();
}
$labelClass = 'CategoryTreeLabel ' . ' CategoryTreeLabelNs' .
$ns;
-
- if ( !$title->getArticleID() ) {
- $labelClass .= ' new';
- $wikiLink = $title->getLocalURL(
'action=edit&redlink=1' );
- } else {
- $wikiLink = $title->getLocalURL();
- }
if ( $ns == NS_CATEGORY ) {
$labelClass .= ' CategoryTreeLabelCategory';
@@ -639,8 +637,7 @@
}
$s .= Xml::tags( 'span', $attr, $bullet ) . ' ';
- $s .= Xml::openElement( 'a', array( 'class' => $labelClass,
'href' => $wikiLink ) )
- . $label . Xml::closeElement( 'a' );
+ $s .= $this->linkRenderer->makeLink( $title, $label, array(
'class' => $labelClass ) );
if ( $count !== false && $this->getOption( 'showcount' ) ) {
$pages = $allCount - $subcatCount - $fileCount;
--
To view, visit https://gerrit.wikimedia.org/r/291702
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I1c644ef364818c4202dc0e30602d557dbec46010
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CategoryTree
Gerrit-Branch: master
Gerrit-Owner: Legoktm <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits