r112954 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112953‎ | r112954 | r112955 >
Date:18:02, 3 March 2012
Author:ialex
Status:ok
Tags:
Comment:
* Removed check for invalid object in formatResult(), Title::makeTitle() always returns an object
* Don't call Title::exists() when result is not cached since the page must exist, and this was issuing a database query per row
* Reorder some variables for better clarity
* Don't execute the LinkBatch if there are now rows
* Call methods directly on ResultWrapper instead of DatabaseBase in preprocessResults()
* Use local context to get message
Modified paths:
  • /trunk/phase3/includes/specials/SpecialShortpages.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/specials/SpecialShortpages.php
@@ -61,16 +61,17 @@
6262 function preprocessResults( $db, $res ) {
6363 # There's no point doing a batch check if we aren't caching results;
6464 # the page must exist for it to have been pulled out of the table
65 - if( $this->isCached() ) {
66 - $batch = new LinkBatch();
67 - foreach ( $res as $row ) {
68 - $batch->add( $row->namespace, $row->title );
69 - }
70 - $batch->execute();
71 - if ( $db->numRows( $res ) > 0 ) {
72 - $db->dataSeek( $res, 0 );
73 - }
 65+ if ( !$this->isCached() || !$res->numRows() ) {
 66+ return;
7467 }
 68+
 69+ $batch = new LinkBatch();
 70+ foreach ( $res as $row ) {
 71+ $batch->add( $row->namespace, $row->title );
 72+ }
 73+ $batch->execute();
 74+
 75+ $res->seek( 0 );
7576 }
7677
7778 function sortDescending() {
@@ -81,23 +82,26 @@
8283 $dm = $this->getLanguage()->getDirMark();
8384
8485 $title = Title::makeTitle( $result->namespace, $result->title );
85 - if ( !$title ) {
86 - return '<!-- Invalid title ' . htmlspecialchars( "{$result->namespace}:{$result->title}" ). '-->';
87 - }
 86+
8887 $hlink = Linker::linkKnown(
8988 $title,
90 - wfMsgHtml( 'hist' ),
 89+ $this->msg( 'hist' )->escaped(),
9190 array(),
9291 array( 'action' => 'history' )
9392 );
94 - $plink = $this->isCached()
95 - ? Linker::link( $title )
96 - : Linker::linkKnown( $title );
 93+ $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
 94+
 95+ if ( $this->isCached() ) {
 96+ $plink = Linker::link( $title );
 97+ $exists = $title->exists();
 98+ } else {
 99+ $plink = Linker::linkKnown( $title );
 100+ $exists = true;
 101+ }
 102+
97103 $size = $this->msg( 'nbytes' )->numParams( $result->value )->escaped();
98104
99 - $hlinkInParentheses = $this->msg( 'parentheses' )->rawParams( $hlink )->escaped();
100 -
101 - return $title->exists()
 105+ return $exists
102106 ? "${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]"
103107 : "<del>${hlinkInParentheses} {$dm}{$plink} {$dm}[{$size}]</del>";
104108 }

Sign-offs

UserFlagDate
Nikerabbitinspected06:59, 5 March 2012

Status & tagging log