84 $contentHandlerFactory,
93 $this->revisionStore = $revisionStore;
94 $this->changeTagDefStore = $changeTagDefStore;
95 $this->changeTagsStore = $changeTagsStore;
96 $this->actorMigration = $actorMigration;
97 $this->titleFormatter = $titleFormatter;
107 $enumRevMode = (
$params[
'user'] !==
null ||
$params[
'excludeuser'] !==
null ||
113 $pageCount = $pageSet->getGoodTitleCount();
114 $revCount = $pageSet->getRevisionCount();
117 if ( $revCount === 0 && $pageCount === 0 ) {
121 if ( $revCount > 0 && count( $pageSet->getLiveRevisionIDs() ) === 0 ) {
126 if ( $revCount > 0 && $enumRevMode ) {
128 [
'apierror-revisions-norevids', $this->
getModulePrefix() ],
'invalidparammix'
132 if ( $pageCount > 1 && $enumRevMode ) {
134 [
'apierror-revisions-singlepage', $this->
getModulePrefix() ],
'invalidparammix'
140 if ( !$enumRevMode ) {
141 $this->setParsedLimit =
false;
145 $db = $this->
getDB();
148 $tsField =
'rev_timestamp';
149 $pageField =
'rev_page';
155 'revision' =>
'rev_timestamp',
158 if ( $resultPageSet ===
null ) {
160 $queryBuilder = $this->revisionStore->newSelectQueryBuilder( $db )
163 if ( $this->fld_user ) {
164 $queryBuilder->joinUser();
170 $this->
addTables( [
'revision',
'page' ] );
172 [
'page' => [
'JOIN', [
'page_id = rev_page' ] ] ]
175 'rev_id' => $idField,
'rev_timestamp' => $tsField,
'rev_page' => $pageField
179 if ( $this->fld_tags ) {
181 'ts_tags' => $this->changeTagsStore->makeTagSummarySubquery(
'revision' )
185 if (
$params[
'tag'] !==
null ) {
188 [
'change_tag' => [
'JOIN', [
'rev_id=ct_rev_id' ] ] ]
198 if ( $resultPageSet ===
null && $this->fetchContent ) {
200 $status = Status::newGood();
203 foreach ( $pageSet->getGoodPages() as $pageIdentity ) {
204 if ( !$this->
getAuthority()->authorizeRead(
'read', $pageIdentity ) ) {
207 'apierror-cannotviewtitle',
208 wfEscapeWikiText( $this->titleFormatter->getPrefixedText( $pageIdentity ) ),
214 if ( !$status->isGood() ) {
219 if ( $enumRevMode ) {
231 if (
$params[
'continue'] !==
null ) {
233 $op = (
$params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
234 $continueTimestamp = $db->timestamp( $cont[0] );
235 $continueId = (int)$cont[1];
236 $this->
addWhere( $db->buildComparison( $op, [
237 $tsField => $continueTimestamp,
238 $idField => $continueId,
244 if (
$params[
'startid'] !==
null ) {
245 $revids[] = (int)
$params[
'startid'];
247 if (
$params[
'endid'] !==
null ) {
248 $revids[] = (int)
$params[
'endid'];
251 $db = $this->
getDB();
252 $uqb = $db->newUnionQueryBuilder();
254 $db->newSelectQueryBuilder()
255 ->select( [
'id' =>
'rev_id',
'ts' =>
'rev_timestamp' ] )
257 ->where( [
'rev_id' => $revids ] )
260 $db->newSelectQueryBuilder()
261 ->select( [
'id' =>
'ar_rev_id',
'ts' =>
'ar_timestamp' ] )
263 ->where( [
'ar_rev_id' => $revids ] )
265 $res = $uqb->caller( __METHOD__ )->fetchResultSet();
266 foreach ( $res as $row ) {
267 if ( (
int)$row->id === (
int)
$params[
'startid'] ) {
270 if ( (
int)$row->id === (
int)
$params[
'endid'] ) {
277 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
282 $this->
dieWithError( [
'apierror-revisions-badid', $p ],
"badid_$p" );
286 if (
$params[
'start'] !==
null ) {
287 $op = (
$params[
'dir'] ===
'newer' ?
'>=' :
'<=' );
289 $ts = $db->timestampOrNull(
$params[
'start'] );
290 if (
$params[
'startid'] !==
null ) {
291 $this->
addWhere( $db->buildComparison( $op, [
293 $idField => (
int)
$params[
'startid'],
296 $this->
addWhere( $db->buildComparison( $op, [ $tsField => $ts ] ) );
300 if (
$params[
'end'] !==
null ) {
301 $op = (
$params[
'dir'] ===
'newer' ?
'<=' :
'>=' );
303 $ts = $db->timestampOrNull(
$params[
'end'] );
304 if (
$params[
'endid'] !==
null ) {
305 $this->
addWhere( $db->buildComparison( $op, [
307 $idField => (
int)
$params[
'endid'],
310 $this->
addWhere( $db->buildComparison( $op, [ $tsField => $ts ] ) );
318 $sort = (
$params[
'dir'] ===
'newer' ?
'' :
'DESC' );
319 $this->
addOption(
'ORDER BY', [
"rev_timestamp $sort",
"rev_id $sort" ] );
322 $ids = array_keys( $pageSet->getGoodPages() );
325 if (
$params[
'user'] !==
null ) {
326 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user',
$params[
'user'] );
327 $this->
addTables( $actorQuery[
'tables'] );
329 $this->
addWhere( $actorQuery[
'conds'] );
330 } elseif (
$params[
'excludeuser'] !==
null ) {
331 $actorQuery = $this->actorMigration->getWhere( $db,
'rev_user',
$params[
'excludeuser'] );
332 $this->
addTables( $actorQuery[
'tables'] );
334 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
340 $useIndex[
'revision'] =
'rev_page_timestamp';
343 if (
$params[
'user'] !==
null ||
$params[
'excludeuser'] !==
null ) {
345 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
346 $bitmask = RevisionRecord::DELETED_USER;
347 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
348 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
353 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
356 } elseif ( $revCount > 0 ) {
359 $revs = $pageSet->getLiveRevisionIDs();
362 $this->
addWhereFld(
'rev_id', array_keys( $revs ) );
364 if (
$params[
'continue'] !==
null ) {
365 $this->
addWhere( $db->buildComparison(
'>=', [
366 'rev_id' => (
int)
$params[
'continue']
369 $this->
addOption(
'ORDER BY',
'rev_id' );
370 } elseif ( $pageCount > 0 ) {
373 $pageids = array_keys( $pageSet->getGoodPages() );
377 $this->
addWhere(
'page_latest=rev_id' );
384 if (
$params[
'continue'] !==
null ) {
386 $this->
addWhere( $db->buildComparison(
'>=', [
387 'rev_page' => $cont[0],
388 'rev_id' => $cont[1],
399 $this->
addOption(
'LIMIT', $this->limit + 1 );
401 $this->
addOption(
'IGNORE INDEX', $ignoreIndex );
404 $this->
addOption(
'USE INDEX', $useIndex );
410 $res = $this->
select( __METHOD__, [], $hookData );
412 foreach ( $res as $row ) {
413 if ( ++$count > $this->limit ) {
416 if ( $enumRevMode ) {
418 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
419 } elseif ( $revCount > 0 ) {
423 '|' . (
int)$row->rev_id );
428 if ( $resultPageSet !==
null ) {
429 $generated[] = $row->rev_id;
431 $revision = $this->revisionStore->newRevisionFromRow( $row, 0, Title::newFromRow( $row ) );
433 $fit = $this->
processRow( $row, $rev, $hookData ) &&
436 if ( $enumRevMode ) {
438 $row->rev_timestamp .
'|' . (
int)$row->rev_id );
439 } elseif ( $revCount > 0 ) {
443 '|' . (
int)$row->rev_id );
450 if ( $resultPageSet !==
null ) {
451 $resultPageSet->populateFromRevisionIDs( $generated );
456 $ret = parent::getAllowedParams() + [
458 ParamValidator::PARAM_TYPE =>
'integer',
462 ParamValidator::PARAM_TYPE =>
'integer',
466 ParamValidator::PARAM_TYPE =>
'timestamp',
470 ParamValidator::PARAM_TYPE =>
'timestamp',
474 ParamValidator::PARAM_DEFAULT =>
'older',
475 ParamValidator::PARAM_TYPE => [
481 'newer' =>
'api-help-paramvalue-direction-newer',
482 'older' =>
'api-help-paramvalue-direction-older',
487 ParamValidator::PARAM_TYPE =>
'user',
488 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
489 UserDef::PARAM_RETURN_OBJECT =>
true,
493 ParamValidator::PARAM_TYPE =>
'user',
494 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
495 UserDef::PARAM_RETURN_OBJECT =>
true,
510 $title = Title::newMainPage()->getPrefixedText();
511 $mp = rawurlencode( $title );
514 "action=query&prop=revisions&titles=API|{$mp}&" .
515 'rvslots=*&rvprop=timestamp|user|comment|content'
516 =>
'apihelp-query+revisions-example-content',
517 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
518 'rvprop=timestamp|user|comment'
519 =>
'apihelp-query+revisions-example-last5',
520 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
521 'rvprop=timestamp|user|comment&rvdir=newer'
522 =>
'apihelp-query+revisions-example-first5',
523 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
524 'rvprop=timestamp|user|comment&rvdir=newer&rvstart=2006-05-01T00:00:00Z'
525 =>
'apihelp-query+revisions-example-first5-after',
526 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
527 'rvprop=timestamp|user|comment&rvexcludeuser=127.0.0.1'
528 =>
'apihelp-query+revisions-example-first5-not-localhost',
529 "action=query&prop=revisions&titles={$mp}&rvlimit=5&" .
530 'rvprop=timestamp|user|comment&rvuser=MediaWiki%20default'
531 =>
'apihelp-query+revisions-example-first5-user',
536 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Revisions';
541class_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.