]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/api/ApiQueryRevisions.php
MediaWiki 1.16.1
[autoinstalls/mediawiki.git] / includes / api / ApiQueryRevisions.php
1 <?php
2
3 /*
4  * Created on Sep 7, 2006
5  *
6  * API for MediaWiki 1.8+
7  *
8  * Copyright (C) 2006 Yuri Astrakhan <Firstname><Lastname>@gmail.com
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License along
21  * with this program; if not, write to the Free Software Foundation, Inc.,
22  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23  * http://www.gnu.org/copyleft/gpl.html
24  */
25
26 if ( !defined( 'MEDIAWIKI' ) ) {
27         // Eclipse helper - will be ignored in production
28         require_once ( 'ApiQueryBase.php' );
29 }
30
31 /**
32  * A query action to enumerate revisions of a given page, or show top revisions of multiple pages.
33  * Various pieces of information may be shown - flags, comments, and the actual wiki markup of the rev.
34  * In the enumeration mode, ranges of revisions may be requested and filtered.
35  *
36  * @ingroup API
37  */
38 class ApiQueryRevisions extends ApiQueryBase {
39
40         public function __construct( $query, $moduleName ) {
41                 parent :: __construct( $query, $moduleName, 'rv' );
42         }
43
44         private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false,
45                         $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_content = false, $fld_tags = false;
46
47         protected function getTokenFunctions() {
48                 // tokenname => function
49                 // function prototype is func($pageid, $title, $rev)
50                 // should return token or false
51
52                 // Don't call the hooks twice
53                 if ( isset( $this->tokenFunctions ) )
54                         return $this->tokenFunctions;
55
56                 // If we're in JSON callback mode, no tokens can be obtained
57                 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) )
58                         return array();
59
60                 $this->tokenFunctions = array(
61                         'rollback' => array( 'ApiQueryRevisions', 'getRollbackToken' )
62                 );
63                 wfRunHooks( 'APIQueryRevisionsTokens', array( &$this->tokenFunctions ) );
64                 return $this->tokenFunctions;
65         }
66
67         public static function getRollbackToken( $pageid, $title, $rev )
68         {
69                 global $wgUser;
70                 if ( !$wgUser->isAllowed( 'rollback' ) )
71                         return false;
72                 return $wgUser->editToken( array( $title->getPrefixedText(),
73                                                 $rev->getUserText() ) );
74         }
75
76         public function execute() {
77                 $params = $this->extractRequestParams( false );
78
79                 // If any of those parameters are used, work in 'enumeration' mode.
80                 // Enum mode can only be used when exactly one page is provided.
81                 // Enumerating revisions on multiple pages make it extremely
82                 // difficult to manage continuations and require additional SQL indexes
83                 $enumRevMode = ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ||
84                                 !is_null( $params['limit'] ) || !is_null( $params['startid'] ) ||
85                                 !is_null( $params['endid'] ) || $params['dir'] === 'newer' ||
86                                 !is_null( $params['start'] ) || !is_null( $params['end'] ) );
87
88
89                 $pageSet = $this->getPageSet();
90                 $pageCount = $pageSet->getGoodTitleCount();
91                 $revCount = $pageSet->getRevisionCount();
92
93                 // Optimization -- nothing to do
94                 if ( $revCount === 0 && $pageCount === 0 )
95                         return;
96
97                 if ( $revCount > 0 && $enumRevMode )
98                         $this->dieUsage( 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids' );
99
100                 if ( $pageCount > 1 && $enumRevMode )
101                         $this->dieUsage( 'titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.', 'multpages' );
102
103                 $this->diffto = $this->difftotext = null;
104                 if ( !is_null( $params['difftotext'] ) ) {
105                         $this->difftotext = $params['difftotext'];
106                 } else if ( !is_null( $params['diffto'] ) ) {
107                         if ( $params['diffto'] == 'cur' )
108                                 $params['diffto'] = 0;
109                         if ( ( !ctype_digit( $params['diffto'] ) || $params['diffto'] < 0 )
110                                         && $params['diffto'] != 'prev' && $params['diffto'] != 'next' )
111                                 $this->dieUsage( 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto' );
112                         // Check whether the revision exists and is readable,
113                         // DifferenceEngine returns a rather ambiguous empty
114                         // string if that's not the case
115                         if ( $params['diffto'] != 0 ) {
116                                 $difftoRev = Revision::newFromID( $params['diffto'] );
117                                 if ( !$difftoRev )
118                                         $this->dieUsageMsg( array( 'nosuchrevid', $params['diffto'] ) );
119                                 if ( !$difftoRev->userCan( Revision::DELETED_TEXT ) ) {
120                                         $this->setWarning( "Couldn't diff to r{$difftoRev->getID()}: content is hidden" );
121                                         $params['diffto'] = null;
122                                 }
123                         }
124                         $this->diffto = $params['diffto'];
125                 }
126
127                 $db = $this->getDB();
128                 $this->addTables( 'page' );
129                 $this->addFields( Revision::selectFields() );
130                 $this->addWhere( 'page_id = rev_page' );
131
132                 $prop = array_flip( $params['prop'] );
133
134                 // Optional fields
135                 $this->fld_ids = isset ( $prop['ids'] );
136                 // $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed?
137                 $this->fld_flags = isset ( $prop['flags'] );
138                 $this->fld_timestamp = isset ( $prop['timestamp'] );
139                 $this->fld_comment = isset ( $prop['comment'] );
140                 $this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
141                 $this->fld_size = isset ( $prop['size'] );
142                 $this->fld_user = isset ( $prop['user'] );
143                 $this->token = $params['token'];
144
145                 // Possible indexes used
146                 $index = array();
147
148                 if ( !is_null( $this->token ) || $pageCount > 0 ) {
149                         $this->addFields( Revision::selectPageFields() );
150                 }
151
152                 if ( isset ( $prop['tags'] ) ) {
153                         $this->fld_tags = true;
154                         $this->addTables( 'tag_summary' );
155                         $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) );
156                         $this->addFields( 'ts_tags' );
157                 }
158                 
159                 if ( !is_null( $params['tag'] ) ) {
160                         $this->addTables( 'change_tag' );
161                         $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
162                         $this->addWhereFld( 'ct_tag' , $params['tag'] );
163                         global $wgOldChangeTagsIndex;
164                         $index['change_tag'] = $wgOldChangeTagsIndex ?  'ct_tag' : 'change_tag_tag_id';
165                 }
166                 
167                 if ( isset( $prop['content'] ) || !is_null( $this->difftotext ) ) {
168
169                         // For each page we will request, the user must have read rights for that page
170                         foreach ( $pageSet->getGoodTitles() as $title ) {
171                                 if ( !$title->userCanRead() )
172                                         $this->dieUsage(
173                                                 'The current user is not allowed to read ' . $title->getPrefixedText(),
174                                                 'accessdenied' );
175                         }
176
177                         $this->addTables( 'text' );
178                         $this->addWhere( 'rev_text_id=old_id' );
179                         $this->addFields( 'old_id' );
180                         $this->addFields( Revision::selectTextFields() );
181
182                         $this->fld_content = isset( $prop['content'] );
183
184                         $this->expandTemplates = $params['expandtemplates'];
185                         $this->generateXML = $params['generatexml'];
186                         if ( isset( $params['section'] ) )
187                                 $this->section = $params['section'];
188                         else
189                                 $this->section = false;
190                 }
191
192                 //Bug 24166 - API error when using rvprop=tags
193                 $this->addTables( 'revision' );
194
195                 $userMax = ( $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
196                 $botMax  = ( $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
197                 $limit = $params['limit'];
198                 if ( $limit == 'max' ) {
199                         $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
200                         $this->getResult()->addValue( 'limits', $this->getModuleName(), $limit );
201                 }
202
203                 if ( $enumRevMode ) {
204
205                         // This is mostly to prevent parameter errors (and optimize SQL?)
206                         if ( !is_null( $params['startid'] ) && !is_null( $params['start'] ) )
207                                 $this->dieUsage( 'start and startid cannot be used together', 'badparams' );
208
209                         if ( !is_null( $params['endid'] ) && !is_null( $params['end'] ) )
210                                 $this->dieUsage( 'end and endid cannot be used together', 'badparams' );
211
212                         if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) )
213                                 $this->dieUsage( 'user and excludeuser cannot be used together', 'badparams' );
214
215                         // This code makes an assumption that sorting by rev_id and rev_timestamp produces
216                         // the same result. This way users may request revisions starting at a given time,
217                         // but to page through results use the rev_id returned after each page.
218                         // Switching to rev_id removes the potential problem of having more than
219                         // one row with the same timestamp for the same page.
220                         // The order needs to be the same as start parameter to avoid SQL filesort.
221
222                         if ( is_null( $params['startid'] ) && is_null( $params['endid'] ) )
223                                 $this->addWhereRange( 'rev_timestamp', $params['dir'],
224                                         $params['start'], $params['end'] );
225                         else {
226                                 $this->addWhereRange( 'rev_id', $params['dir'],
227                                         $params['startid'], $params['endid'] );
228                                 // One of start and end can be set
229                                 // If neither is set, this does nothing
230                                 $this->addWhereRange( 'rev_timestamp', $params['dir'],
231                                         $params['start'], $params['end'], false );
232                         }
233
234                         // must manually initialize unset limit
235                         if ( is_null( $limit ) )
236                                 $limit = 10;
237                         $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
238
239                         // There is only one ID, use it
240                         $ids = array_keys( $pageSet->getGoodTitles() );
241                         $this->addWhereFld( 'rev_page', reset( $ids ) );
242
243                         if ( !is_null( $params['user'] ) ) {
244                                 $this->addWhereFld( 'rev_user_text', $params['user'] );
245                         } elseif ( !is_null( $params['excludeuser'] ) ) {
246                                 $this->addWhere( 'rev_user_text != ' .
247                                         $db->addQuotes( $params['excludeuser'] ) );
248                         }
249                         if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
250                                 // Paranoia: avoid brute force searches (bug 17342)
251                                 $this->addWhere( $db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
252                         }
253                 }
254                 elseif ( $revCount > 0 ) {
255                         $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
256                         $revs = $pageSet->getRevisionIDs();
257                         if ( self::truncateArray( $revs, $max ) )
258                                 $this->setWarning( "Too many values supplied for parameter 'revids': the limit is $max" );
259
260                         // Get all revision IDs
261                         $this->addWhereFld( 'rev_id', array_keys( $revs ) );
262
263                         if ( !is_null( $params['continue'] ) )
264                                 $this->addWhere( "rev_id >= '" . intval( $params['continue'] ) . "'" );
265                         $this->addOption( 'ORDER BY', 'rev_id' );
266
267                         // assumption testing -- we should never get more then $revCount rows.
268                         $limit = $revCount;
269                 }
270                 elseif ( $pageCount > 0 ) {
271                         $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
272                         $titles = $pageSet->getGoodTitles();
273                         if ( self::truncateArray( $titles, $max ) )
274                                 $this->setWarning( "Too many values supplied for parameter 'titles': the limit is $max" );
275                         
276                         // When working in multi-page non-enumeration mode,
277                         // limit to the latest revision only
278                         $this->addWhere( 'page_id=rev_page' );
279                         $this->addWhere( 'page_latest=rev_id' );
280                         
281                         // Get all page IDs
282                         $this->addWhereFld( 'page_id', array_keys( $titles ) );
283                         // Every time someone relies on equality propagation, god kills a kitten :)
284                         $this->addWhereFld( 'rev_page', array_keys( $titles ) );
285                         
286                         if ( !is_null( $params['continue'] ) )
287                         {
288                                 $cont = explode( '|', $params['continue'] );
289                                 if ( count( $cont ) != 2 )
290                                         $this->dieUsage( "Invalid continue param. You should pass the original " .
291                                                         "value returned by the previous query", "_badcontinue" );
292                                 $pageid = intval( $cont[0] );
293                                 $revid = intval( $cont[1] );
294                                 $this->addWhere( "rev_page > '$pageid' OR " .
295                                                 "(rev_page = '$pageid' AND " .
296                                                 "rev_id >= '$revid')" );
297                         }
298                         $this->addOption( 'ORDER BY', 'rev_page, rev_id' );
299
300                         // assumption testing -- we should never get more then $pageCount rows.
301                         $limit = $pageCount;
302                 } else
303                         ApiBase :: dieDebug( __METHOD__, 'param validation?' );
304
305                 $this->addOption( 'LIMIT', $limit + 1 );
306                 $this->addOption( 'USE INDEX', $index );
307
308                 $data = array ();
309                 $count = 0;
310                 $res = $this->select( __METHOD__ );
311
312                 while ( $row = $db->fetchObject( $res ) ) {
313
314                         if ( ++ $count > $limit ) {
315                                 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
316                                 if ( !$enumRevMode )
317                                         ApiBase :: dieDebug( __METHOD__, 'Got more rows then expected' ); // bug report
318                                 $this->setContinueEnumParameter( 'startid', intval( $row->rev_id ) );
319                                 break;
320                         }
321                         
322                         //
323                         $fit = $this->addPageSubItem( $row->rev_page, $this->extractRowInfo( $row ), 'rev' );
324                         if ( !$fit )
325                         {
326                                 if ( $enumRevMode )
327                                         $this->setContinueEnumParameter( 'startid', intval( $row->rev_id ) );
328                                 else if ( $revCount > 0 )
329                                         $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
330                                 else
331                                         $this->setContinueEnumParameter( 'continue', intval( $row->rev_page ) .
332                                                 '|' . intval( $row->rev_id ) );
333                                 break;
334                         }
335                 }
336                 $db->freeResult( $res );
337         }
338
339         private function extractRowInfo( $row ) {
340                 $revision = new Revision( $row );
341                 $title = $revision->getTitle();
342                 $vals = array ();
343
344                 if ( $this->fld_ids ) {
345                         $vals['revid'] = intval( $revision->getId() );
346                         // $vals['oldid'] = intval($row->rev_text_id);  // todo: should this be exposed?
347                         if ( !is_null( $revision->getParentId() ) )
348                                 $vals['parentid'] = intval( $revision->getParentId() );
349                 }
350
351                 if ( $this->fld_flags && $revision->isMinor() )
352                         $vals['minor'] = '';
353
354                 if ( $this->fld_user ) {
355                         if ( $revision->isDeleted( Revision::DELETED_USER ) ) {
356                                 $vals['userhidden'] = '';
357                         } else {
358                                 $vals['user'] = $revision->getUserText();
359                                 if ( !$revision->getUser() )
360                                         $vals['anon'] = '';
361                         }
362                 }
363
364                 if ( $this->fld_timestamp ) {
365                         $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $revision->getTimestamp() );
366                 }
367
368                 if ( $this->fld_size && !is_null( $revision->getSize() ) ) {
369                         $vals['size'] = intval( $revision->getSize() );
370                 }
371
372                 if ( $this->fld_comment || $this->fld_parsedcomment ) {
373                         if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) {
374                                 $vals['commenthidden'] = '';
375                         } else {
376                                 $comment = $revision->getComment();
377                                 if ( strval( $comment ) !== '' )
378                                 {
379                                         if ( $this->fld_comment )
380                                                 $vals['comment'] = $comment;
381                                         
382                                         if ( $this->fld_parsedcomment ) {
383                                                 global $wgUser;
384                                                 $vals['parsedcomment'] = $wgUser->getSkin()->formatComment( $comment, $title );
385                                         }
386                                 }
387                         }
388                 }
389
390                 if ( $this->fld_tags ) {
391                         if ( $row->ts_tags ) {
392                                 $tags = explode( ',', $row->ts_tags );
393                                 $this->getResult()->setIndexedTagName( $tags, 'tag' );
394                                 $vals['tags'] = $tags;
395                         } else {
396                                 $vals['tags'] = array();
397                         }
398                 }
399                 
400                 if ( !is_null( $this->token ) )
401                 {
402                         $tokenFunctions = $this->getTokenFunctions();
403                         foreach ( $this->token as $t )
404                         {
405                                 $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
406                                 if ( $val === false )
407                                         $this->setWarning( "Action '$t' is not allowed for the current user" );
408                                 else
409                                         $vals[$t . 'token'] = $val;
410                         }
411                 }
412                 
413                 $text = null;
414                 if ( $this->fld_content || !is_null( $this->difftotext ) ) {
415                         global $wgParser;
416                         $text = $revision->getText();
417                         // Expand templates after getting section content because
418                         // template-added sections don't count and Parser::preprocess()
419                         // will have less input
420                         if ( $this->section !== false ) {
421                                 $text = $wgParser->getSection( $text, $this->section, false );
422                                 if ( $text === false )
423                                         $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
424                         }
425                 }
426                 if ( $this->fld_content && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
427                         if ( $this->generateXML ) {
428                                 $wgParser->startExternalParse( $title, new ParserOptions(), OT_PREPROCESS );
429                                 $dom = $wgParser->preprocessToDom( $text );
430                                 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
431                                         $xml = $dom->saveXML();
432                                 } else {
433                                         $xml = $dom->__toString();
434                                 }
435                                 $vals['parsetree'] = $xml;
436                                 
437                         }
438                         if ( $this->expandTemplates ) {
439                                 $text = $wgParser->preprocess( $text, $title, new ParserOptions() );
440                         }
441                         ApiResult :: setContent( $vals, $text );
442                 } else if ( $this->fld_content ) {
443                         $vals['texthidden'] = '';
444                 }
445
446                 if ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) {
447                         global $wgAPIMaxUncachedDiffs;
448                         static $n = 0; // Number of uncached diffs we've had
449                         if ( $n < $wgAPIMaxUncachedDiffs ) {
450                                 $vals['diff'] = array();
451                                 if ( !is_null( $this->difftotext ) ) {
452                                         $engine = new DifferenceEngine( $title );
453                                         $engine->setText( $text, $this->difftotext );
454                                 } else {
455                                         $engine = new DifferenceEngine( $title, $revision->getID(), $this->diffto );
456                                         $vals['diff']['from'] = $engine->getOldid();
457                                         $vals['diff']['to'] = $engine->getNewid();
458                                 }
459                                 $difftext = $engine->getDiffBody();
460                                 ApiResult::setContent( $vals['diff'], $difftext );
461                                 if ( !$engine->wasCacheHit() )
462                                         $n++;
463                         } else {
464                                 $vals['diff']['notcached'] = '';
465                         }
466                 }
467                 return $vals;
468         }
469
470         public function getCacheMode( $params ) {
471                 if ( isset( $params['token'] ) ) {
472                         return 'private';
473                 }
474                 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
475                         // formatComment() calls wfMsg() among other things
476                         return 'anon-public-user-private';
477                 }               
478                 return 'public';
479         }
480
481         public function getAllowedParams() {
482                 return array (
483                         'prop' => array (
484                                 ApiBase :: PARAM_ISMULTI => true,
485                                 ApiBase :: PARAM_DFLT => 'ids|timestamp|flags|comment|user',
486                                 ApiBase :: PARAM_TYPE => array (
487                                         'ids',
488                                         'flags',
489                                         'timestamp',
490                                         'user',
491                                         'size',
492                                         'comment',
493                                         'parsedcomment',
494                                         'content',
495                                         'tags'
496                                 )
497                         ),
498                         'limit' => array (
499                                 ApiBase :: PARAM_TYPE => 'limit',
500                                 ApiBase :: PARAM_MIN => 1,
501                                 ApiBase :: PARAM_MAX => ApiBase :: LIMIT_BIG1,
502                                 ApiBase :: PARAM_MAX2 => ApiBase :: LIMIT_BIG2
503                         ),
504                         'startid' => array (
505                                 ApiBase :: PARAM_TYPE => 'integer'
506                         ),
507                         'endid' => array (
508                                 ApiBase :: PARAM_TYPE => 'integer'
509                         ),
510                         'start' => array (
511                                 ApiBase :: PARAM_TYPE => 'timestamp'
512                         ),
513                         'end' => array (
514                                 ApiBase :: PARAM_TYPE => 'timestamp'
515                         ),
516                         'dir' => array (
517                                 ApiBase :: PARAM_DFLT => 'older',
518                                 ApiBase :: PARAM_TYPE => array (
519                                         'newer',
520                                         'older'
521                                 )
522                         ),
523                         'user' => array(
524                                 ApiBase :: PARAM_TYPE => 'user'
525                         ),
526                         'excludeuser' => array(
527                                 ApiBase :: PARAM_TYPE => 'user'
528                         ),
529                         'tag' => null,
530                         'expandtemplates' => false,
531                         'generatexml' => false,
532                         'section' => null,
533                         'token' => array(
534                                 ApiBase :: PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
535                                 ApiBase :: PARAM_ISMULTI => true
536                         ),
537                         'continue' => null,
538                         'diffto' => null,
539                         'difftotext' => null,
540                 );
541         }
542
543         public function getParamDescription() {
544                 return array (
545                         'prop' => 'Which properties to get for each revision.',
546                         'limit' => 'Limit how many revisions will be returned (enum)',
547                         'startid' => 'From which revision id to start enumeration (enum)',
548                         'endid' => 'Stop revision enumeration on this revid (enum)',
549                         'start' => 'From which revision timestamp to start enumeration (enum)',
550                         'end' => 'Enumerate up to this timestamp (enum)',
551                         'dir' => 'Direction of enumeration - towards "newer" or "older" revisions (enum)',
552                         'user' => 'Only include revisions made by user',
553                         'excludeuser' => 'Exclude revisions made by user',
554                         'expandtemplates' => 'Expand templates in revision content',
555                         'generatexml' => 'Generate XML parse tree for revision content',
556                         'section' => 'Only retrieve the content of this section',
557                         'token' => 'Which tokens to obtain for each revision',
558                         'continue' => 'When more results are available, use this to continue',
559                         'diffto' => array( 'Revision ID to diff each revision to.',
560                                 'Use "prev", "next" and "cur" for the previous, next and current revision respectively.' ),
561                         'difftotext' => array( 'Text to diff each revision to. Only diffs a limited number of revisions.',
562                                 'Overrides diffto. If rvsection is set, only that section will be diffed against this text.' ),
563                         'tag' => 'Only list revisions tagged with this tag',
564                 );
565         }
566
567         public function getDescription() {
568                 return array (
569                         'Get revision information.',
570                         'This module may be used in several ways:',
571                         ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter.',
572                         ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params.',
573                         ' 3) Get data about a set of revisions by setting their IDs with revids parameter.',
574                         'All parameters marked as (enum) may only be used with a single page (#2).'
575                 );
576         }
577         
578         public function getPossibleErrors() {
579                 return array_merge( parent::getPossibleErrors(), array(
580                         array( 'nosuchrevid', 'diffto' ),
581                         array( 'code' => 'revids', 'info' => 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).' ),
582                         array( 'code' => 'multpages', 'info' => 'titles, pageids or a generator was used to supply multiple pages, but the limit, startid, endid, dirNewer, user, excludeuser, start and end parameters may only be used on a single page.' ),
583                         array( 'code' => 'diffto', 'info' => 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"' ),
584                         array( 'code' => 'badparams', 'info' => 'start and startid cannot be used together' ),
585                         array( 'code' => 'badparams', 'info' => 'end and endid cannot be used together' ),
586                         array( 'code' => 'badparams', 'info' => 'user and excludeuser cannot be used together' ),
587                         array( 'code' => 'nosuchsection', 'info' => 'There is no section section in rID' ),
588                 ) );
589         }
590
591         protected function getExamples() {
592                 return array (
593                         'Get data with content for the last revision of titles "API" and "Main Page":',
594                         '  api.php?action=query&prop=revisions&titles=API|Main%20Page&rvprop=timestamp|user|comment|content',
595                         'Get last 5 revisions of the "Main Page":',
596                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment',
597                         'Get first 5 revisions of the "Main Page":',
598                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer',
599                         'Get first 5 revisions of the "Main Page" made after 2006-05-01:',
600                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000',
601                         'Get first 5 revisions of the "Main Page" that were not made made by anonymous user "127.0.0.1"',
602                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1',
603                         'Get first 5 revisions of the "Main Page" that were made by the user "MediaWiki default"',
604                         '  api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvuser=MediaWiki%20default',
605                 );
606         }
607
608         public function getVersion() {
609                 return __CLASS__ . ': $Id: ApiQueryRevisions.php 72117 2010-09-01 16:50:07Z reedy $';
610         }
611 }