0bb0d7762b59641715b6e75a6616083b4c8332bb
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
) );
68 return $this->tokenFunctions
;
74 * @param $rev Revision
77 public static function getRollbackToken( $pageid, $title, $rev ) {
79 if ( !$wgUser->isAllowed( 'rollback' ) ) {
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'] ) );
99 $pageSet = $this->getPageSet();
100 $pageCount = $pageSet->getGoodTitleCount();
101 $revCount = $pageSet->getRevisionCount();
103 // Optimization -- nothing to do
104 if ( $revCount === 0 && $pageCount === 0 ) {
108 if ( $revCount > 0 && $enumRevMode ) {
109 $this->dieUsage( 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).', 'revids' );
112 if ( $pageCount > 1 && $enumRevMode ) {
113 $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' );
116 if ( !is_null( $params['difftotext'] ) ) {
117 $this->difftotext
= $params['difftotext'];
118 } elseif ( !is_null( $params['diffto'] ) ) {
119 if ( $params['diffto'] == 'cur' ) {
120 $params['diffto'] = 0;
122 if ( ( !ctype_digit( $params['diffto'] ) ||
$params['diffto'] < 0 )
123 && $params['diffto'] != 'prev' && $params['diffto'] != 'next' ) {
124 $this->dieUsage( 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"', 'diffto' );
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'] );
132 $this->dieUsageMsg( array( 'nosuchrevid', $params['diffto'] ) );
134 if ( $difftoRev->isDeleted( Revision
::DELETED_TEXT
) ) {
135 $this->setWarning( "Couldn't diff to r{$difftoRev->getID()}: content is hidden" );
136 $params['diffto'] = null;
139 $this->diffto
= $params['diffto'];
142 $db = $this->getDB();
143 $this->addTables( 'page' );
144 $this->addFields( Revision
::selectFields() );
145 $this->addWhere( 'page_id = rev_page' );
147 $prop = array_flip( $params['prop'] );
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_sha1
= isset ( $prop['sha1'] );
158 $this->fld_contentmodel
= isset ( $prop['contentmodel'] );
159 $this->fld_userid
= isset( $prop['userid'] );
160 $this->fld_user
= isset ( $prop['user'] );
161 $this->token
= $params['token'];
163 if ( !empty( $params['contentformat'] ) ) {
164 $this->contentFormat
= $params['contentformat'];
167 // Possible indexes used
170 $userMax = ( $this->fld_content ? ApiBase
::LIMIT_SML1
: ApiBase
::LIMIT_BIG1
);
171 $botMax = ( $this->fld_content ? ApiBase
::LIMIT_SML2
: ApiBase
::LIMIT_BIG2
);
172 $limit = $params['limit'];
173 if ( $limit == 'max' ) {
174 $limit = $this->getMain()->canApiHighLimits() ?
$botMax : $userMax;
175 $this->getResult()->setParsedLimit( $this->getModuleName(), $limit );
178 if ( !is_null( $this->token
) ||
$pageCount > 0 ) {
179 $this->addFields( Revision
::selectPageFields() );
182 if ( isset( $prop['tags'] ) ) {
183 $this->fld_tags
= true;
184 $this->addTables( 'tag_summary' );
185 $this->addJoinConds( array( 'tag_summary' => array( 'LEFT JOIN', array( 'rev_id=ts_rev_id' ) ) ) );
186 $this->addFields( 'ts_tags' );
189 if ( !is_null( $params['tag'] ) ) {
190 $this->addTables( 'change_tag' );
191 $this->addJoinConds( array( 'change_tag' => array( 'INNER JOIN', array( 'rev_id=ct_rev_id' ) ) ) );
192 $this->addWhereFld( 'ct_tag' , $params['tag'] );
193 global $wgOldChangeTagsIndex;
194 $index['change_tag'] = $wgOldChangeTagsIndex ?
'ct_tag' : 'change_tag_tag_id';
197 if ( isset( $prop['content'] ) ||
!is_null( $this->difftotext
) ) {
198 // For each page we will request, the user must have read rights for that page
199 foreach ( $pageSet->getGoodTitles() as $title ) {
200 if ( !$title->userCan( 'read' ) ) {
202 'The current user is not allowed to read ' . $title->getPrefixedText(),
207 $this->addTables( 'text' );
208 $this->addWhere( 'rev_text_id=old_id' );
209 $this->addFields( 'old_id' );
210 $this->addFields( Revision
::selectTextFields() );
212 $this->fld_content
= isset( $prop['content'] );
214 $this->expandTemplates
= $params['expandtemplates'];
215 $this->generateXML
= $params['generatexml'];
216 $this->parseContent
= $params['parse'];
217 if ( $this->parseContent
) {
218 // Must manually initialize unset limit
219 if ( is_null( $limit ) ) {
222 // We are only going to parse 1 revision per request
223 $this->validateLimit( 'limit', $limit, 1, 1, 1 );
225 if ( isset( $params['section'] ) ) {
226 $this->section
= $params['section'];
228 $this->section
= false;
232 // add user name, if needed
233 if ( $this->fld_user
) {
234 $this->addTables( 'user' );
235 $this->addJoinConds( array( 'user' => Revision
::userJoinCond() ) );
236 $this->addFields( Revision
::selectUserFields() );
239 // Bug 24166 - API error when using rvprop=tags
240 $this->addTables( 'revision' );
242 if ( $enumRevMode ) {
243 // This is mostly to prevent parameter errors (and optimize SQL?)
244 if ( !is_null( $params['startid'] ) && !is_null( $params['start'] ) ) {
245 $this->dieUsage( 'start and startid cannot be used together', 'badparams' );
248 if ( !is_null( $params['endid'] ) && !is_null( $params['end'] ) ) {
249 $this->dieUsage( 'end and endid cannot be used together', 'badparams' );
252 if ( !is_null( $params['user'] ) && !is_null( $params['excludeuser'] ) ) {
253 $this->dieUsage( 'user and excludeuser cannot be used together', 'badparams' );
256 // This code makes an assumption that sorting by rev_id and rev_timestamp produces
257 // the same result. This way users may request revisions starting at a given time,
258 // but to page through results use the rev_id returned after each page.
259 // Switching to rev_id removes the potential problem of having more than
260 // one row with the same timestamp for the same page.
261 // The order needs to be the same as start parameter to avoid SQL filesort.
262 if ( is_null( $params['startid'] ) && is_null( $params['endid'] ) ) {
263 $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'],
264 $params['start'], $params['end'] );
266 $this->addWhereRange( 'rev_id', $params['dir'],
267 $params['startid'], $params['endid'] );
268 // One of start and end can be set
269 // If neither is set, this does nothing
270 $this->addTimestampWhereRange( 'rev_timestamp', $params['dir'],
271 $params['start'], $params['end'], false );
274 // must manually initialize unset limit
275 if ( is_null( $limit ) ) {
278 $this->validateLimit( 'limit', $limit, 1, $userMax, $botMax );
280 // There is only one ID, use it
281 $ids = array_keys( $pageSet->getGoodTitles() );
282 $this->addWhereFld( 'rev_page', reset( $ids ) );
284 if ( !is_null( $params['user'] ) ) {
285 $this->addWhereFld( 'rev_user_text', $params['user'] );
286 } elseif ( !is_null( $params['excludeuser'] ) ) {
287 $this->addWhere( 'rev_user_text != ' .
288 $db->addQuotes( $params['excludeuser'] ) );
290 if ( !is_null( $params['user'] ) ||
!is_null( $params['excludeuser'] ) ) {
291 // Paranoia: avoid brute force searches (bug 17342)
292 $this->addWhere( $db->bitAnd( 'rev_deleted', Revision
::DELETED_USER
) . ' = 0' );
294 } elseif ( $revCount > 0 ) {
295 $max = $this->getMain()->canApiHighLimits() ?
$botMax : $userMax;
296 $revs = $pageSet->getRevisionIDs();
297 if ( self
::truncateArray( $revs, $max ) ) {
298 $this->setWarning( "Too many values supplied for parameter 'revids': the limit is $max" );
301 // Get all revision IDs
302 $this->addWhereFld( 'rev_id', array_keys( $revs ) );
304 if ( !is_null( $params['continue'] ) ) {
305 $this->addWhere( 'rev_id >= ' . intval( $params['continue'] ) );
307 $this->addOption( 'ORDER BY', 'rev_id' );
309 // assumption testing -- we should never get more then $revCount rows.
311 } elseif ( $pageCount > 0 ) {
312 $max = $this->getMain()->canApiHighLimits() ?
$botMax : $userMax;
313 $titles = $pageSet->getGoodTitles();
314 if ( self
::truncateArray( $titles, $max ) ) {
315 $this->setWarning( "Too many values supplied for parameter 'titles': the limit is $max" );
318 // When working in multi-page non-enumeration mode,
319 // limit to the latest revision only
320 $this->addWhere( 'page_id=rev_page' );
321 $this->addWhere( 'page_latest=rev_id' );
324 $this->addWhereFld( 'page_id', array_keys( $titles ) );
325 // Every time someone relies on equality propagation, god kills a kitten :)
326 $this->addWhereFld( 'rev_page', array_keys( $titles ) );
328 if ( !is_null( $params['continue'] ) ) {
329 $cont = explode( '|', $params['continue'] );
330 if ( count( $cont ) != 2 ) {
331 $this->dieUsage( 'Invalid continue param. You should pass the original ' .
332 'value returned by the previous query', '_badcontinue' );
334 $pageid = intval( $cont[0] );
335 $revid = intval( $cont[1] );
337 "rev_page > $pageid OR " .
338 "(rev_page = $pageid AND " .
342 $this->addOption( 'ORDER BY', array(
347 // assumption testing -- we should never get more then $pageCount rows.
350 ApiBase
::dieDebug( __METHOD__
, 'param validation?' );
353 $this->addOption( 'LIMIT', $limit +
1 );
354 $this->addOption( 'USE INDEX', $index );
357 $res = $this->select( __METHOD__
);
359 foreach ( $res as $row ) {
360 if ( ++
$count > $limit ) {
361 // We've reached the one extra which shows that there are additional pages to be had. Stop here...
362 if ( !$enumRevMode ) {
363 ApiBase
::dieDebug( __METHOD__
, 'Got more rows then expected' ); // bug report
365 $this->setContinueEnumParameter( 'startid', intval( $row->rev_id
) );
369 $fit = $this->addPageSubItem( $row->rev_page
, $this->extractRowInfo( $row ), 'rev' );
371 if ( $enumRevMode ) {
372 $this->setContinueEnumParameter( 'startid', intval( $row->rev_id
) );
373 } elseif ( $revCount > 0 ) {
374 $this->setContinueEnumParameter( 'continue', intval( $row->rev_id
) );
376 $this->setContinueEnumParameter( 'continue', intval( $row->rev_page
) .
377 '|' . intval( $row->rev_id
) );
384 private function extractRowInfo( $row ) {
385 $revision = new Revision( $row );
386 $title = $revision->getTitle();
389 if ( $this->fld_ids
) {
390 $vals['revid'] = intval( $revision->getId() );
391 // $vals['oldid'] = intval( $row->rev_text_id ); // todo: should this be exposed?
392 if ( !is_null( $revision->getParentId() ) ) {
393 $vals['parentid'] = intval( $revision->getParentId() );
397 if ( $this->fld_flags
&& $revision->isMinor() ) {
401 if ( $this->fld_user ||
$this->fld_userid
) {
402 if ( $revision->isDeleted( Revision
::DELETED_USER
) ) {
403 $vals['userhidden'] = '';
405 if ( $this->fld_user
) {
406 $vals['user'] = $revision->getUserText();
408 $userid = $revision->getUser();
413 if ( $this->fld_userid
) {
414 $vals['userid'] = $userid;
419 if ( $this->fld_timestamp
) {
420 $vals['timestamp'] = wfTimestamp( TS_ISO_8601
, $revision->getTimestamp() );
423 if ( $this->fld_size
) {
424 if ( !is_null( $revision->getSize() ) ) {
425 $vals['size'] = intval( $revision->getSize() );
431 if ( $this->fld_sha1
) {
432 if ( $revision->getSha1() != '' ) {
433 $vals['sha1'] = wfBaseConvert( $revision->getSha1(), 36, 16, 40 );
439 if ( $this->fld_contentmodel
) {
440 $vals['contentmodel'] = $revision->getContentModel();
443 if ( $this->fld_comment ||
$this->fld_parsedcomment
) {
444 if ( $revision->isDeleted( Revision
::DELETED_COMMENT
) ) {
445 $vals['commenthidden'] = '';
447 $comment = $revision->getComment();
449 if ( $this->fld_comment
) {
450 $vals['comment'] = $comment;
453 if ( $this->fld_parsedcomment
) {
454 $vals['parsedcomment'] = Linker
::formatComment( $comment, $title );
459 if ( $this->fld_tags
) {
460 if ( $row->ts_tags
) {
461 $tags = explode( ',', $row->ts_tags
);
462 $this->getResult()->setIndexedTagName( $tags, 'tag' );
463 $vals['tags'] = $tags;
465 $vals['tags'] = array();
469 if ( !is_null( $this->token
) ) {
470 $tokenFunctions = $this->getTokenFunctions();
471 foreach ( $this->token
as $t ) {
472 $val = call_user_func( $tokenFunctions[$t], $title->getArticleID(), $title, $revision );
473 if ( $val === false ) {
474 $this->setWarning( "Action '$t' is not allowed for the current user" );
476 $vals[$t . 'token'] = $val;
483 if ( $this->fld_content ||
!is_null( $this->difftotext
) ) {
484 $content = $revision->getContent();
485 // Expand templates after getting section content because
486 // template-added sections don't count and Parser::preprocess()
487 // will have less input
488 if ( $this->section
!== false ) {
489 $content = $content->getSection( $this->section
, false );
491 $this->dieUsage( "There is no section {$this->section} in r" . $revision->getId(), 'nosuchsection' );
495 if ( $this->fld_content
&& !$revision->isDeleted( Revision
::DELETED_TEXT
) ) {
498 if ( $this->generateXML
) {
499 if ( $content->getModel() === CONTENT_MODEL_WIKITEXT
) {
500 $t = $content->getNativeData(); # note: don't set $text
502 $wgParser->startExternalParse( $title, ParserOptions
::newFromContext( $this->getContext() ), OT_PREPROCESS
);
503 $dom = $wgParser->preprocessToDom( $t );
504 if ( is_callable( array( $dom, 'saveXML' ) ) ) {
505 $xml = $dom->saveXML();
507 $xml = $dom->__toString();
509 $vals['parsetree'] = $xml;
511 $this->setWarning( "Conversion to XML is supported for wikitext only, " .
512 $title->getPrefixedDBkey() .
513 " uses content model " . $content->getModel() . ")" );
517 if ( $this->expandTemplates
&& !$this->parseContent
) {
518 #XXX: implement template expansion for all content types in ContentHandler?
519 if ( $content->getModel() === CONTENT_MODEL_WIKITEXT
) {
520 $text = $content->getNativeData();
522 $text = $wgParser->preprocess( $text, $title, ParserOptions
::newFromContext( $this->getContext() ) );
524 $this->setWarning( "Template expansion is supported for wikitext only, " .
525 $title->getPrefixedDBkey() .
526 " uses content model " . $content->getModel() . ")" );
531 if ( $this->parseContent
) {
532 $po = $content->getParserOutput( $title, ParserOptions
::newFromContext( $this->getContext() ) );
533 $text = $po->getText();
536 if ( $text === null ) {
537 $format = $this->contentFormat ?
$this->contentFormat
: $content->getDefaultFormat();
539 if ( !$content->isSupportedFormat( $format ) ) {
540 $model = $content->getModel();
541 $name = $title->getPrefixedDBkey();
543 $this->dieUsage( "The requested format {$this->contentFormat} is not supported for content model $model used by $name", 'badformat' );
546 $text = $content->serialize( $format );
547 $vals['contentformat'] = $format;
550 if ( $text !== false ) {
551 ApiResult
::setContent( $vals, $text );
553 } elseif ( $this->fld_content
) {
554 $vals['texthidden'] = '';
557 if ( !is_null( $this->diffto
) ||
!is_null( $this->difftotext
) ) {
558 global $wgAPIMaxUncachedDiffs;
559 static $n = 0; // Number of uncached diffs we've had
560 if ( $n < $wgAPIMaxUncachedDiffs ) {
561 $vals['diff'] = array();
562 $context = new DerivativeContext( $this->getContext() );
563 $context->setTitle( $title );
564 $handler = ContentHandler
::getForTitle( $title );
566 if ( !is_null( $this->difftotext
) ) {
567 $model = $title->getContentModel();
569 if ( $this->contentFormat
&& !ContentHandler
::getForModelID( $model )->isSupportedFormat( $this->contentFormat
) ) {
570 $name = $title->getPrefixedDBkey();
572 $this->dieUsage( "The requested format {$this->contentFormat} is not supported for content model $model used by $name", 'badformat' );
575 $difftocontent = ContentHandler
::makeContent( $this->difftotext
, $title, $model, $this->contentFormat
);
577 $engine = $handler->createDifferenceEngine( $context );
578 $engine->setContent( $content, $difftocontent );
580 $engine = $handler->createDifferenceEngine( $context, $revision->getID(), $this->diffto
);
581 $vals['diff']['from'] = $engine->getOldid();
582 $vals['diff']['to'] = $engine->getNewid();
584 $difftext = $engine->getDiffBody();
585 ApiResult
::setContent( $vals['diff'], $difftext );
586 if ( !$engine->wasCacheHit() ) {
590 $vals['diff']['notcached'] = '';
596 public function getCacheMode( $params ) {
597 if ( isset( $params['token'] ) ) {
600 if ( !is_null( $params['prop'] ) && in_array( 'parsedcomment', $params['prop'] ) ) {
601 // formatComment() calls wfMsg() among other things
602 return 'anon-public-user-private';
607 public function getAllowedParams() {
610 ApiBase
::PARAM_ISMULTI
=> true,
611 ApiBase
::PARAM_DFLT
=> 'ids|timestamp|flags|comment|user',
612 ApiBase
::PARAM_TYPE
=> array(
628 ApiBase
::PARAM_TYPE
=> 'limit',
629 ApiBase
::PARAM_MIN
=> 1,
630 ApiBase
::PARAM_MAX
=> ApiBase
::LIMIT_BIG1
,
631 ApiBase
::PARAM_MAX2
=> ApiBase
::LIMIT_BIG2
634 ApiBase
::PARAM_TYPE
=> 'integer'
637 ApiBase
::PARAM_TYPE
=> 'integer'
640 ApiBase
::PARAM_TYPE
=> 'timestamp'
643 ApiBase
::PARAM_TYPE
=> 'timestamp'
646 ApiBase
::PARAM_DFLT
=> 'older',
647 ApiBase
::PARAM_TYPE
=> array(
653 ApiBase
::PARAM_TYPE
=> 'user'
655 'excludeuser' => array(
656 ApiBase
::PARAM_TYPE
=> 'user'
659 'expandtemplates' => false,
660 'generatexml' => false,
664 ApiBase
::PARAM_TYPE
=> array_keys( $this->getTokenFunctions() ),
665 ApiBase
::PARAM_ISMULTI
=> true
669 'difftotext' => null,
670 'contentformat' => array(
671 ApiBase
::PARAM_TYPE
=> ContentHandler
::getAllContentFormats(),
672 ApiBase
::PARAM_DFLT
=> null
677 public function getParamDescription() {
678 $p = $this->getModulePrefix();
681 'Which properties to get for each revision:',
682 ' ids - The ID of the revision',
683 ' flags - Revision flags (minor)',
684 ' timestamp - The timestamp of the revision',
685 ' user - User that made the revision',
686 ' userid - User id of revision creator',
687 ' size - Length (bytes) of the revision',
688 ' sha1 - SHA-1 (base 16) of the revision',
689 ' contentmodel - Content model id',
690 ' comment - Comment by the user for revision',
691 ' parsedcomment - Parsed comment by the user for the revision',
692 ' content - Text of the revision',
693 ' tags - Tags for the revision',
695 'limit' => 'Limit how many revisions will be returned (enum)',
696 'startid' => 'From which revision id to start enumeration (enum)',
697 'endid' => 'Stop revision enumeration on this revid (enum)',
698 'start' => 'From which revision timestamp to start enumeration (enum)',
699 'end' => 'Enumerate up to this timestamp (enum)',
700 'dir' => $this->getDirectionDescription( $p, ' (enum)' ),
701 'user' => 'Only include revisions made by user (enum)',
702 'excludeuser' => 'Exclude revisions made by user (enum)',
703 'expandtemplates' => 'Expand templates in revision content',
704 'generatexml' => 'Generate XML parse tree for revision content',
705 'parse' => 'Parse revision content. For performance reasons if this option is used, rvlimit is enforced to 1.',
706 'section' => 'Only retrieve the content of this section number',
707 'token' => 'Which tokens to obtain for each revision',
708 'continue' => 'When more results are available, use this to continue',
709 'diffto' => array( 'Revision ID to diff each revision to.',
710 'Use "prev", "next" and "cur" for the previous, next and current revision respectively' ),
711 'difftotext' => array( 'Text to diff each revision to. Only diffs a limited number of revisions.',
712 "Overrides {$p}diffto. If {$p}section is set, only that section will be diffed against this text" ),
713 'tag' => 'Only list revisions tagged with this tag',
714 'contentformat' => 'Serialization format used for difftotext and expected for output of content',
718 public function getResultProperties() {
722 'revid' => 'integer',
724 ApiBase
::PROP_TYPE
=> 'integer',
725 ApiBase
::PROP_NULLABLE
=> true
732 'userhidden' => 'boolean',
737 'userhidden' => 'boolean',
738 'userid' => 'integer',
741 'timestamp' => array(
742 'timestamp' => 'timestamp'
751 'commenthidden' => 'boolean',
753 ApiBase
::PROP_TYPE
=> 'string',
754 ApiBase
::PROP_NULLABLE
=> true
757 'parsedcomment' => array(
758 'commenthidden' => 'boolean',
759 'parsedcomment' => array(
760 ApiBase
::PROP_TYPE
=> 'string',
761 ApiBase
::PROP_NULLABLE
=> true
766 ApiBase
::PROP_TYPE
=> 'string',
767 ApiBase
::PROP_NULLABLE
=> true
769 'texthidden' => 'boolean'
773 self
::addTokenProperties( $props, $this->getTokenFunctions() );
778 public function getDescription() {
780 'Get revision information',
781 'May be used in several ways:',
782 ' 1) Get data about a set of pages (last revision), by setting titles or pageids parameter',
783 ' 2) Get revisions for one given page, by using titles/pageids with start/end/limit params',
784 ' 3) Get data about a set of revisions by setting their IDs with revids parameter',
785 'All parameters marked as (enum) may only be used with a single page (#2)'
789 public function getPossibleErrors() {
790 return array_merge( parent
::getPossibleErrors(), array(
791 array( 'nosuchrevid', 'diffto' ),
792 array( 'code' => 'revids', 'info' => 'The revids= parameter may not be used with the list options (limit, startid, endid, dirNewer, start, end).' ),
793 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.' ),
794 array( 'code' => 'diffto', 'info' => 'rvdiffto must be set to a non-negative number, "prev", "next" or "cur"' ),
795 array( 'code' => 'badparams', 'info' => 'start and startid cannot be used together' ),
796 array( 'code' => 'badparams', 'info' => 'end and endid cannot be used together' ),
797 array( 'code' => 'badparams', 'info' => 'user and excludeuser cannot be used together' ),
798 array( 'code' => 'nosuchsection', 'info' => 'There is no section section in rID' ),
799 array( 'code' => 'badformat', 'info' => 'The requested serialization format can not be applied to the page\'s content model' ),
803 public function getExamples() {
805 'Get data with content for the last revision of titles "API" and "Main Page"',
806 ' api.php?action=query&prop=revisions&titles=API|Main%20Page&rvprop=timestamp|user|comment|content',
807 'Get last 5 revisions of the "Main Page"',
808 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment',
809 'Get first 5 revisions of the "Main Page"',
810 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer',
811 'Get first 5 revisions of the "Main Page" made after 2006-05-01',
812 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvdir=newer&rvstart=20060501000000',
813 'Get first 5 revisions of the "Main Page" that were not made made by anonymous user "127.0.0.1"',
814 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1',
815 'Get first 5 revisions of the "Main Page" that were made by the user "MediaWiki default"',
816 ' api.php?action=query&prop=revisions&titles=Main%20Page&rvlimit=5&rvprop=timestamp|user|comment&rvuser=MediaWiki%20default',
820 public function getHelpUrls() {
821 return 'https://www.mediawiki.org/wiki/API:Properties#revisions_.2F_rv';
824 public function getVersion() {
825 return __CLASS__
. ': $Id$';