82 $contentHandlerFactory,
91 $this->revisionStore = $revisionStore;
92 $this->changeTagDefStore = $changeTagDefStore;
93 $this->actorMigration = $actorMigration;
94 $this->titleFormatter = $titleFormatter;
104 $enumRevMode = (
$params[
'user'] !==
null ||
$params[
'excludeuser'] !==
null ||
110 $pageCount = $pageSet->getGoodTitleCount();
111 $revCount = $pageSet->getRevisionCount();
114 if ( $revCount === 0 && $pageCount === 0 ) {
118 if ( $revCount > 0 && count( $pageSet->getLiveRevisionIDs() ) === 0 ) {
123 if ( $revCount > 0 && $enumRevMode ) {
125 [
'apierror-revisions-norevids', $this->
getModulePrefix() ],
'invalidparammix'
129 if ( $pageCount > 1 && $enumRevMode ) {
131 [
'apierror-revisions-singlepage', $this->
getModulePrefix() ],
'invalidparammix'
137 if ( !$enumRevMode ) {
138 $this->setParsedLimit =
false;
142 $db = $this->
getDB();
145 $tsField =
'rev_timestamp';
146 $pageField =
'rev_page';
152 'revision' =>
'rev_timestamp',
155 if ( $resultPageSet ===
null ) {
157 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $db )
160 if ( $this->fld_user ) {
161 $queryBuilder->joinUser();
167 $this->
addTables( [
'revision',
'page' ] );
169 [
'page' => [
'JOIN', [
'page_id = rev_page' ] ] ]
172 'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField
176 if ( $this->fld_tags ) {
179 ->makeTagSummarySubquery(
'revision' )
183 if (
$params[
'tag'] !==
null ) {
186 [
'change_tag' => [
'JOIN', [
'rev_id=ct_rev_id' ] ] ]
196 if ( $resultPageSet ===
null && $this->fetchContent ) {
198 $status = Status::newGood();
201 foreach ( $pageSet->getGoodPages() as $pageIdentity ) {
202 if ( !$this->
getAuthority()->authorizeRead(
'read', $pageIdentity ) ) {
205 'apierror-cannotviewtitle',
206 wfEscapeWikiText( $this->titleFormatter->getPrefixedText( $pageIdentity ) ),
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'] ) {
268 if ( (
int)$row->id === (
int)
$params[
'endid'] ) {
275 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
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 ] ) );
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',
'temp',
'id',
'interwiki' ],
487 UserDef::PARAM_RETURN_OBJECT =>
true,
491 ParamValidator::PARAM_TYPE =>
'user',
492 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'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';
539class_alias( ApiQueryRevisions::class,
'ApiQueryRevisions' );
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
array $params
The job parameters.
This class contains a list of pages that the client has requested.
A service to render content.
A service to transform content.
Interface for objects (potentially) representing an editable wiki page.