44 private $commentStore;
47 private $commentFormatter;
50 private $revisionStore;
53 private $changeTagDefStore;
56 private $linkBatchFactory;
76 parent::__construct( $query, $moduleName,
'dr' );
77 $this->commentStore = $commentStore;
78 $this->commentFormatter = $commentFormatter;
79 $this->revisionStore = $revisionStore;
80 $this->changeTagDefStore = $changeTagDefStore;
81 $this->linkBatchFactory = $linkBatchFactory;
88 $this->
addDeprecation(
'apiwarn-deprecation-deletedrevs',
'action=query&list=deletedrevs' );
93 $prop = array_fill_keys( $params[
'prop'],
true );
94 $fld_parentid = isset( $prop[
'parentid'] );
95 $fld_revid = isset( $prop[
'revid'] );
96 $fld_user = isset( $prop[
'user'] );
97 $fld_userid = isset( $prop[
'userid'] );
98 $fld_comment = isset( $prop[
'comment'] );
99 $fld_parsedcomment = isset( $prop[
'parsedcomment'] );
100 $fld_minor = isset( $prop[
'minor'] );
101 $fld_len = isset( $prop[
'len'] );
102 $fld_sha1 = isset( $prop[
'sha1'] );
103 $fld_content = isset( $prop[
'content'] );
104 $fld_token = isset( $prop[
'token'] );
105 $fld_tags = isset( $prop[
'tags'] );
114 if ( !$this->
getAuthority()->isAllowed(
'undelete' ) ) {
120 $titles = $pageSet->getPages();
127 if ( count( $titles ) > 0 ) {
129 } elseif ( $params[
'user'] !==
null ) {
133 if ( $mode ==
'revs' || $mode ==
'user' ) {
135 foreach ( [
'from',
'to',
'prefix', ] as $p ) {
136 if ( $params[$p] !==
null ) {
137 $this->
dieWithError( [
'apierror-deletedrevs-param-not-1-2', $p ],
'badparams' );
141 foreach ( [
'start',
'end' ] as $p ) {
142 if ( $params[$p] !==
null ) {
143 $this->
dieWithError( [
'apierror-deletedrevs-param-not-3', $p ],
'badparams' );
148 if ( $params[
'user'] !==
null && $params[
'excludeuser'] !==
null ) {
149 $this->
dieWithError(
'user and excludeuser cannot be used together',
'badparams' );
152 $arQuery = $this->revisionStore->getArchiveQueryInfo();
156 $this->
addFields( [
'ar_title',
'ar_namespace' ] );
162 if ( $params[
'tag'] !==
null ) {
165 [
'change_tag' => [
'JOIN', [
'ar_rev_id=ct_rev_id' ] ] ]
168 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $params[
'tag'] ) );
176 if ( $fld_content ) {
183 $limit = $params[
'limit'];
185 if ( $limit ==
'max' ) {
186 $limit = $this->
getMain()->canApiHighLimits() ? $botMax : $userMax;
190 $limit = $this->
getMain()->getParamValidator()->validateValue(
191 $this,
'limit', $limit, [
192 ParamValidator::PARAM_TYPE =>
'limit',
193 IntegerDef::PARAM_MIN => 1,
194 IntegerDef::PARAM_MAX => $userMax,
195 IntegerDef::PARAM_MAX2 => $botMax,
196 IntegerDef::PARAM_IGNORE_RANGE =>
true,
205 $dir = $params[
'dir'];
208 if ( $mode ==
'revs' ) {
209 $lb = $this->linkBatchFactory->newLinkBatch( $titles );
210 $where = $lb->constructSet(
'ar', $db );
212 } elseif ( $mode ==
'all' ) {
213 $this->
addWhereFld(
'ar_namespace', $params[
'namespace'] );
215 $from = $params[
'from'] ===
null
218 $to = $params[
'to'] ===
null
223 if ( isset( $params[
'prefix'] ) ) {
224 $this->
addWhere(
'ar_title' . $db->buildLike(
225 $this->titlePartToKey( $params[
'prefix'], $params[
'namespace'] ),
226 $db->anyString() ) );
230 if ( $params[
'user'] !==
null ) {
232 $this->
addWhereFld(
'actor_name', $params[
'user'] );
233 } elseif ( $params[
'excludeuser'] !==
null ) {
234 $this->
addWhere(
'actor_name<>' . $db->addQuotes( $params[
'excludeuser'] ) );
237 if ( $params[
'user'] !==
null || $params[
'excludeuser'] !==
null ) {
241 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
242 $bitmask = RevisionRecord::DELETED_USER;
243 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
244 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
249 $this->
addWhere( $db->bitAnd(
'ar_deleted', $bitmask ) .
" != $bitmask" );
253 if ( $params[
'continue'] !==
null ) {
254 $op = ( $dir ==
'newer' ?
'>=' :
'<=' );
255 if ( $mode ==
'all' || $mode ==
'revs' ) {
257 $this->
addWhere( $db->buildComparison( $op, [
258 'ar_namespace' => $cont[0],
259 'ar_title' => $cont[1],
260 'ar_timestamp' => $db->timestamp( $cont[2] ),
265 $this->
addWhere( $db->buildComparison( $op, [
266 'ar_timestamp' => $db->timestamp( $cont[0] ),
273 if ( $mode ==
'all' ) {
274 if ( $params[
'unique'] ) {
276 $this->
addOption(
'GROUP BY',
'ar_title' );
278 $sort = ( $dir ==
'newer' ?
'' :
' DESC' );
281 'ar_timestamp' . $sort,
286 if ( $mode ==
'revs' ) {
297 $formattedComments = [];
298 if ( $fld_parsedcomment ) {
299 $formattedComments = $this->commentFormatter->formatItems(
300 $this->commentFormatter->rows(
$res )
301 ->indexField(
'ar_id' )
302 ->commentKey(
'ar_comment' )
303 ->namespaceField(
'ar_namespace' )
304 ->titleField(
'ar_title' )
311 foreach (
$res as $row ) {
312 if ( ++$count > $limit ) {
314 if ( $mode ==
'all' || $mode ==
'revs' ) {
316 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
327 $rev[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->ar_timestamp );
329 $rev[
'revid'] = (int)$row->ar_rev_id;
331 if ( $fld_parentid && $row->ar_parent_id !==
null ) {
332 $rev[
'parentid'] = (int)$row->ar_parent_id;
334 if ( $fld_user || $fld_userid ) {
335 if ( $row->ar_deleted & RevisionRecord::DELETED_USER ) {
336 $rev[
'userhidden'] =
true;
339 if ( RevisionRecord::userCanBitfield(
341 RevisionRecord::DELETED_USER,
345 $rev[
'user'] = $row->ar_user_text;
348 $rev[
'userid'] = (int)$row->ar_user;
353 if ( $fld_comment || $fld_parsedcomment ) {
354 if ( $row->ar_deleted & RevisionRecord::DELETED_COMMENT ) {
355 $rev[
'commenthidden'] =
true;
358 if ( RevisionRecord::userCanBitfield(
360 RevisionRecord::DELETED_COMMENT,
363 $comment = $this->commentStore->getComment(
'ar_comment', $row )->text;
364 if ( $fld_comment ) {
365 $rev[
'comment'] = $comment;
367 if ( $fld_parsedcomment ) {
368 $rev[
'parsedcomment'] = $formattedComments[$row->ar_id];
374 $rev[
'minor'] = $row->ar_minor_edit == 1;
377 $rev[
'len'] = $row->ar_len;
380 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
381 $rev[
'sha1hidden'] =
true;
384 if ( RevisionRecord::userCanBitfield(
386 RevisionRecord::DELETED_TEXT,
389 if ( $row->ar_sha1 !=
'' ) {
390 $rev[
'sha1'] = Wikimedia\base_convert( $row->ar_sha1, 36, 16, 40 );
396 if ( $fld_content ) {
397 if ( $row->ar_deleted & RevisionRecord::DELETED_TEXT ) {
398 $rev[
'texthidden'] =
true;
401 if ( RevisionRecord::userCanBitfield(
403 RevisionRecord::DELETED_TEXT,
407 $this->revisionStore->newRevisionFromArchiveRow( $row )
408 ->getContent( SlotRecord::MAIN )->serialize() );
413 if ( $row->ts_tags ) {
414 $tags = explode(
',', $row->ts_tags );
416 $rev[
'tags'] = $tags;
422 if ( $anyHidden && ( $row->ar_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
423 $rev[
'suppressed'] =
true;
426 if ( !isset( $pageMap[$row->ar_namespace][$row->ar_title] ) ) {
427 $pageID = $newPageID++;
428 $pageMap[$row->ar_namespace][$row->ar_title] = $pageID;
429 $a = [
'revisions' => [ $rev ] ];
435 $a[
'token'] = $token;
437 $fit = $result->addValue( [
'query', $this->
getModuleName() ], $pageID, $a );
439 $pageID = $pageMap[$row->ar_namespace][$row->ar_title];
440 $fit = $result->addValue(
445 if ( $mode ==
'all' || $mode ==
'revs' ) {
447 "$row->ar_namespace|$row->ar_title|$row->ar_timestamp|$row->ar_id"
455 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'page' );
465 ParamValidator::PARAM_TYPE =>
'timestamp',
469 ParamValidator::PARAM_TYPE =>
'timestamp',
473 ParamValidator::PARAM_TYPE => [
477 ParamValidator::PARAM_DEFAULT =>
'older',
491 ParamValidator::PARAM_DEFAULT =>
false,
495 ParamValidator::PARAM_TYPE =>
'namespace',
496 ParamValidator::PARAM_DEFAULT =>
NS_MAIN,
501 ParamValidator::PARAM_TYPE =>
'user',
502 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
505 ParamValidator::PARAM_TYPE =>
'user',
506 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'id',
'interwiki' ],
509 ParamValidator::PARAM_DEFAULT =>
'user|comment',
510 ParamValidator::PARAM_TYPE => [
524 ParamValidator::PARAM_ISMULTI =>
true
527 ParamValidator::PARAM_DEFAULT => 10,
528 ParamValidator::PARAM_TYPE =>
'limit',
529 IntegerDef::PARAM_MIN => 1,
541 'action=query&list=deletedrevs&titles=Main%20Page|Talk:Main%20Page&' .
542 'drprop=user|comment|content'
543 =>
'apihelp-query+deletedrevs-example-mode1',
544 'action=query&list=deletedrevs&druser=Bob&drlimit=50'
545 =>
'apihelp-query+deletedrevs-example-mode2',
546 'action=query&list=deletedrevs&drdir=newer&drlimit=50'
547 =>
'apihelp-query+deletedrevs-example-mode3-main',
548 'action=query&list=deletedrevs&drdir=newer&drlimit=50&drnamespace=1&drunique='
549 =>
'apihelp-query+deletedrevs-example-mode3-talk',
554 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Deletedrevs';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
getMain()
Get the main module.
const PARAM_HELP_MSG_INFO
(array) Specify additional information tags for the parameter.
parseContinueParamOrDie(string $continue, array $types)
Parse the 'continue' parameter in the usual format and validate the types of each part,...
addDeprecation( $msg, $feature, $data=[])
Add a deprecation warning for this module.
const LIMIT_BIG1
Fast query, standard limit.
const LIMIT_SML2
Slow query, apihighlimits limit.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const LIMIT_SML1
Slow query, standard limit.
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
const LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
lacksSameOriginSecurity()
Returns true if the current request breaks the same-origin policy.
This is a base class for all Query modules.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
addWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, and an ORDER BY clause to sort in the right direction.
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)
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 ] )
getPageSet()
Get the PageSet object to work on.
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.
Query module to enumerate all deleted revisions.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, RowCommentFormatter $commentFormatter, RevisionStore $revisionStore, NameTableStore $changeTagDefStore, LinkBatchFactory $linkBatchFactory)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
isDeprecated()
Indicates whether this module is deprecated.
This is the main query class.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static setContentValue(array &$arr, $name, $value, $flags=0)
Add an output value to the array by name and mark as META_CONTENT.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.