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