wiki.techinc.nl/includes/specials/SpecialMostLinkedCategories.php
Umherirrender d5c868386e Inject LanguageConverterFactory into special pages
The function SpecialPage::getLanguageConverter does not use service
injection and it seems not useful to inject the factory into every
special page when not used on each special page or used from code
directly in the SpecialPage class.

Bug: T259960
Depends-On: I550f2db0c652193755ad4ad04cececad00be72ea
Change-Id: I11e5d67b7051c159b8d32bf056a0e24aa3b526ae
2020-11-25 18:39:57 +01:00

116 lines
3.2 KiB
PHP

<?php
/**
* Implements Special:Mostlinkedcategories
*
* Copyright © 2005, Ævar Arnfjörð Bjarmason
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
* http://www.gnu.org/copyleft/gpl.html
*
* @file
* @ingroup SpecialPage
* @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
*/
use MediaWiki\Cache\LinkBatchFactory;
use MediaWiki\Languages\LanguageConverterFactory;
use Wikimedia\Rdbms\IDatabase;
use Wikimedia\Rdbms\ILoadBalancer;
use Wikimedia\Rdbms\IResultWrapper;
/**
* A querypage to show categories ordered in descending order by the pages in them
*
* @ingroup SpecialPage
*/
class SpecialMostLinkedCategories extends QueryPage {
/** @var ILanguageConverter */
private $languageConverter;
/**
* @param ILoadBalancer $loadBalancer
* @param LinkBatchFactory $linkBatchFactory
* @param LanguageConverterFactory $languageConverterFactory
*/
public function __construct(
ILoadBalancer $loadBalancer,
LinkBatchFactory $linkBatchFactory,
LanguageConverterFactory $languageConverterFactory
) {
parent::__construct( 'Mostlinkedcategories' );
$this->setDBLoadBalancer( $loadBalancer );
$this->setLinkBatchFactory( $linkBatchFactory );
$this->languageConverter = $languageConverterFactory->getLanguageConverter( $this->getContentLanguage() );
}
public function isSyndicated() {
return false;
}
public function getQueryInfo() {
return [
'tables' => [ 'category' ],
'fields' => [ 'title' => 'cat_title',
'namespace' => NS_CATEGORY,
'value' => 'cat_pages' ],
'conds' => [ 'cat_pages > 0' ],
];
}
protected function sortDescending() {
return true;
}
/**
* Fetch user page links and cache their existence
*
* @param IDatabase $db
* @param IResultWrapper $res
*/
public function preprocessResults( $db, $res ) {
$this->executeLBFromResultWrapper( $res );
}
/**
* @param Skin $skin
* @param stdClass $result Result row
* @return string
*/
public function formatResult( $skin, $result ) {
$nt = Title::makeTitleSafe( NS_CATEGORY, $result->title );
if ( !$nt ) {
return Html::element(
'span',
[ 'class' => 'mw-invalidtitle' ],
Linker::getInvalidTitleDescription(
$this->getContext(),
NS_CATEGORY,
$result->title )
);
}
$text = $this->languageConverter->convertHtml( $nt->getText() );
$plink = $this->getLinkRenderer()->makeLink( $nt, new HtmlArmor( $text ) );
$nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped();
return $this->getLanguage()->specialList( $plink, $nlinks );
}
protected function getGroupName() {
return 'highuse';
}
}