81 $this->
addDeprecation(
'apiwarn-deprecation-deletedrevs',
'action=query&list=deletedrevs' );
86 $prop = array_fill_keys( $params[
'prop'],
true );
87 $fld_parentid = isset( $prop[
'parentid'] );
88 $fld_revid = isset( $prop[
'revid'] );
89 $fld_user = isset( $prop[
'user'] );
90 $fld_userid = isset( $prop[
'userid'] );
91 $fld_comment = isset( $prop[
'comment'] );
92 $fld_parsedcomment = isset( $prop[
'parsedcomment'] );
93 $fld_minor = isset( $prop[
'minor'] );
94 $fld_len = isset( $prop[
'len'] );
95 $fld_sha1 = isset( $prop[
'sha1'] );
96 $fld_content = isset( $prop[
'content'] );
97 $fld_token = isset( $prop[
'token'] );
98 $fld_tags = isset( $prop[
'tags'] );
111 $titles = $pageSet->getPages();
118 if ( count( $titles ) > 0 ) {
120 } elseif ( $params[
'user'] !==
null ) {
124 if ( $mode ==
'revs' || $mode ==
'user' ) {
126 foreach ( [
'from',
'to',
'prefix', ] as $p ) {
127 if ( $params[$p] !==
null ) {
128 $this->
dieWithError( [
'apierror-deletedrevs-param-not-1-2', $p ],
'badparams' );
132 foreach ( [
'start',
'end' ] as $p ) {
133 if ( $params[$p] !==
null ) {
134 $this->
dieWithError( [
'apierror-deletedrevs-param-not-3', $p ],
'badparams' );
139 if ( $params[
'user'] !==
null && $params[
'excludeuser'] !==
null ) {
140 $this->
dieWithError(
'user and excludeuser cannot be used together',
'badparams' );
143 $arQuery = $this->revisionStore->getArchiveQueryInfo();
147 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
153 if ( $params[
'tag'] !==
null ) {
156 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
159 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
167 if ( $fld_content ) {
174 $limit = $params[
'limit'];
176 if ( $limit ==
'max' ) {
177 $limit = $this->
getMain()->canApiHighLimits() ? $botMax : $userMax;
181 $limit = $this->
getMain()->getParamValidator()->validateValue(
182 $this,
'limit', $limit, [
183 ParamValidator::PARAM_TYPE =>
'limit',
184 IntegerDef::PARAM_MIN => 1,
185 IntegerDef::PARAM_MAX => $userMax,
186 IntegerDef::PARAM_MAX2 => $botMax,
187 IntegerDef::PARAM_IGNORE_RANGE =>
true,
196 $dir = $params[
'dir'];
199 if ( $mode ==
'revs' ) {
200 $lb = $this->linkBatchFactory->newLinkBatch( $titles );
201 $where = $lb->constructSet(
'ar', $db );
203 } elseif ( $mode ==
'all' ) {
204 $this->
addWhereFld(
'ar_namespace', $params[
'namespace'] );
206 $from = $params[
'from'] ===
null
209 $to = $params[
'to'] ===
null
214 if ( isset( $params[
'prefix'] ) ) {
215 $this->
addWhere(
'ar_title' . $db->buildLike(
216 $this->titlePartToKey( $params[
'prefix'], $params[
'namespace'] ),
217 $db->anyString() ) );
221 if ( $params[
'user'] !==
null ) {
223 $this->
addWhereFld(
'actor_name', $params[
'user'] );
224 } elseif ( $params[
'excludeuser'] !==
null ) {
225 $this->
addWhere(
'actor_name<>' . $db->addQuotes( $params[
'excludeuser'] ) );
228 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
232 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
233 $bitmask = RevisionRecord::DELETED_USER;
234 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
235 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
240 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
244 if ( $params[
'continue'] !==
null ) {
245 $op = ( $dir ==
'newer' ?
'>=' :
'<=' );
246 if ( $mode ==
'all' || $mode ==
'revs' ) {
248 $this->
addWhere( $db->buildComparison( $op, [
249 'ar_namespace' => $cont[0],
250 'ar_title' => $cont[1],
251 'ar_timestamp' => $db->timestamp( $cont[2] ),
256 $this->
addWhere( $db->buildComparison( $op, [
257 'ar_timestamp' => $db->timestamp( $cont[0] ),
264 if ( $mode ==
'all' ) {
265 if ( $params[
'unique'] ) {
267 $this->
addOption(
'GROUP BY',
'ar_title' );
269 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
272 'ar_timestamp' . $sort,
277 if ( $mode ==
'revs' ) {
286 $res = $this->
select( __METHOD__ );
288 $formattedComments = [];
289 if ( $fld_parsedcomment ) {
290 $formattedComments = $this->commentFormatter->formatItems(
291 $this->commentFormatter->rows( $res )
292 ->indexField(
'ar_id' )
293 ->commentKey(
'ar_comment' )
294 ->namespaceField(
'ar_namespace' )
295 ->titleField(
'ar_title' )
302 foreach ( $res as $row ) {
303 if ( ++$count > $limit ) {
305 if ( $mode ==
'all' || $mode ==
'revs' ) {
307 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
318 $rev[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->ar_timestamp );
320 $rev[
'revid'] = (int)$row->ar_rev_id;
322 if ( $fld_parentid && $row->ar_parent_id !==
null ) {
323 $rev[
'parentid'] = (int)$row->ar_parent_id;
325 if ( $fld_user || $fld_userid ) {
326 if ( $row->ar_deleted & RevisionRecord::DELETED_USER ) {
327 $rev[
'userhidden'] =
true;
330 if ( RevisionRecord::userCanBitfield(
332 RevisionRecord::DELETED_USER,
336 $rev[
'user'] = $row->ar_user_text;
339 $rev[
'userid'] = (int)$row->ar_user;
344 if ( $fld_comment || $fld_parsedcomment ) {
345 if ( $row->ar_deleted & RevisionRecord::DELETED_COMMENT ) {
346 $rev[
'commenthidden'] =
true;
349 if ( RevisionRecord::userCanBitfield(
351 RevisionRecord::DELETED_COMMENT,
354 $comment = $this->commentStore->getComment(
'ar_comment', $row )->text;
355 if ( $fld_comment ) {
356 $rev[
'comment'] = $comment;
358 if ( $fld_parsedcomment ) {
359 $rev[
'parsedcomment'] = $formattedComments[$row->ar_id];
365 $rev[
'minor'] = $row->ar_minor_edit == 1;
368 $rev[
'len'] = $row->ar_len;
371 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
372 $rev[
'sha1hidden'] =
true;
375 if ( RevisionRecord::userCanBitfield(
377 RevisionRecord::DELETED_TEXT,
380 if ( $row->ar_sha1 !=
'' ) {
381 $rev[
'sha1'] = Wikimedia\base_convert( $row->ar_sha1, 36, 16, 40 );
387 if ( $fld_content ) {
388 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
389 $rev[
'texthidden'] =
true;
392 if ( RevisionRecord::userCanBitfield(
394 RevisionRecord::DELETED_TEXT,
397 ApiResult::setContentValue( $rev,
'text',
398 $this->revisionStore->newRevisionFromArchiveRow( $row )
399 ->getContent( SlotRecord::MAIN )->serialize() );
404 if ( $row->ts_tags ) {
405 $tags = explode(
',', $row->ts_tags );
406 ApiResult::setIndexedTagName( $tags,
'tag' );
407 $rev[
'tags'] = $tags;
413 if ( $anyHidden && ( $row->ar_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
414 $rev[
'suppressed'] =
true;
417 if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
418 $pageID = $newPageID++;
419 $pageMap[$row->ar_namespace][$row->ar_title] = $pageID;
420 $a = [
'revisions' => [ $rev ] ];
421 ApiResult::setIndexedTagName( $a[
'revisions'],
'rev' );
422 $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
426 $a[
'token'] = $token;
428 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $pageID, $a );
430 $pageID = $pageMap[$row->ar_namespace][$row->ar_title];
431 $fit = $result->addValue(
436 if ( $mode ==
'all' || $mode ==
'revs' ) {
438 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
446 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );
456 ParamValidator::PARAM_TYPE =>
'timestamp',
460 ParamValidator::PARAM_TYPE =>
'timestamp',
464 ParamValidator::PARAM_TYPE => [
468 ParamValidator::PARAM_DEFAULT =>
'older',
471 'newer' =>
'api-help-paramvalue-direction-newer',
472 'older' =>
'api-help-paramvalue-direction-older',
486 ParamValidator::PARAM_DEFAULT =>
false,
490 ParamValidator::PARAM_TYPE =>
'namespace',
491 ParamValidator::PARAM_DEFAULT =>
NS_MAIN,
496 ParamValidator::PARAM_TYPE =>
'user',
497 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
500 ParamValidator::PARAM_TYPE =>
'user',
501 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
504 ParamValidator::PARAM_DEFAULT =>
'user|comment',
505 ParamValidator::PARAM_TYPE => [
519 ParamValidator::PARAM_ISMULTI =>
true,
521 EnumDef::PARAM_DEPRECATED_VALUES => [
526 ParamValidator::PARAM_DEFAULT => 10,
527 ParamValidator::PARAM_TYPE =>
'limit',
528 IntegerDef::PARAM_MIN => 1,