]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blobdiff - includes/specials/SpecialMostlinkedtemplates.php
MediaWiki 1.30.2
[autoinstallsdev/mediawiki.git] / includes / specials / SpecialMostlinkedtemplates.php
index 822d6bc919c2a65bd8dccd0bbc645deb36d014d7..dee1c8ec5b9ab55af505c1f5f3d44056e140395c 100644 (file)
  * @ingroup SpecialPage
  * @author Rob Church <robchur@gmail.com>
  */
+
+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';
+       }
 }