r83843 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r83842‎ | r83843 | r83844 >
Date:17:59, 13 March 2011
Author:reedy
Status:resolved (Comments)
Tags:
Comment:
Bug 27341 - Add drto param to list=deletedrevs

Tidy code up a little bit
Modified paths:
  • /trunk/phase3/RELEASE-NOTES (modified) (history)
  • /trunk/phase3/includes/api/ApiQueryDeletedrevs.php (modified) (history)

Diff [purge]

Index: trunk/phase3/includes/api/ApiQueryDeletedrevs.php
@@ -128,6 +128,8 @@
129129 $token = $wgUser->editToken( '', $this->getMain()->getRequest() );
130130 }
131131
 132+ $dir = $params['dir'];
 133+
132134 // We need a custom WHERE clause that matches all titles.
133135 if ( $mode == 'revs' ) {
134136 $lb = new LinkBatch( $titles );
@@ -135,10 +137,10 @@
136138 $this->addWhere( $where );
137139 } elseif ( $mode == 'all' ) {
138140 $this->addWhereFld( 'ar_namespace', $params['namespace'] );
139 - if ( !is_null( $params['from'] ) ) {
140 - $from = $this->getDB()->strencode( $this->titleToKey( $params['from'] ) );
141 - $this->addWhere( "ar_title >= '$from'" );
142 - }
 141+
 142+ $from = is_null( $params['from'] ) ? null : $this->titleToKey( $params['from'] );
 143+ $to = is_null( $params['to'] ) ? null : $this->titleToKey( $params['to'] );
 144+ $this->addWhereRange( 'ar_title', $dir, $from, $to );
143145 }
144146
145147 if ( !is_null( $params['user'] ) ) {
@@ -148,8 +150,7 @@
149151 $this->getDB()->addQuotes( $params['excludeuser'] ) );
150152 }
151153
152 - if ( !is_null( $params['continue'] ) && ( $mode == 'all' || $mode == 'revs' ) )
153 - {
 154+ if ( !is_null( $params['continue'] ) && ( $mode == 'all' || $mode == 'revs' ) ) {
154155 $cont = explode( '|', $params['continue'] );
155156 if ( count( $cont ) != 3 ) {
156157 $this->dieUsage( 'Invalid continue param. You should pass the original value returned by the previous query', 'badcontinue' );
@@ -157,7 +158,7 @@
158159 $ns = intval( $cont[0] );
159160 $title = $this->getDB()->strencode( $this->titleToKey( $cont[1] ) );
160161 $ts = $this->getDB()->strencode( $cont[2] );
161 - $op = ( $params['dir'] == 'newer' ? '>' : '<' );
 162+ $op = ( $dir == 'newer' ? '>' : '<' );
162163 $this->addWhere( "ar_namespace $op $ns OR " .
163164 "(ar_namespace = $ns AND " .
164165 "(ar_title $op '$title' OR " .
@@ -170,17 +171,16 @@
171172 if ( $mode == 'all' ) {
172173 if ( $params['unique'] ) {
173174 $this->addOption( 'GROUP BY', 'ar_title' );
174 - $this->addOption( 'ORDER BY', 'ar_title' );
175175 } else {
176 - $this->addOption( 'ORDER BY', 'ar_title, ar_timestamp' );
 176+ $this->addOption( 'ORDER BY', 'ar_timestamp' );
177177 }
178178 } else {
179179 if ( $mode == 'revs' ) {
180180 // Sort by ns and title in the same order as timestamp for efficiency
181 - $this->addWhereRange( 'ar_namespace', $params['dir'], null, null );
182 - $this->addWhereRange( 'ar_title', $params['dir'], null, null );
 181+ $this->addWhereRange( 'ar_namespace', $dir, null, null );
 182+ $this->addWhereRange( 'ar_title', $dir, null, null );
183183 }
184 - $this->addWhereRange( 'ar_timestamp', $params['dir'], $params['start'], $params['end'] );
 184+ $this->addWhereRange( 'ar_timestamp', $dir, $params['start'], $params['end'] );
185185 }
186186 $res = $this->select( __METHOD__ );
187187 $pageMap = array(); // Maps ns&title to (fake) pageid
@@ -273,6 +273,7 @@
274274 ApiBase::PARAM_DFLT => 'older'
275275 ),
276276 'from' => null,
 277+ 'to' => null,
277278 'continue' => null,
278279 'unique' => false,
279280 'user' => array(
@@ -315,6 +316,8 @@
316317 'start' => 'The timestamp to start enumerating from (1,2)',
317318 'end' => 'The timestamp to stop enumerating at (1,2)',
318319 'dir' => $this->getDirectionDescription( $this->getModulePrefix(), ' (1,2)' ),
 320+ 'from' => 'Start listing at this title (3)',
 321+ 'to' => 'Stop listing at this title (3)',
319322 'limit' => 'The maximum amount of revisions to list',
320323 'prop' => array(
321324 'Which properties to get',
@@ -331,7 +334,6 @@
332335 'namespace' => 'Only list pages in this namespace (3)',
333336 'user' => 'Only list revisions by this user',
334337 'excludeuser' => 'Don\'t list revisions by this user',
335 - 'from' => 'Start listing at this title (3)',
336338 'continue' => 'When more results are available, use this to continue (3)',
337339 'unique' => 'List only one revision for each page (3)',
338340 );
Index: trunk/phase3/RELEASE-NOTES
@@ -251,6 +251,7 @@
252252 * (bug 27340) API: Allow listing of "small" categories
253253 * (bug 27342) Add audir param to list=allusers
254254 * (bug 27203) add fato param to list=filearchive
 255+* (bug 27341) Add drto param to list=deletedrevs
255256
256257 === Languages updated in 1.18 ===
257258

Follow-up revisions

RevisionCommit summaryAuthorDate
r83850Followup r83843, r83837, per brian, addOption unconditionally replaces ORDER ...reedy19:28, 13 March 2011

Comments

#Comment by Bryan (talk | contribs)   18:22, 13 March 2011

Why did you modify the ORDER BY option?

#Comment by Reedy (talk | contribs)   18:35, 13 March 2011

addWhereRange when sort is true (default), adds the field to the ORDER BY

So no point ducplicating it

#Comment by Bryan (talk | contribs)   18:42, 13 March 2011

Yes, but the call to setOption() later in the code overwrites the value set by addWhereRange().

#Comment by Reedy (talk | contribs)   19:11, 13 March 2011

Oh ffs. Probably a couple of other revs that need tidying up then too....

#Comment by Reedy (talk | contribs)   19:13, 13 March 2011

Oh, it's only *some* code paths that needs fixing...

Status & tagging log