97 $enumRevMode = ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ||
98 $params[
'limit'] !==
null || $params[
'startid'] !==
null ||
99 $params[
'endid'] !==
null || $params[
'dir'] ===
'newer' ||
100 $params[
'start'] !==
null || $params[
'end'] !== null );
103 $pageCount = $pageSet->getGoodTitleCount();
104 $revCount = $pageSet->getRevisionCount();
107 if ( $revCount === 0 && $pageCount === 0 ) {
111 if ( $revCount > 0 && count( $pageSet->getLiveRevisionIDs() ) === 0 ) {
116 if ( $revCount > 0 && $enumRevMode ) {
118 [
'apierror-revisions-norevids', $this->
getModulePrefix() ],
'invalidparammix'
122 if ( $pageCount > 1 && $enumRevMode ) {
124 [
'apierror-revisions-singlepage', $this->
getModulePrefix() ],
'invalidparammix'
130 if ( !$enumRevMode ) {
131 $this->setParsedLimit =
false;
132 $params[
'limit'] =
'max';
135 $db = $this->
getDB();
138 $tsField =
'rev_timestamp';
139 $pageField =
'rev_page';
145 'revision' =>
'rev_timestamp',
149 if ( $params[
'user'] !==
null &&
154 $idField =
'revactor_rev';
155 $tsField =
'revactor_timestamp';
156 $pageField =
'revactor_page';
159 if ( $resultPageSet ===
null ) {
162 if ( $this->fld_user ) {
165 $revQuery = $this->revisionStore->getQueryInfo( $opts );
167 if ( $idField !==
'rev_id' ) {
168 $aliasFields = [
'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField ];
171 array_diff(
$revQuery[
'fields'], array_keys( $aliasFields ) )
181 $this->
addTables( [
'revision',
'page' ] );
183 [
'page' => [
'JOIN', [
'page_id = rev_page' ] ] ]
186 'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField
190 if ( $this->fld_tags ) {
194 if ( $params[
'tag'] !==
null ) {
197 [
'change_tag' => [
'JOIN', [
'rev_id=ct_rev_id' ] ] ]
200 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
207 if ( $resultPageSet ===
null && $this->fetchContent ) {
209 $status = Status::newGood();
212 foreach ( $pageSet->getGoodTitles() as
$title ) {
214 $status->fatal( ApiMessage::create(
220 if ( !$status->isGood() ) {
225 if ( $enumRevMode ) {
237 if ( $params[
'continue'] !==
null ) {
238 $cont = explode(
'|', $params[
'continue'] );
240 $op = ( $params[
'dir'] ===
'newer' ?
'>' :
'<' );
241 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
242 $continueId = (int)$cont[1];
244 $this->
addWhere(
"$tsField $op $continueTimestamp OR " .
245 "($tsField = $continueTimestamp AND " .
246 "$idField $op= $continueId)"
252 if ( $params[
'startid'] !==
null ) {
253 $revids[] = (int)$params[
'startid'];
255 if ( $params[
'endid'] !==
null ) {
256 $revids[] = (int)$params[
'endid'];
259 $db = $this->
getDB();
260 $sql = $db->unionQueries( [
263 [
'id' =>
'rev_id',
'ts' =>
'rev_timestamp' ],
264 [
'rev_id' => $revids ],
269 [
'id' =>
'ar_rev_id',
'ts' =>
'ar_timestamp' ],
270 [
'ar_rev_id' => $revids ],
273 ], $db::UNION_DISTINCT );
274 $res = $db->query( $sql, __METHOD__ );
275 foreach (
$res as $row ) {
276 if ( (
int)$row->id === (
int)$params[
'startid'] ) {
277 $params[
'start'] = $row->ts;
279 if ( (
int)$row->id === (
int)$params[
'endid'] ) {
280 $params[
'end'] = $row->ts;
283 if ( $params[
'startid'] !==
null && $params[
'start'] ===
null ) {
285 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
287 if ( $params[
'endid'] !==
null && $params[
'end'] ===
null ) {
289 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
292 if ( $params[
'start'] !==
null ) {
293 $op = ( $params[
'dir'] ===
'newer' ?
'>' :
'<' );
294 $ts = $db->addQuotes( $db->timestampOrNull( $params[
'start'] ) );
295 if ( $params[
'startid'] !==
null ) {
296 $this->
addWhere(
"$tsField $op $ts OR "
297 .
"$tsField = $ts AND $idField $op= " . (
int)$params[
'startid'] );
299 $this->
addWhere(
"$tsField $op= $ts" );
302 if ( $params[
'end'] !==
null ) {
303 $op = ( $params[
'dir'] ===
'newer' ?
'<' :
'>' );
304 $ts = $db->addQuotes( $db->timestampOrNull( $params[
'end'] ) );
305 if ( $params[
'endid'] !==
null ) {
306 $this->
addWhere(
"$tsField $op $ts OR "
307 .
"$tsField = $ts AND $idField $op= " . (
int)$params[
'endid'] );
309 $this->
addWhere(
"$tsField $op= $ts" );
314 $params[
'start'], $params[
'end'] );
317 $sort = ( $params[
'dir'] ===
'newer' ?
'' :
'DESC' );
318 $this->
addOption(
'ORDER BY', [
"rev_timestamp $sort",
"rev_id $sort" ] );
321 $ids = array_keys( $pageSet->getGoodTitles() );
324 if ( $params[
'user'] !==
null ) {
325 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user', $params[
'user'] );
326 $this->
addTables( $actorQuery[
'tables'] );
328 $this->
addWhere( $actorQuery[
'conds'] );
329 } elseif ( $params[
'excludeuser'] !==
null ) {
330 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user', $params[
'excludeuser'] );
331 $this->
addTables( $actorQuery[
'tables'] );
333 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
336 $revIndex = $this->
getDB()->indexExists(
'revision',
'page_timestamp', __METHOD__ )
338 :
'rev_page_timestamp';
343 $useIndex[
'revision'] = $revIndex;
346 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
348 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
349 $bitmask = RevisionRecord::DELETED_USER;
350 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' )
352 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
357 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
360 } elseif ( $revCount > 0 ) {
363 $revs = $pageSet->getLiveRevisionIDs();
366 $this->
addWhereFld(
'rev_id', array_keys( $revs ) );
368 if ( $params[
'continue'] !==
null ) {
369 $this->
addWhere(
'rev_id >= ' . (
int)$params[
'continue'] );
371 $this->
addOption(
'ORDER BY',
'rev_id' );
372 } elseif ( $pageCount > 0 ) {
375 $titles = $pageSet->getGoodTitles();
379 $this->
addWhere(
'page_latest=rev_id' );
382 $this->
addWhereFld(
'page_id', array_keys( $titles ) );
384 $this->
addWhereFld(
'rev_page', array_keys( $titles ) );
386 if ( $params[
'continue'] !==
null ) {
387 $cont = explode(
'|', $params[
'continue'] );
389 $pageid = (int)$cont[0];
390 $revid = (int)$cont[1];
392 "rev_page > $pageid OR " .
393 "(rev_page = $pageid AND " .
405 $this->
addOption(
'LIMIT', $this->limit + 1 );
407 $this->
addOption(
'IGNORE INDEX', $ignoreIndex );
410 $this->
addOption(
'USE INDEX', $useIndex );
416 $res = $this->
select( __METHOD__, [], $hookData );
418 foreach (
$res as $row ) {
419 if ( ++$count > $this->limit ) {
422 if ( $enumRevMode ) {
424 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
425 } elseif ( $revCount > 0 ) {
429 '|' . (
int)$row->rev_id );
434 if ( $resultPageSet !==
null ) {
435 $generated[] = $row->rev_id;
437 $revision = $this->revisionStore->newRevisionFromRow( $row, 0, Title::newFromRow( $row ) );
439 $fit = $this->
processRow( $row, $rev, $hookData ) &&
442 if ( $enumRevMode ) {
444 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
445 } elseif ( $revCount > 0 ) {
449 '|' . (
int)$row->rev_id );
456 if ( $resultPageSet !==
null ) {
457 $resultPageSet->populateFromRevisionIDs( $generated );
462 $ret = parent::getAllowedParams() + [
490 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
491 UserDef::PARAM_RETURN_OBJECT =>
true,
496 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
497 UserDef::PARAM_RETURN_OBJECT =>
true,
513 'action=query&prop=revisions&titles=API|Main%20Page&' .
514 'rvslots=*&rvprop=timestamp|user|comment|content'
515 =>
'apihelp-query+revisions-example-content',
516 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
517 'rvprop=timestamp|user|comment'
518 =>
'apihelp-query+revisions-example-last5',
519 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
520 'rvprop=timestamp|user|comment&rvdir=newer'
521 =>
'apihelp-query+revisions-example-first5',
522 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
523 'rvprop=timestamp|user|comment&rvdir=newer&rvstart=2006-05-01T00:00:00Z'
524 =>
'apihelp-query+revisions-example-first5-after',
525 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
526 'rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1'
527 =>
'apihelp-query+revisions-example-first5-not-localhost',
528 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
529 'rvprop=timestamp|user|comment&rvuser=MediaWiki%20default'
530 =>
'apihelp-query+revisions-example-first5-user',
535 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Revisions';
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage, for migration from the temporary table revision_actor_temp to the...
const SCHEMA_COMPAT_READ_TEMP
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This is not intended to be a long-term part of MediaWiki; it will be deprecated and removed once acto...
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.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
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.
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.
IContentHandlerFactory $contentHandlerFactory
ContentTransformer $contentTransformer
SlotRoleRegistry $slotRoleRegistry
ParserFactory $parserFactory
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.
ActorMigration $actorMigration
getHelpUrls()
Return links to more detailed help pages about the module.
run(ApiPageSet $resultPageSet=null)
RevisionStore $revisionStore
__construct(ApiQuery $query, $moduleName, RevisionStore $revisionStore, IContentHandlerFactory $contentHandlerFactory, ParserFactory $parserFactory, SlotRoleRegistry $slotRoleRegistry, NameTableStore $changeTagDefStore, ActorMigration $actorMigration, ContentTransformer $contentTransformer)
NameTableStore $changeTagDefStore
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
A service to transform content.
Represents a title within MediaWiki.