Merge "SkinTemplate: extract formatLanguageName() from outputPage()"
[lhc/web/wiklou.git] / includes / specials / SpecialMostlinkedtemplates.php
index 4369ee4..22932e5 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 /**
+ * Implements Special:Mostlinkedtemplates
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * with this program; if not, write to the Free Software Foundation, Inc.,
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  * http://www.gnu.org/copyleft/gpl.html
- */
-
-/**
+ *
  * @file
  * @ingroup SpecialPage
+ * @author Rob Church <robchur@gmail.com>
  */
+
 /**
  * Special page lists templates with a large number of
  * transclusion links, i.e. "most used" templates
  *
  * @ingroup SpecialPage
- * @author Rob Church <robchur@gmail.com>
  */
-class SpecialMostlinkedtemplates extends QueryPage {
+class MostlinkedTemplatesPage extends QueryPage {
 
-       /**
-        * Name of the report
-        *
-        * @return String
-        */
-       public function getName() {
-               return 'Mostlinkedtemplates';
+       function __construct( $name = 'Mostlinkedtemplates' ) {
+               parent::__construct( $name );
        }
 
        /**
@@ -67,38 +61,35 @@ class SpecialMostlinkedtemplates extends QueryPage {
                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 array (
+                       'tables' => array ( 'templatelinks' ),
+                       'fields' => array ( 'namespace' => 'tl_namespace',
+                                       'title' => 'tl_title',
+                                       'value' => 'COUNT(*)' ),
+                       'conds' => array ( 'tl_namespace' => NS_TEMPLATE ),
+                       'options' => array( 'GROUP BY' => array( 'tl_namespace', 'tl_title' ) )
+               );
        }
 
        /**
         * Pre-cache page existence to speed up link generation
         *
-        * @param $db Database connection
+        * @param $db DatabaseBase connection
         * @param $res ResultWrapper
         */
        public function preprocessResults( $db, $res ) {
+               if ( !$res->numRows() ) {
+                       return;
+               }
+
                $batch = new LinkBatch();
-               while( $row = $db->fetchObject( $res ) ) {
+               foreach ( $res as $row ) {
                        $batch->add( $row->namespace, $row->title );
                }
                $batch->execute();
-               if( $db->numRows( $res ) > 0 )
-                       $db->dataSeek( $res, 0 );
+
+               $res->seek( 0 );
        }
 
        /**
@@ -110,10 +101,14 @@ class SpecialMostlinkedtemplates extends QueryPage {
         */
        public function formatResult( $skin, $result ) {
                $title = Title::makeTitleSafe( $result->namespace, $result->title );
+               if ( !$title ) {
+                       return Html::element( 'span', array( '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(
+                       Linker::link( $title ),
+                       $this->makeWlhLink( $title, $result )
                );
        }
 
@@ -121,26 +116,13 @@ class SpecialMostlinkedtemplates extends QueryPage {
         * 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
         */
-       private function makeWlhLink( $title, $skin, $result ) {
-               global $wgLang;
-               $wlh = SpecialPage::getTitleFor( 'Whatlinkshere' );
-               $label = wfMsgExt( 'nlinks', 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 )->escaped();
+               return Linker::link( $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 );
-}