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