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