Merge "Addition of SearchAfterNoDirectMatch hook"
[lhc/web/wiklou.git] / includes / specials / SpecialShortpages.php
index 3b78501..5a4e8f0 100644 (file)
@@ -33,14 +33,6 @@ class ShortPagesPage extends QueryPage {
                parent::__construct( $name );
        }
 
-       // inexpensive?
-       /**
-        * This query is indexed as of 1.5
-        */
-       function isExpensive() {
-               return true;
-       }
-
        function isSyndicated() {
                return false;
        }
@@ -48,12 +40,13 @@ class ShortPagesPage extends QueryPage {
        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' => MWNamespace::getContentNamespaces(),
+                       'fields' => array ( 'namespace' => 'page_namespace',
+                                       'title' => 'page_title',
+                                       'value' => 'page_len' ),
+                       'conds' => array ( 'page_namespace' =>
+                                       MWNamespace::getContentNamespaces(),
                                        'page_is_redirect' => 0 ),
-                       'options' => array ( 'USE INDEX' => 'page_len' )
+                       'options' => array ( 'USE INDEX' => 'page_redirect_namespace_len' )
                );
        }
 
@@ -69,16 +62,17 @@ class ShortPagesPage extends QueryPage {
        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();
-                       foreach ( $res as $row ) {
-                               $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() {
@@ -86,26 +80,34 @@ class ShortPagesPage extends QueryPage {
        }
 
        function formatResult( $skin, $result ) {
-               global $wgLang;
-               $dm = $wgLang->getDirMark();
+               $dm = $this->getLanguage()->getDirMark();
 
-               $title = Title::makeTitle( $result->namespace, $result->title );
+               $title = Title::makeTitleSafe( $result->namespace, $result->title );
                if ( !$title ) {
-                       return '<!-- Invalid title ' .  htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
+                       return Html::element( 'span', array( 'class' => 'mw-invalidtitle' ),
+                               Linker::getInvalidTitleDescription( $this->getContext(), $result->namespace, $result->title ) );
                }
-               $hlink = $skin->linkKnown(
+
+               $hlink = Linker::linkKnown(
                        $title,
-                       wfMsgHtml( 'hist' ),
+                       $this->msg( 'hist' )->escaped(),
                        array(),
                        array( 'action' => 'history' )
                );
-               $plink = $this->isCached()
-                                       ? $skin->link( $title )
-                                       : $skin->linkKnown( $title );
-               $size = wfMessage( 'nbytes', $wgLang->formatNum( $result->value ) )->escaped();
+               $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
+
+               if ( $this->isCached() ) {
+                       $plink = Linker::link( $title );
+                       $exists = $title->exists();
+               } else {
+                       $plink = Linker::linkKnown( $title );
+                       $exists = true;
+               }
+
+               $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
 
-               return $title->exists()
-                               ? "({$hlink}) {$dm}{$plink} {$dm}[{$size}]"
-                               : "<del>({$hlink}) {$dm}{$plink} {$dm}[{$size}]</del>";
+               return $exists
+                               ? "${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
+                               : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
        }
 }