r92975 caused wikitable in MediaWiki:Recentchangestext (eg. enwiki)
[lhc/web/wiklou.git] / includes / specials / SpecialShortpages.php
index 2e7d24a..c176f91 100644 (file)
@@ -1,5 +1,22 @@
 <?php
 /**
+ * Implements Special:Shortpages
+ *
+ * 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
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * 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
  */
 /**
  * SpecialShortpages extends QueryPage. It is used to return the shortest
  * pages in the database.
+ *
  * @ingroup SpecialPage
  */
 class ShortPagesPage extends QueryPage {
 
-       function getName() {
-               return 'Shortpages';
-       }
-
-       /**
-        * This query is indexed as of 1.5
-        */
-       function isExpensive() {
-               return true;
+       function __construct( $name = 'Shortpages' ) {
+               parent::__construct( $name );
        }
 
        function isSyndicated() {
                return false;
        }
 
-       function getSQL() {
-               global $wgContentNamespaces;
-
-               $dbr = wfGetDB( DB_SLAVE );
-               $page = $dbr->tableName( 'page' );
-               $name = $dbr->addQuotes( $this->getName() );
-
-               $forceindex = $dbr->useIndexClause("page_len");
-
-               if ($wgContentNamespaces)
-                       $nsclause = "page_namespace IN (" . $dbr->makeList($wgContentNamespaces) . ")";
-               else
-                       $nsclause = "page_namespace = " . NS_MAIN;
+       function getQueryInfo() {
+               return array (
+                       'tables' => array ( 'page' ),
+                       'fields' => array ( 'page_namespace AS namespace',
+                                       'page_title AS title',
+                                       'page_len AS value' ),
+                       'conds' => array ( 'page_namespace' => NS_MAIN,
+                                       'page_is_redirect' => 0 ),
+                       'options' => array ( 'USE INDEX' => 'page_redirect_namespace_len' )
+               );
+       }
 
-               return
-                       "SELECT $name as type,
-                               page_namespace as namespace,
-                               page_title as title,
-                               page_len AS value
-                       FROM $page $forceindex
-                       WHERE $nsclause AND page_is_redirect=0";
+       function getOrderFields() {
+               return array( 'page_len' );
        }
 
+       /**
+        * @param $db DatabaseBase
+        * @param $res
+        * @return void
+        */
        function preprocessResults( $db, $res ) {
                # There's no point doing a batch check if we aren't caching results;
                # the page must exist for it to have been pulled out of the table
                if( $this->isCached() ) {
                        $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 )
+                       if ( $db->numRows( $res ) > 0 ) {
                                $db->dataSeek( $res, 0 );
+                       }
                }
        }
 
@@ -67,32 +78,25 @@ class ShortPagesPage extends QueryPage {
        }
 
        function formatResult( $skin, $result ) {
-               global $wgLang, $wgContLang;
-               $dm = $wgContLang->getDirMark();
+               $dm = $this->getLanguage()->getDirMark();
 
-               $title = Title::makeTitleSafe( $result->namespace, $result->title );
+               $title = Title::makeTitle( $result->namespace, $result->title );
                if ( !$title ) {
                        return '<!-- Invalid title ' .  htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
                }
-               $hlink = $skin->makeKnownLinkObj( $title, wfMsgHtml( 'hist' ), 'action=history' );
+               $hlink = Linker::linkKnown(
+                       $title,
+                       wfMsgHtml( 'hist' ),
+                       array(),
+                       array( 'action' => 'history' )
+               );
                $plink = $this->isCached()
-                                       ? $skin->makeLinkObj( $title )
-                                       : $skin->makeKnownLinkObj( $title );
-               $size = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->value ) ) );
+                                       ? Linker::link( $title )
+                                       : Linker::linkKnown( $title );
+               $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
 
                return $title->exists()
                                ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
-                               : "<s>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</s>";
+                               : "<del>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</del>";
        }
 }
-
-/**
- * constructor
- */
-function wfSpecialShortpages() {
-       list( $limit, $offset ) = wfCheckLimits();
-
-       $spp = new ShortPagesPage();
-
-       return $spp->doQuery( $offset, $limit );
-}