67 parent::__construct( $query, $moduleName,
'dr' );
68 $this->commentStore = $commentStore;
69 $this->commentFormatter = $commentFormatter;
70 $this->revisionStore = $revisionStore;
71 $this->changeTagDefStore = $changeTagDefStore;
72 $this->changeTagsStore = $changeTagsStore;
73 $this->linkBatchFactory = $linkBatchFactory;
80 $this->
addDeprecation(
'apiwarn-deprecation-deletedrevs',
'action=query&list=deletedrevs' );
85 $prop = array_fill_keys(
$params[
'prop'],
true );
86 $fld_parentid = isset( $prop[
'parentid'] );
87 $fld_revid = isset( $prop[
'revid'] );
88 $fld_user = isset( $prop[
'user'] );
89 $fld_userid = isset( $prop[
'userid'] );
90 $fld_comment = isset( $prop[
'comment'] );
91 $fld_parsedcomment = isset( $prop[
'parsedcomment'] );
92 $fld_minor = isset( $prop[
'minor'] );
93 $fld_len = isset( $prop[
'len'] );
94 $fld_sha1 = isset( $prop[
'sha1'] );
95 $fld_content = isset( $prop[
'content'] );
96 $fld_token = isset( $prop[
'token'] );
97 $fld_tags = isset( $prop[
'tags'] );
110 $titles = $pageSet->getPages();
117 if ( count( $titles ) > 0 ) {
119 } elseif (
$params[
'user'] !==
null ) {
123 if ( $mode ==
'revs' || $mode ==
'user' ) {
125 foreach ( [
'from',
'to',
'prefix', ] as $p ) {
127 $this->
dieWithError( [
'apierror-deletedrevs-param-not-1-2', $p ],
'badparams' );
131 foreach ( [
'start',
'end' ] as $p ) {
133 $this->
dieWithError( [
'apierror-deletedrevs-param-not-3', $p ],
'badparams' );
138 if (
$params[
'user'] !==
null &&
$params[
'excludeuser'] !==
null ) {
139 $this->
dieWithError(
'user and excludeuser cannot be used together',
'badparams' );
142 $arQuery = $this->revisionStore->getArchiveQueryInfo();
146 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
150 'ts_tags' => $this->changeTagsStore->makeTagSummarySubquery(
'archive' )
154 if (
$params[
'tag'] !==
null ) {
157 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
168 if ( $fld_content ) {
177 if ( $limit ==
'max' ) {
178 $limit = $this->
getMain()->canApiHighLimits() ? $botMax : $userMax;
182 $limit = $this->
getMain()->getParamValidator()->validateValue(
183 $this,
'limit', $limit, [
184 ParamValidator::PARAM_TYPE =>
'limit',
185 IntegerDef::PARAM_MIN => 1,
186 IntegerDef::PARAM_MAX => $userMax,
187 IntegerDef::PARAM_MAX2 => $botMax,
188 IntegerDef::PARAM_IGNORE_RANGE =>
true,
200 if ( $mode ==
'revs' ) {
201 $lb = $this->linkBatchFactory->newLinkBatch( $titles );
202 $where = $lb->constructSet(
'ar', $db );
204 } elseif ( $mode ==
'all' ) {
207 $from =
$params[
'from'] ===
null
215 if ( isset(
$params[
'prefix'] ) ) {
229 if (
$params[
'user'] !==
null ) {
232 } elseif (
$params[
'excludeuser'] !==
null ) {
233 $this->
addWhere( $db->expr(
'actor_name',
'!=',
$params[
'excludeuser'] ) );
236 if (
$params[
'user'] !==
null ||
$params[
'excludeuser'] !==
null ) {
240 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
241 $bitmask = RevisionRecord::DELETED_USER;
242 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
243 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
248 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
252 if (
$params[
'continue'] !==
null ) {
253 $op = ( $dir ==
'newer' ?
'>=' :
'<=' );
254 if ( $mode ==
'all' || $mode ==
'revs' ) {
256 $this->
addWhere( $db->buildComparison( $op, [
257 'ar_namespace' => $cont[0],
258 'ar_title' => $cont[1],
259 'ar_timestamp' => $db->timestamp( $cont[2] ),
264 $this->
addWhere( $db->buildComparison( $op, [
265 'ar_timestamp' => $db->timestamp( $cont[0] ),
272 if ( $mode ==
'all' ) {
275 $this->
addOption(
'GROUP BY',
'ar_title' );
277 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
280 'ar_timestamp' . $sort,
285 if ( $mode ==
'revs' ) {
294 $res = $this->
select( __METHOD__ );
296 $formattedComments = [];
297 if ( $fld_parsedcomment ) {
298 $formattedComments = $this->commentFormatter->formatItems(
299 $this->commentFormatter->rows( $res )
300 ->indexField(
'ar_id' )
301 ->commentKey(
'ar_comment' )
302 ->namespaceField(
'ar_namespace' )
303 ->titleField(
'ar_title' )
310 foreach ( $res as $row ) {
311 if ( ++$count > $limit ) {
313 if ( $mode ==
'all' || $mode ==
'revs' ) {
315 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
326 $rev[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->ar_timestamp );
328 $rev[
'revid'] = (int)$row->ar_rev_id;
330 if ( $fld_parentid && $row->ar_parent_id !==
null ) {
331 $rev[
'parentid'] = (int)$row->ar_parent_id;
333 if ( $fld_user || $fld_userid ) {
334 if ( $row->ar_deleted & RevisionRecord::DELETED_USER ) {
335 $rev[
'userhidden'] =
true;
338 if ( RevisionRecord::userCanBitfield(
340 RevisionRecord::DELETED_USER,
344 $rev[
'user'] = $row->ar_user_text;
347 $rev[
'userid'] = (int)$row->ar_user;
352 if ( $fld_comment || $fld_parsedcomment ) {
353 if ( $row->ar_deleted & RevisionRecord::DELETED_COMMENT ) {
354 $rev[
'commenthidden'] =
true;
357 if ( RevisionRecord::userCanBitfield(
359 RevisionRecord::DELETED_COMMENT,
362 $comment = $this->commentStore->getComment(
'ar_comment', $row )->text;
363 if ( $fld_comment ) {
364 $rev[
'comment'] = $comment;
366 if ( $fld_parsedcomment ) {
367 $rev[
'parsedcomment'] = $formattedComments[$row->ar_id];
373 $rev[
'minor'] = $row->ar_minor_edit == 1;
376 $rev[
'len'] = $row->ar_len;
379 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
380 $rev[
'sha1hidden'] =
true;
383 if ( RevisionRecord::userCanBitfield(
385 RevisionRecord::DELETED_TEXT,
388 if ( $row->ar_sha1 !=
'' ) {
389 $rev[
'sha1'] = \Wikimedia\base_convert( $row->ar_sha1, 36, 16, 40 );
395 if ( $fld_content ) {
396 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
397 $rev[
'texthidden'] =
true;
400 if ( RevisionRecord::userCanBitfield(
402 RevisionRecord::DELETED_TEXT,
406 $this->revisionStore->newRevisionFromArchiveRow( $row )
407 ->getContent( SlotRecord::MAIN )->serialize() );
412 if ( $row->ts_tags ) {
413 $tags = explode(
',', $row->ts_tags );
415 $rev[
'tags'] = $tags;
421 if ( $anyHidden && ( $row->ar_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
422 $rev[
'suppressed'] =
true;
425 if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
426 $pageID = $newPageID++;
427 $pageMap[$row->ar_namespace][$row->ar_title] = $pageID;
428 $a = [
'revisions' => [ $rev ] ];
430 $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
434 $a[
'token'] = $token;
436 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $pageID, $a );
438 $pageID = $pageMap[$row->ar_namespace][$row->ar_title];
439 $fit = $result->addValue(
444 if ( $mode ==
'all' || $mode ==
'revs' ) {
446 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
454 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );
465 ParamValidator::PARAM_TYPE =>
'timestamp',
469 ParamValidator::PARAM_TYPE =>
'timestamp',
473 ParamValidator::PARAM_TYPE => [
477 ParamValidator::PARAM_DEFAULT =>
'older',
480 'newer' =>
'api-help-paramvalue-direction-newer',
481 'older' =>
'api-help-paramvalue-direction-older',
495 ParamValidator::PARAM_DEFAULT =>
false,
499 ParamValidator::PARAM_TYPE =>
'namespace',
500 ParamValidator::PARAM_DEFAULT =>
NS_MAIN,
505 ParamValidator::PARAM_TYPE =>
'user',
506 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
509 ParamValidator::PARAM_TYPE =>
'user',
510 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
513 ParamValidator::PARAM_DEFAULT =>
'user|comment',
514 ParamValidator::PARAM_TYPE => [
528 ParamValidator::PARAM_ISMULTI =>
true,
530 'content' => [
'apihelp-query+deletedrevs-paramvalue-prop-content', $smallLimit ],
532 EnumDef::PARAM_DEPRECATED_VALUES => [
537 ParamValidator::PARAM_DEFAULT => 10,
538 ParamValidator::PARAM_TYPE =>
'limit',
539 IntegerDef::PARAM_MIN => 1,
551 $title = Title::newMainPage();
552 $talkTitle = $title->getTalkPageIfDefined();
556 $title = rawurlencode( $title->getPrefixedText() );
557 $talkTitle = rawurlencode( $talkTitle->getPrefixedText() );
559 "action=query&list=deletedrevs&titles={$title}|{$talkTitle}&" .
560 'drprop=user|comment|content'
561 =>
'apihelp-query+deletedrevs-example-mode1',
565 return array_merge( $examples, [
566 'action=query&list=deletedrevs&druser=Bob&drlimit=50'
567 =>
'apihelp-query+deletedrevs-example-mode2',
568 'action=query&list=deletedrevs&drdir=newer&drlimit=50'
569 =>
'apihelp-query+deletedrevs-example-mode3-main',
570 'action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique='
571 =>
'apihelp-query+deletedrevs-example-mode3-talk',
576 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Deletedrevs';
581class_alias( ApiQueryDeletedrevs::class,
'ApiQueryDeletedrevs' );
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
array $params
The job parameters.