89 $contentHandlerFactory,
98 $this->revisionStore = $revisionStore;
99 $this->changeTagDefStore = $changeTagDefStore;
100 $this->actorMigration = $actorMigration;
110 $enumRevMode = ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ||
111 $params[
'limit'] !==
null || $params[
'startid'] !==
null ||
112 $params[
'endid'] !==
null || $params[
'dir'] ===
'newer' ||
113 $params[
'start'] !==
null || $params[
'end'] !== null );
116 $pageCount = $pageSet->getGoodTitleCount();
117 $revCount = $pageSet->getRevisionCount();
120 if ( $revCount === 0 && $pageCount === 0 ) {
124 if ( $revCount > 0 && count( $pageSet->getLiveRevisionIDs() ) === 0 ) {
129 if ( $revCount > 0 && $enumRevMode ) {
131 [
'apierror-revisions-norevids', $this->
getModulePrefix() ],
'invalidparammix'
135 if ( $pageCount > 1 && $enumRevMode ) {
137 [
'apierror-revisions-singlepage', $this->
getModulePrefix() ],
'invalidparammix'
143 if ( !$enumRevMode ) {
144 $this->setParsedLimit =
false;
145 $params[
'limit'] =
'max';
148 $db = $this->
getDB();
151 $tsField =
'rev_timestamp';
152 $pageField =
'rev_page';
158 'revision' =>
'rev_timestamp',
161 if ( $resultPageSet ===
null ) {
163 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $db )
166 if ( $this->fld_user ) {
167 $queryBuilder->joinUser();
173 $this->
addTables( [
'revision',
'page' ] );
175 [
'page' => [
'JOIN', [
'page_id = rev_page' ] ] ]
178 'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField
182 if ( $this->fld_tags ) {
186 if ( $params[
'tag'] !==
null ) {
189 [
'change_tag' => [
'JOIN', [
'rev_id=ct_rev_id' ] ] ]
192 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
199 if ( $resultPageSet ===
null && $this->fetchContent ) {
201 $status = Status::newGood();
204 foreach ( $pageSet->getGoodTitles() as $title ) {
205 if ( !$this->
getAuthority()->authorizeRead(
'read', $title ) ) {
207 [
'apierror-cannotviewtitle',
wfEscapeWikiText( $title->getPrefixedText() ) ],
212 if ( !$status->isGood() ) {
217 if ( $enumRevMode ) {
229 if ( $params[
'continue'] !==
null ) {
231 $op = ( $params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
232 $continueTimestamp = $db->timestamp( $cont[0] );
233 $continueId = (int)$cont[1];
234 $this->
addWhere( $db->buildComparison( $op, [
235 $tsField => $continueTimestamp,
236 $idField => $continueId,
242 if ( $params[
'startid'] !==
null ) {
243 $revids[] = (int)$params[
'startid'];
245 if ( $params[
'endid'] !==
null ) {
246 $revids[] = (int)$params[
'endid'];
249 $db = $this->
getDB();
250 $uqb = $db->newUnionQueryBuilder();
252 $db->newSelectQueryBuilder()
253 ->select( [
'id' =>
'rev_id',
'ts' =>
'rev_timestamp' ] )
255 ->where( [
'rev_id' => $revids ] )
258 $db->newSelectQueryBuilder()
259 ->select( [
'id' =>
'ar_rev_id',
'ts' =>
'ar_timestamp' ] )
261 ->where( [
'ar_rev_id' => $revids ] )
263 $res = $uqb->caller( __METHOD__ )->fetchResultSet();
264 foreach ( $res as $row ) {
265 if ( (
int)$row->id === (
int)$params[
'startid'] ) {
266 $params[
'start'] = $row->ts;
268 if ( (
int)$row->id === (
int)$params[
'endid'] ) {
269 $params[
'end'] = $row->ts;
273 if ( $params[
'startid'] !==
null && $params[
'start'] ===
null ) {
275 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
278 if ( $params[
'endid'] !==
null && $params[
'end'] ===
null ) {
280 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
284 if ( $params[
'start'] !==
null ) {
285 $op = ( $params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
287 $ts = $db->timestampOrNull( $params[
'start'] );
288 if ( $params[
'startid'] !==
null ) {
289 $this->
addWhere( $db->buildComparison( $op, [
291 $idField => (
int)$params[
'startid'],
294 $this->
addWhere( $db->buildComparison( $op, [ $tsField => $ts ] ) );
298 if ( $params[
'end'] !==
null ) {
299 $op = ( $params[
'dir'] ===
'newer' ?
'<=' :
'>=' );
301 $ts = $db->timestampOrNull( $params[
'end'] );
302 if ( $params[
'endid'] !==
null ) {
303 $this->
addWhere( $db->buildComparison( $op, [
305 $idField => (
int)$params[
'endid'],
308 $this->
addWhere( $db->buildComparison( $op, [ $tsField => $ts ] ) );
313 $params[
'start'], $params[
'end'] );
316 $sort = ( $params[
'dir'] ===
'newer' ?
'' :
'DESC' );
317 $this->
addOption(
'ORDER BY', [
"rev_timestamp $sort",
"rev_id $sort" ] );
320 $ids = array_keys( $pageSet->getGoodPages() );
323 if ( $params[
'user'] !==
null ) {
324 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user', $params[
'user'] );
325 $this->
addTables( $actorQuery[
'tables'] );
327 $this->
addWhere( $actorQuery[
'conds'] );
328 } elseif ( $params[
'excludeuser'] !==
null ) {
329 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user', $params[
'excludeuser'] );
330 $this->
addTables( $actorQuery[
'tables'] );
332 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
338 $useIndex[
'revision'] =
'rev_page_timestamp';
341 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
343 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
344 $bitmask = RevisionRecord::DELETED_USER;
345 } 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( $db->buildComparison(
'>=', [
364 'rev_id' => (
int)$params[
'continue']
367 $this->
addOption(
'ORDER BY',
'rev_id' );
368 } elseif ( $pageCount > 0 ) {
371 $pageids = array_keys( $pageSet->getGoodPages() );
375 $this->
addWhere(
'page_latest=rev_id' );
382 if ( $params[
'continue'] !==
null ) {
384 $this->
addWhere( $db->buildComparison(
'>=', [
385 'rev_page' => $cont[0],
386 'rev_id' => $cont[1],
397 $this->
addOption(
'LIMIT', $this->limit + 1 );
399 $this->
addOption(
'IGNORE INDEX', $ignoreIndex );
402 $this->
addOption(
'USE INDEX', $useIndex );
408 $res = $this->
select( __METHOD__, [], $hookData );
410 foreach ( $res as $row ) {
411 if ( ++$count > $this->limit ) {
414 if ( $enumRevMode ) {
416 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
417 } elseif ( $revCount > 0 ) {
421 '|' . (
int)$row->rev_id );
426 if ( $resultPageSet !==
null ) {
427 $generated[] = $row->rev_id;
429 $revision = $this->revisionStore->newRevisionFromRow( $row, 0, Title::newFromRow( $row ) );
431 $fit = $this->
processRow( $row, $rev, $hookData ) &&
434 if ( $enumRevMode ) {
436 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
437 } elseif ( $revCount > 0 ) {
441 '|' . (
int)$row->rev_id );
448 if ( $resultPageSet !==
null ) {
449 $resultPageSet->populateFromRevisionIDs( $generated );
454 $ret = parent::getAllowedParams() + [
456 ParamValidator::PARAM_TYPE =>
'integer',
460 ParamValidator::PARAM_TYPE =>
'integer',
464 ParamValidator::PARAM_TYPE =>
'timestamp',
468 ParamValidator::PARAM_TYPE =>
'timestamp',
472 ParamValidator::PARAM_DEFAULT =>
'older',
473 ParamValidator::PARAM_TYPE => [
479 'newer' =>
'api-help-paramvalue-direction-newer',
480 'older' =>
'api-help-paramvalue-direction-older',
485 ParamValidator::PARAM_TYPE =>
'user',
486 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
487 UserDef::PARAM_RETURN_OBJECT =>
true,
491 ParamValidator::PARAM_TYPE =>
'user',
492 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
493 UserDef::PARAM_RETURN_OBJECT =>
true,
508 $title = Title::newMainPage()->getPrefixedText();
509 $mp = rawurlencode( $title );
512 "action=query&prop=revisions&titles=API|{$mp}&" .
513 'rvslots=*&rvprop=timestamp|user|comment|content'
514 =>
'apihelp-query+revisions-example-content',
515 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
516 'rvprop=timestamp|user|comment'
517 =>
'apihelp-query+revisions-example-last5',
518 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
519 'rvprop=timestamp|user|comment&rvdir=newer'
520 =>
'apihelp-query+revisions-example-first5',
521 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
522 'rvprop=timestamp|user|comment&rvdir=newer&rvstart=2006-05-01T00:00:00Z'
523 =>
'apihelp-query+revisions-example-first5-after',
524 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
525 'rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1'
526 =>
'apihelp-query+revisions-example-first5-not-localhost',
527 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
528 'rvprop=timestamp|user|comment&rvuser=MediaWiki%20default'
529 =>
'apihelp-query+revisions-example-first5-user',
534 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)
Dies if more than one parameter from a certain set of parameters are 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.
static create( $msg, $code=null, array $data=null)
Create an IApiMessage for the message.
This class contains a list of pages that the client has requested.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
getQueryBuilder()
Get the SelectQueryBuilder.
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.
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName, RevisionStore $revisionStore, IContentHandlerFactory $contentHandlerFactory, ParserFactory $parserFactory, SlotRoleRegistry $slotRoleRegistry, NameTableStore $changeTagDefStore, ActorMigration $actorMigration, ContentRenderer $contentRenderer, ContentTransformer $contentTransformer, CommentFormatter $commentFormatter, TempUserCreator $tempUserCreator, UserFactory $userFactory)
run(ApiPageSet $resultPageSet=null)
getAllowedParams()
@stable to override
getExamplesMessages()
Returns usage examples for this module.
This is the main query class.
A service to render content.
A service to transform content.