65 parent::__construct( $query, $moduleName,
'dr' );
66 $this->commentStore = $commentStore;
67 $this->commentFormatter = $commentFormatter;
68 $this->revisionStore = $revisionStore;
69 $this->changeTagDefStore = $changeTagDefStore;
70 $this->linkBatchFactory = $linkBatchFactory;
77 $this->
addDeprecation(
'apiwarn-deprecation-deletedrevs',
'action=query&list=deletedrevs' );
82 $prop = array_fill_keys(
$params[
'prop'],
true );
83 $fld_parentid = isset( $prop[
'parentid'] );
84 $fld_revid = isset( $prop[
'revid'] );
85 $fld_user = isset( $prop[
'user'] );
86 $fld_userid = isset( $prop[
'userid'] );
87 $fld_comment = isset( $prop[
'comment'] );
88 $fld_parsedcomment = isset( $prop[
'parsedcomment'] );
89 $fld_minor = isset( $prop[
'minor'] );
90 $fld_len = isset( $prop[
'len'] );
91 $fld_sha1 = isset( $prop[
'sha1'] );
92 $fld_content = isset( $prop[
'content'] );
93 $fld_token = isset( $prop[
'token'] );
94 $fld_tags = isset( $prop[
'tags'] );
107 $titles = $pageSet->getPages();
114 if ( count( $titles ) > 0 ) {
116 } elseif (
$params[
'user'] !==
null ) {
120 if ( $mode ==
'revs' || $mode ==
'user' ) {
122 foreach ( [
'from',
'to',
'prefix', ] as $p ) {
124 $this->
dieWithError( [
'apierror-deletedrevs-param-not-1-2', $p ],
'badparams' );
128 foreach ( [
'start',
'end' ] as $p ) {
130 $this->
dieWithError( [
'apierror-deletedrevs-param-not-3', $p ],
'badparams' );
135 if (
$params[
'user'] !==
null &&
$params[
'excludeuser'] !==
null ) {
136 $this->
dieWithError(
'user and excludeuser cannot be used together',
'badparams' );
139 $arQuery = $this->revisionStore->getArchiveQueryInfo();
143 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
148 ->makeTagSummarySubquery(
'archive' )
152 if (
$params[
'tag'] !==
null ) {
155 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
166 if ( $fld_content ) {
175 if ( $limit ==
'max' ) {
176 $limit = $this->
getMain()->canApiHighLimits() ? $botMax : $userMax;
180 $limit = $this->
getMain()->getParamValidator()->validateValue(
181 $this,
'limit', $limit, [
182 ParamValidator::PARAM_TYPE =>
'limit',
183 IntegerDef::PARAM_MIN => 1,
184 IntegerDef::PARAM_MAX => $userMax,
185 IntegerDef::PARAM_MAX2 => $botMax,
186 IntegerDef::PARAM_IGNORE_RANGE =>
true,
198 if ( $mode ==
'revs' ) {
199 $lb = $this->linkBatchFactory->newLinkBatch( $titles );
200 $where = $lb->constructSet(
'ar', $db );
202 } elseif ( $mode ==
'all' ) {
205 $from =
$params[
'from'] ===
null
213 if ( isset(
$params[
'prefix'] ) ) {
227 if (
$params[
'user'] !==
null ) {
230 } elseif (
$params[
'excludeuser'] !==
null ) {
231 $this->
addWhere( $db->expr(
'actor_name',
'!=',
$params[
'excludeuser'] ) );
234 if (
$params[
'user'] !==
null ||
$params[
'excludeuser'] !==
null ) {
238 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
239 $bitmask = RevisionRecord::DELETED_USER;
240 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
241 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
246 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
250 if (
$params[
'continue'] !==
null ) {
251 $op = ( $dir ==
'newer' ?
'>=' :
'<=' );
252 if ( $mode ==
'all' || $mode ==
'revs' ) {
254 $this->
addWhere( $db->buildComparison( $op, [
255 'ar_namespace' => $cont[0],
256 'ar_title' => $cont[1],
257 'ar_timestamp' => $db->timestamp( $cont[2] ),
262 $this->
addWhere( $db->buildComparison( $op, [
263 'ar_timestamp' => $db->timestamp( $cont[0] ),
270 if ( $mode ==
'all' ) {
273 $this->
addOption(
'GROUP BY',
'ar_title' );
275 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
278 'ar_timestamp' . $sort,
283 if ( $mode ==
'revs' ) {
292 $res = $this->
select( __METHOD__ );
294 $formattedComments = [];
295 if ( $fld_parsedcomment ) {
296 $formattedComments = $this->commentFormatter->formatItems(
297 $this->commentFormatter->rows( $res )
298 ->indexField(
'ar_id' )
299 ->commentKey(
'ar_comment' )
300 ->namespaceField(
'ar_namespace' )
301 ->titleField(
'ar_title' )
308 foreach ( $res as $row ) {
309 if ( ++$count > $limit ) {
311 if ( $mode ==
'all' || $mode ==
'revs' ) {
313 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
324 $rev[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->ar_timestamp );
326 $rev[
'revid'] = (int)$row->ar_rev_id;
328 if ( $fld_parentid && $row->ar_parent_id !==
null ) {
329 $rev[
'parentid'] = (int)$row->ar_parent_id;
331 if ( $fld_user || $fld_userid ) {
332 if ( $row->ar_deleted & RevisionRecord::DELETED_USER ) {
333 $rev[
'userhidden'] =
true;
336 if ( RevisionRecord::userCanBitfield(
338 RevisionRecord::DELETED_USER,
342 $rev[
'user'] = $row->ar_user_text;
345 $rev[
'userid'] = (int)$row->ar_user;
350 if ( $fld_comment || $fld_parsedcomment ) {
351 if ( $row->ar_deleted & RevisionRecord::DELETED_COMMENT ) {
352 $rev[
'commenthidden'] =
true;
355 if ( RevisionRecord::userCanBitfield(
357 RevisionRecord::DELETED_COMMENT,
360 $comment = $this->commentStore->getComment(
'ar_comment', $row )->text;
361 if ( $fld_comment ) {
362 $rev[
'comment'] = $comment;
364 if ( $fld_parsedcomment ) {
365 $rev[
'parsedcomment'] = $formattedComments[$row->ar_id];
371 $rev[
'minor'] = $row->ar_minor_edit == 1;
374 $rev[
'len'] = $row->ar_len;
377 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
378 $rev[
'sha1hidden'] =
true;
381 if ( RevisionRecord::userCanBitfield(
383 RevisionRecord::DELETED_TEXT,
386 if ( $row->ar_sha1 !=
'' ) {
387 $rev[
'sha1'] = \Wikimedia\base_convert( $row->ar_sha1, 36, 16, 40 );
393 if ( $fld_content ) {
394 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
395 $rev[
'texthidden'] =
true;
398 if ( RevisionRecord::userCanBitfield(
400 RevisionRecord::DELETED_TEXT,
404 $this->revisionStore->newRevisionFromArchiveRow( $row )
405 ->getContent( SlotRecord::MAIN )->serialize() );
410 if ( $row->ts_tags ) {
411 $tags = explode(
',', $row->ts_tags );
413 $rev[
'tags'] = $tags;
419 if ( $anyHidden && ( $row->ar_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
420 $rev[
'suppressed'] =
true;
423 if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
424 $pageID = $newPageID++;
425 $pageMap[$row->ar_namespace][$row->ar_title] = $pageID;
426 $a = [
'revisions' => [ $rev ] ];
428 $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
432 $a[
'token'] = $token;
434 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $pageID, $a );
436 $pageID = $pageMap[$row->ar_namespace][$row->ar_title];
437 $fit = $result->addValue(
442 if ( $mode ==
'all' || $mode ==
'revs' ) {
444 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
452 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );
463 ParamValidator::PARAM_TYPE =>
'timestamp',
467 ParamValidator::PARAM_TYPE =>
'timestamp',
471 ParamValidator::PARAM_TYPE => [
475 ParamValidator::PARAM_DEFAULT =>
'older',
478 'newer' =>
'api-help-paramvalue-direction-newer',
479 'older' =>
'api-help-paramvalue-direction-older',
493 ParamValidator::PARAM_DEFAULT =>
false,
497 ParamValidator::PARAM_TYPE =>
'namespace',
498 ParamValidator::PARAM_DEFAULT =>
NS_MAIN,
503 ParamValidator::PARAM_TYPE =>
'user',
504 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
507 ParamValidator::PARAM_TYPE =>
'user',
508 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
511 ParamValidator::PARAM_DEFAULT =>
'user|comment',
512 ParamValidator::PARAM_TYPE => [
526 ParamValidator::PARAM_ISMULTI =>
true,
528 'content' => [
'apihelp-query+deletedrevs-paramvalue-prop-content', $smallLimit ],
530 EnumDef::PARAM_DEPRECATED_VALUES => [
535 ParamValidator::PARAM_DEFAULT => 10,
536 ParamValidator::PARAM_TYPE =>
'limit',
537 IntegerDef::PARAM_MIN => 1,
549 $title = Title::newMainPage();
550 $talkTitle = $title->getTalkPageIfDefined();
554 $title = rawurlencode( $title->getPrefixedText() );
555 $talkTitle = rawurlencode( $talkTitle->getPrefixedText() );
557 "action=query&list=deletedrevs&titles={$title}|{$talkTitle}&" .
558 'drprop=user|comment|content'
559 =>
'apihelp-query+deletedrevs-example-mode1',
563 return array_merge( $examples, [
564 'action=query&list=deletedrevs&druser=Bob&drlimit=50'
565 =>
'apihelp-query+deletedrevs-example-mode2',
566 'action=query&list=deletedrevs&drdir=newer&drlimit=50'
567 =>
'apihelp-query+deletedrevs-example-mode3-main',
568 'action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique='
569 =>
'apihelp-query+deletedrevs-example-mode3-talk',
574 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Deletedrevs';
579class_alias( ApiQueryDeletedrevs::class,
'ApiQueryDeletedrevs' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
array $params
The job parameters.