45 private $revisionStore;
48 private $changeTagDefStore;
51 private $actorMigration;
82 $contentHandlerFactory,
88 $this->revisionStore = $revisionStore;
89 $this->changeTagDefStore = $changeTagDefStore;
90 $this->actorMigration = $actorMigration;
100 $enumRevMode = ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ||
101 $params[
'limit'] !==
null || $params[
'startid'] !==
null ||
102 $params[
'endid'] !==
null || $params[
'dir'] ===
'newer' ||
103 $params[
'start'] !==
null || $params[
'end'] !== null );
106 $pageCount = $pageSet->getGoodTitleCount();
107 $revCount = $pageSet->getRevisionCount();
110 if ( $revCount === 0 && $pageCount === 0 ) {
114 if ( $revCount > 0 && count( $pageSet->getLiveRevisionIDs() ) === 0 ) {
119 if ( $revCount > 0 && $enumRevMode ) {
121 [
'apierror-revisions-norevids', $this->
getModulePrefix() ],
'invalidparammix'
125 if ( $pageCount > 1 && $enumRevMode ) {
127 [
'apierror-revisions-singlepage', $this->
getModulePrefix() ],
'invalidparammix'
133 if ( !$enumRevMode ) {
134 $this->setParsedLimit =
false;
135 $params[
'limit'] =
'max';
138 $db = $this->
getDB();
141 $tsField =
'rev_timestamp';
142 $pageField =
'rev_page';
148 'revision' =>
'rev_timestamp',
151 if ( $resultPageSet ===
null ) {
154 if ( $this->fld_user ) {
157 $revQuery = $this->revisionStore->getQueryInfo( $opts );
164 $this->
addTables( [
'revision',
'page' ] );
166 [
'page' => [
'JOIN', [
'page_id = rev_page' ] ] ]
169 'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField
173 if ( $this->fld_tags ) {
177 if ( $params[
'tag'] !==
null ) {
180 [
'change_tag' => [
'JOIN', [
'rev_id=ct_rev_id' ] ] ]
183 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
190 if ( $resultPageSet ===
null && $this->fetchContent ) {
192 $status = Status::newGood();
195 foreach ( $pageSet->getGoodTitles() as
$title ) {
197 $status->fatal( ApiMessage::create(
203 if ( !$status->isGood() ) {
208 if ( $enumRevMode ) {
220 if ( $params[
'continue'] !==
null ) {
221 $cont = explode(
'|', $params[
'continue'] );
223 $op = ( $params[
'dir'] ===
'newer' ?
'>' :
'<' );
224 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
225 $continueId = (int)$cont[1];
227 $this->
addWhere(
"$tsField $op $continueTimestamp OR " .
228 "($tsField = $continueTimestamp AND " .
229 "$idField $op= $continueId)"
235 if ( $params[
'startid'] !==
null ) {
236 $revids[] = (int)$params[
'startid'];
238 if ( $params[
'endid'] !==
null ) {
239 $revids[] = (int)$params[
'endid'];
242 $db = $this->
getDB();
243 $sql = $db->unionQueries( [
246 [
'id' =>
'rev_id',
'ts' =>
'rev_timestamp' ],
247 [
'rev_id' => $revids ],
252 [
'id' =>
'ar_rev_id',
'ts' =>
'ar_timestamp' ],
253 [
'ar_rev_id' => $revids ],
256 ], $db::UNION_DISTINCT );
257 $res = $db->query( $sql, __METHOD__ );
258 foreach (
$res as $row ) {
259 if ( (
int)$row->id === (
int)$params[
'startid'] ) {
260 $params[
'start'] = $row->ts;
262 if ( (
int)$row->id === (
int)$params[
'endid'] ) {
263 $params[
'end'] = $row->ts;
267 if ( $params[
'startid'] !==
null && $params[
'start'] ===
null ) {
269 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
272 if ( $params[
'endid'] !==
null && $params[
'end'] ===
null ) {
274 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
278 if ( $params[
'start'] !==
null ) {
279 $op = ( $params[
'dir'] ===
'newer' ?
'>' :
'<' );
281 $ts = $db->addQuotes( $db->timestampOrNull( $params[
'start'] ) );
282 if ( $params[
'startid'] !==
null ) {
283 $this->
addWhere(
"$tsField $op $ts OR "
284 .
"$tsField = $ts AND $idField $op= " . (
int)$params[
'startid'] );
286 $this->
addWhere(
"$tsField $op= $ts" );
290 if ( $params[
'end'] !==
null ) {
291 $op = ( $params[
'dir'] ===
'newer' ?
'<' :
'>' );
293 $ts = $db->addQuotes( $db->timestampOrNull( $params[
'end'] ) );
294 if ( $params[
'endid'] !==
null ) {
295 $this->
addWhere(
"$tsField $op $ts OR "
296 .
"$tsField = $ts AND $idField $op= " . (
int)$params[
'endid'] );
298 $this->
addWhere(
"$tsField $op= $ts" );
303 $params[
'start'], $params[
'end'] );
306 $sort = ( $params[
'dir'] ===
'newer' ?
'' :
'DESC' );
307 $this->
addOption(
'ORDER BY', [
"rev_timestamp $sort",
"rev_id $sort" ] );
310 $ids = array_keys( $pageSet->getGoodPages() );
313 if ( $params[
'user'] !==
null ) {
314 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user', $params[
'user'] );
315 $this->
addTables( $actorQuery[
'tables'] );
317 $this->
addWhere( $actorQuery[
'conds'] );
318 } elseif ( $params[
'excludeuser'] !==
null ) {
319 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user', $params[
'excludeuser'] );
320 $this->
addTables( $actorQuery[
'tables'] );
322 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
328 $useIndex[
'revision'] =
'rev_page_timestamp';
331 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
333 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
334 $bitmask = RevisionRecord::DELETED_USER;
335 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' )
337 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
342 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
345 } elseif ( $revCount > 0 ) {
348 $revs = $pageSet->getLiveRevisionIDs();
351 $this->
addWhereFld(
'rev_id', array_keys( $revs ) );
353 if ( $params[
'continue'] !==
null ) {
354 $this->
addWhere(
'rev_id >= ' . (
int)$params[
'continue'] );
356 $this->
addOption(
'ORDER BY',
'rev_id' );
357 } elseif ( $pageCount > 0 ) {
360 $pageids = array_keys( $pageSet->getGoodPages() );
364 $this->
addWhere(
'page_latest=rev_id' );
371 if ( $params[
'continue'] !==
null ) {
372 $cont = explode(
'|', $params[
'continue'] );
374 $pageid = (int)$cont[0];
375 $revid = (int)$cont[1];
377 "rev_page > $pageid OR " .
378 "(rev_page = $pageid AND " .
390 $this->
addOption(
'LIMIT', $this->limit + 1 );
392 $this->
addOption(
'IGNORE INDEX', $ignoreIndex );
395 $this->
addOption(
'USE INDEX', $useIndex );
401 $res = $this->
select( __METHOD__, [], $hookData );
403 foreach (
$res as $row ) {
404 if ( ++$count > $this->limit ) {
407 if ( $enumRevMode ) {
409 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
410 } elseif ( $revCount > 0 ) {
414 '|' . (
int)$row->rev_id );
419 if ( $resultPageSet !==
null ) {
420 $generated[] = $row->rev_id;
422 $revision = $this->revisionStore->newRevisionFromRow( $row, 0, Title::newFromRow( $row ) );
424 $fit = $this->
processRow( $row, $rev, $hookData ) &&
427 if ( $enumRevMode ) {
429 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
430 } elseif ( $revCount > 0 ) {
434 '|' . (
int)$row->rev_id );
441 if ( $resultPageSet !==
null ) {
442 $resultPageSet->populateFromRevisionIDs( $generated );
447 $ret = parent::getAllowedParams() + [
449 ParamValidator::PARAM_TYPE =>
'integer',
453 ParamValidator::PARAM_TYPE =>
'integer',
457 ParamValidator::PARAM_TYPE =>
'timestamp',
461 ParamValidator::PARAM_TYPE =>
'timestamp',
465 ParamValidator::PARAM_DEFAULT =>
'older',
466 ParamValidator::PARAM_TYPE => [
472 'newer' =>
'api-help-paramvalue-direction-newer',
473 'older' =>
'api-help-paramvalue-direction-older',
478 ParamValidator::PARAM_TYPE =>
'user',
479 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
480 UserDef::PARAM_RETURN_OBJECT =>
true,
484 ParamValidator::PARAM_TYPE =>
'user',
485 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
486 UserDef::PARAM_RETURN_OBJECT =>
true,
501 $title = Title::newMainPage()->getPrefixedText();
502 $mp = rawurlencode(
$title );
505 "action=query&prop=revisions&titles=API|{$mp}&" .
506 'rvslots=*&rvprop=timestamp|user|comment|content'
507 =>
'apihelp-query+revisions-example-content',
508 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
509 'rvprop=timestamp|user|comment'
510 =>
'apihelp-query+revisions-example-last5',
511 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
512 'rvprop=timestamp|user|comment&rvdir=newer'
513 =>
'apihelp-query+revisions-example-first5',
514 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
515 'rvprop=timestamp|user|comment&rvdir=newer&rvstart=2006-05-01T00:00:00Z'
516 =>
'apihelp-query+revisions-example-first5-after',
517 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
518 'rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1'
519 =>
'apihelp-query+revisions-example-first5-not-localhost',
520 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
521 'rvprop=timestamp|user|comment&rvuser=MediaWiki%20default'
522 =>
'apihelp-query+revisions-example-first5-user',
527 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,...
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.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
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)
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.
Represents a title within MediaWiki.