]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialMostlinkedcategories.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialMostlinkedcategories.php
index e1fc1d95503b7eec493edbb93b82416035fb47cd..956207f883a56e71b7f3972c54245e1b3a6ebb5a 100644 (file)
  * @author Ævar Arnfjörð Bjarmason <avarab@gmail.com>
  */
 
+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';
+       }
 }