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