[FileBackend] Added getScopedLocksForOps() function.
[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 /**
28 * A query action to enumerate revisions of a given page, or show top revisions of multiple pages.
29 * Various pieces of information may be shown - flags, comments, and the actual wiki markup of the rev.
30 * In the enumeration mode, ranges of revisions may be requested and filtered.
31 *
32 * @ingroup API
33 */
34 class ApiQueryRevisions extends ApiQueryBase {
35
36 private $diffto, $difftotext, $expandTemplates, $generateXML, $section,
37 $token, $parseContent;
38
39 public function __construct( $query, $moduleName ) {
40 parent::__construct( $query, $moduleName, 'rv' );
41 }
42
43 private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false,
44 $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
45 $fld_content = false, $fld_tags = false;
46
47 private $tokenFunctions;
48
49 protected function getTokenFunctions() {
50 // tokenname => function
51 // function prototype is func($pageid, $title, $rev)
52 // should return token or false
53
54 // Don't call the hooks twice
55 if ( isset( $this->tokenFunctions ) ) {
56 return $this->tokenFunctions;
57 }
58
59 // If we're in JSON callback mode, no tokens can be obtained
60 if ( !is_null( $this->getMain()->getRequest()->getVal( 'callback' ) ) ) {
61 return array();
62 }
63
64 $this->tokenFunctions = array(
65 'rollback' => array( 'ApiQueryRevisions', 'getRollbackToken' )
66 );
67 wfRunHooks( 'APIQueryRevisionsTokens', array( &$this->tokenFunctions ) );
68 return $this->tokenFunctions;
69 }
70
71 /**
72 * @param $pageid
73 * @param $title Title
74 * @param $rev Revision
75 * @return bool|String
76 */
77 public static function getRollbackToken( $pageid, $title, $rev ) {
78 global $wgUser;
79 if ( !$wgUser->isAllowed( 'rollback' ) ) {
80 return false;
81 }
82 return $wgUser->getEditToken(
83 array( $title->getPrefixedText(), $rev->getUserText() ) );
84 }
85
86 public function execute() {
87 $params = $this->extractRequestParams( false );
88
89 // If any of those parameters are used, work in 'enumeration' mode.
90 // Enum mode can only be used when exactly one page is provided.
91 // Enumerating revisions on multiple pages make it extremely
92 // difficult to manage continuations and require additional SQL indexes
93 $enumRevMode = ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ||
94 !is_null( $params['limit'] ) || !is_null( $params['startid'] ) ||
95 !is_null( $params['endid'] ) || $params['dir'] === 'newer' ||
96 !is_null( $params['start'] ) || !is_null( $params['end'] ) );
97
98
99 $pageSet = $this->getPageSet();
100 $pageCount = $pageSet->getGoodTitleCount();
101 $revCount = $pageSet->getRevisionCount();
102
103 // Optimization -- nothing to do
104 if ( $revCount === 0 && $pageCount === 0 ) {
105 return;
106 }
107
108 if ( $revCount > 0 && $enumRevMode ) {
109 $this->dieUsage( 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids' );
110 }
111
112 if ( $pageCount > 1 && $enumRevMode ) {
113 $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' );
114 }
115
116 if ( !is_null( $params['difftotext'] ) ) {
117 $this->difftotext = $params['difftotext'];
118 } elseif ( !is_null( $params['diffto'] ) ) {
119 if ( $params['diffto'] == 'cur' ) {
120 $params['diffto'] = 0;
121 }
122 if ( ( !ctype_digit( $params['diffto'] ) || $params['diffto'] < 0 )
123 && $params['diffto'] != 'prev' && $params['diffto'] != 'next' ) {
124 $this->dieUsage( 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto' );
125 }
126 // Check whether the revision exists and is readable,
127 // DifferenceEngine returns a rather ambiguous empty
128 // string if that's not the case
129 if ( $params['diffto'] != 0 ) {
130 $difftoRev = Revision::newFromID( $params['diffto'] );
131 if ( !$difftoRev ) {
132 $this->dieUsageMsg( array( 'nosuchrevid', $params['diffto'] ) );
133 }
134 if ( $difftoRev->isDeleted( Revision::DELETED_TEXT ) ) {
135 $this->setWarning( "Couldn't diff to r{$difftoRev->getID()}: content is hidden" );
136 $params['diffto'] = null;
137 }
138 }
139 $this->diffto = $params['diffto'];
140 }
141
142 $db = $this->getDB();
143 $this->addTables( 'page' );
144 $this->addFields( Revision::selectFields() );
145 $this->addWhere( 'page_id = rev_page' );
146
147 $prop = array_flip( $params['prop'] );
148
149 // Optional fields
150 $this->fld_ids = isset ( $prop['ids'] );
151 // $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed?
152 $this->fld_flags = isset ( $prop['flags'] );
153 $this->fld_timestamp = isset ( $prop['timestamp'] );
154 $this->fld_comment = isset ( $prop['comment'] );
155 $this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
156 $this->fld_size = isset ( $prop['size'] );
157 $this->fld_sha1 = isset ( $prop['sha1'] );
158 $this->fld_userid = isset( $prop['userid'] );
159 $this->fld_user = isset ( $prop['user'] );
160 $this->token = $params['token'];
161
162 // Possible indexes used
163 $index = array();
164
165 $userMax = ( $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
166 $botMax = ( $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
167 $limit = $params['limit'];
168 if ( $limit == 'max' ) {
169 $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
170 $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
171 }
172
173 if ( !is_null( $this->token ) || $pageCount > 0 ) {
174 $this->addFields( Revision::selectPageFields() );
175 }
176
177 if ( isset( $prop['tags'] ) ) {
178 $this->fld_tags = true;
179 $this->addTables( 'tag_summary' );
180 $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) );
181 $this->addFields( 'ts_tags' );
182 }
183
184 if ( !is_null( $params['tag'] ) ) {
185 $this->addTables( 'change_tag' );
186 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
187 $this->addWhereFld( 'ct_tag' , $params['tag'] );
188 global $wgOldChangeTagsIndex;
189 $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
190 }
191
192 if ( isset( $prop['content'] ) || !is_null( $this->difftotext ) ) {
193 // For each page we will request, the user must have read rights for that page
194 foreach ( $pageSet->getGoodTitles() as $title ) {
195 if ( !$title->userCan( 'read' ) ) {
196 $this->dieUsage(
197 'The current user is not allowed to read ' . $title->getPrefixedText(),
198 'accessdenied' );
199 }
200 }
201
202 $this->addTables( 'text' );
203 $this->addWhere( 'rev_text_id=old_id' );
204 $this->addFields( 'old_id' );
205 $this->addFields( Revision::selectTextFields() );
206
207 $this->fld_content = isset( $prop['content'] );
208
209 $this->expandTemplates = $params['expandtemplates'];
210 $this->generateXML = $params['generatexml'];
211 $this->parseContent = $params['parse'];
212 if ( $this->parseContent ) {
213 // Must manually initialize unset limit
214 if ( is_null( $limit ) ) {
215 $limit = 1;
216 }
217 // We are only going to parse 1 revision per request
218 $this->validateLimit( 'limit', $limit, 1, 1, 1 );
219 }
220 if ( isset( $params['section'] ) ) {
221 $this->section = $params['section'];
222 } else {
223 $this->section = false;
224 }
225 }
226
227 // Bug 24166 - API error when using rvprop=tags
228 $this->addTables( 'revision' );
229
230 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->addTimestampWhereRange( '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->addTimestampWhereRange( '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 ) {
409 if ( !is_null( $revision->getSize() ) ) {
410 $vals['size'] = intval( $revision->getSize() );
411 } else {
412 $vals['size'] = 0;
413 }
414 }
415
416 if ( $this->fld_sha1 ) {
417 if ( $revision->getSha1() != '' ) {
418 $vals['sha1'] = wfBaseConvert( $revision->getSha1(), 36, 16, 40 );
419 } else {
420 $vals['sha1'] = '';
421 }
422 }
423
424 if ( $this->fld_comment || $this->fld_parsedcomment ) {
425 if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) {
426 $vals['commenthidden'] = '';
427 } else {
428 $comment = $revision->getComment();
429
430 if ( $this->fld_comment ) {
431 $vals['comment'] = $comment;
432 }
433
434 if ( $this->fld_parsedcomment ) {
435 $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
436 }
437 }
438 }
439
440 if ( $this->fld_tags ) {
441 if ( $row->ts_tags ) {
442 $tags = explode( ',', $row->ts_tags );
443 $this->getResult()->setIndexedTagName( $tags, 'tag' );
444 $vals['tags'] = $tags;
445 } else {
446 $vals['tags'] = array();
447 }
448 }
449
450 if ( !is_null( $this->token ) ) {
451 $tokenFunctions = $this->getTokenFunctions();
452 foreach ( $this->token as $t ) {
453 $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
454 if ( $val === false ) {
455 $this->setWarning( "Action '$t' is not allowed for the current user" );
456 } else {
457 $vals[$t . 'token'] = $val;
458 }
459 }
460 }
461
462 $text = null;
463 global $wgParser;
464 if ( $this->fld_content || !is_null( $this->difftotext ) ) {
465 $text = $revision->getText();
466 // Expand templates after getting section content because
467 // template-added sections don't count and Parser::preprocess()
468 // will have less input
469 if ( $this->section !== false ) {
470 $text = $wgParser->getSection( $text, $this->section, false );
471 if ( $text === false ) {
472 $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
473 }
474 }
475 }
476 if ( $this->fld_content && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
477 if ( $this->generateXML ) {
478 $wgParser->startExternalParse( $title, ParserOptions::newFromContext( $this->getContext() ), OT_PREPROCESS );
479 $dom = $wgParser->preprocessToDom( $text );
480 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
481 $xml = $dom->saveXML();
482 } else {
483 $xml = $dom->__toString();
484 }
485 $vals['parsetree'] = $xml;
486
487 }
488 if ( $this->expandTemplates && !$this->parseContent ) {
489 $text = $wgParser->preprocess( $text, $title, ParserOptions::newFromContext( $this->getContext() ) );
490 }
491 if ( $this->parseContent ) {
492 $text = $wgParser->parse( $text, $title, ParserOptions::newFromContext( $this->getContext() ) )->getText();
493 }
494 ApiResult::setContent( $vals, $text );
495 } elseif ( $this->fld_content ) {
496 $vals['texthidden'] = '';
497 }
498
499 if ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) {
500 global $wgAPIMaxUncachedDiffs;
501 static $n = 0; // Number of uncached diffs we've had
502 if ( $n < $wgAPIMaxUncachedDiffs ) {
503 $vals['diff'] = array();
504 $context = new DerivativeContext( $this->getContext() );
505 $context->setTitle( $title );
506 if ( !is_null( $this->difftotext ) ) {
507 $engine = new DifferenceEngine( $context );
508 $engine->setText( $text, $this->difftotext );
509 } else {
510 $engine = new DifferenceEngine( $context, $revision->getID(), $this->diffto );
511 $vals['diff']['from'] = $engine->getOldid();
512 $vals['diff']['to'] = $engine->getNewid();
513 }
514 $difftext = $engine->getDiffBody();
515 ApiResult::setContent( $vals['diff'], $difftext );
516 if ( !$engine->wasCacheHit() ) {
517 $n++;
518 }
519 } else {
520 $vals['diff']['notcached'] = '';
521 }
522 }
523 return $vals;
524 }
525
526 public function getCacheMode( $params ) {
527 if ( isset( $params['token'] ) ) {
528 return 'private';
529 }
530 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
531 // formatComment() calls wfMsg() among other things
532 return 'anon-public-user-private';
533 }
534 return 'public';
535 }
536
537 public function getAllowedParams() {
538 return array(
539 'prop' => array(
540 ApiBase::PARAM_ISMULTI => true,
541 ApiBase::PARAM_DFLT => 'ids|timestamp|flags|comment|user',
542 ApiBase::PARAM_TYPE => array(
543 'ids',
544 'flags',
545 'timestamp',
546 'user',
547 'userid',
548 'size',
549 'sha1',
550 'comment',
551 'parsedcomment',
552 'content',
553 'tags'
554 )
555 ),
556 'limit' => array(
557 ApiBase::PARAM_TYPE => 'limit',
558 ApiBase::PARAM_MIN => 1,
559 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
560 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
561 ),
562 'startid' => array(
563 ApiBase::PARAM_TYPE => 'integer'
564 ),
565 'endid' => array(
566 ApiBase::PARAM_TYPE => 'integer'
567 ),
568 'start' => array(
569 ApiBase::PARAM_TYPE => 'timestamp'
570 ),
571 'end' => array(
572 ApiBase::PARAM_TYPE => 'timestamp'
573 ),
574 'dir' => array(
575 ApiBase::PARAM_DFLT => 'older',
576 ApiBase::PARAM_TYPE => array(
577 'newer',
578 'older'
579 )
580 ),
581 'user' => array(
582 ApiBase::PARAM_TYPE => 'user'
583 ),
584 'excludeuser' => array(
585 ApiBase::PARAM_TYPE => 'user'
586 ),
587 'tag' => null,
588 'expandtemplates' => false,
589 'generatexml' => false,
590 'parse' => false,
591 'section' => null,
592 'token' => array(
593 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
594 ApiBase::PARAM_ISMULTI => true
595 ),
596 'continue' => null,
597 'diffto' => null,
598 'difftotext' => null,
599 );
600 }
601
602 public function getParamDescription() {
603 $p = $this->getModulePrefix();
604 return array(
605 'prop' => array(
606 'Which properties to get for each revision:',
607 ' ids - The ID of the revision',
608 ' flags - Revision flags (minor)',
609 ' timestamp - The timestamp of the revision',
610 ' user - User that made the revision',
611 ' userid - User id of revision creator',
612 ' size - Length (bytes) of the revision',
613 ' sha1 - SHA-1 (base 16) of the revision',
614 ' comment - Comment by the user for revision',
615 ' parsedcomment - Parsed comment by the user for the revision',
616 ' content - Text of the revision',
617 ' tags - Tags for the revision',
618 ),
619 'limit' => 'Limit how many revisions will be returned (enum)',
620 'startid' => 'From which revision id to start enumeration (enum)',
621 'endid' => 'Stop revision enumeration on this revid (enum)',
622 'start' => 'From which revision timestamp to start enumeration (enum)',
623 'end' => 'Enumerate up to this timestamp (enum)',
624 'dir' => $this->getDirectionDescription( $p, ' (enum)' ),
625 'user' => 'Only include revisions made by user (enum)',
626 'excludeuser' => 'Exclude revisions made by user (enum)',
627 'expandtemplates' => 'Expand templates in revision content',
628 'generatexml' => 'Generate XML parse tree for revision content',
629 'parse' => 'Parse revision content. For performance reasons if this option is used, rvlimit is enforced to 1.',
630 'section' => 'Only retrieve the content of this section number',
631 'token' => 'Which tokens to obtain for each revision',
632 'continue' => 'When more results are available, use this to continue',
633 'diffto' => array( 'Revision ID to diff each revision to.',
634 'Use "prev", "next" and "cur" for the previous, next and current revision respectively' ),
635 'difftotext' => array( 'Text to diff each revision to. Only diffs a limited number of revisions.',
636 "Overrides {$p}diffto. If {$p}section is set, only that section will be diffed against this text" ),
637 'tag' => 'Only list revisions tagged with this tag',
638 );
639 }
640
641 public function getDescription() {
642 return array(
643 'Get revision information',
644 'May be used in several ways:',
645 ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter',
646 ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params',
647 ' 3) Get data about a set of revisions by setting their IDs with revids parameter',
648 'All parameters marked as (enum) may only be used with a single page (#2)'
649 );
650 }
651
652 public function getPossibleErrors() {
653 return array_merge( parent::getPossibleErrors(), array(
654 array( 'nosuchrevid', 'diffto' ),
655 array( 'code' => 'revids', 'info' => 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).' ),
656 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.' ),
657 array( 'code' => 'diffto', 'info' => 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"' ),
658 array( 'code' => 'badparams', 'info' => 'start and startid cannot be used together' ),
659 array( 'code' => 'badparams', 'info' => 'end and endid cannot be used together' ),
660 array( 'code' => 'badparams', 'info' => 'user and excludeuser cannot be used together' ),
661 array( 'code' => 'nosuchsection', 'info' => 'There is no section section in rID' ),
662 ) );
663 }
664
665 public function getExamples() {
666 return array(
667 'Get data with content for the last revision of titles "API" and "Main Page"',
668 ' api.php?action=query&prop=revisions&titles=API|Main%20Page&rvprop=timestamp|user|comment|content',
669 'Get last 5 revisions of the "Main Page"',
670 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment',
671 'Get first 5 revisions of the "Main Page"',
672 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer',
673 'Get first 5 revisions of the "Main Page" made after 2006-05-01',
674 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000',
675 'Get first 5 revisions of the "Main Page" that were not made made by anonymous user "127.0.0.1"',
676 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1',
677 'Get first 5 revisions of the "Main Page" that were made by the user "MediaWiki default"',
678 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvuser=MediaWiki%20default',
679 );
680 }
681
682 public function getHelpUrls() {
683 return 'https://www.mediawiki.org/wiki/API:Properties#revisions_.2F_rv';
684 }
685
686 public function getVersion() {
687 return __CLASS__ . ': $Id$';
688 }
689 }