35 parent::__construct(
$query, $moduleName,
'uc' );
50 $this->commentStore = CommentStore::getStore();
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();
69 $sort = ( $this->params[
'dir'] ==
'newer' ?
'' :
' DESC' );
70 $op = ( $this->params[
'dir'] ==
'older' ?
'<' :
'>' );
76 if ( isset( $this->params[
'userprefix'] ) ) {
77 $this->multiUserMode =
true;
78 $this->orderBy =
'name';
84 $userIter = call_user_func(
function ()
use ( $dbSecondary,
$sort, $op,
$fname ) {
88 if ( !is_null( $this->params[
'continue'] ) ) {
89 $continue = explode(
'|', $this->params[
'continue'] );
92 $fromName = $continue[1];
94 $like = $dbSecondary->buildLike( $this->params[
'userprefix'], $dbSecondary->anyString() );
99 $from = $fromName ?
"$op= " . $dbSecondary->addQuotes( $fromName ) :
false;
104 $res = $dbSecondary->select(
106 [
'actor_id',
'user_id' =>
'COALESCE(actor_user,0)',
'user_name' =>
'actor_name' ],
107 array_merge( [
"actor_name$like" ], $from ? [
"actor_name $from" ] : [] ),
109 [
'ORDER BY' => [
"user_name $sort" ],
'LIMIT' => $limit ]
112 $res = $dbSecondary->select(
114 [
'actor_id' =>
'NULL',
'user_id' =>
'rev_user',
'user_name' =>
'rev_user_text' ],
115 array_merge( [
"rev_user_text$like" ], $from ? [
"rev_user_text $from" ] : [] ),
117 [
'DISTINCT',
'ORDER BY' => [
"rev_user_text $sort" ],
'LIMIT' => $limit ]
123 foreach (
$res as $row ) {
124 if ( ++$count >= $limit ) {
125 $fromName = $row->user_name;
130 }
while ( $fromName !==
false );
135 } elseif ( isset( $this->params[
'userids'] ) ) {
136 if ( $this->params[
'userids'] === [] ) {
138 $this->
dieWithError( [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName" );
142 foreach ( $this->params[
'userids']
as $uid ) {
144 $this->
dieWithError( [
'apierror-invaliduserid', $uid ],
'invaliduserid' );
149 $this->orderBy =
'id';
150 $this->multiUserMode = count( $ids ) > 1;
152 $from = $fromId =
false;
153 if ( $this->multiUserMode && !is_null( $this->params[
'continue'] ) ) {
154 $continue = explode(
'|', $this->params[
'continue'] );
157 $fromId = (int)$continue[1];
159 $from =
"$op= $fromId";
165 $res = $dbSecondary->select(
167 [
'actor_id',
'user_id' =>
'actor_user',
'user_name' =>
'actor_name' ],
168 array_merge( [
'actor_user' => $ids ], $from ? [
"actor_id $from" ] : [] ),
170 [
'ORDER BY' =>
"user_id $sort" ]
173 $res = $dbSecondary->select(
175 [
'actor_id' =>
'NULL',
'user_id' =>
'user_id',
'user_name' =>
'user_name' ],
176 array_merge( [
'user_id' => $ids ], $from ? [
"user_id $from" ] : [] ),
178 [
'ORDER BY' =>
"user_id $sort" ]
182 $batchSize = count( $ids );
185 if ( !count( $this->params[
'user'] ) ) {
188 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
191 foreach ( $this->params[
'user']
as $u ) {
195 [
'apierror-paramempty', $encParamName ],
"paramempty_$encParamName"
203 if (
$name ===
false ) {
206 [
'apierror-baduser', $encParamName,
wfEscapeWikiText( $u ) ],
"baduser_$encParamName"
209 $names[
$name] =
null;
213 $this->orderBy =
'name';
214 $this->multiUserMode = count( $names ) > 1;
216 $from = $fromName =
false;
217 if ( $this->multiUserMode && !is_null( $this->params[
'continue'] ) ) {
218 $continue = explode(
'|', $this->params[
'continue'] );
221 $fromName = $continue[1];
222 $from =
"$op= " . $dbSecondary->addQuotes( $fromName );
228 $res = $dbSecondary->select(
230 [
'actor_id',
'user_id' =>
'actor_user',
'user_name' =>
'actor_name' ],
231 array_merge( [
'actor_name' => array_keys( $names ) ], $from ? [
"actor_id $from" ] : [] ),
233 [
'ORDER BY' =>
"actor_name $sort" ]
237 $res = $dbSecondary->select(
239 [
'actor_id' =>
'NULL',
'user_id',
'user_name' ],
240 array_merge( [
'user_name' => array_keys( $names ) ], $from ? [
"user_name $from" ] : [] ),
243 foreach (
$res as $row ) {
244 $names[$row->user_name] = $row;
246 if ( $this->params[
'dir'] ==
'newer' ) {
247 ksort( $names, SORT_STRING );
249 krsort( $names, SORT_STRING );
251 $neg = $op ===
'>' ? -1 : 1;
252 $userIter = call_user_func(
function ()
use ( $names, $fromName, $neg ) {
253 foreach ( $names
as $name => $row ) {
254 if ( $fromName ===
false || $neg * strcmp(
$name, $fromName ) <= 0 ) {
261 $batchSize = count( $names );
266 $this->orderBy =
'actor';
270 if ( $this->orderBy ===
'id' &&
277 $limit = $this->params[
'limit'];
279 while ( $userIter->valid() ) {
281 while ( count( $users ) < $batchSize && $userIter->valid() ) {
282 $users[] = $userIter->current();
288 $res = $this->
select( __METHOD__, [], $hookData );
290 if ( $this->fld_sizediff ) {
292 foreach (
$res as $row ) {
293 if ( $row->rev_parent_id ) {
294 $revIds[] = $row->rev_parent_id;
297 $this->parentLens = MediaWikiServices::getInstance()->getRevisionStore()
298 ->listRevisionSizes( $dbSecondary, $revIds );
301 foreach (
$res as $row ) {
302 if ( ++$count > $limit ) {
310 $fit = $this->
processRow( $row, $vals, $hookData ) &&
331 $db = $this->
getDB();
333 $revQuery = MediaWikiServices::getInstance()->getRevisionStore()->getQueryInfo( [
'page' ] );
339 $revWhere = ActorMigration::newMigration()->getWhere( $db,
'rev_user', $users );
340 $orderUserField =
'rev_actor';
341 $userField = $this->orderBy ===
'actor' ?
'revactor_actor' :
'actor_name';
342 $tsField =
'revactor_timestamp';
343 $idField =
'revactor_rev';
348 $revWhere = ActorMigration::newMigration()
349 ->getWhere( $db,
'rev_user', $users, $this->orderBy ===
'id' );
350 $orderUserField = $this->orderBy ===
'id' ?
'rev_user' :
'rev_user_text';
351 $userField =
$revQuery[
'fields'][$orderUserField];
352 $tsField =
'rev_timestamp';
356 $this->
addWhere( $revWhere[
'conds'] );
359 if ( !is_null( $this->params[
'continue'] ) ) {
360 $continue = explode(
'|', $this->params[
'continue'] );
361 if ( $this->multiUserMode ) {
363 $modeFlag = array_shift( $continue );
365 $encUser = $db->addQuotes( array_shift( $continue ) );
369 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
370 $encId = (int)$continue[1];
372 $op = ( $this->params[
'dir'] ==
'older' ?
'<' :
'>' );
373 if ( $this->multiUserMode ) {
375 "$userField $op $encUser OR " .
376 "($userField = $encUser AND " .
377 "($tsField $op $encTS OR " .
378 "($tsField = $encTS AND " .
379 "$idField $op= $encId)))"
383 "$tsField $op $encTS OR " .
384 "($tsField = $encTS AND " .
385 "$idField $op= $encId)"
393 if ( !
$user->isAllowed(
'deletedhistory' ) ) {
394 $bitmask = RevisionRecord::DELETED_USER;
395 } elseif ( !
$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
396 $bitmask = RevisionRecord::DELETED_USER | RevisionRecord::DELETED_RESTRICTED;
401 $this->
addWhere( $db->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
405 if ( count( $users ) > 1 ) {
406 $this->
addWhereRange( $orderUserField, $this->params[
'dir'],
null,
null );
411 $this->params[
'dir'], $this->params[
'start'], $this->params[
'end'] );
414 $this->
addWhereRange( $idField, $this->params[
'dir'],
null,
null );
416 $this->
addWhereFld(
'page_namespace', $this->params[
'namespace'] );
418 $show = $this->params[
'show'];
419 if ( $this->params[
'toponly'] ) {
422 if ( !is_null( $show ) ) {
423 $show = array_flip( $show );
425 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
426 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
427 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!autopatrolled'] ) )
428 || ( isset( $show[
'autopatrolled'] ) && isset( $show[
'!patrolled'] ) )
429 || ( isset( $show[
'top'] ) && isset( $show[
'!top'] ) )
430 || ( isset( $show[
'new'] ) && isset( $show[
'!new'] ) )
435 $this->
addWhereIf(
'rev_minor_edit = 0', isset( $show[
'!minor'] ) );
436 $this->
addWhereIf(
'rev_minor_edit != 0', isset( $show[
'minor'] ) );
438 'rc_patrolled = ' . RecentChange::PRC_UNPATROLLED,
439 isset( $show[
'!patrolled'] )
442 'rc_patrolled != ' . RecentChange::PRC_UNPATROLLED,
443 isset( $show[
'patrolled'] )
446 'rc_patrolled != ' . RecentChange::PRC_AUTOPATROLLED,
447 isset( $show[
'!autopatrolled'] )
450 'rc_patrolled = ' . RecentChange::PRC_AUTOPATROLLED,
451 isset( $show[
'autopatrolled'] )
453 $this->
addWhereIf( $idField .
' != page_latest', isset( $show[
'!top'] ) );
454 $this->
addWhereIf( $idField .
' = page_latest', isset( $show[
'top'] ) );
455 $this->
addWhereIf(
'rev_parent_id != 0', isset( $show[
'!new'] ) );
456 $this->
addWhereIf(
'rev_parent_id = 0', isset( $show[
'new'] ) );
460 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
461 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] ) || $this->fld_patrolled
463 if ( !
$user->useRCPatrol() && !
$user->useNPPatrol() ) {
464 $this->
dieWithError(
'apierror-permissiondenied-patrolflag',
'permissiondenied' );
467 $isFilterset = isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
468 isset( $show[
'autopatrolled'] ) || isset( $show[
'!autopatrolled'] );
471 $isFilterset ?
'JOIN' :
'LEFT JOIN',
476 'rc_timestamp = ' . $tsField,
477 'rc_this_oldid = ' . $idField,
482 $this->
addFieldsIf(
'rc_patrolled', $this->fld_patrolled );
484 if ( $this->fld_tags ) {
488 if ( isset( $this->params[
'tag'] ) ) {
491 [
'change_tag' => [
'JOIN', [ $idField .
' = ct_rev_id' ] ] ]
493 $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
495 $this->
addWhereFld(
'ct_tag_id', $changeTagDefStore->getId( $this->params[
'tag'] ) );
513 if ( $row->rev_deleted & RevisionRecord::DELETED_TEXT ) {
514 $vals[
'texthidden'] =
true;
519 $vals[
'userid'] = (int)$row->rev_user;
520 $vals[
'user'] = $row->rev_user_text;
521 if ( $row->rev_deleted & RevisionRecord::DELETED_USER ) {
522 $vals[
'userhidden'] =
true;
525 if ( $this->fld_ids ) {
526 $vals[
'pageid'] = (int)$row->rev_page;
527 $vals[
'revid'] = (int)$row->rev_id;
529 if ( !is_null( $row->rev_parent_id ) ) {
530 $vals[
'parentid'] = (int)$row->rev_parent_id;
534 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
536 if ( $this->fld_title ) {
540 if ( $this->fld_timestamp ) {
541 $vals[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->rev_timestamp );
544 if ( $this->fld_flags ) {
545 $vals[
'new'] = $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id );
546 $vals[
'minor'] = (bool)$row->rev_minor_edit;
547 $vals[
'top'] = $row->page_latest == $row->rev_id;
550 if ( $this->fld_comment || $this->fld_parsedcomment ) {
551 if ( $row->rev_deleted & RevisionRecord::DELETED_COMMENT ) {
552 $vals[
'commenthidden'] =
true;
556 $userCanView = RevisionRecord::userCanBitfield(
558 RevisionRecord::DELETED_COMMENT, $this->getUser()
561 if ( $userCanView ) {
562 $comment = $this->commentStore->getComment(
'rev_comment', $row )->text;
563 if ( $this->fld_comment ) {
564 $vals[
'comment'] = $comment;
567 if ( $this->fld_parsedcomment ) {
573 if ( $this->fld_patrolled ) {
574 $vals[
'patrolled'] = $row->rc_patrolled != RecentChange::PRC_UNPATROLLED;
575 $vals[
'autopatrolled'] = $row->rc_patrolled == RecentChange::PRC_AUTOPATROLLED;
578 if ( $this->fld_size && !is_null( $row->rev_len ) ) {
579 $vals[
'size'] = (int)$row->rev_len;
582 if ( $this->fld_sizediff
583 && !is_null( $row->rev_len )
584 && !is_null( $row->rev_parent_id )
586 $parentLen = $this->parentLens[$row->rev_parent_id] ?? 0;
587 $vals[
'sizediff'] = (int)$row->rev_len - $parentLen;
590 if ( $this->fld_tags ) {
591 if ( $row->ts_tags ) {
592 $tags = explode(
',', $row->ts_tags );
594 $vals[
'tags'] = $tags;
600 if ( $anyHidden && ( $row->rev_deleted & RevisionRecord::DELETED_RESTRICTED ) ) {
601 $vals[
'suppressed'] =
true;
608 if ( $this->multiUserMode ) {
609 switch ( $this->orderBy ) {
611 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
613 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
615 return "actor|$row->rev_actor|$row->rev_timestamp|$row->rev_id";
618 return "$row->rev_timestamp|$row->rev_id";
625 return 'anon-public-user-private';
654 'userprefix' =>
null,
699 'apihelp-query+usercontribs-param-show',
713 'action=query&list=usercontribs&ucuser=Example'
714 =>
'apihelp-query+usercontribs-example-user',
715 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
716 =>
'apihelp-query+usercontribs-example-ipprefix',
721 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Usercontribs';
729class_alias( ApiQueryUserContribs::class,
'ApiQueryContributions' );
Apache License January AND DISTRIBUTION Definitions License shall mean the terms and conditions for use
int $wgActorTableSchemaMigrationStage
Actor table schema migration stage.
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,...
if(defined( 'MW_SETUP_CALLBACK')) $fname
Customization point after all loading (constants, functions, classes, DefaultSettings,...
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right,...
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
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 PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
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.
requireOnlyOneParameter( $params, $required)
Die if none or more than one of a certain set of parameters is set and not false.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
This is a base class for all Query modules.
selectNamedDB( $name, $db, $groups)
Selects the query database connection with the given name.
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)
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(array($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.
getExamplesMessages()
Returns usage examples for this module.
__construct(ApiQuery $query, $moduleName)
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
prepareQuery(array $users, $limit)
Prepares the query and returns the limit of rows requested.
extractRowInfo( $row)
Extract fields from the database row and append them to a result array.
This is the main query class.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
static isExternal( $username)
Tells whether the username is external or not.
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...
static newFromResult( $res)
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
static getCanonicalName( $name, $validate='valid')
Given unvalidated user input, return a canonical username, or false if the username is invalid.
static newFromRow( $row, $data=null)
Create a new user object from a user row.
static isIP( $name)
Does the string match an anonymous IP address?
We use the convention $dbr for read and $dbw for write to help you keep track of whether the database object is a the world will explode Or to be a subsequent write query which succeeded on the master may fail when replicated to the slave due to a unique key collision Replication on the slave will stop and it may take hours to repair the database and get it back online Setting read_only in my cnf on the slave will avoid this but given the dire we prefer to have as many checks as possible We provide a but the wrapper functions like select() and insert() are usually more convenient. They take care of things like table prefixes and escaping for you. If you really need to make your own SQL
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
const SCHEMA_COMPAT_READ_NEW
namespace and then decline to actually register it file or subcat img or subcat $title
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
Allows to change the fields on the form that will be generated $name
null for the local 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
return true to allow those checks to and false if checking is done & $user
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
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))