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