]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blobdiff - includes/specials/SpecialMostcategories.php
MediaWiki 1.30.2-scripts
[autoinstalls/mediawiki.git] / includes / specials / SpecialMostcategories.php
index 124f0bd5d0ad81b8f37c93018cd36b6dd71bb00d..bebed12e381c30779e7ad2b684a5672c1a6283ad 100644 (file)
  * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
  */
 
+use Wikimedia\Rdbms\ResultWrapper;
+use Wikimedia\Rdbms\IDatabase;
+
 /**
  * A special page that list pages that have highest category count
  *
  * @ingroup SpecialPage
  */
 class MostcategoriesPage extends QueryPage {
+       function __construct( $name = 'Mostcategories' ) {
+               parent::__construct( $name );
+       }
+
+       public function isExpensive() {
+               return true;
+       }
 
-       function getName() { return 'Mostcategories'; }
-       function isExpensive() { return true; }
-       function isSyndicated() { return false; }
+       function isSyndicated() {
+               return false;
+       }
+
+       public function getQueryInfo() {
+               return [
+                       'tables' => [ 'categorylinks', 'page' ],
+                       'fields' => [
+                               'namespace' => 'page_namespace',
+                               'title' => 'page_title',
+                               'value' => 'COUNT(*)'
+                       ],
+                       'conds' => [ 'page_namespace' => MWNamespace::getContentNamespaces() ],
+                       'options' => [
+                               'HAVING' => 'COUNT(*) > 1',
+                               'GROUP BY' => [ 'page_namespace', 'page_title' ]
+                       ],
+                       'join_conds' => [
+                               'page' => [
+                                       'LEFT JOIN',
+                                       'page_id = cl_from'
+                               ]
+                       ]
+               ];
+       }
 
-       function getSQL() {
-               $dbr = wfGetDB( DB_SLAVE );
-               list( $categorylinks, $page) = $dbr->tableNamesN( 'categorylinks', 'page' );
-               return
-                       "
-                       SELECT
-                               'Mostcategories' as type,
-                               page_namespace as namespace,
-                               page_title as title,
-                               COUNT(*) as value
-                       FROM $categorylinks
-                       LEFT JOIN $page ON cl_from = page_id
-                       WHERE page_namespace = " . NS_MAIN . "
-                       GROUP BY page_namespace, page_title
-                       HAVING COUNT(*) > 1
-                       ";
+       /**
+        * @param IDatabase $db
+        * @param ResultWrapper $res
+        */
+       function preprocessResults( $db, $res ) {
+               $this->executeLBFromResultWrapper( $res );
        }
 
+       /**
+        * @param Skin $skin
+        * @param object $result Result row
+        * @return string
+        */
        function formatResult( $skin, $result ) {
-               global $wgLang;
                $title = Title::makeTitleSafe( $result->namespace, $result->title );
+               if ( !$title ) {
+                       return Html::element(
+                               'span',
+                               [ 'class' => 'mw-invalidtitle' ],
+                               Linker::getInvalidTitleDescription(
+                                       $this->getContext(),
+                                       $result->namespace,
+                                       $result->title
+                               )
+                       );
+               }
 
-               $count = wfMsgExt( 'ncategories', array( 'parsemag', 'escape' ), $wgLang->formatNum( $result->value ) );
-               $link = $skin->link( $title );
-               return wfSpecialList( $link, $count );
-       }
-}
+               $linkRenderer = $this->getLinkRenderer();
+               if ( $this->isCached() ) {
+                       $link = $linkRenderer->makeLink( $title );
+               } else {
+                       $link = $linkRenderer->makeKnownLink( $title );
+               }
 
-/**
- * constructor
- */
-function wfSpecialMostcategories() {
-       list( $limit, $offset ) = wfCheckLimits();
+               $count = $this->msg( 'ncategories' )->numParams( $result->value )->escaped();
 
-       $wpp = new MostcategoriesPage();
+               return $this->getLanguage()->specialList( $link, $count );
+       }
 
-       $wpp->doQuery( $offset, $limit );
+       protected function getGroupName() {
+               return 'highuse';
+       }
 }