49 private $revisionStore;
52 private $changeTagDefStore;
55 private $actorMigration;
88 $contentHandlerFactory,
95 $this->revisionStore = $revisionStore;
96 $this->changeTagDefStore = $changeTagDefStore;
97 $this->actorMigration = $actorMigration;
107 $enumRevMode = ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ||
108 $params[
'limit'] !==
null || $params[
'startid'] !==
null ||
109 $params[
'endid'] !==
null || $params[
'dir'] ===
'newer' ||
110 $params[
'start'] !==
null || $params[
'end'] !== null );
113 $pageCount = $pageSet->getGoodTitleCount();
114 $revCount = $pageSet->getRevisionCount();
117 if ( $revCount === 0 && $pageCount === 0 ) {
121 if ( $revCount > 0 && count( $pageSet->getLiveRevisionIDs() ) === 0 ) {
126 if ( $revCount > 0 && $enumRevMode ) {
128 [
'apierror-revisions-norevids', $this->
getModulePrefix() ],
'invalidparammix'
132 if ( $pageCount > 1 && $enumRevMode ) {
134 [
'apierror-revisions-singlepage', $this->
getModulePrefix() ],
'invalidparammix'
140 if ( !$enumRevMode ) {
141 $this->setParsedLimit =
false;
142 $params[
'limit'] =
'max';
145 $db = $this->
getDB();
148 $tsField =
'rev_timestamp';
149 $pageField =
'rev_page';
155 'revision' =>
'rev_timestamp',
158 if ( $resultPageSet ===
null ) {
161 if ( $this->fld_user ) {
164 $revQuery = $this->revisionStore->getQueryInfo( $opts );
171 $this->
addTables( [
'revision',
'page' ] );
173 [
'page' => [
'JOIN', [
'page_id = rev_page' ] ] ]
176 'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField
180 if ( $this->fld_tags ) {
184 if ( $params[
'tag'] !==
null ) {
187 [
'change_tag' => [
'JOIN', [
'rev_id=ct_rev_id' ] ] ]
190 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
197 if ( $resultPageSet ===
null && $this->fetchContent ) {
199 $status = Status::newGood();
202 foreach ( $pageSet->getGoodTitles() as
$title ) {
204 $status->fatal( ApiMessage::create(
210 if ( !$status->isGood() ) {
215 if ( $enumRevMode ) {
227 if ( $params[
'continue'] !==
null ) {
229 $op = ( $params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
230 $continueTimestamp = $db->timestamp( $cont[0] );
231 $continueId = (int)$cont[1];
232 $this->
addWhere( $db->buildComparison( $op, [
233 $tsField => $continueTimestamp,
234 $idField => $continueId,
240 if ( $params[
'startid'] !==
null ) {
241 $revids[] = (int)$params[
'startid'];
243 if ( $params[
'endid'] !==
null ) {
244 $revids[] = (int)$params[
'endid'];
247 $db = $this->
getDB();
248 $sql = $db->unionQueries( [
251 [
'id' =>
'rev_id',
'ts' =>
'rev_timestamp' ],
252 [
'rev_id' => $revids ],
257 [
'id' =>
'ar_rev_id',
'ts' =>
'ar_timestamp' ],
258 [
'ar_rev_id' => $revids ],
261 ], $db::UNION_DISTINCT );
262 $res = $db->query( $sql, __METHOD__, ISQLPlatform::QUERY_CHANGE_NONE );
263 foreach (
$res as $row ) {
264 if ( (
int)$row->id === (
int)$params[
'startid'] ) {
265 $params[
'start'] = $row->ts;
267 if ( (
int)$row->id === (
int)$params[
'endid'] ) {
268 $params[
'end'] = $row->ts;
272 if ( $params[
'startid'] !==
null && $params[
'start'] ===
null ) {
274 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
277 if ( $params[
'endid'] !==
null && $params[
'end'] ===
null ) {
279 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
283 if ( $params[
'start'] !==
null ) {
284 $op = ( $params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
286 $ts = $db->timestampOrNull( $params[
'start'] );
287 if ( $params[
'startid'] !==
null ) {
288 $this->
addWhere( $db->buildComparison( $op, [
290 $idField => (
int)$params[
'startid'],
293 $this->
addWhere( $db->buildComparison( $op, [ $tsField => $ts ] ) );
297 if ( $params[
'end'] !==
null ) {
298 $op = ( $params[
'dir'] ===
'newer' ?
'<=' :
'>=' );
300 $ts = $db->timestampOrNull( $params[
'end'] );
301 if ( $params[
'endid'] !==
null ) {
302 $this->
addWhere( $db->buildComparison( $op, [
304 $idField => (
int)$params[
'endid'],
307 $this->
addWhere( $db->buildComparison( $op, [ $tsField => $ts ] ) );
312 $params[
'start'], $params[
'end'] );
315 $sort = ( $params[
'dir'] ===
'newer' ?
'' :
'DESC' );
316 $this->
addOption(
'ORDER BY', [
"rev_timestamp $sort",
"rev_id $sort" ] );
319 $ids = array_keys( $pageSet->getGoodPages() );
322 if ( $params[
'user'] !==
null ) {
323 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user', $params[
'user'] );
324 $this->
addTables( $actorQuery[
'tables'] );
326 $this->
addWhere( $actorQuery[
'conds'] );
327 } elseif ( $params[
'excludeuser'] !==
null ) {
328 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user', $params[
'excludeuser'] );
329 $this->
addTables( $actorQuery[
'tables'] );
331 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
337 $useIndex[
'revision'] =
'rev_page_timestamp';
340 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
342 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
343 $bitmask = RevisionRecord::DELETED_USER;
344 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' )
346 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
351 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
354 } elseif ( $revCount > 0 ) {
357 $revs = $pageSet->getLiveRevisionIDs();
360 $this->
addWhereFld(
'rev_id', array_keys( $revs ) );
362 if ( $params[
'continue'] !==
null ) {
363 $this->
addWhere(
'rev_id >= ' . (
int)$params[
'continue'] );
365 $this->
addOption(
'ORDER BY',
'rev_id' );
366 } elseif ( $pageCount > 0 ) {
369 $pageids = array_keys( $pageSet->getGoodPages() );
373 $this->
addWhere(
'page_latest=rev_id' );
380 if ( $params[
'continue'] !==
null ) {
382 $this->
addWhere( $db->buildComparison(
'>=', [
383 'rev_page' => $cont[0],
384 'rev_id' => $cont[1],
395 $this->
addOption(
'LIMIT', $this->limit + 1 );
397 $this->
addOption(
'IGNORE INDEX', $ignoreIndex );
400 $this->
addOption(
'USE INDEX', $useIndex );
406 $res = $this->
select( __METHOD__, [], $hookData );
408 foreach (
$res as $row ) {
409 if ( ++$count > $this->limit ) {
412 if ( $enumRevMode ) {
414 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
415 } elseif ( $revCount > 0 ) {
419 '|' . (
int)$row->rev_id );
424 if ( $resultPageSet !==
null ) {
425 $generated[] = $row->rev_id;
427 $revision = $this->revisionStore->newRevisionFromRow( $row, 0, Title::newFromRow( $row ) );
429 $fit = $this->
processRow( $row, $rev, $hookData ) &&
432 if ( $enumRevMode ) {
434 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
435 } elseif ( $revCount > 0 ) {
439 '|' . (
int)$row->rev_id );
446 if ( $resultPageSet !==
null ) {
447 $resultPageSet->populateFromRevisionIDs( $generated );
452 $ret = parent::getAllowedParams() + [
454 ParamValidator::PARAM_TYPE =>
'integer',
458 ParamValidator::PARAM_TYPE =>
'integer',
462 ParamValidator::PARAM_TYPE =>
'timestamp',
466 ParamValidator::PARAM_TYPE =>
'timestamp',
470 ParamValidator::PARAM_DEFAULT =>
'older',
471 ParamValidator::PARAM_TYPE => [
477 'newer' =>
'api-help-paramvalue-direction-newer',
478 'older' =>
'api-help-paramvalue-direction-older',
483 ParamValidator::PARAM_TYPE =>
'user',
484 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
485 UserDef::PARAM_RETURN_OBJECT =>
true,
489 ParamValidator::PARAM_TYPE =>
'user',
490 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
491 UserDef::PARAM_RETURN_OBJECT =>
true,
506 $title = Title::newMainPage()->getPrefixedText();
507 $mp = rawurlencode(
$title );
510 "action=query&prop=revisions&titles=API|{$mp}&" .
511 'rvslots=*&rvprop=timestamp|user|comment|content'
512 =>
'apihelp-query+revisions-example-content',
513 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
514 'rvprop=timestamp|user|comment'
515 =>
'apihelp-query+revisions-example-last5',
516 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
517 'rvprop=timestamp|user|comment&rvdir=newer'
518 =>
'apihelp-query+revisions-example-first5',
519 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
520 'rvprop=timestamp|user|comment&rvdir=newer&rvstart=2006-05-01T00:00:00Z'
521 =>
'apihelp-query+revisions-example-first5-after',
522 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
523 'rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1'
524 =>
'apihelp-query+revisions-example-first5-not-localhost',
525 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
526 'rvprop=timestamp|user|comment&rvuser=MediaWiki%20default'
527 =>
'apihelp-query+revisions-example-first5-user',
532 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Revisions';
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
getParameter( $paramName, $parseLimit=true)
Get a value for the given parameter.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, or 'string' with PARAM_ISMULTI,...
requireMaxOneParameter( $params,... $required)
Die if more than one of a certain set of parameters is set and not false.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
This class contains a list of pages that the client has requested.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
addFields( $value)
Add a set of fields to select to the internal array.
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only)
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
getPageSet()
Get the PageSet object to work on.
encodeParamName( $paramName)
Overrides ApiBase to prepend 'g' to every generator parameter.
A base class for functions common to producing a list of revisions.
parseParameters( $params)
Parse the parameters into the various instance fields.
extractRevisionInfo(RevisionRecord $revision, $row)
Extract information from the RevisionRecord.
A query action to enumerate revisions of a given page, or show top revisions of multiple pages.
__construct(ApiQuery $query, $moduleName, RevisionStore $revisionStore, IContentHandlerFactory $contentHandlerFactory, ParserFactory $parserFactory, SlotRoleRegistry $slotRoleRegistry, NameTableStore $changeTagDefStore, ActorMigration $actorMigration, ContentRenderer $contentRenderer, ContentTransformer $contentTransformer, CommentFormatter $commentFormatter)
getHelpUrls()
Return links to more detailed help pages about the module.
run(ApiPageSet $resultPageSet=null)
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
A service to render content.
A service to transform content.