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'] );
106 if ( !$this->
getAuthority()->isAllowed(
'undelete' ) ) {
112 $titles = $pageSet->getPages();
119 if ( count( $titles ) > 0 ) {
121 } elseif ( $params[
'user'] !==
null ) {
125 if ( $mode ==
'revs' || $mode ==
'user' ) {
127 foreach ( [
'from',
'to',
'prefix', ] as $p ) {
128 if ( $params[$p] !==
null ) {
129 $this->
dieWithError( [
'apierror-deletedrevs-param-not-1-2', $p ],
'badparams' );
133 foreach ( [
'start',
'end' ] as $p ) {
134 if ( $params[$p] !==
null ) {
135 $this->
dieWithError( [
'apierror-deletedrevs-param-not-3', $p ],
'badparams' );
140 if ( $params[
'user'] !==
null && $params[
'excludeuser'] !==
null ) {
141 $this->
dieWithError(
'user and excludeuser cannot be used together',
'badparams' );
144 $arQuery = $this->revisionStore->getArchiveQueryInfo();
148 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
154 if ( $params[
'tag'] !==
null ) {
157 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
160 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
168 if ( $fld_content ) {
175 $limit = $params[
'limit'];
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,
197 $dir = $params[
'dir'];
200 if ( $mode ==
'revs' ) {
201 $lb = $this->linkBatchFactory->newLinkBatch( $titles );
202 $where = $lb->constructSet(
'ar', $db );
204 } elseif ( $mode ==
'all' ) {
205 $this->
addWhereFld(
'ar_namespace', $params[
'namespace'] );
207 $from = $params[
'from'] ===
null
210 $to = $params[
'to'] ===
null
215 if ( isset( $params[
'prefix'] ) ) {
216 $this->
addWhere(
'ar_title' . $db->buildLike(
217 $this->titlePartToKey( $params[
'prefix'], $params[
'namespace'] ),
218 $db->anyString() ) );
222 if ( $params[
'user'] !==
null ) {
224 $this->
addWhereFld(
'actor_name', $params[
'user'] );
225 } elseif ( $params[
'excludeuser'] !==
null ) {
226 $this->
addWhere(
'actor_name<>' . $db->addQuotes( $params[
'excludeuser'] ) );
229 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
233 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
234 $bitmask = RevisionRecord::DELETED_USER;
235 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
236 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
241 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
245 if ( $params[
'continue'] !==
null ) {
246 $cont = explode(
'|', $params[
'continue'] );
247 $op = ( $dir ==
'newer' ?
'>' :
'<' );
248 if ( $mode ==
'all' || $mode ==
'revs' ) {
252 $title = $db->addQuotes( $cont[1] );
253 $ts = $db->addQuotes( $db->timestamp( $cont[2] ) );
254 $ar_id = (int)$cont[3];
256 $this->
addWhere(
"ar_namespace $op $ns OR " .
257 "(ar_namespace = $ns AND " .
258 "(ar_title $op $title OR " .
259 "(ar_title = $title AND " .
260 "(ar_timestamp $op $ts OR " .
261 "(ar_timestamp = $ts AND " .
262 "ar_id $op= $ar_id)))))" );
265 $ts = $db->addQuotes( $db->timestamp( $cont[0] ) );
266 $ar_id = (int)$cont[1];
268 $this->
addWhere(
"ar_timestamp $op $ts OR " .
269 "(ar_timestamp = $ts AND " .
270 "ar_id $op= $ar_id)" );
275 if ( $mode ==
'all' ) {
276 if ( $params[
'unique'] ) {
278 $this->
addOption(
'GROUP BY',
'ar_title' );
280 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
283 'ar_timestamp' . $sort,
288 if ( $mode ==
'revs' ) {
301 foreach (
$res as $row ) {
302 if ( ++$count > $limit ) {
304 if ( $mode ==
'all' || $mode ==
'revs' ) {
306 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
317 $rev[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->ar_timestamp );
319 $rev[
'revid'] = (int)$row->ar_rev_id;
321 if ( $fld_parentid && $row->ar_parent_id !==
null ) {
322 $rev[
'parentid'] = (int)$row->ar_parent_id;
324 if ( $fld_user || $fld_userid ) {
325 if ( $row->ar_deleted & RevisionRecord::DELETED_USER ) {
326 $rev[
'userhidden'] =
true;
329 if ( RevisionRecord::userCanBitfield(
331 RevisionRecord::DELETED_USER,
335 $rev[
'user'] = $row->ar_user_text;
338 $rev[
'userid'] = (int)$row->ar_user;
343 if ( $fld_comment || $fld_parsedcomment ) {
344 if ( $row->ar_deleted & RevisionRecord::DELETED_COMMENT ) {
345 $rev[
'commenthidden'] =
true;
348 if ( RevisionRecord::userCanBitfield(
350 RevisionRecord::DELETED_COMMENT,
353 $comment = $this->commentStore->getComment(
'ar_comment', $row )->text;
354 if ( $fld_comment ) {
355 $rev[
'comment'] = $comment;
357 if ( $fld_parsedcomment ) {
358 $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
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 );
425 $a[
'token'] = $token;
427 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $pageID, $a );
429 $pageID = $pageMap[$row->ar_namespace][$row->ar_title];
430 $fit = $result->addValue(
435 if ( $mode ==
'all' || $mode ==
'revs' ) {
437 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
445 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );