Go to the documentation of this file.
35 parent::__construct(
$query, $moduleName,
'uc' );
52 $prop = array_flip( $this->params[
'prop'] );
53 $this->fld_ids = isset( $prop[
'ids'] );
54 $this->fld_title = isset( $prop[
'title'] );
55 $this->fld_comment = isset( $prop[
'comment'] );
56 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
57 $this->fld_size = isset( $prop[
'size'] );
58 $this->fld_sizediff = isset( $prop[
'sizediff'] );
59 $this->fld_flags = isset( $prop[
'flags'] );
60 $this->fld_timestamp = isset( $prop[
'timestamp'] );
61 $this->fld_patrolled = isset( $prop[
'patrolled'] );
62 $this->fld_tags = isset( $prop[
'tags'] );
67 $dbSecondary = $this->
getDB();
72 $sort = ( $this->params[
'dir'] ==
'newer' ?
'' :
' DESC' );
73 $op = ( $this->params[
'dir'] ==
'older' ?
'<' :
'>' );
79 if ( isset( $this->params[
'userprefix'] ) ) {
80 $this->multiUserMode =
true;
81 $this->orderBy =
'name';
87 $userIter = call_user_func(
function ()
use ( $dbSecondary,
$sort, $op,
$fname ) {
91 if ( !is_null( $this->params[
'continue'] ) ) {
92 $continue = explode(
'|', $this->params[
'continue'] );
95 $fromName = $continue[1];
97 $like = $dbSecondary->buildLike( $this->params[
'userprefix'], $dbSecondary->anyString() );
102 $from = $fromName ?
"$op= " . $dbSecondary->addQuotes( $fromName ) :
false;
107 $res = $dbSecondary->select(
109 [
'actor_id',
'user_id' =>
'COALESCE(actor_user,0)',
'user_name' =>
'actor_name' ],
110 array_merge( [
"actor_name$like" ], $from ? [
"actor_name $from" ] : [] ),
112 [
'ORDER BY' => [
"user_name $sort" ],
'LIMIT' => $limit ]
115 $res = $dbSecondary->select(
117 [
'actor_id' =>
'NULL',
'user_id' =>
'rev_user',
'user_name' =>
'rev_user_text' ],
118 array_merge( [
"rev_user_text$like" ], $from ? [
"rev_user_text $from" ] : [] ),
120 [
'DISTINCT',
'ORDER BY' => [
"rev_user_text $sort" ],
'LIMIT' => $limit ]
126 foreach (
$res as $row ) {
127 if ( ++$count >= $limit ) {
128 $fromName = $row->user_name;
133 }
while ( $fromName !==
false );
138 } elseif ( isset( $this->params[
'userids'] ) ) {
139 if ( !
count( $this->params[
'userids'] ) ) {
141 $this->
dieWithError( [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName" );
145 foreach ( $this->params[
'userids']
as $uid ) {
147 $this->
dieWithError( [
'apierror-invaliduserid', $uid ],
'invaliduserid' );
152 $this->orderBy =
'id';
153 $this->multiUserMode =
count( $ids ) > 1;
155 $from = $fromId =
false;
156 if ( $this->multiUserMode && !is_null( $this->params[
'continue'] ) ) {
157 $continue = explode(
'|', $this->params[
'continue'] );
160 $fromId = (int)$continue[1];
162 $from =
"$op= $fromId";
168 $res = $dbSecondary->select(
170 [
'actor_id',
'user_id' =>
'actor_user',
'user_name' =>
'actor_name' ],
171 array_merge( [
'actor_user' => $ids ], $from ? [
"actor_id $from" ] : [] ),
173 [
'ORDER BY' =>
"user_id $sort" ]
176 $res = $dbSecondary->select(
178 [
'actor_id' =>
'NULL',
'user_id' =>
'user_id',
'user_name' =>
'user_name' ],
179 array_merge( [
'user_id' => $ids ], $from ? [
"user_id $from" ] : [] ),
181 [
'ORDER BY' =>
"user_id $sort" ]
185 $batchSize =
count( $ids );
188 if ( !
count( $this->params[
'user'] ) ) {
191 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
194 foreach ( $this->params[
'user']
as $u ) {
198 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
206 if (
$name ===
false ) {
209 [
'apierror-baduser', $encParamName,
wfEscapeWikiText( $u ) ],
"baduser_$encParamName"
212 $names[
$name] =
null;
216 $this->orderBy =
'name';
217 $this->multiUserMode =
count( $names ) > 1;
219 $from = $fromName =
false;
220 if ( $this->multiUserMode && !is_null( $this->params[
'continue'] ) ) {
221 $continue = explode(
'|', $this->params[
'continue'] );
224 $fromName = $continue[1];
225 $from =
"$op= " . $dbSecondary->addQuotes( $fromName );
231 $res = $dbSecondary->select(
233 [
'actor_id',
'user_id' =>
'actor_user',
'user_name' =>
'actor_name' ],
234 array_merge( [
'actor_name' => array_keys( $names ) ], $from ? [
"actor_id $from" ] : [] ),
236 [
'ORDER BY' =>
"actor_name $sort" ]
240 $res = $dbSecondary->select(
242 [
'actor_id' =>
'NULL',
'user_id',
'user_name' ],
243 array_merge( [
'user_name' => array_keys( $names ) ], $from ? [
"user_name $from" ] : [] ),
246 foreach (
$res as $row ) {
247 $names[$row->user_name] = $row;
249 if ( $this->params[
'dir'] ==
'newer' ) {
250 ksort( $names, SORT_STRING );
252 krsort( $names, SORT_STRING );
254 $neg = $op ===
'>' ? -1 : 1;
255 $userIter = call_user_func(
function ()
use ( $names, $fromName, $neg ) {
256 foreach ( $names
as $name => $row ) {
257 if ( $fromName ===
false || $neg * strcmp(
$name, $fromName ) <= 0 ) {
264 $batchSize =
count( $names );
269 $this->orderBy =
'actor';
273 $limit = $this->params[
'limit'];
275 while ( $userIter->valid() ) {
277 while (
count( $users ) < $batchSize && $userIter->valid() ) {
278 $users[] = $userIter->current();
284 $res = $this->
select( __METHOD__, [], $hookData );
286 if ( $this->fld_sizediff ) {
288 foreach (
$res as $row ) {
289 if ( $row->rev_parent_id ) {
290 $revIds[] = $row->rev_parent_id;
293 $this->parentLens = MediaWikiServices::getInstance()->getRevisionStore()
294 ->listRevisionSizes( $dbSecondary, $revIds );
297 foreach (
$res as $row ) {
298 if ( ++$count > $limit ) {
306 $fit = $this->
processRow( $row, $vals, $hookData ) &&
327 $db = $this->
getDB();
329 $revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo( [
'page' ] );
336 $orderUserField =
'rev_actor';
337 $userField = $this->orderBy ===
'actor' ?
'revactor_actor' :
'actor_name';
338 $tsField =
'revactor_timestamp';
339 $idField =
'revactor_rev';
345 ->getWhere( $db,
'rev_user', $users, $this->orderBy ===
'id' );
346 $orderUserField = $this->orderBy ===
'id' ?
'rev_user' :
'rev_user_text';
347 $userField =
$revQuery[
'fields'][$orderUserField];
348 $tsField =
'rev_timestamp';
352 $this->
addWhere( $revWhere[
'conds'] );
355 if ( !is_null( $this->params[
'continue'] ) ) {
356 $continue = explode(
'|', $this->params[
'continue'] );
357 if ( $this->multiUserMode ) {
359 $modeFlag = array_shift( $continue );
361 $encUser = $db->addQuotes( array_shift( $continue ) );
365 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
366 $encId = (int)$continue[1];
368 $op = ( $this->params[
'dir'] ==
'older' ?
'<' :
'>' );
369 if ( $this->multiUserMode ) {
371 "$userField $op $encUser OR " .
372 "($userField = $encUser AND " .
373 "($tsField $op $encTS OR " .
374 "($tsField = $encTS AND " .
375 "$idField $op= $encId)))"
379 "$tsField $op $encTS OR " .
380 "($tsField = $encTS AND " .
381 "$idField $op= $encId)"
389 if ( !
$user->isAllowed(
'deletedhistory' ) ) {
390 $bitmask = RevisionRecord::DELETED_USER;
391 } elseif ( !
$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
392 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
397 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
401 if (
count( $users ) > 1 ) {
402 $this->
addWhereRange( $orderUserField, $this->params[
'dir'],
null,
null );
407 $this->params[
'dir'], $this->params[
'start'], $this->params[
'end'] );
410 $this->
addWhereRange( $idField, $this->params[
'dir'],
null,
null );
412 $this->
addWhereFld(
'page_namespace', $this->params[
'namespace'] );
414 $show = $this->params[
'show'];
415 if ( $this->params[
'toponly'] ) {
418 if ( !is_null( $show ) ) {
419 $show = array_flip( $show );
421 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
422 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
423 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
424 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
425 || ( isset( $show[
'top'] ) && isset( $show[
'!top'] ) )
426 || ( isset( $show[
'new'] ) && isset( $show[
'!new'] ) )
431 $this->
addWhereIf(
'rev_minor_edit = 0', isset( $show[
'!minor'] ) );
432 $this->
addWhereIf(
'rev_minor_edit != 0', isset( $show[
'minor'] ) );
435 isset( $show[
'!patrolled'] )
439 isset( $show[
'patrolled'] )
443 isset( $show[
'!autopatrolled'] )
447 isset( $show[
'autopatrolled'] )
449 $this->
addWhereIf( $idField .
' != page_latest', isset( $show[
'!top'] ) );
450 $this->
addWhereIf( $idField .
' = page_latest', isset( $show[
'top'] ) );
451 $this->
addWhereIf(
'rev_parent_id != 0', isset( $show[
'!new'] ) );
452 $this->
addWhereIf(
'rev_parent_id = 0', isset( $show[
'new'] ) );
456 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
457 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] ) || $this->fld_patrolled
459 if ( !
$user->useRCPatrol() && !
$user->useNPPatrol() ) {
460 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
463 $isFilterset = isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
464 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] );
467 $isFilterset ?
'JOIN' :
'LEFT JOIN',
472 'rc_timestamp = ' . $tsField,
473 'rc_this_oldid = ' . $idField,
478 $this->
addFieldsIf(
'rc_patrolled', $this->fld_patrolled );
480 if ( $this->fld_tags ) {
483 [
'tag_summary' => [
'LEFT JOIN', [ $idField .
' = ts_rev_id' ] ] ]
488 if ( isset( $this->params[
'tag'] ) ) {
491 [
'change_tag' => [
'INNER JOIN', [ $idField .
' = ct_rev_id' ] ] ]
494 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
496 $this->
addWhereFld(
'ct_tag_id', $changeTagDefStore->getId( $this->params[
'tag'] ) );
502 $this->
addWhereFld(
'ct_tag', $this->params[
'tag'] );
517 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
518 $vals[
'texthidden'] =
true;
523 $vals[
'userid'] = (int)$row->rev_user;
524 $vals[
'user'] = $row->rev_user_text;
525 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
526 $vals[
'userhidden'] =
true;
529 if ( $this->fld_ids ) {
530 $vals[
'pageid'] = intval( $row->rev_page );
531 $vals[
'revid'] = intval( $row->rev_id );
534 if ( !is_null( $row->rev_parent_id ) ) {
535 $vals[
'parentid'] = intval( $row->rev_parent_id );
541 if ( $this->fld_title ) {
545 if ( $this->fld_timestamp ) {
546 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
549 if ( $this->fld_flags ) {
550 $vals[
'new'] = $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id );
551 $vals[
'minor'] = (bool)$row->rev_minor_edit;
552 $vals[
'top'] = $row->page_latest == $row->rev_id;
555 if ( $this->fld_comment || $this->fld_parsedcomment ) {
556 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
557 $vals[
'commenthidden'] =
true;
561 $userCanView = RevisionRecord::userCanBitfield(
563 RevisionRecord::DELETED_COMMENT, $this->getUser()
566 if ( $userCanView ) {
567 $comment = $this->commentStore->getComment(
'rev_comment', $row )->text;
568 if ( $this->fld_comment ) {
569 $vals[
'comment'] = $comment;
572 if ( $this->fld_parsedcomment ) {
578 if ( $this->fld_patrolled ) {
583 if ( $this->fld_size && !is_null( $row->rev_len ) ) {
584 $vals[
'size'] = intval( $row->rev_len );
587 if ( $this->fld_sizediff
588 && !is_null( $row->rev_len )
589 && !is_null( $row->rev_parent_id )
591 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
592 $vals[
'sizediff'] = intval( $row->rev_len - $parentLen );
595 if ( $this->fld_tags ) {
596 if ( $row->ts_tags ) {
597 $tags = explode(
',', $row->ts_tags );
599 $vals[
'tags'] = $tags;
605 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
606 $vals[
'suppressed'] =
true;
613 if ( $this->multiUserMode ) {
614 switch ( $this->orderBy ) {
616 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
618 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
620 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
623 return "$row->rev_timestamp|$row->rev_id";
630 return 'anon-public-user-private';
659 'userprefix' =>
null,
704 'apihelp-query+usercontribs-param-show',
718 'action=query&list=usercontribs&ucuser=Example'
719 =>
'apihelp-query+usercontribs-example-user',
720 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
721 =>
'apihelp-query+usercontribs-example-ipprefix',
726 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
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.
const SCHEMA_COMPAT_READ_NEW
resetQueryParams()
Blank the internal arrays with query parameters.
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.
const MIGRATION_WRITE_BOTH
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
addOption( $name, $value=null)
Add an option such as LIMIT or USE INDEX.
static newFromRow( $row, $data=null)
Create a new user object from a user row.
static newMigration()
Static constructor.
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
__construct(ApiQuery $query, $moduleName)
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.
This query action adds a list of a specified user's contributions to the output.
getDB()
Get the Query database connection (read-only)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
static newFromResult( $res)
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
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.
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
static makeTitle( $ns, $title, $fragment='', $interwiki='')
Create a new Title from a namespace index and a DB key.
The wiki should then use memcached to cache various data To use multiple just add more items to the array To increase the weight of a make its entry a array("192.168.0.1:11211", 2))
extractRowInfo( $row)
Extract fields from the database row and append them to a result array.
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.
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
int $wgChangeTagsSchemaMigrationStage
change_tag table schema migration stage.
Allows to change the fields on the form that will be generated $name
prepareQuery(array $users, $limit)
Prepares the query and returns the limit of rows requested.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
getExamplesMessages()
Returns usage examples for this module.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
getHelpUrls()
Return links to more detailed help pages about the module.
getCacheMode( $params)
Get the cache mode for the data generated by this module.
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))
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
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.
you have access to all of the normal MediaWiki so you can get a DB use the etc For full docs on the Maintenance class
setContinueEnumParameter( $paramName, $paramValue)
Set a query-continue value.
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 MediaWikiServices
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
static isExternal( $username)
Tells whether the username is external or not.
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.
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.