63 $contentHandlerFactory,
85 if ( $params[
'namespace'] === [] ) {
86 if ( $resultPageSet ===
null ) {
96 if ( $params[
'user'] !==
null ) {
100 if ( $mode ==
'user' ) {
101 foreach ( [
'from',
'to',
'prefix',
'excludeuser' ] as $param ) {
102 if ( $params[$param] !==
null ) {
105 [
'apierror-invalidparammix-cannotusewith', $p . $param,
"{$p}user" ],
111 foreach ( [
'start',
'end' ] as $param ) {
112 if ( $params[$param] !==
null ) {
115 [
'apierror-invalidparammix-mustusewith', $p . $param,
"{$p}user" ],
126 $dir = $params[
'dir'];
127 $optimizeGenerateTitles =
false;
128 if ( $mode ===
'all' && $params[
'generatetitles'] && $resultPageSet !==
null ) {
129 if ( $dir ===
'newer' ) {
130 $optimizeGenerateTitles =
true;
133 $this->
addWarning( [
'apiwarn-alldeletedrevisions-performance', $p ],
'performance' );
137 if ( $resultPageSet ===
null ) {
139 $arQuery = $this->revisionStore->getArchiveQueryInfo();
143 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
147 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
148 if ( $optimizeGenerateTitles ) {
151 $this->
addFields( [
'ar_timestamp',
'ar_rev_id',
'ar_id' ] );
153 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
155 $this->
addJoinConds( [
'actor' =>
'actor_id=ar_actor' ] );
159 if ( $this->fld_tags ) {
161 'ts_tags' => $this->changeTagsStore->makeTagSummarySubquery(
'archive', $this->getAuthority() )
165 if ( $params[
'tag'] !==
null ) {
166 if ( !$this->changeTagsStore->canViewTag( $params[
'tag'], $this->getAuthority() ) ) {
172 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
175 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
183 if ( ( $this->fld_comment || $this->fld_parsedcomment ) &&
186 $this->
dieWithError(
'apierror-cantview-deleted-comment',
'permissiondenied' );
188 if ( $this->fetchContent &&
189 !$this->
getAuthority()->isAllowedAny(
'deletedtext',
'undelete' )
191 $this->
dieWithError(
'apierror-cantview-deleted-revision-content',
'permissiondenied' );
196 if ( $mode ==
'all' ) {
197 $namespaces = $params[
'namespace'] ?? $this->namespaceInfo->getValidNamespaces();
204 if ( $params[
'from'] !==
null || $params[
'to'] !==
null ) {
205 $isDirNewer = ( $dir ===
'newer' );
206 $after = ( $isDirNewer ?
'>=' :
'<=' );
207 $before = ( $isDirNewer ?
'<=' :
'>=' );
209 foreach ( $namespaces as $ns ) {
210 if ( $params[
'from'] !==
null ) {
215 if ( $params[
'to'] !==
null ) {
220 $titleParts[$fromTitlePart .
'|' . $toTitlePart][] = $ns;
222 if ( count( $titleParts ) === 1 ) {
223 [ $fromTitlePart, $toTitlePart, ] = explode(
'|', key( $titleParts ), 2 );
224 if ( $fromTitlePart !==
'' ) {
225 $this->
addWhere( $db->expr(
'ar_title', $after, $fromTitlePart ) );
227 if ( $toTitlePart !==
'' ) {
228 $this->
addWhere( $db->expr(
'ar_title', $before, $toTitlePart ) );
232 foreach ( $titleParts as $titlePart => $ns ) {
233 [ $fromTitlePart, $toTitlePart, ] = explode(
'|', $titlePart, 2 );
234 $expr = $db->expr(
'ar_namespace',
'=', $ns );
235 if ( $fromTitlePart !==
'' ) {
236 $expr = $expr->and(
'ar_title', $after, $fromTitlePart );
238 if ( $toTitlePart !==
'' ) {
239 $expr = $expr->and(
'ar_title', $before, $toTitlePart );
243 $this->
addWhere( $db->orExpr( $where ) );
247 if ( isset( $params[
'prefix'] ) ) {
249 foreach ( $namespaces as $ns ) {
250 $prefixTitlePart = $this->
titlePartToKey( $params[
'prefix'], $ns );
251 $titleParts[$prefixTitlePart][] = $ns;
253 if ( count( $titleParts ) === 1 ) {
254 $prefixTitlePart = key( $titleParts );
255 $this->
addWhere( $db->expr(
'ar_title', IExpression::LIKE,
256 new LikeValue( $prefixTitlePart, $db->anyString() )
260 foreach ( $titleParts as $prefixTitlePart => $ns ) {
261 $where[] = $db->expr(
'ar_namespace',
'=', $ns )
262 ->and(
'ar_title', IExpression::LIKE,
263 new LikeValue( $prefixTitlePart, $db->anyString() ) );
265 $this->
addWhere( $db->orExpr( $where ) );
270 $miser_ns = $params[
'namespace'];
272 $this->
addWhereFld(
'ar_namespace', $params[
'namespace'] );
277 if ( $params[
'user'] !==
null ) {
282 $this->
addWhereFld(
'actor_name', $params[
'user'] );
283 } elseif ( $params[
'excludeuser'] !==
null ) {
284 $this->
addWhere( $db->expr(
'actor_name',
'!=', $params[
'excludeuser'] ) );
287 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
289 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
290 $bitmask = RevisionRecord::DELETED_USER;
291 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
292 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
297 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
301 if ( $params[
'continue'] !==
null ) {
302 $op = ( $dir ==
'newer' ?
'>=' :
'<=' );
303 if ( $optimizeGenerateTitles ) {
305 $this->
addWhere( $db->buildComparison( $op, [
306 'ar_namespace' => $cont[0],
307 'ar_title' => $cont[1],
309 } elseif ( $mode ==
'all' ) {
311 $this->
addWhere( $db->buildComparison( $op, [
312 'ar_namespace' => $cont[0],
313 'ar_title' => $cont[1],
314 'ar_timestamp' => $db->timestamp( $cont[2] ),
319 $this->
addWhere( $db->buildComparison( $op, [
320 'ar_timestamp' => $db->timestamp( $cont[0] ),
326 $this->
addOption(
'LIMIT', $this->limit + 1 );
328 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
330 if ( $optimizeGenerateTitles ) {
332 if ( $params[
'namespace'] ===
null || count( array_unique( $params[
'namespace'] ) ) > 1 ) {
333 $orderby[] =
"ar_namespace $sort";
335 $orderby[] =
"ar_title $sort";
336 } elseif ( $mode ==
'all' ) {
338 if ( $params[
'namespace'] ===
null || count( array_unique( $params[
'namespace'] ) ) > 1 ) {
339 $orderby[] =
"ar_namespace $sort";
341 $orderby[] =
"ar_title $sort";
342 $orderby[] =
"ar_timestamp $sort";
343 $orderby[] =
"ar_id $sort";
347 $orderby[] =
"ar_timestamp $sort";
348 $orderby[] =
"ar_id $sort";
350 $this->
addOption(
'ORDER BY', $orderby );
352 $res = $this->
select( __METHOD__ );
354 if ( $resultPageSet ===
null ) {
362 foreach ( $res as $row ) {
363 if ( ++$count > $this->limit ) {
365 if ( $optimizeGenerateTitles ) {
367 } elseif ( $mode ==
'all' ) {
369 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
378 if ( $miser_ns !==
null && !in_array( $row->ar_namespace, $miser_ns ) ) {
382 if ( $resultPageSet !==
null ) {
383 if ( $params[
'generatetitles'] ) {
384 $key =
"{$row->ar_namespace}:{$row->ar_title}";
385 if ( !isset( $generated[$key] ) ) {
389 $generated[] = $row->ar_rev_id;
392 $revision = $this->revisionStore->newRevisionFromArchiveRow( $row );
395 if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
396 $index = $nextIndex++;
397 $pageMap[$row->ar_namespace][$row->ar_title] = $index;
398 $title = Title::newFromPageIdentity( $revision->getPage() );
400 'pageid' => $title->getArticleID(),
401 'revisions' => [ $rev ],
405 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $index, $a );
407 $index = $pageMap[$row->ar_namespace][$row->ar_title];
408 $fit = $result->addValue(
413 if ( $mode ==
'all' ) {
415 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
425 if ( $resultPageSet !==
null ) {
426 if ( $params[
'generatetitles'] ) {
427 $resultPageSet->populateFromTitles( $generated );
429 $resultPageSet->populateFromRevisionIDs( $generated );
432 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );
438 $ret = parent::getAllowedParams() + [
440 ParamValidator::PARAM_TYPE =>
'user',
441 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
444 ParamValidator::PARAM_ISMULTI =>
true,
445 ParamValidator::PARAM_TYPE =>
'namespace',
448 ParamValidator::PARAM_TYPE =>
'timestamp',
452 ParamValidator::PARAM_TYPE =>
'timestamp',
456 ParamValidator::PARAM_TYPE => [
460 ParamValidator::PARAM_DEFAULT =>
'older',
463 'newer' =>
'api-help-paramvalue-direction-newer',
464 'older' =>
'api-help-paramvalue-direction-older',
477 ParamValidator::PARAM_TYPE =>
'user',
478 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
485 'generatetitles' => [
486 ParamValidator::PARAM_DEFAULT => false
492 'apihelp-query+alldeletedrevisions-param-miser-user-namespace',
495 'apihelp-query+alldeletedrevisions-param-miser-user-namespace',
505 'action=query&list=alldeletedrevisions&adruser=Example&adrlimit=50'
506 =>
'apihelp-query+alldeletedrevisions-example-user',
507 'action=query&list=alldeletedrevisions&adrdir=newer&adrnamespace=0&adrlimit=50'
508 =>
'apihelp-query+alldeletedrevisions-example-ns-main',
514 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Alldeletedrevisions';
519class_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()