45 private $commentStore;
48 private $userIdentityLookup;
51 private $userNameUtils;
54 private $revisionStore;
57 private $changeTagDefStore;
60 private $actorMigration;
82 parent::__construct( $query, $moduleName,
'uc' );
83 $this->commentStore = $commentStore;
84 $this->userIdentityLookup = $userIdentityLookup;
85 $this->userNameUtils = $userNameUtils;
86 $this->revisionStore = $revisionStore;
87 $this->changeTagDefStore = $changeTagDefStore;
88 $this->actorMigration = $actorMigration;
91 private $params, $multiUserMode, $orderBy, $parentLens;
93 private $fld_ids =
false, $fld_title =
false, $fld_timestamp =
false,
94 $fld_comment =
false, $fld_parsedcomment =
false, $fld_flags =
false,
95 $fld_patrolled =
false, $fld_tags =
false, $fld_size =
false, $fld_sizediff =
false;
101 $prop = array_fill_keys( $this->params[
'prop'],
true );
102 $this->fld_ids = isset( $prop[
'ids'] );
103 $this->fld_title = isset( $prop[
'title'] );
104 $this->fld_comment = isset( $prop[
'comment'] );
105 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
106 $this->fld_size = isset( $prop[
'size'] );
107 $this->fld_sizediff = isset( $prop[
'sizediff'] );
108 $this->fld_flags = isset( $prop[
'flags'] );
109 $this->fld_timestamp = isset( $prop[
'timestamp'] );
110 $this->fld_patrolled = isset( $prop[
'patrolled'] );
111 $this->fld_tags = isset( $prop[
'tags'] );
116 $dbSecondary = $this->
getDB();
118 $sort = ( $this->params[
'dir'] ==
'newer' ?
119 SelectQueryBuilder::SORT_ASC : SelectQueryBuilder::SORT_DESC );
120 $op = ( $this->params[
'dir'] ==
'older' ?
'<' :
'>' );
126 if ( isset( $this->params[
'userprefix'] ) ) {
127 $this->multiUserMode =
true;
128 $this->orderBy =
'name';
134 $userIter = call_user_func(
function () use ( $dbSecondary, $sort, $op, $fname ) {
136 if ( $this->params[
'continue'] !==
null ) {
137 $continue = explode(
'|', $this->params[
'continue'] );
140 $fromName = $continue[1];
145 $from = $fromName ?
"$op= " . $dbSecondary->addQuotes( $fromName ) :
false;
146 $usersBatch = $this->userIdentityLookup
147 ->newSelectQueryBuilder()
150 ->whereUserNamePrefix( $this->params[
'userprefix'] )
151 ->where( $from ? [
"actor_name $from" ] : [] )
152 ->orderByName( $sort )
153 ->fetchUserIdentities();
157 foreach ( $usersBatch as $user ) {
158 if ( ++$count >= $limit ) {
159 $fromName = $user->getName();
164 }
while ( $fromName !==
false );
169 } elseif ( isset( $this->params[
'userids'] ) ) {
170 if ( $this->params[
'userids'] === [] ) {
172 $this->
dieWithError( [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName" );
176 foreach ( $this->params[
'userids'] as $uid ) {
178 $this->
dieWithError( [
'apierror-invaliduserid', $uid ],
'invaliduserid' );
183 $this->orderBy =
'id';
184 $this->multiUserMode = count( $ids ) > 1;
186 $from = $fromId =
false;
187 if ( $this->multiUserMode && $this->params[
'continue'] !==
null ) {
188 $continue = explode(
'|', $this->params[
'continue'] );
191 $fromId = (int)$continue[1];
193 $from =
"$op= $fromId";
196 $userIter = $this->userIdentityLookup
197 ->newSelectQueryBuilder()
198 ->caller( __METHOD__ )
199 ->whereUserIds( $ids )
200 ->orderByUserId( $sort )
201 ->where( $from ? [
"actor_id $from" ] : [] )
202 ->fetchUserIdentities();
203 $batchSize = count( $ids );
204 } elseif ( isset( $this->params[
'iprange'] ) ) {
206 $ipRange = $this->params[
'iprange'];
207 $contribsCIDRLimit = $this->
getConfig()->get( MainConfigNames::RangeContributionsCIDRLimit );
208 if ( IPUtils::isIPv4( $ipRange ) ) {
210 $cidrLimit = $contribsCIDRLimit[
'IPv4'];
211 } elseif ( IPUtils::isIPv6( $ipRange ) ) {
213 $cidrLimit = $contribsCIDRLimit[
'IPv6'];
215 $this->
dieWithError( [
'apierror-invalidiprange', $ipRange ],
'invalidiprange' );
217 $range = IPUtils::parseCIDR( $ipRange )[1];
218 if ( $range ===
false ) {
219 $this->
dieWithError( [
'apierror-invalidiprange', $ipRange ],
'invalidiprange' );
220 } elseif ( $range < $cidrLimit ) {
224 $this->multiUserMode =
true;
225 $this->orderBy =
'name';
230 $userIter = call_user_func(
function () use ( $dbSecondary, $sort, $op, $fname, $ipRange ) {
232 list( $start, $end ) = IPUtils::parseRange( $ipRange );
233 if ( $this->params[
'continue'] !==
null ) {
234 $continue = explode(
'|', $this->params[
'continue'] );
237 $fromName = $continue[1];
238 $fromIPHex = IPUtils::toHex( $fromName );
250 $res = $dbSecondary->newSelectQueryBuilder()
251 ->select(
'ipc_hex' )
252 ->from(
'ip_changes' )
253 ->where( [
'ipc_hex BETWEEN ' . $dbSecondary->addQuotes( $start ) .
254 ' AND ' . $dbSecondary->addQuotes( $end )
256 ->groupBy(
'ipc_hex' )
257 ->orderBy(
'ipc_hex', $sort )
264 foreach (
$res as $row ) {
265 $ipAddr = IPUtils::formatHex( $row->ipc_hex );
266 if ( ++$count >= $limit ) {
272 }
while ( $fromName !==
false );
279 if ( !count( $this->params[
'user'] ) ) {
282 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
285 foreach ( $this->params[
'user'] as $u ) {
289 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
293 if ( $this->userNameUtils->isIP( $u ) || ExternalUserNames::isExternal( $u ) ) {
296 $name = $this->userNameUtils->getCanonical( $u );
297 if ( $name ===
false ) {
300 [
'apierror-baduser', $encParamName,
wfEscapeWikiText( $u ) ],
"baduser_$encParamName"
303 $names[$name] =
null;
307 $this->orderBy =
'name';
308 $this->multiUserMode = count( $names ) > 1;
310 $from = $fromName =
false;
311 if ( $this->multiUserMode && $this->params[
'continue'] !==
null ) {
312 $continue = explode(
'|', $this->params[
'continue'] );
315 $fromName = $continue[1];
316 $from =
"$op= " . $dbSecondary->addQuotes( $fromName );
319 $userIter = $this->userIdentityLookup
320 ->newSelectQueryBuilder()
321 ->caller( __METHOD__ )
322 ->whereUserNames( array_keys( $names ) )
323 ->where( $from ? [
"actor_id $from" ] : [] )
324 ->orderByName( $sort )
325 ->fetchUserIdentities();
326 $batchSize = count( $names );
330 if ( $batchSize > 1 ) {
331 $this->orderBy =
'actor';
335 $limit = $this->params[
'limit'];
337 while ( $userIter->valid() ) {
339 while ( count( $users ) < $batchSize && $userIter->valid() ) {
340 $users[] = $userIter->current();
345 $this->prepareQuery( $users, $limit - $count );
346 $res = $this->
select( __METHOD__, [], $hookData );
348 if ( $this->fld_title ) {
352 if ( $this->fld_sizediff ) {
354 foreach (
$res as $row ) {
355 if ( $row->rev_parent_id ) {
356 $revIds[] = (int)$row->rev_parent_id;
359 $this->parentLens = $this->revisionStore->getRevisionSizes( $revIds );
362 foreach (
$res as $row ) {
363 if ( ++$count > $limit ) {
370 $vals = $this->extractRowInfo( $row );
371 $fit = $this->
processRow( $row, $vals, $hookData ) &&
388 private function prepareQuery( array $users, $limit ) {
390 $db = $this->
getDB();
392 $revQuery = $this->revisionStore->getQueryInfo( [
'page' ] );
393 $revWhere = $this->actorMigration->getWhere( $db,
'rev_user', $users );
395 $orderUserField =
'rev_actor';
396 $userField = $this->orderBy ===
'actor' ?
'rev_actor' :
'actor_name';
397 $tsField =
'rev_timestamp';
403 $this->
addWhere( $revWhere[
'conds'] );
406 if ( $this->params[
'continue'] !==
null ) {
407 $continue = explode(
'|', $this->params[
'continue'] );
408 if ( $this->multiUserMode ) {
410 $modeFlag = array_shift( $continue );
412 $encUser = $db->addQuotes( array_shift( $continue ) );
416 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
417 $encId = (int)$continue[1];
419 $op = ( $this->params[
'dir'] ==
'older' ?
'<' :
'>' );
420 if ( $this->multiUserMode ) {
423 "$userField $op $encUser OR " .
425 "($userField = $encUser AND " .
426 "($tsField $op $encTS OR " .
427 "($tsField = $encTS AND " .
428 "$idField $op= $encId)))"
432 "$tsField $op $encTS OR " .
433 "($tsField = $encTS AND " .
434 "$idField $op= $encId)"
441 if ( !$this->
getAuthority()->isAllowed(
'deletedhistory' ) ) {
442 $bitmask = RevisionRecord::DELETED_USER;
443 } elseif ( !$this->
getAuthority()->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
444 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
449 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
453 if ( count( $users ) > 1 ) {
454 $this->
addWhereRange( $orderUserField, $this->params[
'dir'],
null,
null );
459 $this->params[
'dir'], $this->params[
'start'], $this->params[
'end'] );
462 $this->
addWhereRange( $idField, $this->params[
'dir'],
null,
null );
464 $this->
addWhereFld(
'page_namespace', $this->params[
'namespace'] );
466 $show = $this->params[
'show'];
467 if ( $this->params[
'toponly'] ) {
470 if ( $show !==
null ) {
471 $show = array_fill_keys( $show,
true );
473 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
474 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
475 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
476 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
477 || ( isset( $show[
'top'] ) && isset( $show[
'!top'] ) )
478 || ( isset( $show[
'new'] ) && isset( $show[
'!new'] ) )
483 $this->
addWhereIf(
'rev_minor_edit = 0', isset( $show[
'!minor'] ) );
484 $this->
addWhereIf(
'rev_minor_edit != 0', isset( $show[
'minor'] ) );
486 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED,
487 isset( $show[
'!patrolled'] )
490 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
491 isset( $show[
'patrolled'] )
494 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
495 isset( $show[
'!autopatrolled'] )
498 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
499 isset( $show[
'autopatrolled'] )
501 $this->
addWhereIf( $idField .
' != page_latest', isset( $show[
'!top'] ) );
502 $this->
addWhereIf( $idField .
' = page_latest', isset( $show[
'top'] ) );
503 $this->
addWhereIf(
'rev_parent_id != 0', isset( $show[
'!new'] ) );
504 $this->
addWhereIf(
'rev_parent_id = 0', isset( $show[
'new'] ) );
508 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
509 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] ) || $this->fld_patrolled
512 if ( !$user->useRCPatrol() && !$user->useNPPatrol() ) {
513 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
516 $isFilterset = isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
517 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] );
520 $isFilterset ?
'JOIN' :
'LEFT JOIN',
521 [
'rc_this_oldid = ' . $idField ]
525 $this->
addFieldsIf(
'rc_patrolled', $this->fld_patrolled );
527 if ( $this->fld_tags ) {
531 if ( isset( $this->params[
'tag'] ) ) {
534 [
'change_tag' => [
'JOIN', [ $idField .
' = ct_rev_id' ] ] ]
537 $this->
addWhereFld(
'ct_tag_id', $this->changeTagDefStore->getId( $this->params[
'tag'] ) );
544 'MAX_EXECUTION_TIME',
545 $this->
getConfig()->
get( MainConfigNames::MaxExecutionTimeForExpensiveQueries )
555 private function extractRowInfo( $row ) {
559 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
560 $vals[
'texthidden'] =
true;
565 $vals[
'userid'] = (int)$row->rev_user;
566 $vals[
'user'] = $row->rev_user_text;
567 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
568 $vals[
'userhidden'] =
true;
571 if ( $this->fld_ids ) {
572 $vals[
'pageid'] = (int)$row->rev_page;
573 $vals[
'revid'] = (int)$row->rev_id;
575 if ( $row->rev_parent_id !==
null ) {
576 $vals[
'parentid'] = (int)$row->rev_parent_id;
582 if ( $this->fld_title ) {
586 if ( $this->fld_timestamp ) {
587 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
590 if ( $this->fld_flags ) {
591 $vals[
'new'] = $row->rev_parent_id == 0 && $row->rev_parent_id !==
null;
592 $vals[
'minor'] = (bool)$row->rev_minor_edit;
593 $vals[
'top'] = $row->page_latest == $row->rev_id;
596 if ( $this->fld_comment || $this->fld_parsedcomment ) {
597 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
598 $vals[
'commenthidden'] =
true;
602 $userCanView = RevisionRecord::userCanBitfield(
604 RevisionRecord::DELETED_COMMENT, $this->getAuthority()
607 if ( $userCanView ) {
608 $comment = $this->commentStore->getComment(
'rev_comment', $row )->text;
609 if ( $this->fld_comment ) {
610 $vals[
'comment'] = $comment;
613 if ( $this->fld_parsedcomment ) {
619 if ( $this->fld_patrolled ) {
624 if ( $this->fld_size && $row->rev_len !==
null ) {
625 $vals[
'size'] = (int)$row->rev_len;
628 if ( $this->fld_sizediff
629 && $row->rev_len !==
null
630 && $row->rev_parent_id !==
null
632 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
633 $vals[
'sizediff'] = (int)$row->rev_len - $parentLen;
636 if ( $this->fld_tags ) {
637 if ( $row->ts_tags ) {
638 $tags = explode(
',', $row->ts_tags );
640 $vals[
'tags'] = $tags;
646 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
647 $vals[
'suppressed'] =
true;
653 private function continueStr( $row ) {
654 if ( $this->multiUserMode ) {
655 switch ( $this->orderBy ) {
657 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
659 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
661 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
664 return "$row->rev_timestamp|$row->rev_id";
671 return 'anon-public-user-private';
677 ParamValidator::PARAM_DEFAULT => 10,
678 ParamValidator::PARAM_TYPE =>
'limit',
679 IntegerDef::PARAM_MIN => 1,
684 ParamValidator::PARAM_TYPE =>
'timestamp'
687 ParamValidator::PARAM_TYPE =>
'timestamp'
693 ParamValidator::PARAM_TYPE =>
'user',
694 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'interwiki' ],
695 ParamValidator::PARAM_ISMULTI =>
true
698 ParamValidator::PARAM_TYPE =>
'integer',
699 ParamValidator::PARAM_ISMULTI =>
true
701 'userprefix' =>
null,
704 ParamValidator::PARAM_DEFAULT =>
'older',
705 ParamValidator::PARAM_TYPE => [
711 'newer' =>
'api-help-paramvalue-direction-newer',
712 'older' =>
'api-help-paramvalue-direction-older',
716 ParamValidator::PARAM_ISMULTI =>
true,
717 ParamValidator::PARAM_TYPE =>
'namespace'
720 ParamValidator::PARAM_ISMULTI =>
true,
721 ParamValidator::PARAM_DEFAULT =>
'ids|title|timestamp|comment|size|flags',
722 ParamValidator::PARAM_TYPE => [
737 ParamValidator::PARAM_ISMULTI =>
true,
738 ParamValidator::PARAM_TYPE => [
751 'apihelp-query+usercontribs-param-show',
752 $this->
getConfig()->get( MainConfigNames::RCMaxAge )
757 ParamValidator::PARAM_DEFAULT =>
false,
758 ParamValidator::PARAM_DEPRECATED =>
true,
765 'action=query&list=usercontribs&ucuser=Example'
766 =>
'apihelp-query+usercontribs-example-user',
767 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
768 =>
'apihelp-query+usercontribs-example-ipprefix',
773 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This is not intended to be a long-term part of MediaWiki; it will be deprecated and removed once acto...
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
requireOnlyOneParameter( $params,... $required)
Die if none or more than one of a certain set of parameters is set and not false.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
const LIMIT_BIG1
Fast query, standard limit.
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.
const LIMIT_BIG2
Fast query, apihighlimits limit.
getModuleName()
Get the name of the module being executed by this instance.
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.
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
resetQueryParams()
Blank the internal arrays with query parameters.
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
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)
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.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
This query action adds a list of a specified user's contributions to the output.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getCacheMode( $params)
Get the cache mode for the data generated by this module.
getHelpUrls()
Return links to more detailed help pages about the module.
__construct(ApiQuery $query, $moduleName, CommentStore $commentStore, UserIdentityLookup $userIdentityLookup, UserNameUtils $userNameUtils, RevisionStore $revisionStore, NameTableStore $changeTagDefStore, ActorMigration $actorMigration)
getExamplesMessages()
Returns usage examples for this module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
This is the main query class.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static formatComment( $comment, $title=null, $local=false, $wikiId=null)
This function is called by all recent changes variants, by the page history, and by the user contribu...
A class containing constants representing the names of configuration variables.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
static newFromName( $name, $validate='valid')