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