68 $contentHandlerFactory,
77 $this->revisionStore = $revisionStore;
78 $this->changeTagDefStore = $changeTagDefStore;
79 $this->changeTagsStore = $changeTagsStore;
80 $this->namespaceInfo = $namespaceInfo;
94 if ( $params[
'namespace'] === [] ) {
95 if ( $resultPageSet ===
null ) {
105 if ( $params[
'user'] !==
null ) {
109 if ( $mode ==
'user' ) {
110 foreach ( [
'from',
'to',
'prefix',
'excludeuser' ] as $param ) {
111 if ( $params[$param] !==
null ) {
114 [
'apierror-invalidparammix-cannotusewith', $p . $param,
"{$p}user" ],
120 foreach ( [
'start',
'end' ] as $param ) {
121 if ( $params[$param] !==
null ) {
124 [
'apierror-invalidparammix-mustusewith', $p . $param,
"{$p}user" ],
135 $dir = $params[
'dir'];
136 $optimizeGenerateTitles =
false;
137 if ( $mode ===
'all' && $params[
'generatetitles'] && $resultPageSet !==
null ) {
138 if ( $dir ===
'newer' ) {
139 $optimizeGenerateTitles =
true;
142 $this->
addWarning( [
'apiwarn-alldeletedrevisions-performance', $p ],
'performance' );
146 if ( $resultPageSet ===
null ) {
148 $arQuery = $this->revisionStore->getArchiveQueryInfo();
152 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
156 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
157 if ( $optimizeGenerateTitles ) {
160 $this->
addFields( [
'ar_timestamp',
'ar_rev_id',
'ar_id' ] );
162 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
164 $this->
addJoinConds( [
'actor' =>
'actor_id=ar_actor' ] );
168 if ( $this->fld_tags ) {
170 'ts_tags' => $this->changeTagsStore->makeTagSummarySubquery(
'archive' )
174 if ( $params[
'tag'] !==
null ) {
177 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
180 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
188 if ( ( $this->fld_comment || $this->fld_parsedcomment ) &&
191 $this->
dieWithError(
'apierror-cantview-deleted-comment',
'permissiondenied' );
193 if ( $this->fetchContent &&
194 !$this->
getAuthority()->isAllowedAny(
'deletedtext',
'undelete' )
196 $this->
dieWithError(
'apierror-cantview-deleted-revision-content',
'permissiondenied' );
201 if ( $mode ==
'all' ) {
202 $namespaces = $params[
'namespace'] ?? $this->namespaceInfo->getValidNamespaces();
209 if ( $params[
'from'] !==
null || $params[
'to'] !==
null ) {
210 $isDirNewer = ( $dir ===
'newer' );
211 $after = ( $isDirNewer ?
'>=' :
'<=' );
212 $before = ( $isDirNewer ?
'<=' :
'>=' );
214 foreach ( $namespaces as $ns ) {
215 if ( $params[
'from'] !==
null ) {
220 if ( $params[
'to'] !==
null ) {
225 $titleParts[$fromTitlePart .
'|' . $toTitlePart][] = $ns;
227 if ( count( $titleParts ) === 1 ) {
228 [ $fromTitlePart, $toTitlePart, ] = explode(
'|', key( $titleParts ), 2 );
229 if ( $fromTitlePart !==
'' ) {
230 $this->
addWhere( $db->expr(
'ar_title', $after, $fromTitlePart ) );
232 if ( $toTitlePart !==
'' ) {
233 $this->
addWhere( $db->expr(
'ar_title', $before, $toTitlePart ) );
237 foreach ( $titleParts as $titlePart => $ns ) {
238 [ $fromTitlePart, $toTitlePart, ] = explode(
'|', $titlePart, 2 );
239 $expr = $db->expr(
'ar_namespace',
'=', $ns );
240 if ( $fromTitlePart !==
'' ) {
241 $expr = $expr->and(
'ar_title', $after, $fromTitlePart );
243 if ( $toTitlePart !==
'' ) {
244 $expr = $expr->and(
'ar_title', $before, $toTitlePart );
248 $this->
addWhere( $db->orExpr( $where ) );
252 if ( isset( $params[
'prefix'] ) ) {
254 foreach ( $namespaces as $ns ) {
255 $prefixTitlePart = $this->
titlePartToKey( $params[
'prefix'], $ns );
256 $titleParts[$prefixTitlePart][] = $ns;
258 if ( count( $titleParts ) === 1 ) {
259 $prefixTitlePart = key( $titleParts );
260 $this->
addWhere( $db->expr(
'ar_title', IExpression::LIKE,
261 new LikeValue( $prefixTitlePart, $db->anyString() )
265 foreach ( $titleParts as $prefixTitlePart => $ns ) {
266 $where[] = $db->expr(
'ar_namespace',
'=', $ns )
267 ->and(
'ar_title', IExpression::LIKE,
268 new LikeValue( $prefixTitlePart, $db->anyString() ) );
270 $this->
addWhere( $db->orExpr( $where ) );
275 $miser_ns = $params[
'namespace'];
277 $this->
addWhereFld(
'ar_namespace', $params[
'namespace'] );
282 if ( $params[
'user'] !==
null ) {
287 $this->
addWhereFld(
'actor_name', $params[
'user'] );
288 } elseif ( $params[
'excludeuser'] !==
null ) {
289 $this->
addWhere( $db->expr(
'actor_name',
'!=', $params[
'excludeuser'] ) );
292 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
294 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
295 $bitmask = RevisionRecord::DELETED_USER;
296 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
297 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
302 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
306 if ( $params[
'continue'] !==
null ) {
307 $op = ( $dir ==
'newer' ?
'>=' :
'<=' );
308 if ( $optimizeGenerateTitles ) {
310 $this->
addWhere( $db->buildComparison( $op, [
311 'ar_namespace' => $cont[0],
312 'ar_title' => $cont[1],
314 } elseif ( $mode ==
'all' ) {
316 $this->
addWhere( $db->buildComparison( $op, [
317 'ar_namespace' => $cont[0],
318 'ar_title' => $cont[1],
319 'ar_timestamp' => $db->timestamp( $cont[2] ),
324 $this->
addWhere( $db->buildComparison( $op, [
325 'ar_timestamp' => $db->timestamp( $cont[0] ),
331 $this->
addOption(
'LIMIT', $this->limit + 1 );
333 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
335 if ( $optimizeGenerateTitles ) {
337 if ( $params[
'namespace'] ===
null || count( array_unique( $params[
'namespace'] ) ) > 1 ) {
338 $orderby[] =
"ar_namespace $sort";
340 $orderby[] =
"ar_title $sort";
341 } elseif ( $mode ==
'all' ) {
343 if ( $params[
'namespace'] ===
null || count( array_unique( $params[
'namespace'] ) ) > 1 ) {
344 $orderby[] =
"ar_namespace $sort";
346 $orderby[] =
"ar_title $sort";
347 $orderby[] =
"ar_timestamp $sort";
348 $orderby[] =
"ar_id $sort";
352 $orderby[] =
"ar_timestamp $sort";
353 $orderby[] =
"ar_id $sort";
355 $this->
addOption(
'ORDER BY', $orderby );
357 $res = $this->
select( __METHOD__ );
359 if ( $resultPageSet ===
null ) {
367 foreach ( $res as $row ) {
368 if ( ++$count > $this->limit ) {
370 if ( $optimizeGenerateTitles ) {
372 } elseif ( $mode ==
'all' ) {
374 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
383 if ( $miser_ns !==
null && !in_array( $row->ar_namespace, $miser_ns ) ) {
387 if ( $resultPageSet !==
null ) {
388 if ( $params[
'generatetitles'] ) {
389 $key =
"{$row->ar_namespace}:{$row->ar_title}";
390 if ( !isset( $generated[$key] ) ) {
394 $generated[] = $row->ar_rev_id;
397 $revision = $this->revisionStore->newRevisionFromArchiveRow( $row );
400 if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
401 $index = $nextIndex++;
402 $pageMap[$row->ar_namespace][$row->ar_title] = $index;
403 $title = Title::newFromPageIdentity( $revision->getPage() );
405 'pageid' => $title->getArticleID(),
406 'revisions' => [ $rev ],
410 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $index, $a );
412 $index = $pageMap[$row->ar_namespace][$row->ar_title];
413 $fit = $result->addValue(
418 if ( $mode ==
'all' ) {
420 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
430 if ( $resultPageSet !==
null ) {
431 if ( $params[
'generatetitles'] ) {
432 $resultPageSet->populateFromTitles( $generated );
434 $resultPageSet->populateFromRevisionIDs( $generated );
437 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );
443 $ret = parent::getAllowedParams() + [
445 ParamValidator::PARAM_TYPE =>
'user',
446 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
449 ParamValidator::PARAM_ISMULTI =>
true,
450 ParamValidator::PARAM_TYPE =>
'namespace',
453 ParamValidator::PARAM_TYPE =>
'timestamp',
457 ParamValidator::PARAM_TYPE =>
'timestamp',
461 ParamValidator::PARAM_TYPE => [
465 ParamValidator::PARAM_DEFAULT =>
'older',
468 'newer' =>
'api-help-paramvalue-direction-newer',
469 'older' =>
'api-help-paramvalue-direction-older',
482 ParamValidator::PARAM_TYPE =>
'user',
483 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
490 'generatetitles' => [
491 ParamValidator::PARAM_DEFAULT => false
497 'apihelp-query+alldeletedrevisions-param-miser-user-namespace',
500 'apihelp-query+alldeletedrevisions-param-miser-user-namespace',
510 'action=query&list=alldeletedrevisions&adruser=Example&adrlimit=50'
511 =>
'apihelp-query+alldeletedrevisions-example-user',
512 'action=query&list=alldeletedrevisions&adrdir=newer&adrnamespace=0&adrlimit=50'
513 =>
'apihelp-query+alldeletedrevisions-example-ns-main',
519 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Alldeletedrevisions';
524class_alias( ApiQueryAllDeletedRevisions::class,
'ApiQueryAllDeletedRevisions' );
This class contains a list of pages that the client has requested.
A service to render content.
A service to transform content.
A class containing constants representing the names of configuration variables.
const MiserMode
Name constant for the MiserMode setting, for use with Config::get()