Go to the documentation of this file.
35 parent::__construct(
$query, $moduleName,
'uc' );
50 $prop = array_flip( $this->params[
'prop'] );
51 $this->fld_ids = isset( $prop[
'ids'] );
52 $this->fld_title = isset( $prop[
'title'] );
53 $this->fld_comment = isset( $prop[
'comment'] );
54 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
55 $this->fld_size = isset( $prop[
'size'] );
56 $this->fld_sizediff = isset( $prop[
'sizediff'] );
57 $this->fld_flags = isset( $prop[
'flags'] );
58 $this->fld_timestamp = isset( $prop[
'timestamp'] );
59 $this->fld_patrolled = isset( $prop[
'patrolled'] );
60 $this->fld_tags = isset( $prop[
'tags'] );
65 $dbSecondary = $this->
getDB();
72 $this->idMode =
false;
73 if ( isset( $this->params[
'userprefix'] ) ) {
74 $this->prefixMode =
true;
75 $this->multiUserMode =
true;
76 $this->userprefix = $this->params[
'userprefix'];
77 } elseif ( isset( $this->params[
'userids'] ) ) {
80 if ( !
count( $this->params[
'userids'] ) ) {
82 $this->
dieWithError( [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName" );
85 foreach ( $this->params[
'userids']
as $uid ) {
87 $this->
dieWithError( [
'apierror-invaliduserid', $uid ],
'invaliduserid' );
90 $this->userids[] = $uid;
93 $this->prefixMode =
false;
94 $this->multiUserMode = (
count( $this->params[
'userids'] ) > 1 );
99 $this->usernames = [];
100 if ( !
count( $this->params[
'user'] ) ) {
103 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
106 foreach ( $this->params[
'user']
as $u ) {
110 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
116 $this->usernames[] = $u;
119 if (
$name ===
false ) {
122 [
'apierror-baduser', $encParamName,
wfEscapeWikiText( $u ) ],
"baduser_$encParamName"
125 $this->usernames[] =
$name;
128 $this->prefixMode =
false;
129 $this->multiUserMode = (
count( $this->params[
'user'] ) > 1 );
133 $res =
$dbr->select(
'user',
'user_id', [
'user_name' => $this->usernames ], __METHOD__ );
134 foreach (
$res as $row ) {
135 $this->userids[] = $row->user_id;
137 $this->idMode =
count( $this->userids ) ===
count( $this->usernames );
145 $res = $this->
select( __METHOD__, [], $hookData );
147 if ( $this->fld_sizediff ) {
149 foreach (
$res as $row ) {
150 if ( $row->rev_parent_id ) {
151 $revIds[] = $row->rev_parent_id;
160 $limit = $this->params[
'limit'];
163 foreach (
$res as $row ) {
164 if ( ++$count > $limit ) {
172 $fit = $this->
processRow( $row, $vals, $hookData ) &&
194 $tables = [
'page',
'revision' ];
195 $this->
addWhere(
'page_id=rev_page' );
198 if ( !is_null( $this->params[
'continue'] ) ) {
199 $continue = explode(
'|', $this->params[
'continue'] );
200 $db = $this->
getDB();
201 if ( $this->multiUserMode ) {
203 $modeFlag = array_shift( $continue );
205 if ( $this->idMode && $modeFlag ===
'name' ) {
209 $this->idMode =
false;
212 $userField = $this->idMode ?
'rev_user' :
'rev_user_text';
213 $encUser = $db->addQuotes( array_shift( $continue ) );
217 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
218 $encId = (int)$continue[1];
220 $op = ( $this->params[
'dir'] ==
'older' ?
'<' :
'>' );
221 if ( $this->multiUserMode ) {
223 "$userField $op $encUser OR " .
224 "($userField = $encUser AND " .
225 "(rev_timestamp $op $encTS OR " .
226 "(rev_timestamp = $encTS AND " .
227 "rev_id $op= $encId)))"
231 "rev_timestamp $op $encTS OR " .
232 "(rev_timestamp = $encTS AND " .
233 "rev_id $op= $encId)"
240 if ( !
$user->isAllowed(
'deletedhistory' ) ) {
242 } elseif ( !
$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
248 $this->
addWhere( $this->
getDB()->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
252 if ( $this->prefixMode ) {
254 $this->
getDB()->buildLike( $this->userprefix, $this->
getDB()->anyString() ) );
255 } elseif ( $this->idMode ) {
258 $this->
addWhereFld(
'rev_user_text', $this->usernames );
263 if ( $this->multiUserMode ) {
264 $this->
addWhereRange( $this->idMode ?
'rev_user' :
'rev_user_text',
265 $this->params[
'dir'],
null,
null );
268 $this->params[
'dir'], $this->params[
'start'], $this->params[
'end'] );
270 $this->
addWhereRange(
'rev_id', $this->params[
'dir'],
null,
null );
272 $this->
addWhereFld(
'page_namespace', $this->params[
'namespace'] );
274 $show = $this->params[
'show'];
275 if ( $this->params[
'toponly'] ) {
278 if ( !is_null( $show ) ) {
279 $show = array_flip( $show );
281 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
282 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
283 || ( isset( $show[
'top'] ) && isset( $show[
'!top'] ) )
284 || ( isset( $show[
'new'] ) && isset( $show[
'!new'] ) )
289 $this->
addWhereIf(
'rev_minor_edit = 0', isset( $show[
'!minor'] ) );
290 $this->
addWhereIf(
'rev_minor_edit != 0', isset( $show[
'minor'] ) );
291 $this->
addWhereIf(
'rc_patrolled = 0', isset( $show[
'!patrolled'] ) );
292 $this->
addWhereIf(
'rc_patrolled != 0', isset( $show[
'patrolled'] ) );
293 $this->
addWhereIf(
'rev_id != page_latest', isset( $show[
'!top'] ) );
294 $this->
addWhereIf(
'rev_id = page_latest', isset( $show[
'top'] ) );
295 $this->
addWhereIf(
'rev_parent_id != 0', isset( $show[
'!new'] ) );
296 $this->
addWhereIf(
'rev_parent_id = 0', isset( $show[
'new'] ) );
298 $this->
addOption(
'LIMIT', $this->params[
'limit'] + 1 );
313 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
316 if ( !
$user->useRCPatrol() && !
$user->useNPPatrol() ) {
317 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
323 $index[
'recentchanges'] =
'rc_user_text';
324 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ) {
327 $tables = [
'revision',
'recentchanges',
'page' ];
329 $this->
addWhere(
'rc_user_text=rev_user_text' );
330 $this->
addWhere(
'rc_timestamp=rev_timestamp' );
331 $this->
addWhere(
'rc_this_oldid=rev_id' );
336 'rc_user_text=rev_user_text',
337 'rc_timestamp=rev_timestamp',
338 'rc_this_oldid=rev_id' ] ] ] );
344 $this->
addFieldsIf(
'page_latest', $this->fld_flags );
346 $this->
addFieldsIf(
'rev_len', $this->fld_size || $this->fld_sizediff );
347 $this->
addFieldsIf(
'rev_minor_edit', $this->fld_flags );
348 $this->
addFieldsIf(
'rev_parent_id', $this->fld_flags || $this->fld_sizediff || $this->fld_ids );
349 $this->
addFieldsIf(
'rc_patrolled', $this->fld_patrolled );
351 if ( $this->fld_comment || $this->fld_parsedcomment ) {
352 $commentQuery = $this->commentStore->getJoin();
353 $this->
addTables( $commentQuery[
'tables'] );
354 $this->
addFields( $commentQuery[
'fields'] );
358 if ( $this->fld_tags ) {
361 [
'tag_summary' => [
'LEFT JOIN', [
'rev_id=ts_rev_id' ] ] ]
366 if ( isset( $this->params[
'tag'] ) ) {
369 [
'change_tag' => [
'INNER JOIN', [
'rev_id=ct_rev_id' ] ] ]
371 $this->
addWhereFld(
'ct_tag', $this->params[
'tag'] );
374 if ( isset( $index ) ) {
390 $vals[
'texthidden'] =
true;
395 $vals[
'userid'] = (int)$row->rev_user;
396 $vals[
'user'] = $row->rev_user_text;
398 $vals[
'userhidden'] =
true;
401 if ( $this->fld_ids ) {
402 $vals[
'pageid'] = intval( $row->rev_page );
403 $vals[
'revid'] = intval( $row->rev_id );
406 if ( !is_null( $row->rev_parent_id ) ) {
407 $vals[
'parentid'] = intval( $row->rev_parent_id );
413 if ( $this->fld_title ) {
417 if ( $this->fld_timestamp ) {
418 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
421 if ( $this->fld_flags ) {
422 $vals[
'new'] = $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id );
423 $vals[
'minor'] = (bool)$row->rev_minor_edit;
424 $vals[
'top'] = $row->page_latest == $row->rev_id;
427 if ( $this->fld_comment || $this->fld_parsedcomment ) {
429 $vals[
'commenthidden'] =
true;
438 if ( $userCanView ) {
439 $comment = $this->commentStore->getComment( $row )->text;
440 if ( $this->fld_comment ) {
441 $vals[
'comment'] = $comment;
444 if ( $this->fld_parsedcomment ) {
450 if ( $this->fld_patrolled ) {
451 $vals[
'patrolled'] = (bool)$row->rc_patrolled;
454 if ( $this->fld_size && !is_null( $row->rev_len ) ) {
455 $vals[
'size'] = intval( $row->rev_len );
458 if ( $this->fld_sizediff
459 && !is_null( $row->rev_len )
460 && !is_null( $row->rev_parent_id )
462 $parentLen = isset( $this->parentLens[$row->rev_parent_id] )
463 ? $this->parentLens[$row->rev_parent_id]
465 $vals[
'sizediff'] = intval( $row->rev_len - $parentLen );
468 if ( $this->fld_tags ) {
469 if ( $row->ts_tags ) {
470 $tags = explode(
',', $row->ts_tags );
472 $vals[
'tags'] = $tags;
479 $vals[
'suppressed'] =
true;
486 if ( $this->multiUserMode ) {
487 if ( $this->idMode ) {
488 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
490 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
493 return "$row->rev_timestamp|$row->rev_id";
500 return 'anon-public-user-private';
529 'userprefix' =>
null,
572 'apihelp-query+usercontribs-param-show',
586 'action=query&list=usercontribs&ucuser=Example'
587 =>
'apihelp-query+usercontribs-example-user',
588 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
589 =>
'apihelp-query+usercontribs-example-ipprefix',
594 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
getConfig()
Get the Config object.
please add to it if you re going to add events to the MediaWiki code where normally authentication against an external auth plugin would be creating a account $user
processRow( $row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
addFields( $value)
Add a set of fields to select to the internal array.
This is the main query class.
static userCanBitfield( $bitfield, $field, User $user=null, Title $title=null)
Determine if the current user is allowed to view a particular field of this revision,...
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
addTimestampWhereRange( $field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter.
wfTimestamp( $outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getResult()
Get the result object.
Allows to change the fields on the form that will be generated $name
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
getUser()
Get the User object.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
null for the wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
namespace and then decline to actually register it file or subcat img or subcat $title
This is a base class for all Query modules.
const LIMIT_BIG1
Fast query, standard limit.
getDB()
Get the Query database connection (read-only)
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
getExamplesMessages()
Returns usage examples for this module.
static isIP( $name)
Does the string match an anonymous IP address?
addTables( $tables, $alias=null)
Add a set of tables to the internal array.
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
getHelpUrls()
Return links to more detailed help pages about the module.
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.
prepareQuery()
Prepares the query and returns the limit of rows requested.
extractRequestParams( $parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user,...
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
static getParentLengths( $db, array $revIds)
Do a batched query to get the parent revision lengths.
extractRowInfo( $row)
Extract fields from the database row and append them to a result array.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
addWhereFld( $field, $value)
Equivalent to addWhere(array($field => $value))
requireOnlyOneParameter( $params, $required)
Die if none or more than one of a certain set of parameters is set and not false.
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...
selectNamedDB( $name, $db, $groups)
Selects the query database connection with the given name.
const LIMIT_BIG2
Fast query, apihighlimits limit.
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
This document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
null means default in associative array with keys and values unescaped Should be merged with default with a value of false meaning to suppress the attribute in associative array with keys and values unescaped noclasses just before the function returns a value If you return true
addWhere( $value)
Add a set of WHERE clauses to the internal array.
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
addWhereIf( $value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
static addTitleInfo(&$arr, $title, $prefix='')
Add information (title and namespace) about a Title object to a result array.
__construct(ApiQuery $query, $moduleName)
This query action adds a list of a specified user's contributions to the output.