Merge "[FileBackend] Improved connection error handling and logging a bit for Swift."
[lhc/web/wiklou.git] / includes / specials / SpecialShortpages.php
index c1aa9fc..8622b92 100644 (file)
  */
 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 ) )
-                               $batch->add( $row->namespace, $row->title );
-                       $batch->execute();
-                       if( $db->numRows( $res ) > 0 )
-                               $db->dataSeek( $res, 0 );
+               if ( !$this->isCached() || !$res->numRows() ) {
+                       return;
+               }
+
+               $batch = new LinkBatch();
+               foreach ( $res as $row ) {
+                       $batch->add( $row->namespace, $row->title );
                }
+               $batch->execute();
+
+               $res->seek( 0 );
        }
 
        function sortDescending() {
@@ -85,37 +79,30 @@ 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 );
-               if ( !$title ) {
-                       return '<!-- Invalid title ' .  htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
-               }
-               $hlink = $skin->linkKnown(
+               $title = Title::makeTitle( $result->namespace, $result->title );
+
+               $hlink = Linker::linkKnown(
                        $title,
-                       wfMsgHtml( 'hist' ),
+                       $this->msg( 'hist' )->escaped(),
                        array(),
                        array( 'action' => 'history' )
                );
-               $plink = $this->isCached()
-                                       ? $skin->link( $title )
-                                       : $skin->linkKnown( $title );
-               $size = wfMsgExt( 'nbytes', array( 'parsemag', 'escape' ), $wgLang->formatNum( htmlspecialchars( $result->value ) ) );
-
-               return $title->exists()
-                               ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
-                               : "<del>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</del>";
-       }
-}
-
-/**
- * constructor
- */
-function wfSpecialShortpages() {
-       list( $limit, $offset ) = wfCheckLimits();
+               $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
+
+               if ( $this->isCached() ) {
+                       $plink = Linker::link( $title );
+                       $exists = $title->exists();
+               } else {
+                       $plink = Linker::linkKnown( $title );
+                       $exists = true;
+               }
 
-       $spp = new ShortPagesPage();
+               $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
 
-       return $spp->doQuery( $offset, $limit );
+               return $exists
+                               ? "${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
+                               : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
+       }
 }