X-Git-Url: https://scripts.mit.edu/gitweb/autoinstallsdev/mediawiki.git/blobdiff_plain/19e297c21b10b1b8a3acad5e73fc71dcb35db44a..6932310fd58ebef145fa01eb76edf7150284d8ea:/includes/specials/SpecialMostlinkedtemplates.php diff --git a/includes/specials/SpecialMostlinkedtemplates.php b/includes/specials/SpecialMostlinkedtemplates.php index 822d6bc9..dee1c8ec 100644 --- a/includes/specials/SpecialMostlinkedtemplates.php +++ b/includes/specials/SpecialMostlinkedtemplates.php @@ -21,28 +21,25 @@ * @ingroup SpecialPage * @author Rob Church */ - + +use Wikimedia\Rdbms\ResultWrapper; +use Wikimedia\Rdbms\IDatabase; + /** * Special page lists templates with a large number of * transclusion links, i.e. "most used" templates * * @ingroup SpecialPage */ -class SpecialMostlinkedtemplates extends QueryPage { - - /** - * Name of the report - * - * @return String - */ - public function getName() { - return 'Mostlinkedtemplates'; +class MostlinkedTemplatesPage extends QueryPage { + function __construct( $name = 'Mostlinkedtemplates' ) { + parent::__construct( $name ); } /** * Is this report expensive, i.e should it be cached? * - * @return Boolean + * @return bool */ public function isExpensive() { return true; @@ -51,7 +48,7 @@ class SpecialMostlinkedtemplates extends QueryPage { /** * Is there a feed available? * - * @return Boolean + * @return bool */ public function isSyndicated() { return false; @@ -60,86 +57,76 @@ class SpecialMostlinkedtemplates extends QueryPage { /** * Sort the results in descending order? * - * @return Boolean + * @return bool */ public function sortDescending() { return true; } - /** - * Generate SQL for the report - * - * @return String - */ - public function getSql() { - $dbr = wfGetDB( DB_SLAVE ); - $templatelinks = $dbr->tableName( 'templatelinks' ); - $name = $dbr->addQuotes( $this->getName() ); - return "SELECT {$name} AS type, - " . NS_TEMPLATE . " AS namespace, - tl_title AS title, - COUNT(*) AS value - FROM {$templatelinks} - WHERE tl_namespace = " . NS_TEMPLATE . " - GROUP BY tl_title"; + public function getQueryInfo() { + return [ + 'tables' => [ 'templatelinks' ], + 'fields' => [ + 'namespace' => 'tl_namespace', + 'title' => 'tl_title', + 'value' => 'COUNT(*)' + ], + 'options' => [ 'GROUP BY' => [ 'tl_namespace', 'tl_title' ] ] + ]; } /** * Pre-cache page existence to speed up link generation * - * @param $db Database connection - * @param $res ResultWrapper + * @param IDatabase $db + * @param ResultWrapper $res */ public function preprocessResults( $db, $res ) { - $batch = new LinkBatch(); - foreach ( $res as $row ) { - $batch->add( $row->namespace, $row->title ); - } - $batch->execute(); - if( $db->numRows( $res ) > 0 ) - $db->dataSeek( $res, 0 ); + $this->executeLBFromResultWrapper( $res ); } /** * Format a result row * - * @param $skin Skin to use for UI elements - * @param $result Result row - * @return String + * @param Skin $skin + * @param object $result Result row + * @return string */ public function formatResult( $skin, $result ) { $title = Title::makeTitleSafe( $result->namespace, $result->title ); + if ( !$title ) { + return Html::element( + 'span', + [ 'class' => 'mw-invalidtitle' ], + Linker::getInvalidTitleDescription( + $this->getContext(), + $result->namespace, + $result->title + ) + ); + } - return wfSpecialList( - $skin->link( $title ), - $this->makeWlhLink( $title, $skin, $result ) + return $this->getLanguage()->specialList( + $this->getLinkRenderer()->makeLink( $title ), + $this->makeWlhLink( $title, $result ) ); } /** * Make a "what links here" link for a given title * - * @param $title Title to make the link for - * @param $skin Skin to use - * @param $result Result row - * @return String + * @param Title $title Title to make the link for + * @param object $result Result row + * @return string */ - private function makeWlhLink( $title, $skin, $result ) { - global $wgLang; - $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' ); - $label = wfMsgExt( 'ntransclusions', array( 'parsemag', 'escape' ), - $wgLang->formatNum( $result->value ) ); - return $skin->link( $wlh, $label, array(), array( 'target' => $title->getPrefixedText() ) ); + private function makeWlhLink( $title, $result ) { + $wlh = SpecialPage::getTitleFor( 'Whatlinkshere', $title->getPrefixedText() ); + $label = $this->msg( 'ntransclusions' )->numParams( $result->value )->text(); + + return $this->getLinkRenderer()->makeLink( $wlh, $label ); } -} -/** - * Execution function - * - * @param $par Mixed: parameters passed to the page - */ -function wfSpecialMostlinkedtemplates( $par = false ) { - list( $limit, $offset ) = wfCheckLimits(); - $mlt = new SpecialMostlinkedtemplates(); - $mlt->doQuery( $offset, $limit ); + protected function getGroupName() { + return 'highuse'; + } }