28use Wikimedia\Timestamp\TimestampFormat as TS;
48 parent::__construct( $query, $moduleName,
'dr' );
55 $this->
addDeprecation(
'apiwarn-deprecation-deletedrevs',
'action=query&list=deletedrevs' );
60 $prop = array_fill_keys( $params[
'prop'],
true );
61 $fld_parentid = isset( $prop[
'parentid'] );
62 $fld_revid = isset( $prop[
'revid'] );
63 $fld_user = isset( $prop[
'user'] );
64 $fld_userid = isset( $prop[
'userid'] );
65 $fld_comment = isset( $prop[
'comment'] );
66 $fld_parsedcomment = isset( $prop[
'parsedcomment'] );
67 $fld_minor = isset( $prop[
'minor'] );
68 $fld_len = isset( $prop[
'len'] );
69 $fld_sha1 = isset( $prop[
'sha1'] );
70 $fld_content = isset( $prop[
'content'] );
71 $fld_token = isset( $prop[
'token'] );
72 $fld_tags = isset( $prop[
'tags'] );
85 $titles = $pageSet->getPages();
92 if ( count( $titles ) > 0 ) {
94 } elseif ( $params[
'user'] !==
null ) {
98 if ( $mode ==
'revs' || $mode ==
'user' ) {
100 foreach ( [
'from',
'to',
'prefix', ] as $p ) {
101 if ( $params[$p] !==
null ) {
102 $this->
dieWithError( [
'apierror-deletedrevs-param-not-1-2', $p ],
'badparams' );
106 foreach ( [
'start',
'end' ] as $p ) {
107 if ( $params[$p] !==
null ) {
108 $this->
dieWithError( [
'apierror-deletedrevs-param-not-3', $p ],
'badparams' );
113 if ( $params[
'user'] !==
null && $params[
'excludeuser'] !==
null ) {
114 $this->
dieWithError(
'user and excludeuser cannot be used together',
'badparams' );
117 $arQuery = $this->revisionStore->getArchiveQueryInfo();
121 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
125 'ts_tags' => $this->changeTagsStore->makeTagSummarySubquery(
'archive' )
130 $pairExpr = $db->buildGroupConcat(
131 $db->buildConcat( [
'sr.role_name', $db->addQuotes(
':' ),
'c.content_sha1' ] ),
134 $sha1Subquery = $db->newSelectQueryBuilder()
138 'ar_slot_pairs' => $pairExpr,
141 ->join(
'slots',
's', [
'ar_rev_id = s.slot_revision_id' ] )
142 ->join(
'content',
'c', [
's.slot_content_id = c.content_id' ] )
143 ->join(
'slot_roles',
'sr', [
's.slot_role_id = sr.role_id' ] )
144 ->groupBy( [
'ar_rev_id',
'ar_deleted' ] )
145 ->caller( __METHOD__ )
150 'ar_deleted' =>
'arsha1.ar_deleted',
151 'ar_slot_pairs' =>
'arsha1.ar_slot_pairs'
153 $this->
addJoinConds( [
'arsha1' => [
'LEFT JOIN', [
'ar_rev_id = arsha1.ar_rev_id' ] ] ] );
156 if ( $params[
'tag'] !==
null ) {
159 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
162 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
170 if ( $fld_content ) {
177 $limit = $params[
'limit'];
179 if ( $limit ==
'max' ) {
180 $limit = $this->
getMain()->canApiHighLimits() ? $botMax : $userMax;
184 $limit = $this->
getMain()->getParamValidator()->validateValue(
185 $this,
'limit', $limit, [
186 ParamValidator::PARAM_TYPE =>
'limit',
187 IntegerDef::PARAM_MIN => 1,
188 IntegerDef::PARAM_MAX => $userMax,
189 IntegerDef::PARAM_MAX2 => $botMax,
190 IntegerDef::PARAM_IGNORE_RANGE =>
true,
199 $dir = $params[
'dir'];
202 if ( $mode ==
'revs' ) {
203 $lb = $this->linkBatchFactory->newLinkBatch( $titles );
204 $where = $lb->constructSet(
'ar', $db );
206 } elseif ( $mode ==
'all' ) {
207 $this->
addWhereFld(
'ar_namespace', $params[
'namespace'] );
209 $from = $params[
'from'] ===
null
212 $to = $params[
'to'] ===
null
217 if ( isset( $params[
'prefix'] ) ) {
231 if ( $params[
'user'] !==
null ) {
233 $this->
addWhereFld(
'actor_name', $params[
'user'] );
234 } elseif ( $params[
'excludeuser'] !==
null ) {
235 $this->
addWhere( $db->expr(
'actor_name',
'!=', $params[
'excludeuser'] ) );
238 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
242 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
243 $bitmask = RevisionRecord::DELETED_USER;
244 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
245 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
250 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
254 if ( $params[
'continue'] !==
null ) {
255 $op = ( $dir ==
'newer' ?
'>=' :
'<=' );
256 if ( $mode ==
'all' || $mode ==
'revs' ) {
258 $this->
addWhere( $db->buildComparison( $op, [
259 'ar_namespace' => $cont[0],
260 'ar_title' => $cont[1],
261 'ar_timestamp' => $db->timestamp( $cont[2] ),
266 $this->
addWhere( $db->buildComparison( $op, [
267 'ar_timestamp' => $db->timestamp( $cont[0] ),
274 if ( $mode ==
'all' ) {
275 if ( $params[
'unique'] ) {
277 $this->
addOption(
'GROUP BY',
'ar_title' );
279 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
282 'ar_timestamp' . $sort,
287 if ( $mode ==
'revs' ) {
296 $res = $this->
select( __METHOD__ );
298 $formattedComments = [];
299 if ( $fld_parsedcomment ) {
300 $formattedComments = $this->commentFormatter->formatItems(
301 $this->commentFormatter->rows( $res )
302 ->indexField(
'ar_id' )
303 ->commentKey(
'ar_comment' )
304 ->namespaceField(
'ar_namespace' )
305 ->titleField(
'ar_title' )
312 foreach ( $res as $row ) {
313 if ( ++$count > $limit ) {
315 if ( $mode ==
'all' || $mode ==
'revs' ) {
317 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
328 $rev[
'timestamp'] =
wfTimestamp( TS::ISO_8601, $row->ar_timestamp );
330 $rev[
'revid'] = (int)$row->ar_rev_id;
332 if ( $fld_parentid && $row->ar_parent_id !==
null ) {
333 $rev[
'parentid'] = (int)$row->ar_parent_id;
335 if ( $fld_user || $fld_userid ) {
336 if ( $row->ar_deleted & RevisionRecord::DELETED_USER ) {
337 $rev[
'userhidden'] =
true;
340 if ( RevisionRecord::userCanBitfield(
342 RevisionRecord::DELETED_USER,
346 $rev[
'user'] = $row->ar_user_text;
349 $rev[
'userid'] = (int)$row->ar_user;
354 if ( $fld_comment || $fld_parsedcomment ) {
355 if ( $row->ar_deleted & RevisionRecord::DELETED_COMMENT ) {
356 $rev[
'commenthidden'] =
true;
359 if ( RevisionRecord::userCanBitfield(
361 RevisionRecord::DELETED_COMMENT,
364 $comment = $this->commentStore->getComment(
'ar_comment', $row )->text;
365 if ( $fld_comment ) {
366 $rev[
'comment'] = $comment;
368 if ( $fld_parsedcomment ) {
369 $rev[
'parsedcomment'] = $formattedComments[$row->ar_id];
375 $rev[
'minor'] = $row->ar_minor_edit == 1;
378 $rev[
'len'] = $row->ar_len;
381 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
382 $rev[
'sha1hidden'] =
true;
385 if ( RevisionRecord::userCanBitfield(
387 RevisionRecord::DELETED_TEXT,
390 if ( $row->ar_slot_pairs !==
null ) {
391 $combinedBase36 =
'';
392 if ( $row->ar_slot_pairs !==
'' ) {
393 $items = explode(
',', $row->ar_slot_pairs );
395 foreach ( $items as $item ) {
396 $parts = explode(
':', $item );
397 $slotHashes[$parts[0]] = $parts[1];
399 ksort( $slotHashes );
402 foreach ( $slotHashes as $slotHash ) {
403 $accu = $accu ===
null
405 : SlotRecord::base36Sha1( $accu . $slotHash );
407 $combinedBase36 = $accu ?? SlotRecord::base36Sha1(
'' );
410 $rev[
'sha1'] = $combinedBase36 !==
''
411 ? \Wikimedia\base_convert( $combinedBase36, 36, 16, 40 )
416 if ( $fld_content ) {
417 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
418 $rev[
'texthidden'] =
true;
421 if ( RevisionRecord::userCanBitfield(
423 RevisionRecord::DELETED_TEXT,
427 $this->revisionStore->newRevisionFromArchiveRow( $row )
428 ->getContent( SlotRecord::MAIN )->serialize() );
433 if ( $row->ts_tags ) {
434 $tags = explode(
',', $row->ts_tags );
436 $rev[
'tags'] = $tags;
442 if ( $anyHidden && ( $row->ar_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
443 $rev[
'suppressed'] =
true;
446 if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
447 $pageID = $newPageID++;
448 $pageMap[$row->ar_namespace][$row->ar_title] = $pageID;
449 $a = [
'revisions' => [ $rev ] ];
455 $a[
'token'] = $token;
457 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $pageID, $a );
459 $pageID = $pageMap[$row->ar_namespace][$row->ar_title];
460 $fit = $result->addValue(
465 if ( $mode ==
'all' || $mode ==
'revs' ) {
467 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
475 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );
488 ParamValidator::PARAM_TYPE =>
'timestamp',
492 ParamValidator::PARAM_TYPE =>
'timestamp',
496 ParamValidator::PARAM_TYPE => [
500 ParamValidator::PARAM_DEFAULT =>
'older',
503 'newer' =>
'api-help-paramvalue-direction-newer',
504 'older' =>
'api-help-paramvalue-direction-older',
518 ParamValidator::PARAM_DEFAULT =>
false,
522 ParamValidator::PARAM_TYPE =>
'namespace',
523 ParamValidator::PARAM_DEFAULT =>
NS_MAIN,
528 ParamValidator::PARAM_TYPE =>
'user',
529 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
532 ParamValidator::PARAM_TYPE =>
'user',
533 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
536 ParamValidator::PARAM_DEFAULT =>
'user|comment',
537 ParamValidator::PARAM_TYPE => [
551 ParamValidator::PARAM_ISMULTI =>
true,
553 'content' => [
'apihelp-query+deletedrevs-paramvalue-prop-content', $smallLimit ],
555 EnumDef::PARAM_DEPRECATED_VALUES => [
560 ParamValidator::PARAM_DEFAULT => 10,
561 ParamValidator::PARAM_TYPE =>
'limit',
562 IntegerDef::PARAM_MIN => 1,
575 $title = Title::newMainPage();
576 $talkTitle = $title->getTalkPageIfDefined();
580 $title = rawurlencode( $title->getPrefixedText() );
581 $talkTitle = rawurlencode( $talkTitle->getPrefixedText() );
583 "action=query&list=deletedrevs&titles={$title}|{$talkTitle}&" .
584 'drprop=user|comment|content'
585 =>
'apihelp-query+deletedrevs-example-mode1',
589 return array_merge( $examples, [
590 'action=query&list=deletedrevs&druser=Bob&drlimit=50'
591 =>
'apihelp-query+deletedrevs-example-mode2',
592 'action=query&list=deletedrevs&drdir=newer&drlimit=50'
593 =>
'apihelp-query+deletedrevs-example-mode3-main',
594 'action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique='
595 =>
'apihelp-query+deletedrevs-example-mode3-talk',
601 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Deletedrevs';
606class_alias( ApiQueryDeletedrevs::class,
'ApiQueryDeletedrevs' );
wfTimestamp( $outputtype=TS::UNIX, $ts=0)
Get a timestamp string in one of various formats.
Factory for LinkBatch objects to batch query page metadata.