41 parent::__construct( $query, $moduleName,
'rv' );
53 if ( isset( $this->tokenFunctions ) ) {
63 $this->tokenFunctions = [
64 'rollback' => [ self::class,
'getRollbackToken' ]
66 $this->
getHookRunner()->onAPIQueryRevisionsTokens( $this->tokenFunctions );
81 wfDeprecated( __METHOD__ .
' with a Revision object',
'1.35' );
86 ->userHasRight( $wgUser,
'rollback' ) ) {
90 return $wgUser->getEditToken(
'rollback' );
95 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
101 $enumRevMode = ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ||
102 $params[
'limit'] !==
null || $params[
'startid'] !==
null ||
103 $params[
'endid'] !==
null || $params[
'dir'] ===
'newer' ||
104 $params[
'start'] !==
null || $params[
'end'] !== null );
107 $pageCount = $pageSet->getGoodTitleCount();
108 $revCount = $pageSet->getRevisionCount();
111 if ( $revCount === 0 && $pageCount === 0 ) {
115 if ( $revCount > 0 && count( $pageSet->getLiveRevisionIDs() ) === 0 ) {
120 if ( $revCount > 0 && $enumRevMode ) {
122 [
'apierror-revisions-norevids', $this->
getModulePrefix() ],
'invalidparammix'
126 if ( $pageCount > 1 && $enumRevMode ) {
128 [
'apierror-revisions-singlepage', $this->
getModulePrefix() ],
'invalidparammix'
134 if ( !$enumRevMode ) {
135 $this->setParsedLimit =
false;
136 $params[
'limit'] =
'max';
139 $db = $this->
getDB();
142 $tsField =
'rev_timestamp';
143 $pageField =
'rev_page';
144 if ( $params[
'user'] !==
null ) {
147 $idField =
'revactor_rev';
148 $tsField =
'revactor_timestamp';
149 $pageField =
'revactor_page';
152 if ( $resultPageSet ===
null ) {
154 $this->token = $params[
'token'];
156 if ( $this->fld_user ) {
159 $revQuery = $revisionStore->getQueryInfo( $opts );
161 if ( $idField !==
'rev_id' ) {
162 $aliasFields = [
'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField ];
165 array_diff(
$revQuery[
'fields'], array_keys( $aliasFields ) )
175 $this->
addTables( [
'revision',
'page' ] );
177 [
'page' => [
'JOIN', [
'page_id = rev_page' ] ] ]
180 'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField
184 if ( $this->fld_tags ) {
188 if ( $params[
'tag'] !==
null ) {
191 [
'change_tag' => [
'JOIN', [
'rev_id=ct_rev_id' ] ] ]
193 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
195 $this->
addWhereFld(
'ct_tag_id', $changeTagDefStore->getId( $params[
'tag'] ) );
202 if ( $resultPageSet ===
null && $this->fetchContent ) {
204 $status = Status::newGood();
208 foreach ( $pageSet->getGoodTitles() as
$title ) {
210 $status->fatal( ApiMessage::create(
216 if ( !$status->isGood() ) {
221 if ( $enumRevMode ) {
233 if ( $params[
'continue'] !==
null ) {
234 $cont = explode(
'|', $params[
'continue'] );
236 $op = ( $params[
'dir'] ===
'newer' ?
'>' :
'<' );
237 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
238 $continueId = (int)$cont[1];
240 $this->
addWhere(
"$tsField $op $continueTimestamp OR " .
241 "($tsField = $continueTimestamp AND " .
242 "$idField $op= $continueId)"
248 if ( $params[
'startid'] !==
null ) {
249 $revids[] = (int)$params[
'startid'];
251 if ( $params[
'endid'] !==
null ) {
252 $revids[] = (int)$params[
'endid'];
255 $db = $this->
getDB();
256 $sql = $db->unionQueries( [
259 [
'id' =>
'rev_id',
'ts' =>
'rev_timestamp' ],
260 [
'rev_id' => $revids ],
265 [
'id' =>
'ar_rev_id',
'ts' =>
'ar_timestamp' ],
266 [
'ar_rev_id' => $revids ],
269 ], $db::UNION_DISTINCT );
270 $res = $db->query( $sql, __METHOD__ );
271 foreach (
$res as $row ) {
272 if ( (
int)$row->id === (
int)$params[
'startid'] ) {
273 $params[
'start'] = $row->ts;
275 if ( (
int)$row->id === (
int)$params[
'endid'] ) {
276 $params[
'end'] = $row->ts;
279 if ( $params[
'startid'] !==
null && $params[
'start'] ===
null ) {
281 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
283 if ( $params[
'endid'] !==
null && $params[
'end'] ===
null ) {
285 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
288 if ( $params[
'start'] !==
null ) {
289 $op = ( $params[
'dir'] ===
'newer' ?
'>' :
'<' );
290 $ts = $db->addQuotes( $db->timestampOrNull( $params[
'start'] ) );
291 if ( $params[
'startid'] !==
null ) {
292 $this->
addWhere(
"$tsField $op $ts OR "
293 .
"$tsField = $ts AND $idField $op= " . (
int)$params[
'startid'] );
295 $this->
addWhere(
"$tsField $op= $ts" );
298 if ( $params[
'end'] !==
null ) {
299 $op = ( $params[
'dir'] ===
'newer' ?
'<' :
'>' );
300 $ts = $db->addQuotes( $db->timestampOrNull( $params[
'end'] ) );
301 if ( $params[
'endid'] !==
null ) {
302 $this->
addWhere(
"$tsField $op $ts OR "
303 .
"$tsField = $ts AND $idField $op= " . (
int)$params[
'endid'] );
305 $this->
addWhere(
"$tsField $op= $ts" );
310 $params[
'start'], $params[
'end'] );
313 $sort = ( $params[
'dir'] ===
'newer' ?
'' :
'DESC' );
314 $this->
addOption(
'ORDER BY', [
"rev_timestamp $sort",
"rev_id $sort" ] );
317 $ids = array_keys( $pageSet->getGoodTitles() );
320 if ( $params[
'user'] !==
null ) {
321 $actorQuery = ActorMigration::newMigration()
322 ->getWhere( $db,
'rev_user', $params[
'user'] );
323 $this->
addTables( $actorQuery[
'tables'] );
325 $this->
addWhere( $actorQuery[
'conds'] );
326 } elseif ( $params[
'excludeuser'] !==
null ) {
327 $actorQuery = ActorMigration::newMigration()
328 ->getWhere( $db,
'rev_user', $params[
'excludeuser'] );
329 $this->
addTables( $actorQuery[
'tables'] );
331 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
333 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
336 $bitmask = RevisionRecord::DELETED_USER;
338 ->userHasAnyRight( $this->
getUser(),
'suppressrevision',
'viewsuppressed' )
340 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
345 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
348 } elseif ( $revCount > 0 ) {
351 $revs = $pageSet->getLiveRevisionIDs();
354 $this->
addWhereFld(
'rev_id', array_keys( $revs ) );
356 if ( $params[
'continue'] !==
null ) {
357 $this->
addWhere(
'rev_id >= ' . (
int)$params[
'continue'] );
359 $this->
addOption(
'ORDER BY',
'rev_id' );
360 } elseif ( $pageCount > 0 ) {
363 $titles = $pageSet->getGoodTitles();
367 $this->
addWhere(
'page_latest=rev_id' );
370 $this->
addWhereFld(
'page_id', array_keys( $titles ) );
372 $this->
addWhereFld(
'rev_page', array_keys( $titles ) );
374 if ( $params[
'continue'] !==
null ) {
375 $cont = explode(
'|', $params[
'continue'] );
377 $pageid = (int)$cont[0];
378 $revid = (int)$cont[1];
380 "rev_page > $pageid OR " .
381 "(rev_page = $pageid AND " .
393 $this->
addOption(
'LIMIT', $this->limit + 1 );
397 $this->
addOption(
'IGNORE INDEX', [
'revision' =>
'rev_timestamp' ] );
402 $res = $this->
select( __METHOD__, [], $hookData );
404 foreach (
$res as $row ) {
405 if ( ++$count > $this->limit ) {
408 if ( $enumRevMode ) {
410 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
411 } elseif ( $revCount > 0 ) {
415 '|' . (
int)$row->rev_id );
420 if ( $resultPageSet !==
null ) {
421 $generated[] = $row->rev_id;
423 $revision = $revisionStore->newRevisionFromRow( $row, 0, Title::newFromRow( $row ) );
426 if ( $this->token !==
null ) {
427 $title = Title::newFromLinkTarget( $revision->getPageAsLinkTarget() );
429 foreach ( $this->token as
$t ) {
430 if (
$t ===
'rollback' ) {
431 $val = call_user_func(
441 $val = call_user_func(
448 if ( $val ===
false ) {
449 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
451 $rev[
$t .
'token'] = $val;
456 $fit = $this->
processRow( $row, $rev, $hookData ) &&
459 if ( $enumRevMode ) {
461 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
462 } elseif ( $revCount > 0 ) {
466 '|' . (
int)$row->rev_id );
473 if ( $resultPageSet !==
null ) {
474 $resultPageSet->populateFromRevisionIDs( $generated );
479 if ( isset( $params[
'token'] ) ) {
482 return parent::getCacheMode( $params );
486 $ret = parent::getAllowedParams() + [
514 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
515 UserDef::PARAM_RETURN_OBJECT =>
true,
520 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
521 UserDef::PARAM_RETURN_OBJECT =>
true,
542 'action=query&prop=revisions&titles=API|Main%20Page&' .
543 'rvslots=*&rvprop=timestamp|user|comment|content'
544 =>
'apihelp-query+revisions-example-content',
545 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
546 'rvprop=timestamp|user|comment'
547 =>
'apihelp-query+revisions-example-last5',
548 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
549 'rvprop=timestamp|user|comment&rvdir=newer'
550 =>
'apihelp-query+revisions-example-first5',
551 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
552 'rvprop=timestamp|user|comment&rvdir=newer&rvstart=2006-05-01T00:00:00Z'
553 =>
'apihelp-query+revisions-example-first5-after',
554 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
555 'rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1'
556 =>
'apihelp-query+revisions-example-first5-not-localhost',
557 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
558 'rvprop=timestamp|user|comment&rvuser=MediaWiki%20default'
559 =>
'apihelp-query+revisions-example-first5-user',
564 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,...
wfDeprecated( $function, $version=false, $component=false, $callerOffset=2)
Logs a warning that $function is deprecated.
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.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
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.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
getHookRunner()
Get an ApiHookRunner for running core API hooks.
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
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) Stable to override.
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)
getCacheMode( $params)
Stable to override.
getHelpUrls()
Return links to more detailed help pages about the module.
run(ApiPageSet $resultPageSet=null)
getAllowedParams()
Stable to override.
static getRollbackToken( $pageid, $title, $rev)
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
Represents a title within MediaWiki.