82 $contentHandlerFactory,
91 $this->revisionStore = $revisionStore;
92 $this->changeTagDefStore = $changeTagDefStore;
93 $this->changeTagsStore = $changeTagsStore;
94 $this->namespaceInfo = $namespaceInfo;
102 $db = $this->
getDB();
108 if (
$params[
'namespace'] === [] ) {
109 if ( $resultPageSet ===
null ) {
119 if (
$params[
'user'] !==
null ) {
123 if ( $mode ==
'user' ) {
124 foreach ( [
'from',
'to',
'prefix',
'excludeuser' ] as $param ) {
125 if (
$params[$param] !==
null ) {
128 [
'apierror-invalidparammix-cannotusewith', $p . $param,
"{$p}user" ],
134 foreach ( [
'start',
'end' ] as $param ) {
135 if (
$params[$param] !==
null ) {
138 [
'apierror-invalidparammix-mustusewith', $p . $param,
"{$p}user" ],
150 $optimizeGenerateTitles =
false;
151 if ( $mode ===
'all' &&
$params[
'generatetitles'] && $resultPageSet !==
null ) {
152 if ( $dir ===
'newer' ) {
153 $optimizeGenerateTitles =
true;
156 $this->
addWarning( [
'apiwarn-alldeletedrevisions-performance', $p ],
'performance' );
160 if ( $resultPageSet ===
null ) {
162 $arQuery = $this->revisionStore->getArchiveQueryInfo();
166 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
170 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
171 if ( $optimizeGenerateTitles ) {
174 $this->
addFields( [
'ar_timestamp',
'ar_rev_id',
'ar_id' ] );
176 if (
$params[
'user'] !==
null ||
$params[
'excludeuser'] !==
null ) {
178 $this->
addJoinConds( [
'actor' =>
'actor_id=ar_actor' ] );
182 if ( $this->fld_tags ) {
184 'ts_tags' => $this->changeTagsStore->makeTagSummarySubquery(
'archive' )
188 if (
$params[
'tag'] !==
null ) {
191 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
202 if ( ( $this->fld_comment || $this->fld_parsedcomment ) &&
205 $this->
dieWithError(
'apierror-cantview-deleted-comment',
'permissiondenied' );
207 if ( $this->fetchContent &&
208 !$this->
getAuthority()->isAllowedAny(
'deletedtext',
'undelete' )
210 $this->
dieWithError(
'apierror-cantview-deleted-revision-content',
'permissiondenied' );
215 if ( $mode ==
'all' ) {
216 $namespaces =
$params[
'namespace'] ?? $this->namespaceInfo->getValidNamespaces();
224 $isDirNewer = ( $dir ===
'newer' );
225 $after = ( $isDirNewer ?
'>=' :
'<=' );
226 $before = ( $isDirNewer ?
'<=' :
'>=' );
228 foreach ( $namespaces as $ns ) {
229 if (
$params[
'from'] !==
null ) {
234 if (
$params[
'to'] !==
null ) {
239 $titleParts[$fromTitlePart .
'|' . $toTitlePart][] = $ns;
241 if ( count( $titleParts ) === 1 ) {
242 [ $fromTitlePart, $toTitlePart, ] = explode(
'|', key( $titleParts ), 2 );
243 if ( $fromTitlePart !==
'' ) {
244 $this->
addWhere( $db->expr(
'ar_title', $after, $fromTitlePart ) );
246 if ( $toTitlePart !==
'' ) {
247 $this->
addWhere( $db->expr(
'ar_title', $before, $toTitlePart ) );
251 foreach ( $titleParts as $titlePart => $ns ) {
252 [ $fromTitlePart, $toTitlePart, ] = explode(
'|', $titlePart, 2 );
253 $expr = $db->expr(
'ar_namespace',
'=', $ns );
254 if ( $fromTitlePart !==
'' ) {
255 $expr = $expr->and(
'ar_title', $after, $fromTitlePart );
257 if ( $toTitlePart !==
'' ) {
258 $expr = $expr->and(
'ar_title', $before, $toTitlePart );
262 $this->
addWhere( $db->orExpr( $where ) );
266 if ( isset(
$params[
'prefix'] ) ) {
268 foreach ( $namespaces as $ns ) {
270 $titleParts[$prefixTitlePart][] = $ns;
272 if ( count( $titleParts ) === 1 ) {
273 $prefixTitlePart = key( $titleParts );
274 $this->
addWhere( $db->expr(
'ar_title', IExpression::LIKE,
275 new LikeValue( $prefixTitlePart, $db->anyString() )
279 foreach ( $titleParts as $prefixTitlePart => $ns ) {
280 $where[] = $db->expr(
'ar_namespace',
'=', $ns )
281 ->and(
'ar_title', IExpression::LIKE,
282 new LikeValue( $prefixTitlePart, $db->anyString() ) );
284 $this->
addWhere( $db->orExpr( $where ) );
289 $miser_ns =
$params[
'namespace'];
296 if (
$params[
'user'] !==
null ) {
302 } elseif (
$params[
'excludeuser'] !==
null ) {
303 $this->
addWhere( $db->expr(
'actor_name',
'!=',
$params[
'excludeuser'] ) );
306 if (
$params[
'user'] !==
null ||
$params[
'excludeuser'] !==
null ) {
308 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
309 $bitmask = RevisionRecord::DELETED_USER;
310 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
311 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
316 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
320 if (
$params[
'continue'] !==
null ) {
321 $op = ( $dir ==
'newer' ?
'>=' :
'<=' );
322 if ( $optimizeGenerateTitles ) {
324 $this->
addWhere( $db->buildComparison( $op, [
325 'ar_namespace' => $cont[0],
326 'ar_title' => $cont[1],
328 } elseif ( $mode ==
'all' ) {
330 $this->
addWhere( $db->buildComparison( $op, [
331 'ar_namespace' => $cont[0],
332 'ar_title' => $cont[1],
333 'ar_timestamp' => $db->timestamp( $cont[2] ),
338 $this->
addWhere( $db->buildComparison( $op, [
339 'ar_timestamp' => $db->timestamp( $cont[0] ),
345 $this->
addOption(
'LIMIT', $this->limit + 1 );
347 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
349 if ( $optimizeGenerateTitles ) {
351 if (
$params[
'namespace'] ===
null || count( array_unique(
$params[
'namespace'] ) ) > 1 ) {
352 $orderby[] =
"ar_namespace $sort";
354 $orderby[] =
"ar_title $sort";
355 } elseif ( $mode ==
'all' ) {
357 if (
$params[
'namespace'] ===
null || count( array_unique(
$params[
'namespace'] ) ) > 1 ) {
358 $orderby[] =
"ar_namespace $sort";
360 $orderby[] =
"ar_title $sort";
361 $orderby[] =
"ar_timestamp $sort";
362 $orderby[] =
"ar_id $sort";
366 $orderby[] =
"ar_timestamp $sort";
367 $orderby[] =
"ar_id $sort";
369 $this->
addOption(
'ORDER BY', $orderby );
371 $res = $this->
select( __METHOD__ );
373 if ( $resultPageSet ===
null ) {
381 foreach ( $res as $row ) {
382 if ( ++$count > $this->limit ) {
384 if ( $optimizeGenerateTitles ) {
386 } elseif ( $mode ==
'all' ) {
388 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
397 if ( $miser_ns !==
null && !in_array( $row->ar_namespace, $miser_ns ) ) {
401 if ( $resultPageSet !==
null ) {
402 if (
$params[
'generatetitles'] ) {
403 $key =
"{$row->ar_namespace}:{$row->ar_title}";
404 if ( !isset( $generated[$key] ) ) {
405 $generated[$key] = Title::makeTitle( $row->ar_namespace, $row->ar_title );
408 $generated[] = $row->ar_rev_id;
411 $revision = $this->revisionStore->newRevisionFromArchiveRow( $row );
414 if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
415 $index = $nextIndex++;
416 $pageMap[$row->ar_namespace][$row->ar_title] = $index;
417 $title = Title::newFromLinkTarget( $revision->getPageAsLinkTarget() );
419 'pageid' => $title->getArticleID(),
420 'revisions' => [ $rev ],
424 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $index, $a );
426 $index = $pageMap[$row->ar_namespace][$row->ar_title];
427 $fit = $result->addValue(
432 if ( $mode ==
'all' ) {
434 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
444 if ( $resultPageSet !==
null ) {
445 if (
$params[
'generatetitles'] ) {
446 $resultPageSet->populateFromTitles( $generated );
448 $resultPageSet->populateFromRevisionIDs( $generated );
451 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );
456 $ret = parent::getAllowedParams() + [
458 ParamValidator::PARAM_TYPE =>
'user',
459 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
462 ParamValidator::PARAM_ISMULTI =>
true,
463 ParamValidator::PARAM_TYPE =>
'namespace',
466 ParamValidator::PARAM_TYPE =>
'timestamp',
470 ParamValidator::PARAM_TYPE =>
'timestamp',
474 ParamValidator::PARAM_TYPE => [
478 ParamValidator::PARAM_DEFAULT =>
'older',
481 'newer' =>
'api-help-paramvalue-direction-newer',
482 'older' =>
'api-help-paramvalue-direction-older',
495 ParamValidator::PARAM_TYPE =>
'user',
496 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'id',
'interwiki' ],
503 'generatetitles' => [
504 ParamValidator::PARAM_DEFAULT => false
510 'apihelp-query+alldeletedrevisions-param-miser-user-namespace',
513 'apihelp-query+alldeletedrevisions-param-miser-user-namespace',
522 'action=query&list=alldeletedrevisions&adruser=Example&adrlimit=50'
523 =>
'apihelp-query+alldeletedrevisions-example-user',
524 'action=query&list=alldeletedrevisions&adrdir=newer&adrnamespace=0&adrlimit=50'
525 =>
'apihelp-query+alldeletedrevisions-example-ns-main',
530 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Alldeletedrevisions';
535class_alias( ApiQueryAllDeletedRevisions::class,
'ApiQueryAllDeletedRevisions' );
array $params
The job parameters.
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()