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