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