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