X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/specials/SpecialMostlinkedcategories.php diff --git a/includes/specials/SpecialMostlinkedcategories.php b/includes/specials/SpecialMostlinkedcategories.php index e1fc1d95..956207f8 100644 --- a/includes/specials/SpecialMostlinkedcategories.php +++ b/includes/specials/SpecialMostlinkedcategories.php @@ -24,72 +24,75 @@ * @author Ævar Arnfjörð Bjarmason */ +use Wikimedia\Rdbms\ResultWrapper; +use Wikimedia\Rdbms\IDatabase; + /** - * A querypage to show categories ordered in descending order by the pages in them + * A querypage to show categories ordered in descending order by the pages in them * * @ingroup SpecialPage */ class MostlinkedCategoriesPage extends QueryPage { + function __construct( $name = 'Mostlinkedcategories' ) { + parent::__construct( $name ); + } - function getName() { return 'Mostlinkedcategories'; } - function isExpensive() { return true; } - function isSyndicated() { return false; } + function isSyndicated() { + return false; + } - function getSQL() { - $dbr = wfGetDB( DB_SLAVE ); - $categorylinks = $dbr->tableName( 'categorylinks' ); - $name = $dbr->addQuotes( $this->getName() ); - return - " - SELECT - $name as type, - " . NS_CATEGORY . " as namespace, - cl_to as title, - COUNT(*) as value - FROM $categorylinks - GROUP BY cl_to - "; + public function getQueryInfo() { + return [ + 'tables' => [ 'category' ], + 'fields' => [ 'title' => 'cat_title', + 'namespace' => NS_CATEGORY, + 'value' => 'cat_pages' ], + 'conds' => [ 'cat_pages > 0' ], + ]; } - function sortDescending() { return true; } + function sortDescending() { + return true; + } /** * Fetch user page links and cache their existence + * + * @param IDatabase $db + * @param ResultWrapper $res */ function preprocessResults( $db, $res ) { - $batch = new LinkBatch; - foreach ( $res as $row ) { - $batch->add( $row->namespace, $row->title ); - } - $batch->execute(); - - // Back to start for display - if ( $db->numRows( $res ) > 0 ) - // If there are no rows we get an error seeking. - $db->dataSeek( $res, 0 ); + $this->executeLBFromResultWrapper( $res ); } + /** + * @param Skin $skin + * @param object $result Result row + * @return string + */ function formatResult( $skin, $result ) { - global $wgLang, $wgContLang; + global $wgContLang; - $nt = Title::makeTitle( $result->namespace, $result->title ); - $text = $wgContLang->convert( $nt->getText() ); + $nt = Title::makeTitleSafe( NS_CATEGORY, $result->title ); + if ( !$nt ) { + return Html::element( + 'span', + [ 'class' => 'mw-invalidtitle' ], + Linker::getInvalidTitleDescription( + $this->getContext(), + NS_CATEGORY, + $result->title ) + ); + } - $plink = $skin->link( $nt, htmlspecialchars( $text ) ); + $text = $wgContLang->convert( $nt->getText() ); + $plink = $this->getLinkRenderer()->makeLink( $nt, $text ); + $nlinks = $this->msg( 'nmembers' )->numParams( $result->value )->escaped(); - $nlinks = wfMsgExt( 'nmembers', array( 'parsemag', 'escape'), - $wgLang->formatNum( $result->value ) ); - return wfSpecialList($plink, $nlinks); + return $this->getLanguage()->specialList( $plink, $nlinks ); } -} - -/** - * constructor - */ -function wfSpecialMostlinkedCategories() { - list( $limit, $offset ) = wfCheckLimits(); - $wpp = new MostlinkedCategoriesPage(); - - $wpp->doQuery( $offset, $limit ); + protected function getGroupName() { + return 'highuse'; + } }