98 $contentHandlerFactory,
107 $this->revisionStore = $revisionStore;
108 $this->changeTagDefStore = $changeTagDefStore;
109 $this->actorMigration = $actorMigration;
110 $this->titleFormatter = $titleFormatter;
120 $enumRevMode = (
$params[
'user'] !==
null ||
$params[
'excludeuser'] !==
null ||
126 $pageCount = $pageSet->getGoodTitleCount();
127 $revCount = $pageSet->getRevisionCount();
130 if ( $revCount === 0 && $pageCount === 0 ) {
134 if ( $revCount > 0 && count( $pageSet->getLiveRevisionIDs() ) === 0 ) {
139 if ( $revCount > 0 && $enumRevMode ) {
141 [
'apierror-revisions-norevids', $this->
getModulePrefix() ],
'invalidparammix'
145 if ( $pageCount > 1 && $enumRevMode ) {
147 [
'apierror-revisions-singlepage', $this->
getModulePrefix() ],
'invalidparammix'
153 if ( !$enumRevMode ) {
154 $this->setParsedLimit =
false;
158 $db = $this->
getDB();
161 $tsField =
'rev_timestamp';
162 $pageField =
'rev_page';
168 'revision' =>
'rev_timestamp',
171 if ( $resultPageSet ===
null ) {
173 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $db )
176 if ( $this->fld_user ) {
177 $queryBuilder->joinUser();
183 $this->
addTables( [
'revision',
'page' ] );
185 [
'page' => [
'JOIN', [
'page_id = rev_page' ] ] ]
188 'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField
192 if ( $this->fld_tags ) {
196 if (
$params[
'tag'] !==
null ) {
199 [
'change_tag' => [
'JOIN', [
'rev_id=ct_rev_id' ] ] ]
209 if ( $resultPageSet ===
null && $this->fetchContent ) {
211 $status = Status::newGood();
214 foreach ( $pageSet->getGoodPages() as $pageIdentity ) {
215 if ( !$this->
getAuthority()->authorizeRead(
'read', $pageIdentity ) ) {
218 'apierror-cannotviewtitle',
219 wfEscapeWikiText( $this->titleFormatter->getPrefixedText( $pageIdentity ) ),
225 if ( !$status->isGood() ) {
230 if ( $enumRevMode ) {
242 if (
$params[
'continue'] !==
null ) {
244 $op = (
$params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
245 $continueTimestamp = $db->timestamp( $cont[0] );
246 $continueId = (int)$cont[1];
247 $this->
addWhere( $db->buildComparison( $op, [
248 $tsField => $continueTimestamp,
249 $idField => $continueId,
255 if (
$params[
'startid'] !==
null ) {
256 $revids[] = (int)
$params[
'startid'];
258 if (
$params[
'endid'] !==
null ) {
259 $revids[] = (int)
$params[
'endid'];
262 $db = $this->
getDB();
263 $uqb = $db->newUnionQueryBuilder();
265 $db->newSelectQueryBuilder()
266 ->select( [
'id' =>
'rev_id',
'ts' =>
'rev_timestamp' ] )
268 ->where( [
'rev_id' => $revids ] )
271 $db->newSelectQueryBuilder()
272 ->select( [
'id' =>
'ar_rev_id',
'ts' =>
'ar_timestamp' ] )
274 ->where( [
'ar_rev_id' => $revids ] )
276 $res = $uqb->caller( __METHOD__ )->fetchResultSet();
277 foreach ( $res as $row ) {
278 if ( (
int)$row->id === (
int)
$params[
'startid'] ) {
281 if ( (
int)$row->id === (
int)
$params[
'endid'] ) {
288 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
293 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
297 if (
$params[
'start'] !==
null ) {
298 $op = (
$params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
300 $ts = $db->timestampOrNull(
$params[
'start'] );
301 if (
$params[
'startid'] !==
null ) {
302 $this->
addWhere( $db->buildComparison( $op, [
304 $idField => (
int)
$params[
'startid'],
307 $this->
addWhere( $db->buildComparison( $op, [ $tsField => $ts ] ) );
311 if (
$params[
'end'] !==
null ) {
312 $op = (
$params[
'dir'] ===
'newer' ?
'<=' :
'>=' );
314 $ts = $db->timestampOrNull(
$params[
'end'] );
315 if (
$params[
'endid'] !==
null ) {
316 $this->
addWhere( $db->buildComparison( $op, [
318 $idField => (
int)
$params[
'endid'],
321 $this->
addWhere( $db->buildComparison( $op, [ $tsField => $ts ] ) );
329 $sort = (
$params[
'dir'] ===
'newer' ?
'' :
'DESC' );
330 $this->
addOption(
'ORDER BY', [
"rev_timestamp $sort",
"rev_id $sort" ] );
333 $ids = array_keys( $pageSet->getGoodPages() );
336 if (
$params[
'user'] !==
null ) {
337 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user',
$params[
'user'] );
338 $this->
addTables( $actorQuery[
'tables'] );
340 $this->
addWhere( $actorQuery[
'conds'] );
341 } elseif (
$params[
'excludeuser'] !==
null ) {
342 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user',
$params[
'excludeuser'] );
343 $this->
addTables( $actorQuery[
'tables'] );
345 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
351 $useIndex[
'revision'] =
'rev_page_timestamp';
354 if (
$params[
'user'] !==
null ||
$params[
'excludeuser'] !==
null ) {
356 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
357 $bitmask = RevisionRecord::DELETED_USER;
358 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
359 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
364 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
367 } elseif ( $revCount > 0 ) {
370 $revs = $pageSet->getLiveRevisionIDs();
373 $this->
addWhereFld(
'rev_id', array_keys( $revs ) );
375 if (
$params[
'continue'] !==
null ) {
376 $this->
addWhere( $db->buildComparison(
'>=', [
377 'rev_id' => (
int)
$params[
'continue']
380 $this->
addOption(
'ORDER BY',
'rev_id' );
381 } elseif ( $pageCount > 0 ) {
384 $pageids = array_keys( $pageSet->getGoodPages() );
388 $this->
addWhere(
'page_latest=rev_id' );
395 if (
$params[
'continue'] !==
null ) {
397 $this->
addWhere( $db->buildComparison(
'>=', [
398 'rev_page' => $cont[0],
399 'rev_id' => $cont[1],
410 $this->
addOption(
'LIMIT', $this->limit + 1 );
412 $this->
addOption(
'IGNORE INDEX', $ignoreIndex );
415 $this->
addOption(
'USE INDEX', $useIndex );
421 $res = $this->
select( __METHOD__, [], $hookData );
423 foreach ( $res as $row ) {
424 if ( ++$count > $this->limit ) {
427 if ( $enumRevMode ) {
429 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
430 } elseif ( $revCount > 0 ) {
434 '|' . (
int)$row->rev_id );
439 if ( $resultPageSet !==
null ) {
440 $generated[] = $row->rev_id;
442 $revision = $this->revisionStore->newRevisionFromRow( $row, 0, Title::newFromRow( $row ) );
444 $fit = $this->
processRow( $row, $rev, $hookData ) &&
447 if ( $enumRevMode ) {
449 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
450 } elseif ( $revCount > 0 ) {
454 '|' . (
int)$row->rev_id );
461 if ( $resultPageSet !==
null ) {
462 $resultPageSet->populateFromRevisionIDs( $generated );
467 $ret = parent::getAllowedParams() + [
469 ParamValidator::PARAM_TYPE =>
'integer',
473 ParamValidator::PARAM_TYPE =>
'integer',
477 ParamValidator::PARAM_TYPE =>
'timestamp',
481 ParamValidator::PARAM_TYPE =>
'timestamp',
485 ParamValidator::PARAM_DEFAULT =>
'older',
486 ParamValidator::PARAM_TYPE => [
492 'newer' =>
'api-help-paramvalue-direction-newer',
493 'older' =>
'api-help-paramvalue-direction-older',
498 ParamValidator::PARAM_TYPE =>
'user',
499 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
500 UserDef::PARAM_RETURN_OBJECT =>
true,
504 ParamValidator::PARAM_TYPE =>
'user',
505 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
506 UserDef::PARAM_RETURN_OBJECT =>
true,
521 $title = Title::newMainPage()->getPrefixedText();
522 $mp = rawurlencode( $title );
525 "action=query&prop=revisions&titles=API|{$mp}&" .
526 'rvslots=*&rvprop=timestamp|user|comment|content'
527 =>
'apihelp-query+revisions-example-content',
528 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
529 'rvprop=timestamp|user|comment'
530 =>
'apihelp-query+revisions-example-last5',
531 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
532 'rvprop=timestamp|user|comment&rvdir=newer'
533 =>
'apihelp-query+revisions-example-first5',
534 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
535 'rvprop=timestamp|user|comment&rvdir=newer&rvstart=2006-05-01T00:00:00Z'
536 =>
'apihelp-query+revisions-example-first5-after',
537 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
538 'rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1'
539 =>
'apihelp-query+revisions-example-first5-not-localhost',
540 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
541 'rvprop=timestamp|user|comment&rvuser=MediaWiki%20default'
542 =>
'apihelp-query+revisions-example-first5-user',
547 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Revisions';
552class_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.