47 $this->
addDeprecation(
'apiwarn-deprecation-deletedrevs',
'action=query&list=deletedrevs' );
51 $commentStore = CommentStore::getStore();
53 $prop = array_flip( $params[
'prop'] );
54 $fld_parentid = isset( $prop[
'parentid'] );
55 $fld_revid = isset( $prop[
'revid'] );
56 $fld_user = isset( $prop[
'user'] );
57 $fld_userid = isset( $prop[
'userid'] );
58 $fld_comment = isset( $prop[
'comment'] );
59 $fld_parsedcomment = isset( $prop[
'parsedcomment'] );
60 $fld_minor = isset( $prop[
'minor'] );
61 $fld_len = isset( $prop[
'len'] );
62 $fld_sha1 = isset( $prop[
'sha1'] );
63 $fld_content = isset( $prop[
'content'] );
64 $fld_token = isset( $prop[
'token'] );
65 $fld_tags = isset( $prop[
'tags'] );
80 $titles = $pageSet->getTitles();
87 if ( count( $titles ) > 0 ) {
89 } elseif ( $params[
'user'] !==
null ) {
93 if ( $mode ==
'revs' || $mode ==
'user' ) {
95 foreach ( [
'from',
'to',
'prefix', ] as $p ) {
96 if ( $params[$p] !==
null ) {
97 $this->
dieWithError( [
'apierror-deletedrevs-param-not-1-2', $p ],
'badparams' );
101 foreach ( [
'start',
'end' ] as $p ) {
102 if ( $params[$p] !==
null ) {
103 $this->
dieWithError( [
'apierror-deletedrevs-param-not-3', $p ],
'badparams' );
108 if ( $params[
'user'] !==
null && $params[
'excludeuser'] !==
null ) {
109 $this->
dieWithError(
'user and excludeuser cannot be used together',
'badparams' );
112 $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
113 $arQuery = $revisionStore->getArchiveQueryInfo();
117 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
123 if ( $params[
'tag'] !==
null ) {
126 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
128 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
130 $this->
addWhereFld(
'ct_tag_id', $changeTagDefStore->getId( $params[
'tag'] ) );
138 if ( $fld_content ) {
145 $limit = $params[
'limit'];
147 if ( $limit ==
'max' ) {
148 $limit = $this->
getMain()->canApiHighLimits() ? $botMax : $userMax;
152 $limit = $this->
getMain()->getParamValidator()->validateValue(
153 $this,
'limit', $limit, [
154 ParamValidator::PARAM_TYPE =>
'limit',
155 IntegerDef::PARAM_MIN => 1,
156 IntegerDef::PARAM_MAX => $userMax,
157 IntegerDef::PARAM_MAX2 => $botMax,
158 IntegerDef::PARAM_IGNORE_RANGE =>
true,
167 $dir = $params[
'dir'];
170 if ( $mode ==
'revs' ) {
172 $where = $lb->constructSet(
'ar', $db );
174 } elseif ( $mode ==
'all' ) {
175 $this->
addWhereFld(
'ar_namespace', $params[
'namespace'] );
177 $from = $params[
'from'] ===
null
180 $to = $params[
'to'] ===
null
185 if ( isset( $params[
'prefix'] ) ) {
186 $this->
addWhere(
'ar_title' . $db->buildLike(
187 $this->titlePartToKey( $params[
'prefix'], $params[
'namespace'] ),
188 $db->anyString() ) );
192 if ( $params[
'user'] !==
null ) {
194 $actorQuery = ActorMigration::newMigration()
195 ->getWhere( $db,
'ar_user', $params[
'user'],
false );
196 $this->
addTables( $actorQuery[
'tables'] );
198 $this->
addWhere( $actorQuery[
'conds'] );
199 } elseif ( $params[
'excludeuser'] !==
null ) {
201 $actorQuery = ActorMigration::newMigration()
202 ->getWhere( $db,
'ar_user', $params[
'excludeuser'] );
203 $this->
addTables( $actorQuery[
'tables'] );
205 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
208 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
213 $bitmask = RevisionRecord::DELETED_USER;
215 ->userHasAnyRight( $user,
'suppressrevision',
'viewsuppressed' )
217 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
222 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
226 if ( $params[
'continue'] !==
null ) {
227 $cont = explode(
'|', $params[
'continue'] );
228 $op = ( $dir ==
'newer' ?
'>' :
'<' );
229 if ( $mode ==
'all' || $mode ==
'revs' ) {
233 $title = $db->addQuotes( $cont[1] );
234 $ts = $db->addQuotes( $db->timestamp( $cont[2] ) );
235 $ar_id = (int)$cont[3];
237 $this->
addWhere(
"ar_namespace $op $ns OR " .
238 "(ar_namespace = $ns AND " .
239 "(ar_title $op $title OR " .
240 "(ar_title = $title AND " .
241 "(ar_timestamp $op $ts OR " .
242 "(ar_timestamp = $ts AND " .
243 "ar_id $op= $ar_id)))))" );
246 $ts = $db->addQuotes( $db->timestamp( $cont[0] ) );
247 $ar_id = (int)$cont[1];
249 $this->
addWhere(
"ar_timestamp $op $ts OR " .
250 "(ar_timestamp = $ts AND " .
251 "ar_id $op= $ar_id)" );
256 if ( $mode ==
'all' ) {
257 if ( $params[
'unique'] ) {
259 $this->
addOption(
'GROUP BY',
'ar_title' );
261 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
264 'ar_timestamp' . $sort,
269 if ( $mode ==
'revs' ) {
282 foreach (
$res as $row ) {
283 if ( ++$count > $limit ) {
285 if ( $mode ==
'all' || $mode ==
'revs' ) {
287 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
298 $rev[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->ar_timestamp );
300 $rev[
'revid'] = (int)$row->ar_rev_id;
302 if ( $fld_parentid && $row->ar_parent_id !==
null ) {
303 $rev[
'parentid'] = (int)$row->ar_parent_id;
305 if ( $fld_user || $fld_userid ) {
306 if ( $row->ar_deleted & RevisionRecord::DELETED_USER ) {
307 $rev[
'userhidden'] =
true;
310 if ( RevisionRecord::userCanBitfield(
312 RevisionRecord::DELETED_USER,
316 $rev[
'user'] = $row->ar_user_text;
319 $rev[
'userid'] = (int)$row->ar_user;
324 if ( $fld_comment || $fld_parsedcomment ) {
325 if ( $row->ar_deleted & RevisionRecord::DELETED_COMMENT ) {
326 $rev[
'commenthidden'] =
true;
329 if ( RevisionRecord::userCanBitfield(
331 RevisionRecord::DELETED_COMMENT,
334 $comment = $commentStore->getComment(
'ar_comment', $row )->text;
335 if ( $fld_comment ) {
336 $rev[
'comment'] = $comment;
338 if ( $fld_parsedcomment ) {
339 $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
346 $rev[
'minor'] = $row->ar_minor_edit == 1;
349 $rev[
'len'] = $row->ar_len;
352 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
353 $rev[
'sha1hidden'] =
true;
356 if ( RevisionRecord::userCanBitfield(
358 RevisionRecord::DELETED_TEXT,
361 if ( $row->ar_sha1 !=
'' ) {
362 $rev[
'sha1'] = Wikimedia\base_convert( $row->ar_sha1, 36, 16, 40 );
368 if ( $fld_content ) {
369 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
370 $rev[
'texthidden'] =
true;
373 if ( RevisionRecord::userCanBitfield(
375 RevisionRecord::DELETED_TEXT,
378 ApiResult::setContentValue( $rev,
'text',
379 $revisionStore->newRevisionFromArchiveRow( $row )
380 ->getContent( SlotRecord::MAIN )->serialize() );
385 if ( $row->ts_tags ) {
386 $tags = explode(
',', $row->ts_tags );
387 ApiResult::setIndexedTagName( $tags,
'tag' );
388 $rev[
'tags'] = $tags;
394 if ( $anyHidden && ( $row->ar_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
395 $rev[
'suppressed'] =
true;
398 if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
399 $pageID = $newPageID++;
400 $pageMap[$row->ar_namespace][$row->ar_title] = $pageID;
401 $a = [
'revisions' => [ $rev ] ];
402 ApiResult::setIndexedTagName( $a[
'revisions'],
'rev' );
403 $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
406 $a[
'token'] = $token;
408 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $pageID, $a );
410 $pageID = $pageMap[$row->ar_namespace][$row->ar_title];
411 $fit = $result->addValue(
416 if ( $mode ==
'all' || $mode ==
'revs' ) {
418 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
426 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );