Go to the documentation of this file.
40 parent::__construct( $query, $moduleName,
'rv' );
52 if ( isset( $this->tokenFunctions ) ) {
62 $this->tokenFunctions = [
63 'rollback' => [ self::class,
'getRollbackToken' ]
65 Hooks::run(
'APIQueryRevisionsTokens', [ &$this->tokenFunctions ] );
80 ->userHasRight( $wgUser,
'rollback' ) ) {
84 return $wgUser->getEditToken(
'rollback' );
89 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
95 $enumRevMode = ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ||
96 $params[
'limit'] !==
null || $params[
'startid'] !==
null ||
97 $params[
'endid'] !==
null || $params[
'dir'] ===
'newer' ||
98 $params[
'start'] !==
null || $params[
'end'] !== null );
101 $pageCount = $pageSet->getGoodTitleCount();
102 $revCount = $pageSet->getRevisionCount();
105 if ( $revCount === 0 && $pageCount === 0 ) {
109 if ( $revCount > 0 && count( $pageSet->getLiveRevisionIDs() ) === 0 ) {
114 if ( $revCount > 0 && $enumRevMode ) {
116 [
'apierror-revisions-norevids', $this->
getModulePrefix() ],
'invalidparammix'
120 if ( $pageCount > 1 && $enumRevMode ) {
122 [
'apierror-revisions-singlepage', $this->
getModulePrefix() ],
'invalidparammix'
128 if ( !$enumRevMode ) {
129 $this->setParsedLimit =
false;
130 $params[
'limit'] =
'max';
133 $db = $this->
getDB();
136 $tsField =
'rev_timestamp';
137 $pageField =
'rev_page';
138 if ( $params[
'user'] !==
null ) {
141 $idField =
'revactor_rev';
142 $tsField =
'revactor_timestamp';
143 $pageField =
'revactor_page';
146 if ( $resultPageSet ===
null ) {
148 $this->token = $params[
'token'];
150 if ( $this->token !==
null || $pageCount > 0 ) {
153 if ( $this->fld_user ) {
156 $revQuery = $revisionStore->getQueryInfo( $opts );
158 if ( $idField !==
'rev_id' ) {
159 $aliasFields = [
'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField ];
162 array_diff(
$revQuery[
'fields'], array_keys( $aliasFields ) )
172 $this->
addTables( [
'revision',
'page' ] );
174 [
'page' => [
'JOIN', [
'page_id = rev_page' ] ] ]
177 'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField
181 if ( $this->fld_tags ) {
185 if ( $params[
'tag'] !==
null ) {
188 [
'change_tag' => [
'JOIN', [
'rev_id=ct_rev_id' ] ] ]
190 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
192 $this->
addWhereFld(
'ct_tag_id', $changeTagDefStore->getId( $params[
'tag'] ) );
199 if ( $resultPageSet ===
null && $this->fetchContent ) {
205 foreach ( $pageSet->getGoodTitles() as
$title ) {
218 if ( $enumRevMode ) {
230 if ( $params[
'continue'] !==
null ) {
231 $cont = explode(
'|', $params[
'continue'] );
233 $op = ( $params[
'dir'] ===
'newer' ?
'>' :
'<' );
234 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
235 $continueId = (int)$cont[1];
237 $this->
addWhere(
"$tsField $op $continueTimestamp OR " .
238 "($tsField = $continueTimestamp AND " .
239 "$idField $op= $continueId)"
245 if ( $params[
'startid'] !==
null ) {
246 $revids[] = (int)$params[
'startid'];
248 if ( $params[
'endid'] !==
null ) {
249 $revids[] = (int)$params[
'endid'];
252 $db = $this->
getDB();
253 $sql = $db->unionQueries( [
256 [
'id' =>
'rev_id',
'ts' =>
'rev_timestamp' ],
257 [
'rev_id' => $revids ],
262 [
'id' =>
'ar_rev_id',
'ts' =>
'ar_timestamp' ],
263 [
'ar_rev_id' => $revids ],
266 ], $db::UNION_DISTINCT );
267 $res = $db->query( $sql, __METHOD__ );
268 foreach (
$res as $row ) {
269 if ( (
int)$row->id === (
int)$params[
'startid'] ) {
270 $params[
'start'] = $row->ts;
272 if ( (
int)$row->id === (
int)$params[
'endid'] ) {
273 $params[
'end'] = $row->ts;
276 if ( $params[
'startid'] !==
null && $params[
'start'] ===
null ) {
278 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
280 if ( $params[
'endid'] !==
null && $params[
'end'] ===
null ) {
282 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
285 if ( $params[
'start'] !==
null ) {
286 $op = ( $params[
'dir'] ===
'newer' ?
'>' :
'<' );
287 $ts = $db->addQuotes( $db->timestampOrNull( $params[
'start'] ) );
288 if ( $params[
'startid'] !==
null ) {
289 $this->
addWhere(
"$tsField $op $ts OR "
290 .
"$tsField = $ts AND $idField $op= " . (
int)$params[
'startid'] );
292 $this->
addWhere(
"$tsField $op= $ts" );
295 if ( $params[
'end'] !==
null ) {
296 $op = ( $params[
'dir'] ===
'newer' ?
'<' :
'>' );
297 $ts = $db->addQuotes( $db->timestampOrNull( $params[
'end'] ) );
298 if ( $params[
'endid'] !==
null ) {
299 $this->
addWhere(
"$tsField $op $ts OR "
300 .
"$tsField = $ts AND $idField $op= " . (
int)$params[
'endid'] );
302 $this->
addWhere(
"$tsField $op= $ts" );
307 $params[
'start'], $params[
'end'] );
310 $sort = ( $params[
'dir'] ===
'newer' ?
'' :
'DESC' );
311 $this->
addOption(
'ORDER BY', [
"rev_timestamp $sort",
"rev_id $sort" ] );
314 $ids = array_keys( $pageSet->getGoodTitles() );
317 if ( $params[
'user'] !==
null ) {
320 $this->
addTables( $actorQuery[
'tables'] );
322 $this->
addWhere( $actorQuery[
'conds'] );
323 } elseif ( $params[
'excludeuser'] !==
null ) {
325 ->getWhere( $db,
'rev_user',
User::newFromName( $params[
'excludeuser'],
false ) );
326 $this->
addTables( $actorQuery[
'tables'] );
328 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
330 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
333 $bitmask = RevisionRecord::DELETED_USER;
335 ->userHasAnyRight( $this->
getUser(),
'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 $titles = $pageSet->getGoodTitles();
364 $this->
addWhere(
'page_latest=rev_id' );
367 $this->
addWhereFld(
'page_id', array_keys( $titles ) );
369 $this->
addWhereFld(
'rev_page', array_keys( $titles ) );
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 );
394 $this->
addOption(
'IGNORE INDEX', [
'revision' =>
'rev_timestamp' ] );
399 $res = $this->
select( __METHOD__, [], $hookData );
401 foreach (
$res as $row ) {
402 if ( ++$count > $this->limit ) {
405 if ( $enumRevMode ) {
407 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
408 } elseif ( $revCount > 0 ) {
412 '|' . (
int)$row->rev_id );
417 if ( $resultPageSet !==
null ) {
418 $generated[] = $row->rev_id;
420 $revision = $revisionStore->newRevisionFromRow( $row );
423 if ( $this->token !==
null ) {
425 $revisionCompat =
new Revision( $revision );
427 foreach ( $this->token as
$t ) {
429 if ( $val ===
false ) {
430 $this->
addWarning( [
'apiwarn-tokennotallowed', $t ] );
432 $rev[
$t .
'token'] = $val;
437 $fit = $this->
processRow( $row, $rev, $hookData ) &&
440 if ( $enumRevMode ) {
442 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
443 } elseif ( $revCount > 0 ) {
447 '|' . (
int)$row->rev_id );
454 if ( $resultPageSet !==
null ) {
455 $resultPageSet->populateFromRevisionIDs( $generated );
460 if ( isset( $params[
'token'] ) ) {
463 return parent::getCacheMode( $params );
467 $ret = parent::getAllowedParams() + [
519 'action=query&prop=revisions&titles=API|Main%20Page&' .
520 'rvslots=*&rvprop=timestamp|user|comment|content'
521 =>
'apihelp-query+revisions-example-content',
522 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
523 'rvprop=timestamp|user|comment'
524 =>
'apihelp-query+revisions-example-last5',
525 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
526 'rvprop=timestamp|user|comment&rvdir=newer'
527 =>
'apihelp-query+revisions-example-first5',
528 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
529 'rvprop=timestamp|user|comment&rvdir=newer&rvstart=2006-05-01T00:00:00Z'
530 =>
'apihelp-query+revisions-example-first5-after',
531 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
532 'rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1'
533 =>
'apihelp-query+revisions-example-first5-not-localhost',
534 'action=query&prop=revisions&titles=Main%20Page&rvlimit=5&' .
535 'rvprop=timestamp|user|comment&rvuser=MediaWiki%20default'
536 =>
'apihelp-query+revisions-example-first5-user',
541 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Revisions';
parseParameters( $params)
Parse the parameters into the various instance fields.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
addFields( $value)
Add a set of fields to select to the internal array.
This is the main query class.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
encodeParamName( $paramName)
Overrides ApiBase to prepend 'g' to every generator parameter.
static getRollbackToken( $pageid, $title, $rev)
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
run(ApiPageSet $resultPageSet=null)
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
static newMigration()
Static constructor.
This class contains a list of pages that the client has requested.
A base class for functions common to producing a list of revisions.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
getPageSet()
Get the PageSet object to work on.
getDB()
Get the Query database connection (read-only)
getExamplesMessages()
Returns usage examples for this module.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
static newGood( $value=null)
Factory function for good results.
extractRevisionInfo(RevisionRecord $revision, $row)
Extract information from the RevisionRecord.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
getCacheMode( $params)
Get the cache mode for the data generated by this module.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
requireMaxOneParameter( $params, $required)
Die if more than one of a certain set of parameters is set and not false.
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
static newFromLinkTarget(LinkTarget $linkTarget, $forceClone='')
Returns a Title given a LinkTarget.
Represents a title within MediaWiki.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
getParameter( $paramName, $parseLimit=true)
Get a value for the given parameter.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName)
addWhere( $value)
Add a set of WHERE clauses to the internal array.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
static run( $event, array $args=[], $deprecatedVersion=null)
Call hook functions defined in Hooks::register and $wgHooks.
addPageSubItem( $pageId, $item, $elemname=null)
Same as addPageSubItems(), but one element of $data at a time.
static dieDebug( $method, $message)
Internal code errors should be reported with this method.
A query action to enumerate revisions of a given page, or show top revisions of multiple pages.