4be15943117ee11ca5a601de8f538f7a95b15a08
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
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.
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' ) ) ) {
64 $this->tokenFunctions
= array(
65 'rollback' => array( 'ApiQueryRevisions', 'getRollbackToken' )
67 wfRunHooks( 'APIQueryRevisionsTokens', array( &$this->tokenFunctions
) );
69 return $this->tokenFunctions
;
75 * @param $rev Revision
78 public static function getRollbackToken( $pageid, $title, $rev ) {
80 if ( !$wgUser->isAllowed( 'rollback' ) ) {
84 return $wgUser->getEditToken(
85 array( $title->getPrefixedText(), $rev->getUserText() ) );
88 public function execute() {
89 $params = $this->extractRequestParams( false );
91 // If any of those parameters are used, work in 'enumeration' mode.
92 // Enum mode can only be used when exactly one page is provided.
93 // Enumerating revisions on multiple pages make it extremely
94 // difficult to manage continuations and require additional SQL indexes
95 $enumRevMode = ( !is_null( $params['user'] ) ||
!is_null( $params['excludeuser'] ) ||
96 !is_null( $params['limit'] ) ||
!is_null( $params['startid'] ) ||
97 !is_null( $params['endid'] ) ||
$params['dir'] === 'newer' ||
98 !is_null( $params['start'] ) ||
!is_null( $params['end'] ) );
100 $pageSet = $this->getPageSet();
101 $pageCount = $pageSet->getGoodTitleCount();
102 $revCount = $pageSet->getRevisionCount();
104 // Optimization -- nothing to do
105 if ( $revCount === 0 && $pageCount === 0 ) {
109 if ( $revCount > 0 && $enumRevMode ) {
110 $this->dieUsage( 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids' );
113 if ( $pageCount > 1 && $enumRevMode ) {
114 $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' );
117 if ( !is_null( $params['difftotext'] ) ) {
118 $this->difftotext
= $params['difftotext'];
119 } elseif ( !is_null( $params['diffto'] ) ) {
120 if ( $params['diffto'] == 'cur' ) {
121 $params['diffto'] = 0;
123 if ( ( !ctype_digit( $params['diffto'] ) ||
$params['diffto'] < 0 )
124 && $params['diffto'] != 'prev' && $params['diffto'] != 'next'
126 $this->dieUsage( 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto' );
128 // Check whether the revision exists and is readable,
129 // DifferenceEngine returns a rather ambiguous empty
130 // string if that's not the case
131 if ( $params['diffto'] != 0 ) {
132 $difftoRev = Revision
::newFromID( $params['diffto'] );
134 $this->dieUsageMsg( array( 'nosuchrevid', $params['diffto'] ) );
136 if ( $difftoRev->isDeleted( Revision
::DELETED_TEXT
) ) {
137 $this->setWarning( "Couldn't diff to r{$difftoRev->getID()}: content is hidden" );
138 $params['diffto'] = null;
141 $this->diffto
= $params['diffto'];
144 $db = $this->getDB();
145 $this->addTables( 'page' );
146 $this->addFields( Revision
::selectFields() );
147 $this->addWhere( 'page_id = rev_page' );
149 $prop = array_flip( $params['prop'] );
152 $this->fld_ids
= isset( $prop['ids'] );
153 // $this->addFieldsIf('rev_text_id', $this->fld_ids); // should this be exposed?
154 $this->fld_flags
= isset( $prop['flags'] );
155 $this->fld_timestamp
= isset( $prop['timestamp'] );
156 $this->fld_comment
= isset( $prop['comment'] );
157 $this->fld_parsedcomment
= isset( $prop['parsedcomment'] );
158 $this->fld_size
= isset( $prop['size'] );
159 $this->fld_sha1
= isset( $prop['sha1'] );
160 $this->fld_contentmodel
= isset( $prop['contentmodel'] );
161 $this->fld_userid
= isset( $prop['userid'] );
162 $this->fld_user
= isset( $prop['user'] );
163 $this->token
= $params['token'];
165 if ( !empty( $params['contentformat'] ) ) {
166 $this->contentFormat
= $params['contentformat'];
169 // Possible indexes used
172 $userMax = ( $this->fld_content ? ApiBase
::LIMIT_SML1
: ApiBase
::LIMIT_BIG1
);
173 $botMax = ( $this->fld_content ? ApiBase
::LIMIT_SML2
: ApiBase
::LIMIT_BIG2
);
174 $limit = $params['limit'];
175 if ( $limit == 'max' ) {
176 $limit = $this->getMain()->canApiHighLimits() ?
$botMax : $userMax;
177 $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
180 if ( !is_null( $this->token
) ||
$pageCount > 0 ) {
181 $this->addFields( Revision
::selectPageFields() );
184 if ( isset( $prop['tags'] ) ) {
185 $this->fld_tags
= true;
186 $this->addTables( 'tag_summary' );
187 $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) );
188 $this->addFields( 'ts_tags' );
191 if ( !is_null( $params['tag'] ) ) {
192 $this->addTables( 'change_tag' );
193 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
194 $this->addWhereFld( 'ct_tag', $params['tag'] );
195 $index['change_tag'] = 'change_tag_tag_id';
198 if ( isset( $prop['content'] ) ||
!is_null( $this->difftotext
) ) {
199 // For each page we will request, the user must have read rights for that page
200 $user = $this->getUser();
201 /** @var $title Title */
202 foreach ( $pageSet->getGoodTitles() as $title ) {
203 if ( !$title->userCan( 'read', $user ) ) {
205 'The current user is not allowed to read ' . $title->getPrefixedText(),
210 $this->addTables( 'text' );
211 $this->addWhere( 'rev_text_id=old_id' );
212 $this->addFields( 'old_id' );
213 $this->addFields( Revision
::selectTextFields() );
215 $this->fld_content
= isset( $prop['content'] );
217 $this->expandTemplates
= $params['expandtemplates'];
218 $this->generateXML
= $params['generatexml'];
219 $this->parseContent
= $params['parse'];
220 if ( $this->parseContent
) {
221 // Must manually initialize unset limit
222 if ( is_null( $limit ) ) {
225 // We are only going to parse 1 revision per request
226 $this->validateLimit( 'limit', $limit, 1, 1, 1 );
228 if ( isset( $params['section'] ) ) {
229 $this->section
= $params['section'];
231 $this->section
= false;
235 // add user name, if needed
236 if ( $this->fld_user
) {
237 $this->addTables( 'user' );
238 $this->addJoinConds( array( 'user' => Revision
::userJoinCond() ) );
239 $this->addFields( Revision
::selectUserFields() );
242 // Bug 24166 - API error when using rvprop=tags
243 $this->addTables( 'revision' );
245 if ( $enumRevMode ) {
246 // This is mostly to prevent parameter errors (and optimize SQL?)
247 if ( !is_null( $params['startid'] ) && !is_null( $params['start'] ) ) {
248 $this->dieUsage( 'start and startid cannot be used together', 'badparams' );
251 if ( !is_null( $params['endid'] ) && !is_null( $params['end'] ) ) {
252 $this->dieUsage( 'end and endid cannot be used together', 'badparams' );
255 if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
256 $this->dieUsage( 'user and excludeuser cannot be used together', 'badparams' );
259 // Continuing effectively uses startid. But we can't use rvstartid
260 // directly, because there is no way to tell the client to ''not''
261 // send rvstart if it sent it in the original query. So instead we
262 // send the continuation startid as rvcontinue, and ignore both
263 // rvstart and rvstartid when that is supplied.
264 if ( !is_null( $params['continue'] ) ) {
265 $params['startid'] = $params['continue'];
266 $params['start'] = null;
269 // This code makes an assumption that sorting by rev_id and rev_timestamp produces
270 // the same result. This way users may request revisions starting at a given time,
271 // but to page through results use the rev_id returned after each page.
272 // Switching to rev_id removes the potential problem of having more than
273 // one row with the same timestamp for the same page.
274 // The order needs to be the same as start parameter to avoid SQL filesort.
275 if ( is_null( $params['startid'] ) && is_null( $params['endid'] ) ) {
276 $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'],
277 $params['start'], $params['end'] );
279 $this->addWhereRange( 'rev_id', $params['dir'],
280 $params['startid'], $params['endid'] );
281 // One of start and end can be set
282 // If neither is set, this does nothing
283 $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'],
284 $params['start'], $params['end'], false );
287 // must manually initialize unset limit
288 if ( is_null( $limit ) ) {
291 $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
293 // There is only one ID, use it
294 $ids = array_keys( $pageSet->getGoodTitles() );
295 $this->addWhereFld( 'rev_page', reset( $ids ) );
297 if ( !is_null( $params['user'] ) ) {
298 $this->addWhereFld( 'rev_user_text', $params['user'] );
299 } elseif ( !is_null( $params['excludeuser'] ) ) {
300 $this->addWhere( 'rev_user_text != ' .
301 $db->addQuotes( $params['excludeuser'] ) );
303 if ( !is_null( $params['user'] ) ||
!is_null( $params['excludeuser'] ) ) {
304 // Paranoia: avoid brute force searches (bug 17342)
305 $this->addWhere( $db->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0' );
307 } elseif ( $revCount > 0 ) {
308 $max = $this->getMain()->canApiHighLimits() ?
$botMax : $userMax;
309 $revs = $pageSet->getRevisionIDs();
310 if ( self
::truncateArray( $revs, $max ) ) {
311 $this->setWarning( "Too many values supplied for parameter 'revids': the limit is $max" );
314 // Get all revision IDs
315 $this->addWhereFld( 'rev_id', array_keys( $revs ) );
317 if ( !is_null( $params['continue'] ) ) {
318 $this->addWhere( 'rev_id >= ' . intval( $params['continue'] ) );
320 $this->addOption( 'ORDER BY', 'rev_id' );
322 // assumption testing -- we should never get more then $revCount rows.
324 } elseif ( $pageCount > 0 ) {
325 $max = $this->getMain()->canApiHighLimits() ?
$botMax : $userMax;
326 $titles = $pageSet->getGoodTitles();
327 if ( self
::truncateArray( $titles, $max ) ) {
328 $this->setWarning( "Too many values supplied for parameter 'titles': the limit is $max" );
331 // When working in multi-page non-enumeration mode,
332 // limit to the latest revision only
333 $this->addWhere( 'page_id=rev_page' );
334 $this->addWhere( 'page_latest=rev_id' );
337 $this->addWhereFld( 'page_id', array_keys( $titles ) );
338 // Every time someone relies on equality propagation, god kills a kitten :)
339 $this->addWhereFld( 'rev_page', array_keys( $titles ) );
341 if ( !is_null( $params['continue'] ) ) {
342 $cont = explode( '|', $params['continue'] );
343 $this->dieContinueUsageIf( count( $cont ) != 2 );
344 $pageid = intval( $cont[0] );
345 $revid = intval( $cont[1] );
347 "rev_page > $pageid OR " .
348 "(rev_page = $pageid AND " .
352 $this->addOption( 'ORDER BY', array(
357 // assumption testing -- we should never get more then $pageCount rows.
360 ApiBase
::dieDebug( __METHOD__
, 'param validation?' );
363 $this->addOption( 'LIMIT', $limit +
1 );
364 $this->addOption( 'USE INDEX', $index );
367 $res = $this->select( __METHOD__
);
369 foreach ( $res as $row ) {
370 if ( ++
$count > $limit ) {
371 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
372 if ( !$enumRevMode ) {
373 ApiBase
::dieDebug( __METHOD__
, 'Got more rows then expected' ); // bug report
375 $this->setContinueEnumParameter( 'continue', intval( $row->rev_id
) );
379 $fit = $this->addPageSubItem( $row->rev_page
, $this->extractRowInfo( $row ), 'rev' );
381 if ( $enumRevMode ) {
382 $this->setContinueEnumParameter( 'continue', intval( $row->rev_id
) );
383 } elseif ( $revCount > 0 ) {
384 $this->setContinueEnumParameter( 'continue', intval( $row->rev_id
) );
386 $this->setContinueEnumParameter( 'continue', intval( $row->rev_page
) .
387 '|' . intval( $row->rev_id
) );
394 private function extractRowInfo( $row ) {
395 $revision = new Revision( $row );
396 $title = $revision->getTitle();
399 if ( $this->fld_ids
) {
400 $vals['revid'] = intval( $revision->getId() );
401 // $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
402 if ( !is_null( $revision->getParentId() ) ) {
403 $vals['parentid'] = intval( $revision->getParentId() );
407 if ( $this->fld_flags
&& $revision->isMinor() ) {
411 if ( $this->fld_user ||
$this->fld_userid
) {
412 if ( $revision->isDeleted( Revision
::DELETED_USER
) ) {
413 $vals['userhidden'] = '';
415 if ( $this->fld_user
) {
416 $vals['user'] = $revision->getUserText();
418 $userid = $revision->getUser();
423 if ( $this->fld_userid
) {
424 $vals['userid'] = $userid;
429 if ( $this->fld_timestamp
) {
430 $vals['timestamp'] = wfTimestamp( TS_ISO_8601
, $revision->getTimestamp() );
433 if ( $this->fld_size
) {
434 if ( !is_null( $revision->getSize() ) ) {
435 $vals['size'] = intval( $revision->getSize() );
441 if ( $this->fld_sha1
&& !$revision->isDeleted( Revision
::DELETED_TEXT
) ) {
442 if ( $revision->getSha1() != '' ) {
443 $vals['sha1'] = wfBaseConvert( $revision->getSha1(), 36, 16, 40 );
447 } elseif ( $this->fld_sha1
) {
448 $vals['sha1hidden'] = '';
451 if ( $this->fld_contentmodel
) {
452 $vals['contentmodel'] = $revision->getContentModel();
455 if ( $this->fld_comment ||
$this->fld_parsedcomment
) {
456 if ( $revision->isDeleted( Revision
::DELETED_COMMENT
) ) {
457 $vals['commenthidden'] = '';
459 $comment = $revision->getComment();
461 if ( $this->fld_comment
) {
462 $vals['comment'] = $comment;
465 if ( $this->fld_parsedcomment
) {
466 $vals['parsedcomment'] = Linker
::formatComment( $comment, $title );
471 if ( $this->fld_tags
) {
472 if ( $row->ts_tags
) {
473 $tags = explode( ',', $row->ts_tags
);
474 $this->getResult()->setIndexedTagName( $tags, 'tag' );
475 $vals['tags'] = $tags;
477 $vals['tags'] = array();
481 if ( !is_null( $this->token
) ) {
482 $tokenFunctions = $this->getTokenFunctions();
483 foreach ( $this->token
as $t ) {
484 $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
485 if ( $val === false ) {
486 $this->setWarning( "Action '$t' is not allowed for the current user" );
488 $vals[$t . 'token'] = $val;
495 if ( $this->fld_content ||
!is_null( $this->diffto
) ||
!is_null( $this->difftotext
) ) {
496 $content = $revision->getContent();
497 // Expand templates after getting section content because
498 // template-added sections don't count and Parser::preprocess()
499 // will have less input
500 if ( $content && $this->section
!== false ) {
501 $content = $content->getSection( $this->section
, false );
503 $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
507 if ( $this->fld_content
&& $content && !$revision->isDeleted( Revision
::DELETED_TEXT
) ) {
510 if ( $this->generateXML
) {
511 if ( $content->getModel() === CONTENT_MODEL_WIKITEXT
) {
512 $t = $content->getNativeData(); # note: don't set $text
514 $wgParser->startExternalParse( $title, ParserOptions
::newFromContext( $this->getContext() ), OT_PREPROCESS
);
515 $dom = $wgParser->preprocessToDom( $t );
516 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
517 $xml = $dom->saveXML();
519 $xml = $dom->__toString();
521 $vals['parsetree'] = $xml;
523 $this->setWarning( "Conversion to XML is supported for wikitext only, " .
524 $title->getPrefixedDBkey() .
525 " uses content model " . $content->getModel() );
529 if ( $this->expandTemplates
&& !$this->parseContent
) {
530 #XXX: implement template expansion for all content types in ContentHandler?
531 if ( $content->getModel() === CONTENT_MODEL_WIKITEXT
) {
532 $text = $content->getNativeData();
534 $text = $wgParser->preprocess( $text, $title, ParserOptions
::newFromContext( $this->getContext() ) );
536 $this->setWarning( "Template expansion is supported for wikitext only, " .
537 $title->getPrefixedDBkey() .
538 " uses content model " . $content->getModel() );
543 if ( $this->parseContent
) {
544 $po = $content->getParserOutput( $title, $revision->getId(), ParserOptions
::newFromContext( $this->getContext() ) );
545 $text = $po->getText();
548 if ( $text === null ) {
549 $format = $this->contentFormat ?
$this->contentFormat
: $content->getDefaultFormat();
550 $model = $content->getModel();
552 if ( !$content->isSupportedFormat( $format ) ) {
553 $name = $title->getPrefixedDBkey();
555 $this->dieUsage( "The requested format {$this->contentFormat} is not supported " .
556 "for content model $model used by $name", 'badformat' );
559 $text = $content->serialize( $format );
561 // always include format and model.
562 // Format is needed to deserialize, model is needed to interpret.
563 $vals['contentformat'] = $format;
564 $vals['contentmodel'] = $model;
567 if ( $text !== false ) {
568 ApiResult
::setContent( $vals, $text );
570 } elseif ( $this->fld_content
) {
571 if ( $revision->isDeleted( Revision
::DELETED_TEXT
) ) {
572 $vals['texthidden'] = '';
574 $vals['textmissing'] = '';
578 if ( !is_null( $this->diffto
) ||
!is_null( $this->difftotext
) ) {
579 global $wgAPIMaxUncachedDiffs;
580 static $n = 0; // Number of uncached diffs we've had
582 if ( is_null( $content ) ) {
583 $vals['textmissing'] = '';
584 } elseif ( $n < $wgAPIMaxUncachedDiffs ) {
585 $vals['diff'] = array();
586 $context = new DerivativeContext( $this->getContext() );
587 $context->setTitle( $title );
588 $handler = $revision->getContentHandler();
590 if ( !is_null( $this->difftotext
) ) {
591 $model = $title->getContentModel();
593 if ( $this->contentFormat
594 && !ContentHandler
::getForModelID( $model )->isSupportedFormat( $this->contentFormat
)
597 $name = $title->getPrefixedDBkey();
599 $this->dieUsage( "The requested format {$this->contentFormat} is not supported for " .
600 "content model $model used by $name", 'badformat' );
603 $difftocontent = ContentHandler
::makeContent( $this->difftotext
, $title, $model, $this->contentFormat
);
605 $engine = $handler->createDifferenceEngine( $context );
606 $engine->setContent( $content, $difftocontent );
608 $engine = $handler->createDifferenceEngine( $context, $revision->getID(), $this->diffto
);
609 $vals['diff']['from'] = $engine->getOldid();
610 $vals['diff']['to'] = $engine->getNewid();
612 $difftext = $engine->getDiffBody();
613 ApiResult
::setContent( $vals['diff'], $difftext );
614 if ( !$engine->wasCacheHit() ) {
618 $vals['diff']['notcached'] = '';
625 public function getCacheMode( $params ) {
626 if ( isset( $params['token'] ) ) {
629 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
630 // formatComment() calls wfMessage() among other things
631 return 'anon-public-user-private';
637 public function getAllowedParams() {
640 ApiBase
::PARAM_ISMULTI
=> true,
641 ApiBase
::PARAM_DFLT
=> 'ids|timestamp|flags|comment|user',
642 ApiBase
::PARAM_TYPE
=> array(
658 ApiBase
::PARAM_TYPE
=> 'limit',
659 ApiBase
::PARAM_MIN
=> 1,
660 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
661 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
664 ApiBase
::PARAM_TYPE
=> 'integer'
667 ApiBase
::PARAM_TYPE
=> 'integer'
670 ApiBase
::PARAM_TYPE
=> 'timestamp'
673 ApiBase
::PARAM_TYPE
=> 'timestamp'
676 ApiBase
::PARAM_DFLT
=> 'older',
677 ApiBase
::PARAM_TYPE
=> array(
683 ApiBase
::PARAM_TYPE
=> 'user'
685 'excludeuser' => array(
686 ApiBase
::PARAM_TYPE
=> 'user'
689 'expandtemplates' => false,
690 'generatexml' => false,
694 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() ),
695 ApiBase
::PARAM_ISMULTI
=> true
699 'difftotext' => null,
700 'contentformat' => array(
701 ApiBase
::PARAM_TYPE
=> ContentHandler
::getAllContentFormats(),
702 ApiBase
::PARAM_DFLT
=> null
707 public function getParamDescription() {
708 $p = $this->getModulePrefix();
712 'Which properties to get for each revision:',
713 ' ids - The ID of the revision',
714 ' flags - Revision flags (minor)',
715 ' timestamp - The timestamp of the revision',
716 ' user - User that made the revision',
717 ' userid - User id of revision creator',
718 ' size - Length (bytes) of the revision',
719 ' sha1 - SHA-1 (base 16) of the revision',
720 ' contentmodel - Content model id',
721 ' comment - Comment by the user for revision',
722 ' parsedcomment - Parsed comment by the user for the revision',
723 ' content - Text of the revision',
724 ' tags - Tags for the revision',
726 'limit' => 'Limit how many revisions will be returned (enum)',
727 'startid' => 'From which revision id to start enumeration (enum)',
728 'endid' => 'Stop revision enumeration on this revid (enum)',
729 'start' => 'From which revision timestamp to start enumeration (enum)',
730 'end' => 'Enumerate up to this timestamp (enum)',
731 'dir' => $this->getDirectionDescription( $p, ' (enum)' ),
732 'user' => 'Only include revisions made by user (enum)',
733 'excludeuser' => 'Exclude revisions made by user (enum)',
734 'expandtemplates' => "Expand templates in revision content (requires {$p}prop=content)",
735 'generatexml' => "Generate XML parse tree for revision content (requires {$p}prop=content)",
736 'parse' => array( "Parse revision content (requires {$p}prop=content).",
737 'For performance reasons if this option is used, rvlimit is enforced to 1.' ),
738 'section' => 'Only retrieve the content of this section number',
739 'token' => 'Which tokens to obtain for each revision',
740 'continue' => 'When more results are available, use this to continue',
741 'diffto' => array( 'Revision ID to diff each revision to.',
742 'Use "prev", "next" and "cur" for the previous, next and current revision respectively' ),
743 'difftotext' => array( 'Text to diff each revision to. Only diffs a limited number of revisions.',
744 "Overrides {$p}diffto. If {$p}section is set, only that section will be diffed against this text" ),
745 'tag' => 'Only list revisions tagged with this tag',
746 'contentformat' => 'Serialization format used for difftotext and expected for output of content',
750 public function getResultProperties() {
754 'revid' => 'integer',
756 ApiBase
::PROP_TYPE
=> 'integer',
757 ApiBase
::PROP_NULLABLE
=> true
764 'userhidden' => 'boolean',
769 'userhidden' => 'boolean',
770 'userid' => 'integer',
773 'timestamp' => array(
774 'timestamp' => 'timestamp'
783 'commenthidden' => 'boolean',
785 ApiBase
::PROP_TYPE
=> 'string',
786 ApiBase
::PROP_NULLABLE
=> true
789 'parsedcomment' => array(
790 'commenthidden' => 'boolean',
791 'parsedcomment' => array(
792 ApiBase
::PROP_TYPE
=> 'string',
793 ApiBase
::PROP_NULLABLE
=> true
798 ApiBase
::PROP_TYPE
=> 'string',
799 ApiBase
::PROP_NULLABLE
=> true
801 'texthidden' => 'boolean',
802 'textmissing' => 'boolean',
804 'contentmodel' => array(
805 'contentmodel' => 'string'
809 self
::addTokenProperties( $props, $this->getTokenFunctions() );
814 public function getDescription() {
816 'Get revision information',
817 'May be used in several ways:',
818 ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter',
819 ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params',
820 ' 3) Get data about a set of revisions by setting their IDs with revids parameter',
821 'All parameters marked as (enum) may only be used with a single page (#2)'
825 public function getPossibleErrors() {
826 return array_merge( parent
::getPossibleErrors(), array(
827 array( 'nosuchrevid', 'diffto' ),
828 array( 'code' => 'revids', 'info' => 'The revids= parameter may not be used with the list options '
829 . '(limit, startid, endid, dirNewer, start, end).' ),
830 array( 'code' => 'multpages', 'info' => 'titles, pageids or a generator was used to supply multiple pages, '
831 . ' but the limit, startid, endid, dirNewer, user, excludeuser, '
832 . 'start and end parameters may only be used on a single page.' ),
833 array( 'code' => 'diffto', 'info' => 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"' ),
834 array( 'code' => 'badparams', 'info' => 'start and startid cannot be used together' ),
835 array( 'code' => 'badparams', 'info' => 'end and endid cannot be used together' ),
836 array( 'code' => 'badparams', 'info' => 'user and excludeuser cannot be used together' ),
837 array( 'code' => 'nosuchsection', 'info' => 'There is no section section in rID' ),
838 array( 'code' => 'badformat', 'info' => 'The requested serialization format can not be applied '
839 . ' to the page\'s content model' ),
843 public function getExamples() {
845 'Get data with content for the last revision of titles "API" and "Main Page"',
846 ' api.php?action=query&prop=revisions&titles=API|Main%20Page&rvprop=timestamp|user|comment|content',
847 'Get last 5 revisions of the "Main Page"',
848 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment',
849 'Get first 5 revisions of the "Main Page"',
850 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer',
851 'Get first 5 revisions of the "Main Page" made after 2006-05-01',
852 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000',
853 'Get first 5 revisions of the "Main Page" that were not made made by anonymous user "127.0.0.1"',
854 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1',
855 'Get first 5 revisions of the "Main Page" that were made by the user "MediaWiki default"',
856 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvuser=MediaWiki%20default',
860 public function getHelpUrls() {
861 return 'https://www.mediawiki.org/wiki/API:Properties#revisions_.2F_rv';