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