39 parent::__construct( $query, $moduleName,
'adr' );
50 $services = MediaWikiServices::getInstance();
51 $revisionStore = $services->getRevisionStore();
56 if ( $params[
'namespace'] === [] ) {
57 if ( $resultPageSet ===
null ) {
67 if ( $params[
'user'] !==
null ) {
71 if ( $mode ==
'user' ) {
72 foreach ( [
'from',
'to',
'prefix',
'excludeuser' ] as $param ) {
73 if ( $params[$param] !==
null ) {
76 [
'apierror-invalidparammix-cannotusewith', $p . $param,
"{$p}user" ],
82 foreach ( [
'start',
'end' ] as $param ) {
83 if ( $params[$param] !==
null ) {
86 [
'apierror-invalidparammix-mustusewith', $p . $param,
"{$p}user" ],
97 $dir = $params[
'dir'];
98 $optimizeGenerateTitles =
false;
99 if ( $mode ===
'all' && $params[
'generatetitles'] && $resultPageSet !==
null ) {
100 if ( $dir ===
'newer' ) {
101 $optimizeGenerateTitles =
true;
104 $this->
addWarning( [
'apiwarn-alldeletedrevisions-performance', $p ],
'performance' );
108 if ( $resultPageSet ===
null ) {
110 $arQuery = $revisionStore->getArchiveQueryInfo();
114 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
118 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
119 if ( $optimizeGenerateTitles ) {
122 $this->
addFields( [
'ar_timestamp',
'ar_rev_id',
'ar_id' ] );
126 if ( $this->fld_tags ) {
130 if ( $params[
'tag'] !==
null ) {
133 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
135 $changeTagDefStore = $services->getChangeTagDefStore();
137 $this->
addWhereFld(
'ct_tag_id', $changeTagDefStore->getId( $params[
'tag'] ) );
145 if ( ( $this->fld_comment || $this->fld_parsedcomment ) &&
148 $this->
dieWithError(
'apierror-cantview-deleted-comment',
'permissiondenied' );
150 if ( $this->fetchContent &&
153 $this->
dieWithError(
'apierror-cantview-deleted-revision-content',
'permissiondenied' );
158 if ( $mode ==
'all' ) {
159 $namespaces = $params[
'namespace'] ??
160 $services->getNamespaceInfo()->getValidNamespaces();
167 if ( $params[
'from'] !==
null || $params[
'to'] !==
null ) {
168 $isDirNewer = ( $dir ===
'newer' );
169 $after = ( $isDirNewer ?
'>=' :
'<=' );
170 $before = ( $isDirNewer ?
'<=' :
'>=' );
172 foreach ( $namespaces as $ns ) {
174 if ( $params[
'from'] !==
null ) {
175 $w[] =
'ar_title' . $after .
178 if ( $params[
'to'] !==
null ) {
179 $w[] =
'ar_title' . $before .
185 if ( count( $where ) == 1 ) {
186 $where = key( $where );
190 foreach ( $where as $w => $ns ) {
191 $where2[] = $db->makeList( [ $w,
'ar_namespace' => $ns ],
LIST_AND );
197 if ( isset( $params[
'prefix'] ) ) {
199 foreach ( $namespaces as $ns ) {
200 $w =
'ar_title' . $db->buildLike(
205 if ( count( $where ) == 1 ) {
206 $where = key( $where );
210 foreach ( $where as $w => $ns ) {
211 $where2[] = $db->makeList( [ $w,
'ar_namespace' => $ns ],
LIST_AND );
217 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
218 $miser_ns = $params[
'namespace'];
220 $this->
addWhereFld(
'ar_namespace', $params[
'namespace'] );
225 if ( $params[
'user'] !==
null ) {
227 $actorQuery = ActorMigration::newMigration()
228 ->getWhere( $db,
'ar_user', $params[
'user'],
false );
229 $this->
addTables( $actorQuery[
'tables'] );
231 $this->
addWhere( $actorQuery[
'conds'] );
232 } elseif ( $params[
'excludeuser'] !==
null ) {
234 $actorQuery = ActorMigration::newMigration()
235 ->getWhere( $db,
'ar_user', $params[
'excludeuser'] );
236 $this->
addTables( $actorQuery[
'tables'] );
238 $this->
addWhere(
'NOT(' . $actorQuery[
'conds'] .
')' );
241 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
244 $bitmask = RevisionRecord::DELETED_USER;
246 ->userHasAnyRight( $user,
'suppressrevision',
'viewsuppressed' )
248 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
253 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
257 if ( $params[
'continue'] !==
null ) {
258 $cont = explode(
'|', $params[
'continue'] );
259 $op = ( $dir ==
'newer' ?
'>' :
'<' );
260 if ( $optimizeGenerateTitles ) {
264 $title = $db->addQuotes( $cont[1] );
265 $this->
addWhere(
"ar_namespace $op $ns OR " .
266 "(ar_namespace = $ns AND ar_title $op= $title)" );
267 } elseif ( $mode ==
'all' ) {
271 $title = $db->addQuotes( $cont[1] );
272 $ts = $db->addQuotes( $db->timestamp( $cont[2] ) );
273 $ar_id = (int)$cont[3];
275 $this->
addWhere(
"ar_namespace $op $ns OR " .
276 "(ar_namespace = $ns AND " .
277 "(ar_title $op $title OR " .
278 "(ar_title = $title AND " .
279 "(ar_timestamp $op $ts OR " .
280 "(ar_timestamp = $ts AND " .
281 "ar_id $op= $ar_id)))))" );
284 $ts = $db->addQuotes( $db->timestamp( $cont[0] ) );
285 $ar_id = (int)$cont[1];
287 $this->
addWhere(
"ar_timestamp $op $ts OR " .
288 "(ar_timestamp = $ts AND " .
289 "ar_id $op= $ar_id)" );
293 $this->
addOption(
'LIMIT', $this->limit + 1 );
295 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
297 if ( $optimizeGenerateTitles ) {
299 if ( $params[
'namespace'] ===
null || count( array_unique( $params[
'namespace'] ) ) > 1 ) {
300 $orderby[] =
"ar_namespace $sort";
302 $orderby[] =
"ar_title $sort";
303 } elseif ( $mode ==
'all' ) {
305 if ( $params[
'namespace'] ===
null || count( array_unique( $params[
'namespace'] ) ) > 1 ) {
306 $orderby[] =
"ar_namespace $sort";
308 $orderby[] =
"ar_title $sort";
309 $orderby[] =
"ar_timestamp $sort";
310 $orderby[] =
"ar_id $sort";
314 $orderby[] =
"ar_timestamp $sort";
315 $orderby[] =
"ar_id $sort";
317 $this->
addOption(
'ORDER BY', $orderby );
321 if ( $resultPageSet ===
null ) {
329 foreach (
$res as $row ) {
330 if ( ++$count > $this->limit ) {
332 if ( $optimizeGenerateTitles ) {
334 } elseif ( $mode ==
'all' ) {
336 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
345 if ( $miser_ns !==
null && !in_array( $row->ar_namespace, $miser_ns ) ) {
349 if ( $resultPageSet !==
null ) {
350 if ( $params[
'generatetitles'] ) {
351 $key =
"{$row->ar_namespace}:{$row->ar_title}";
352 if ( !isset( $generated[$key] ) ) {
353 $generated[$key] = Title::makeTitle( $row->ar_namespace, $row->ar_title );
356 $generated[] = $row->ar_rev_id;
359 $revision = $revisionStore->newRevisionFromArchiveRow( $row );
362 if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
363 $index = $nextIndex++;
364 $pageMap[$row->ar_namespace][$row->ar_title] = $index;
365 $title = Title::newFromLinkTarget( $revision->getPageAsLinkTarget() );
367 'pageid' =>
$title->getArticleID(),
368 'revisions' => [ $rev ],
370 ApiResult::setIndexedTagName( $a[
'revisions'],
'rev' );
372 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $index, $a );
374 $index = $pageMap[$row->ar_namespace][$row->ar_title];
375 $fit = $result->addValue(
380 if ( $mode ==
'all' ) {
382 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
392 if ( $resultPageSet !==
null ) {
393 if ( $params[
'generatetitles'] ) {
394 $resultPageSet->populateFromTitles( $generated );
396 $resultPageSet->populateFromRevisionIDs( $generated );
399 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );
404 $ret = parent::getAllowedParams() + [
407 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
408 UserDef::PARAM_RETURN_OBJECT =>
true,
441 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
442 UserDef::PARAM_RETURN_OBJECT =>
true,
449 'generatetitles' => [
454 if ( $this->
getConfig()->
get(
'MiserMode' ) ) {
456 'apihelp-query+alldeletedrevisions-param-miser-user-namespace',
459 'apihelp-query+alldeletedrevisions-param-miser-user-namespace',
468 'action=query&list=alldeletedrevisions&adruser=Example&adrlimit=50'
469 =>
'apihelp-query+alldeletedrevisions-example-user',
470 'action=query&list=alldeletedrevisions&adrdir=newer&adrnamespace=0&adrlimit=50'
471 =>
'apihelp-query+alldeletedrevisions-example-ns-main',
476 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Alldeletedrevisions';
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
getModulePrefix()
Get parameter prefix (usually two letters or an empty string).
getParameter( $paramName, $parseLimit=true)
Get a value for the given parameter.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
addWarning( $msg, $code=null, $data=null)
Add a warning for this module.
getModuleName()
Get the name of the module being executed by this instance.
This class contains a list of pages that the client has requested.
Query module to enumerate all deleted revisions.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Stable to override.
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName)
run(ApiPageSet $resultPageSet=null)
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
addFields( $value)
Add a set of fields to select to the internal array.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
getDB()
Get the Query database connection (read-only) Stable to override.
executeGenderCacheFromResultWrapper(IResultWrapper $res, $fname=__METHOD__, $fieldPrefix='page')
Preprocess the result set to fill the GenderCache with the necessary information before using self::a...
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
titlePartToKey( $titlePart, $namespace=NS_MAIN)
Convert an input title or title prefix into a dbkey.
addWhere( $value)
Add a set of WHERE clauses to the internal array.
setContinueEnumParameter( $paramName, $paramValue)
Overridden to set the generator param if in generator mode.
A base class for functions common to producing a list of revisions.
parseParameters( $params)
Parse the parameters into the various instance fields.
extractRevisionInfo(RevisionRecord $revision, $row)
Extract information from the RevisionRecord.
This is the main query class.