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