Fixed spacing in db/debug/diff/externalstore/objectcache folder
[mediawiki.git] / includes / api / ApiQueryRevisions.php
blob317b7ba57c9a9477354cffe3727c54df04a04674
1 <?php
2 /**
5 * Created on Sep 7, 2006
7 * Copyright © 2006 Yuri Astrakhan "<Firstname><Lastname>@gmail.com"
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.
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.
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
24 * @file
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.
32 * @ingroup API
34 class ApiQueryRevisions extends ApiQueryBase {
36 private $diffto, $difftotext, $expandTemplates, $generateXML, $section,
37 $token, $parseContent, $contentFormat;
39 public function __construct( $query, $moduleName ) {
40 parent::__construct( $query, $moduleName, 'rv' );
43 private $fld_ids = false, $fld_flags = false, $fld_timestamp = false, $fld_size = false, $fld_sha1 = false,
44 $fld_comment = false, $fld_parsedcomment = false, $fld_user = false, $fld_userid = false,
45 $fld_content = false, $fld_tags = false, $fld_contentmodel = false;
47 private $tokenFunctions;
49 protected function getTokenFunctions() {
50 // tokenname => function
51 // function prototype is func($pageid, $title, $rev)
52 // should return token or false
54 // Don't call the hooks twice
55 if ( isset( $this->tokenFunctions ) ) {
56 return $this->tokenFunctions;
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();
64 $this->tokenFunctions = array(
65 'rollback' => array( 'ApiQueryRevisions', 'getRollbackToken' )
67 wfRunHooks( 'APIQueryRevisionsTokens', array( &$this->tokenFunctions ) );
68 return $this->tokenFunctions;
71 /**
72 * @param $pageid
73 * @param $title Title
74 * @param $rev Revision
75 * @return bool|String
77 public static function getRollbackToken( $pageid, $title, $rev ) {
78 global $wgUser;
79 if ( !$wgUser->isAllowed( 'rollback' ) ) {
80 return false;
82 return $wgUser->getEditToken(
83 array( $title->getPrefixedText(), $rev->getUserText() ) );
86 public function execute() {
87 $params = $this->extractRequestParams( false );
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'] ) );
98 $pageSet = $this->getPageSet();
99 $pageCount = $pageSet->getGoodTitleCount();
100 $revCount = $pageSet->getRevisionCount();
102 // Optimization -- nothing to do
103 if ( $revCount === 0 && $pageCount === 0 ) {
104 return;
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' );
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' );
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;
121 if ( ( !ctype_digit( $params['diffto'] ) || $params['diffto'] < 0 )
122 && $params['diffto'] != 'prev' && $params['diffto'] != 'next' ) {
123 $this->dieUsage( 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto' );
125 // Check whether the revision exists and is readable,
126 // DifferenceEngine returns a rather ambiguous empty
127 // string if that's not the case
128 if ( $params['diffto'] != 0 ) {
129 $difftoRev = Revision::newFromID( $params['diffto'] );
130 if ( !$difftoRev ) {
131 $this->dieUsageMsg( array( 'nosuchrevid', $params['diffto'] ) );
133 if ( $difftoRev->isDeleted( Revision::DELETED_TEXT ) ) {
134 $this->setWarning( "Couldn't diff to r{$difftoRev->getID()}: content is hidden" );
135 $params['diffto'] = null;
138 $this->diffto = $params['diffto'];
141 $db = $this->getDB();
142 $this->addTables( 'page' );
143 $this->addFields( Revision::selectFields() );
144 $this->addWhere( 'page_id = rev_page' );
146 $prop = array_flip( $params['prop'] );
148 // Optional fields
149 $this->fld_ids = isset ( $prop['ids'] );
150 // $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed?
151 $this->fld_flags = isset ( $prop['flags'] );
152 $this->fld_timestamp = isset ( $prop['timestamp'] );
153 $this->fld_comment = isset ( $prop['comment'] );
154 $this->fld_parsedcomment = isset ( $prop['parsedcomment'] );
155 $this->fld_size = isset ( $prop['size'] );
156 $this->fld_sha1 = isset ( $prop['sha1'] );
157 $this->fld_contentmodel = isset ( $prop['contentmodel'] );
158 $this->fld_userid = isset( $prop['userid'] );
159 $this->fld_user = isset ( $prop['user'] );
160 $this->token = $params['token'];
162 if ( !empty( $params['contentformat'] ) ) {
163 $this->contentFormat = $params['contentformat'];
166 // Possible indexes used
167 $index = array();
169 $userMax = ( $this->fld_content ? ApiBase::LIMIT_SML1 : ApiBase::LIMIT_BIG1 );
170 $botMax = ( $this->fld_content ? ApiBase::LIMIT_SML2 : ApiBase::LIMIT_BIG2 );
171 $limit = $params['limit'];
172 if ( $limit == 'max' ) {
173 $limit = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
174 $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
177 if ( !is_null( $this->token ) || $pageCount > 0 ) {
178 $this->addFields( Revision::selectPageFields() );
181 if ( isset( $prop['tags'] ) ) {
182 $this->fld_tags = true;
183 $this->addTables( 'tag_summary' );
184 $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) );
185 $this->addFields( 'ts_tags' );
188 if ( !is_null( $params['tag'] ) ) {
189 $this->addTables( 'change_tag' );
190 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
191 $this->addWhereFld( 'ct_tag', $params['tag'] );
192 global $wgOldChangeTagsIndex;
193 $index['change_tag'] = $wgOldChangeTagsIndex ? 'ct_tag' : 'change_tag_tag_id';
196 if ( isset( $prop['content'] ) || !is_null( $this->difftotext ) ) {
197 // For each page we will request, the user must have read rights for that page
198 $user = $this->getUser();
199 /** @var $title Title */
200 foreach ( $pageSet->getGoodTitles() as $title ) {
201 if ( !$title->userCan( 'read', $user ) ) {
202 $this->dieUsage(
203 'The current user is not allowed to read ' . $title->getPrefixedText(),
204 'accessdenied' );
208 $this->addTables( 'text' );
209 $this->addWhere( 'rev_text_id=old_id' );
210 $this->addFields( 'old_id' );
211 $this->addFields( Revision::selectTextFields() );
213 $this->fld_content = isset( $prop['content'] );
215 $this->expandTemplates = $params['expandtemplates'];
216 $this->generateXML = $params['generatexml'];
217 $this->parseContent = $params['parse'];
218 if ( $this->parseContent ) {
219 // Must manually initialize unset limit
220 if ( is_null( $limit ) ) {
221 $limit = 1;
223 // We are only going to parse 1 revision per request
224 $this->validateLimit( 'limit', $limit, 1, 1, 1 );
226 if ( isset( $params['section'] ) ) {
227 $this->section = $params['section'];
228 } else {
229 $this->section = false;
233 // add user name, if needed
234 if ( $this->fld_user ) {
235 $this->addTables( 'user' );
236 $this->addJoinConds( array( 'user' => Revision::userJoinCond() ) );
237 $this->addFields( Revision::selectUserFields() );
240 // Bug 24166 - API error when using rvprop=tags
241 $this->addTables( 'revision' );
243 if ( $enumRevMode ) {
244 // This is mostly to prevent parameter errors (and optimize SQL?)
245 if ( !is_null( $params['startid'] ) && !is_null( $params['start'] ) ) {
246 $this->dieUsage( 'start and startid cannot be used together', 'badparams' );
249 if ( !is_null( $params['endid'] ) && !is_null( $params['end'] ) ) {
250 $this->dieUsage( 'end and endid cannot be used together', 'badparams' );
253 if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
254 $this->dieUsage( 'user and excludeuser cannot be used together', 'badparams' );
257 // Continuing effectively uses startid. But we can't use rvstartid
258 // directly, because there is no way to tell the client to ''not''
259 // send rvstart if it sent it in the original query. So instead we
260 // send the continuation startid as rvcontinue, and ignore both
261 // rvstart and rvstartid when that is supplied.
262 if ( !is_null( $params['continue'] ) ) {
263 $params['startid'] = $params['continue'];
264 $params['start'] = null;
267 // This code makes an assumption that sorting by rev_id and rev_timestamp produces
268 // the same result. This way users may request revisions starting at a given time,
269 // but to page through results use the rev_id returned after each page.
270 // Switching to rev_id removes the potential problem of having more than
271 // one row with the same timestamp for the same page.
272 // The order needs to be the same as start parameter to avoid SQL filesort.
273 if ( is_null( $params['startid'] ) && is_null( $params['endid'] ) ) {
274 $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'],
275 $params['start'], $params['end'] );
276 } else {
277 $this->addWhereRange( 'rev_id', $params['dir'],
278 $params['startid'], $params['endid'] );
279 // One of start and end can be set
280 // If neither is set, this does nothing
281 $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'],
282 $params['start'], $params['end'], false );
285 // must manually initialize unset limit
286 if ( is_null( $limit ) ) {
287 $limit = 10;
289 $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
291 // There is only one ID, use it
292 $ids = array_keys( $pageSet->getGoodTitles() );
293 $this->addWhereFld( 'rev_page', reset( $ids ) );
295 if ( !is_null( $params['user'] ) ) {
296 $this->addWhereFld( 'rev_user_text', $params['user'] );
297 } elseif ( !is_null( $params['excludeuser'] ) ) {
298 $this->addWhere( 'rev_user_text != ' .
299 $db->addQuotes( $params['excludeuser'] ) );
301 if ( !is_null( $params['user'] ) || !is_null( $params['excludeuser'] ) ) {
302 // Paranoia: avoid brute force searches (bug 17342)
303 $this->addWhere( $db->bitAnd( 'rev_deleted', Revision::DELETED_USER ) . ' = 0' );
305 } elseif ( $revCount > 0 ) {
306 $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
307 $revs = $pageSet->getRevisionIDs();
308 if ( self::truncateArray( $revs, $max ) ) {
309 $this->setWarning( "Too many values supplied for parameter 'revids': the limit is $max" );
312 // Get all revision IDs
313 $this->addWhereFld( 'rev_id', array_keys( $revs ) );
315 if ( !is_null( $params['continue'] ) ) {
316 $this->addWhere( 'rev_id >= ' . intval( $params['continue'] ) );
318 $this->addOption( 'ORDER BY', 'rev_id' );
320 // assumption testing -- we should never get more then $revCount rows.
321 $limit = $revCount;
322 } elseif ( $pageCount > 0 ) {
323 $max = $this->getMain()->canApiHighLimits() ? $botMax : $userMax;
324 $titles = $pageSet->getGoodTitles();
325 if ( self::truncateArray( $titles, $max ) ) {
326 $this->setWarning( "Too many values supplied for parameter 'titles': the limit is $max" );
329 // When working in multi-page non-enumeration mode,
330 // limit to the latest revision only
331 $this->addWhere( 'page_id=rev_page' );
332 $this->addWhere( 'page_latest=rev_id' );
334 // Get all page IDs
335 $this->addWhereFld( 'page_id', array_keys( $titles ) );
336 // Every time someone relies on equality propagation, god kills a kitten :)
337 $this->addWhereFld( 'rev_page', array_keys( $titles ) );
339 if ( !is_null( $params['continue'] ) ) {
340 $cont = explode( '|', $params['continue'] );
341 $this->dieContinueUsageIf( count( $cont ) != 2 );
342 $pageid = intval( $cont[0] );
343 $revid = intval( $cont[1] );
344 $this->addWhere(
345 "rev_page > $pageid OR " .
346 "(rev_page = $pageid AND " .
347 "rev_id >= $revid)"
350 $this->addOption( 'ORDER BY', array(
351 'rev_page',
352 'rev_id'
355 // assumption testing -- we should never get more then $pageCount rows.
356 $limit = $pageCount;
357 } else {
358 ApiBase::dieDebug( __METHOD__, 'param validation?' );
361 $this->addOption( 'LIMIT', $limit + 1 );
362 $this->addOption( 'USE INDEX', $index );
364 $count = 0;
365 $res = $this->select( __METHOD__ );
367 foreach ( $res as $row ) {
368 if ( ++ $count > $limit ) {
369 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
370 if ( !$enumRevMode ) {
371 ApiBase::dieDebug( __METHOD__, 'Got more rows then expected' ); // bug report
373 $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
374 break;
377 $fit = $this->addPageSubItem( $row->rev_page, $this->extractRowInfo( $row ), 'rev' );
378 if ( !$fit ) {
379 if ( $enumRevMode ) {
380 $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
381 } elseif ( $revCount > 0 ) {
382 $this->setContinueEnumParameter( 'continue', intval( $row->rev_id ) );
383 } else {
384 $this->setContinueEnumParameter( 'continue', intval( $row->rev_page ) .
385 '|' . intval( $row->rev_id ) );
387 break;
392 private function extractRowInfo( $row ) {
393 $revision = new Revision( $row );
394 $title = $revision->getTitle();
395 $vals = array();
397 if ( $this->fld_ids ) {
398 $vals['revid'] = intval( $revision->getId() );
399 // $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
400 if ( !is_null( $revision->getParentId() ) ) {
401 $vals['parentid'] = intval( $revision->getParentId() );
405 if ( $this->fld_flags && $revision->isMinor() ) {
406 $vals['minor'] = '';
409 if ( $this->fld_user || $this->fld_userid ) {
410 if ( $revision->isDeleted( Revision::DELETED_USER ) ) {
411 $vals['userhidden'] = '';
412 } else {
413 if ( $this->fld_user ) {
414 $vals['user'] = $revision->getUserText();
416 $userid = $revision->getUser();
417 if ( !$userid ) {
418 $vals['anon'] = '';
421 if ( $this->fld_userid ) {
422 $vals['userid'] = $userid;
427 if ( $this->fld_timestamp ) {
428 $vals['timestamp'] = wfTimestamp( TS_ISO_8601, $revision->getTimestamp() );
431 if ( $this->fld_size ) {
432 if ( !is_null( $revision->getSize() ) ) {
433 $vals['size'] = intval( $revision->getSize() );
434 } else {
435 $vals['size'] = 0;
439 if ( $this->fld_sha1 && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
440 if ( $revision->getSha1() != '' ) {
441 $vals['sha1'] = wfBaseConvert( $revision->getSha1(), 36, 16, 40 );
442 } else {
443 $vals['sha1'] = '';
445 } elseif ( $this->fld_sha1 ) {
446 $vals['sha1hidden'] = '';
449 if ( $this->fld_contentmodel ) {
450 $vals['contentmodel'] = $revision->getContentModel();
453 if ( $this->fld_comment || $this->fld_parsedcomment ) {
454 if ( $revision->isDeleted( Revision::DELETED_COMMENT ) ) {
455 $vals['commenthidden'] = '';
456 } else {
457 $comment = $revision->getComment();
459 if ( $this->fld_comment ) {
460 $vals['comment'] = $comment;
463 if ( $this->fld_parsedcomment ) {
464 $vals['parsedcomment'] = Linker::formatComment( $comment, $title );
469 if ( $this->fld_tags ) {
470 if ( $row->ts_tags ) {
471 $tags = explode( ',', $row->ts_tags );
472 $this->getResult()->setIndexedTagName( $tags, 'tag' );
473 $vals['tags'] = $tags;
474 } else {
475 $vals['tags'] = array();
479 if ( !is_null( $this->token ) ) {
480 $tokenFunctions = $this->getTokenFunctions();
481 foreach ( $this->token as $t ) {
482 $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
483 if ( $val === false ) {
484 $this->setWarning( "Action '$t' is not allowed for the current user" );
485 } else {
486 $vals[$t . 'token'] = $val;
491 $content = null;
492 global $wgParser;
493 if ( $this->fld_content || !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) {
494 $content = $revision->getContent();
495 // Expand templates after getting section content because
496 // template-added sections don't count and Parser::preprocess()
497 // will have less input
498 if ( $content && $this->section !== false ) {
499 $content = $content->getSection( $this->section, false );
500 if ( !$content ) {
501 $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
505 if ( $this->fld_content && $content && !$revision->isDeleted( Revision::DELETED_TEXT ) ) {
506 $text = null;
508 if ( $this->generateXML ) {
509 if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
510 $t = $content->getNativeData(); # note: don't set $text
512 $wgParser->startExternalParse( $title, ParserOptions::newFromContext( $this->getContext() ), OT_PREPROCESS );
513 $dom = $wgParser->preprocessToDom( $t );
514 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
515 $xml = $dom->saveXML();
516 } else {
517 $xml = $dom->__toString();
519 $vals['parsetree'] = $xml;
520 } else {
521 $this->setWarning( "Conversion to XML is supported for wikitext only, " .
522 $title->getPrefixedDBkey() .
523 " uses content model " . $content->getModel() . ")" );
527 if ( $this->expandTemplates && !$this->parseContent ) {
528 #XXX: implement template expansion for all content types in ContentHandler?
529 if ( $content->getModel() === CONTENT_MODEL_WIKITEXT ) {
530 $text = $content->getNativeData();
532 $text = $wgParser->preprocess( $text, $title, ParserOptions::newFromContext( $this->getContext() ) );
533 } else {
534 $this->setWarning( "Template expansion is supported for wikitext only, " .
535 $title->getPrefixedDBkey() .
536 " uses content model " . $content->getModel() . ")" );
538 $text = false;
541 if ( $this->parseContent ) {
542 $po = $content->getParserOutput( $title, $revision->getId(), ParserOptions::newFromContext( $this->getContext() ) );
543 $text = $po->getText();
546 if ( $text === null ) {
547 $format = $this->contentFormat ? $this->contentFormat : $content->getDefaultFormat();
548 $model = $content->getModel();
550 if ( !$content->isSupportedFormat( $format ) ) {
551 $name = $title->getPrefixedDBkey();
553 $this->dieUsage( "The requested format {$this->contentFormat} is not supported " .
554 "for content model $model used by $name", 'badformat' );
557 $text = $content->serialize( $format );
559 // always include format and model.
560 // Format is needed to deserialize, model is needed to interpret.
561 $vals['contentformat'] = $format;
562 $vals['contentmodel'] = $model;
565 if ( $text !== false ) {
566 ApiResult::setContent( $vals, $text );
568 } elseif ( $this->fld_content ) {
569 if ( $revision->isDeleted( Revision::DELETED_TEXT ) ) {
570 $vals['texthidden'] = '';
571 } else {
572 $vals['textmissing'] = '';
576 if ( !is_null( $this->diffto ) || !is_null( $this->difftotext ) ) {
577 global $wgAPIMaxUncachedDiffs;
578 static $n = 0; // Number of uncached diffs we've had
580 if ( is_null( $content ) ) {
581 $vals['textmissing'] = '';
582 } elseif ( $n < $wgAPIMaxUncachedDiffs ) {
583 $vals['diff'] = array();
584 $context = new DerivativeContext( $this->getContext() );
585 $context->setTitle( $title );
586 $handler = $revision->getContentHandler();
588 if ( !is_null( $this->difftotext ) ) {
589 $model = $title->getContentModel();
591 if ( $this->contentFormat
592 && !ContentHandler::getForModelID( $model )->isSupportedFormat( $this->contentFormat ) ) {
594 $name = $title->getPrefixedDBkey();
596 $this->dieUsage( "The requested format {$this->contentFormat} is not supported for " .
597 "content model $model used by $name", 'badformat' );
600 $difftocontent = ContentHandler::makeContent( $this->difftotext, $title, $model, $this->contentFormat );
602 $engine = $handler->createDifferenceEngine( $context );
603 $engine->setContent( $content, $difftocontent );
604 } else {
605 $engine = $handler->createDifferenceEngine( $context, $revision->getID(), $this->diffto );
606 $vals['diff']['from'] = $engine->getOldid();
607 $vals['diff']['to'] = $engine->getNewid();
609 $difftext = $engine->getDiffBody();
610 ApiResult::setContent( $vals['diff'], $difftext );
611 if ( !$engine->wasCacheHit() ) {
612 $n++;
614 } else {
615 $vals['diff']['notcached'] = '';
618 return $vals;
621 public function getCacheMode( $params ) {
622 if ( isset( $params['token'] ) ) {
623 return 'private';
625 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
626 // formatComment() calls wfMessage() among other things
627 return 'anon-public-user-private';
629 return 'public';
632 public function getAllowedParams() {
633 return array(
634 'prop' => array(
635 ApiBase::PARAM_ISMULTI => true,
636 ApiBase::PARAM_DFLT => 'ids|timestamp|flags|comment|user',
637 ApiBase::PARAM_TYPE => array(
638 'ids',
639 'flags',
640 'timestamp',
641 'user',
642 'userid',
643 'size',
644 'sha1',
645 'contentmodel',
646 'comment',
647 'parsedcomment',
648 'content',
649 'tags'
652 'limit' => array(
653 ApiBase::PARAM_TYPE => 'limit',
654 ApiBase::PARAM_MIN => 1,
655 ApiBase::PARAM_MAX => ApiBase::LIMIT_BIG1,
656 ApiBase::PARAM_MAX2 => ApiBase::LIMIT_BIG2
658 'startid' => array(
659 ApiBase::PARAM_TYPE => 'integer'
661 'endid' => array(
662 ApiBase::PARAM_TYPE => 'integer'
664 'start' => array(
665 ApiBase::PARAM_TYPE => 'timestamp'
667 'end' => array(
668 ApiBase::PARAM_TYPE => 'timestamp'
670 'dir' => array(
671 ApiBase::PARAM_DFLT => 'older',
672 ApiBase::PARAM_TYPE => array(
673 'newer',
674 'older'
677 'user' => array(
678 ApiBase::PARAM_TYPE => 'user'
680 'excludeuser' => array(
681 ApiBase::PARAM_TYPE => 'user'
683 'tag' => null,
684 'expandtemplates' => false,
685 'generatexml' => false,
686 'parse' => false,
687 'section' => null,
688 'token' => array(
689 ApiBase::PARAM_TYPE => array_keys( $this->getTokenFunctions() ),
690 ApiBase::PARAM_ISMULTI => true
692 'continue' => null,
693 'diffto' => null,
694 'difftotext' => null,
695 'contentformat' => array(
696 ApiBase::PARAM_TYPE => ContentHandler::getAllContentFormats(),
697 ApiBase::PARAM_DFLT => null
702 public function getParamDescription() {
703 $p = $this->getModulePrefix();
704 return array(
705 'prop' => array(
706 'Which properties to get for each revision:',
707 ' ids - The ID of the revision',
708 ' flags - Revision flags (minor)',
709 ' timestamp - The timestamp of the revision',
710 ' user - User that made the revision',
711 ' userid - User id of revision creator',
712 ' size - Length (bytes) of the revision',
713 ' sha1 - SHA-1 (base 16) of the revision',
714 ' contentmodel - Content model id',
715 ' comment - Comment by the user for revision',
716 ' parsedcomment - Parsed comment by the user for the revision',
717 ' content - Text of the revision',
718 ' tags - Tags for the revision',
720 'limit' => 'Limit how many revisions will be returned (enum)',
721 'startid' => 'From which revision id to start enumeration (enum)',
722 'endid' => 'Stop revision enumeration on this revid (enum)',
723 'start' => 'From which revision timestamp to start enumeration (enum)',
724 'end' => 'Enumerate up to this timestamp (enum)',
725 'dir' => $this->getDirectionDescription( $p, ' (enum)' ),
726 'user' => 'Only include revisions made by user (enum)',
727 'excludeuser' => 'Exclude revisions made by user (enum)',
728 'expandtemplates' => "Expand templates in revision content (requires {$p}prop=content)",
729 'generatexml' => "Generate XML parse tree for revision content (requires {$p}prop=content)",
730 'parse' => array( "Parse revision content (requires {$p}prop=content).",
731 'For performance reasons if this option is used, rvlimit is enforced to 1.' ),
732 'section' => 'Only retrieve the content of this section number',
733 'token' => 'Which tokens to obtain for each revision',
734 'continue' => 'When more results are available, use this to continue',
735 'diffto' => array( 'Revision ID to diff each revision to.',
736 'Use "prev", "next" and "cur" for the previous, next and current revision respectively' ),
737 'difftotext' => array( 'Text to diff each revision to. Only diffs a limited number of revisions.',
738 "Overrides {$p}diffto. If {$p}section is set, only that section will be diffed against this text" ),
739 'tag' => 'Only list revisions tagged with this tag',
740 'contentformat' => 'Serialization format used for difftotext and expected for output of content',
744 public function getResultProperties() {
745 $props = array(
746 '' => array(),
747 'ids' => array(
748 'revid' => 'integer',
749 'parentid' => array(
750 ApiBase::PROP_TYPE => 'integer',
751 ApiBase::PROP_NULLABLE => true
754 'flags' => array(
755 'minor' => 'boolean'
757 'user' => array(
758 'userhidden' => 'boolean',
759 'user' => 'string',
760 'anon' => 'boolean'
762 'userid' => array(
763 'userhidden' => 'boolean',
764 'userid' => 'integer',
765 'anon' => 'boolean'
767 'timestamp' => array(
768 'timestamp' => 'timestamp'
770 'size' => array(
771 'size' => 'integer'
773 'sha1' => array(
774 'sha1' => 'string'
776 'comment' => array(
777 'commenthidden' => 'boolean',
778 'comment' => array(
779 ApiBase::PROP_TYPE => 'string',
780 ApiBase::PROP_NULLABLE => true
783 'parsedcomment' => array(
784 'commenthidden' => 'boolean',
785 'parsedcomment' => array(
786 ApiBase::PROP_TYPE => 'string',
787 ApiBase::PROP_NULLABLE => true
790 'content' => array(
791 '*' => array(
792 ApiBase::PROP_TYPE => 'string',
793 ApiBase::PROP_NULLABLE => true
795 'texthidden' => 'boolean',
796 'textmissing' => 'boolean',
798 'contentmodel' => array(
799 'contentmodel' => 'string'
803 self::addTokenProperties( $props, $this->getTokenFunctions() );
805 return $props;
808 public function getDescription() {
809 return array(
810 'Get revision information',
811 'May be used in several ways:',
812 ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter',
813 ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params',
814 ' 3) Get data about a set of revisions by setting their IDs with revids parameter',
815 'All parameters marked as (enum) may only be used with a single page (#2)'
819 public function getPossibleErrors() {
820 return array_merge( parent::getPossibleErrors(), array(
821 array( 'nosuchrevid', 'diffto' ),
822 array( 'code' => 'revids', 'info' => 'The revids= parameter may not be used with the list options '
823 . '(limit, startid, endid, dirNewer, start, end).' ),
824 array( 'code' => 'multpages', 'info' => 'titles, pageids or a generator was used to supply multiple pages, '
825 . ' but the limit, startid, endid, dirNewer, user, excludeuser, '
826 . 'start and end parameters may only be used on a single page.' ),
827 array( 'code' => 'diffto', 'info' => 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"' ),
828 array( 'code' => 'badparams', 'info' => 'start and startid cannot be used together' ),
829 array( 'code' => 'badparams', 'info' => 'end and endid cannot be used together' ),
830 array( 'code' => 'badparams', 'info' => 'user and excludeuser cannot be used together' ),
831 array( 'code' => 'nosuchsection', 'info' => 'There is no section section in rID' ),
832 array( 'code' => 'badformat', 'info' => 'The requested serialization format can not be applied '
833 . ' to the page\'s content model' ),
834 ) );
837 public function getExamples() {
838 return array(
839 'Get data with content for the last revision of titles "API" and "Main Page"',
840 ' api.php?action=query&prop=revisions&titles=API|Main%20Page&rvprop=timestamp|user|comment|content',
841 'Get last 5 revisions of the "Main Page"',
842 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment',
843 'Get first 5 revisions of the "Main Page"',
844 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer',
845 'Get first 5 revisions of the "Main Page" made after 2006-05-01',
846 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000',
847 'Get first 5 revisions of the "Main Page" that were not made made by anonymous user "127.0.0.1"',
848 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1',
849 'Get first 5 revisions of the "Main Page" that were made by the user "MediaWiki default"',
850 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvuser=MediaWiki%20default',
854 public function getHelpUrls() {
855 return 'https://www.mediawiki.org/wiki/API:Properties#revisions_.2F_rv';