35 parent::__construct( $query, $moduleName,
'uc' );
48 $prop = array_flip( $this->params[
'prop'] );
49 $this->fld_ids = isset( $prop[
'ids'] );
50 $this->fld_title = isset( $prop[
'title'] );
51 $this->fld_comment = isset( $prop[
'comment'] );
52 $this->fld_parsedcomment = isset( $prop[
'parsedcomment'] );
53 $this->fld_size = isset( $prop[
'size'] );
54 $this->fld_sizediff = isset( $prop[
'sizediff'] );
55 $this->fld_flags = isset( $prop[
'flags'] );
56 $this->fld_timestamp = isset( $prop[
'timestamp'] );
57 $this->fld_patrolled = isset( $prop[
'patrolled'] );
58 $this->fld_tags = isset( $prop[
'tags'] );
63 $dbSecondary = $this->
getDB();
68 $this->idMode =
false;
69 if ( isset( $this->params[
'userprefix'] ) ) {
70 $this->prefixMode =
true;
71 $this->multiUserMode =
true;
72 $this->userprefix = $this->params[
'userprefix'];
76 $this->usernames = [];
77 if ( !is_array( $this->params[
'user'] ) ) {
78 $this->params[
'user'] = [ $this->params[
'user'] ];
80 if ( !count( $this->params[
'user'] ) ) {
81 $this->
dieUsage(
'User parameter may not be empty.',
'param_user' );
83 foreach ( $this->params[
'user']
as $u ) {
84 if ( is_null( $u ) || $u ===
'' ) {
85 $this->
dieUsage(
'User parameter may not be empty',
'param_user' );
90 $this->usernames[] = $u;
93 if (
$name ===
false ) {
94 $this->
dieUsage(
"User name {$u} is not valid",
'param_user' );
96 $this->usernames[] =
$name;
99 $this->prefixMode =
false;
100 $this->multiUserMode = ( count( $this->params[
'user'] ) > 1 );
104 $res =
$dbr->select(
'user',
'user_id', [
'user_name' => $this->usernames ], __METHOD__ );
105 foreach (
$res as $row ) {
106 $this->userids[] = $row->user_id;
108 $this->idMode = count( $this->userids ) === count( $this->usernames );
116 $res = $this->
select( __METHOD__, [], $hookData );
118 if ( $this->fld_sizediff ) {
120 foreach (
$res as $row ) {
121 if ( $row->rev_parent_id ) {
122 $revIds[] = $row->rev_parent_id;
131 $limit = $this->params[
'limit'];
134 foreach (
$res as $row ) {
143 $fit = $this->
processRow( $row, $vals, $hookData ) &&
165 $tables = [
'page',
'revision' ];
166 $this->
addWhere(
'page_id=rev_page' );
169 if ( !is_null( $this->params[
'continue'] ) ) {
170 $continue = explode(
'|', $this->params[
'continue'] );
171 $db = $this->
getDB();
172 if ( $this->multiUserMode ) {
174 $modeFlag = array_shift( $continue );
176 if ( $this->idMode && $modeFlag ===
'name' ) {
180 $this->idMode =
false;
183 $userField = $this->idMode ?
'rev_user' :
'rev_user_text';
184 $encUser = $db->addQuotes( array_shift( $continue ) );
188 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
189 $encId = (int)$continue[1];
191 $op = ( $this->params[
'dir'] ==
'older' ?
'<' :
'>' );
192 if ( $this->multiUserMode ) {
194 "$userField $op $encUser OR " .
195 "($userField = $encUser AND " .
196 "(rev_timestamp $op $encTS OR " .
197 "(rev_timestamp = $encTS AND " .
198 "rev_id $op= $encId)))"
202 "rev_timestamp $op $encTS OR " .
203 "(rev_timestamp = $encTS AND " .
204 "rev_id $op= $encId)"
211 if ( !
$user->isAllowed(
'deletedhistory' ) ) {
213 } elseif ( !
$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
219 $this->
addWhere( $this->
getDB()->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
223 if ( $this->prefixMode ) {
225 $this->
getDB()->buildLike( $this->userprefix, $this->
getDB()->anyString() ) );
226 } elseif ( $this->idMode ) {
229 $this->
addWhereFld(
'rev_user_text', $this->usernames );
234 if ( $this->multiUserMode ) {
235 $this->
addWhereRange( $this->idMode ?
'rev_user' :
'rev_user_text',
236 $this->params[
'dir'], null, null );
239 $this->params[
'dir'], $this->params[
'start'], $this->params[
'end'] );
241 $this->
addWhereRange(
'rev_id', $this->params[
'dir'], null, null );
243 $this->
addWhereFld(
'page_namespace', $this->params[
'namespace'] );
245 $show = $this->params[
'show'];
246 if ( $this->params[
'toponly'] ) {
249 if ( !is_null( $show ) ) {
250 $show = array_flip( $show );
252 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
253 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
254 || ( isset( $show[
'top'] ) && isset( $show[
'!top'] ) )
255 || ( isset( $show[
'new'] ) && isset( $show[
'!new'] ) )
260 $this->
addWhereIf(
'rev_minor_edit = 0', isset( $show[
'!minor'] ) );
261 $this->
addWhereIf(
'rev_minor_edit != 0', isset( $show[
'minor'] ) );
262 $this->
addWhereIf(
'rc_patrolled = 0', isset( $show[
'!patrolled'] ) );
263 $this->
addWhereIf(
'rc_patrolled != 0', isset( $show[
'patrolled'] ) );
264 $this->
addWhereIf(
'rev_id != page_latest', isset( $show[
'!top'] ) );
265 $this->
addWhereIf(
'rev_id = page_latest', isset( $show[
'top'] ) );
266 $this->
addWhereIf(
'rev_parent_id != 0', isset( $show[
'!new'] ) );
267 $this->
addWhereIf(
'rev_parent_id = 0', isset( $show[
'new'] ) );
269 $this->
addOption(
'LIMIT', $this->params[
'limit'] + 1 );
284 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
287 if ( !
$user->useRCPatrol() && !
$user->useNPPatrol() ) {
289 'You need the patrol right to request the patrolled flag',
297 $index[
'recentchanges'] =
'rc_user_text';
298 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ) {
301 $tables = [
'revision',
'recentchanges',
'page' ];
303 $this->
addWhere(
'rc_user_text=rev_user_text' );
304 $this->
addWhere(
'rc_timestamp=rev_timestamp' );
305 $this->
addWhere(
'rc_this_oldid=rev_id' );
310 'rc_user_text=rev_user_text',
311 'rc_timestamp=rev_timestamp',
312 'rc_this_oldid=rev_id' ] ] ] );
318 $this->
addFieldsIf(
'page_latest', $this->fld_flags );
320 $this->
addFieldsIf(
'rev_comment', $this->fld_comment || $this->fld_parsedcomment );
321 $this->
addFieldsIf(
'rev_len', $this->fld_size || $this->fld_sizediff );
322 $this->
addFieldsIf(
'rev_minor_edit', $this->fld_flags );
323 $this->
addFieldsIf(
'rev_parent_id', $this->fld_flags || $this->fld_sizediff || $this->fld_ids );
324 $this->
addFieldsIf(
'rc_patrolled', $this->fld_patrolled );
326 if ( $this->fld_tags ) {
329 [
'tag_summary' => [
'LEFT JOIN', [
'rev_id=ts_rev_id' ] ] ]
334 if ( isset( $this->params[
'tag'] ) ) {
337 [
'change_tag' => [
'INNER JOIN', [
'rev_id=ct_rev_id' ] ] ]
339 $this->
addWhereFld(
'ct_tag', $this->params[
'tag'] );
342 if ( isset( $index ) ) {
358 $vals[
'texthidden'] =
true;
363 $vals[
'userid'] = (int)$row->rev_user;
364 $vals[
'user'] = $row->rev_user_text;
366 $vals[
'userhidden'] =
true;
369 if ( $this->fld_ids ) {
370 $vals[
'pageid'] = intval( $row->rev_page );
371 $vals[
'revid'] = intval( $row->rev_id );
374 if ( !is_null( $row->rev_parent_id ) ) {
375 $vals[
'parentid'] = intval( $row->rev_parent_id );
381 if ( $this->fld_title ) {
385 if ( $this->fld_timestamp ) {
389 if ( $this->fld_flags ) {
390 $vals[
'new'] = $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id );
391 $vals[
'minor'] = (bool)$row->rev_minor_edit;
392 $vals[
'top'] = $row->page_latest == $row->rev_id;
395 if ( ( $this->fld_comment || $this->fld_parsedcomment ) && isset( $row->rev_comment ) ) {
397 $vals[
'commenthidden'] =
true;
406 if ( $userCanView ) {
407 if ( $this->fld_comment ) {
408 $vals[
'comment'] = $row->rev_comment;
411 if ( $this->fld_parsedcomment ) {
417 if ( $this->fld_patrolled ) {
418 $vals[
'patrolled'] = (bool)$row->rc_patrolled;
421 if ( $this->fld_size && !is_null( $row->rev_len ) ) {
422 $vals[
'size'] = intval( $row->rev_len );
425 if ( $this->fld_sizediff
426 && !is_null( $row->rev_len )
427 && !is_null( $row->rev_parent_id )
429 $parentLen = isset( $this->parentLens[$row->rev_parent_id] )
430 ? $this->parentLens[$row->rev_parent_id]
432 $vals[
'sizediff'] = intval( $row->rev_len - $parentLen );
435 if ( $this->fld_tags ) {
436 if ( $row->ts_tags ) {
437 $tags = explode(
',', $row->ts_tags );
439 $vals[
'tags'] = $tags;
446 $vals[
'suppressed'] =
true;
453 if ( $this->multiUserMode ) {
454 if ( $this->idMode ) {
455 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
457 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
460 return "$row->rev_timestamp|$row->rev_id";
467 return 'anon-public-user-private';
492 'userprefix' => null,
535 'apihelp-query+usercontribs-param-show',
549 'action=query&list=usercontribs&ucuser=Example'
550 =>
'apihelp-query+usercontribs-example-user',
551 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
552 =>
'apihelp-query+usercontribs-example-ipprefix',
557 return 'https://www.mediawiki.org/wiki/API:Usercontribs';
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below...
getDB()
Get the Query database connection (read-only)
const LIMIT_BIG2
Fast query, apihighlimits limit.
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
getResult()
Get the result object.
addWhereFld($field, $value)
Equivalent to addWhere(array($field => $value))
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.
const LIMIT_BIG1
Fast query, standard limit.
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...
const PARAM_MAX
(integer) Max value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
This is a base class for all Query modules.
extractRequestParams($parseLimit=true)
Using getAllowedParams(), this function makes an array of the values provided by the user...
const PARAM_HELP_MSG_PER_VALUE
((string|array|Message)[]) When PARAM_TYPE is an array, this is an array mapping those values to $msg...
select($method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addTimestampWhereRange($field, $dir, $start, $end, $sort=true)
Add a WHERE clause corresponding to a range, similar to addWhereRange, but converts $start and $end t...
addWhere($value)
Add a set of WHERE clauses to the internal array.
const TS_ISO_8601
ISO 8601 format with no timezone: 1986-02-09T20:00:00Z.
addJoinConds($join_conds)
Add a set of JOIN conditions to the internal array.
static setIndexedTagName(array &$arr, $tag)
Set the tag name for numeric-keyed values in XML format.
wfTimestamp($outputtype=TS_UNIX, $ts=0)
Get a timestamp string in one of various formats.
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
prepareQuery()
Prepares the query and returns the limit of rows requested.
addWhereIf($value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
getConfig()
Get the Config object.
processRow($row, array &$data, array &$hookData)
Call the ApiQueryBaseProcessRow hook.
addOption($name, $value=null)
Add an option such as LIMIT or USE INDEX.
static isIP($name)
Does the string match an anonymous IP address?
namespace and then decline to actually register it file or subcat img or subcat $title
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_MAX2
(integer) Max value allowed for the parameter for users with the apihighlimits right, for PARAM_TYPE 'limit'.
This is the main query class.
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
dieContinueUsageIf($condition)
Die with the $prefix.
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...
const PARAM_HELP_MSG
(string|array|Message) Specify an alternative i18n documentation message for this parameter...
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 local account $user
addFieldsIf($value, $condition)
Same as addFields(), but add the fields only if a condition is met.
__construct(ApiQuery $query, $moduleName)
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
addFields($value)
Add a set of fields to select to the internal array.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
extractRowInfo($row)
Extract fields from the database row and append them to a result array.
setContinueEnumParameter($paramName, $paramValue)
Set a query-continue value.
dieUsage($description, $errorCode, $httpRespCode=0, $extradata=null)
Throw a UsageException, which will (if uncaught) call the main module's error handler and die with an...
this hook is for auditing only RecentChangesLinked and Watchlist RecentChangesLinked and Watchlist e g Watchlist removed from all revisions and log entries to which it was applied This gives extensions a chance to take it off their books as the deletion has already been partly carried out by this point or something similar the user will be unable to create the tag set and then return false from the hook function Ensure you consume the ChangeTagAfterDelete hook to carry out custom deletion actions as context called by AbstractContent::getParserOutput May be used to override the normal model specific rendering of page content as context as context the output can only depend on parameters provided to this hook not on global state indicating whether full HTML should be generated If generation of HTML may be but other information should still be present in the ParserOutput object to manipulate or replace but no entry for that model exists in $wgContentHandlers if desired whether it is OK to use $contentModel on $title Handler functions that modify $ok should generally return false to prevent further hooks from further modifying $ok inclusive $limit
static getParentLengths($db, array $revIds)
Do a batched query to get the parent revision lengths.
This query action adds a list of a specified user's contributions to the output.
const PARAM_DEPRECATED
(boolean) Is the parameter deprecated (will show a warning)?
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, if it's marked as deleted.
const PARAM_MIN
(integer) Lowest value allowed for the parameter, for PARAM_TYPE 'integer' and 'limit'.
static addTitleInfo(&$arr, $title, $prefix= '')
Add information (title and namespace) about a Title object to a result array.
getUser()
Get the User object.
addTables($tables, $alias=null)
Add a set of tables to the internal array.
static makeTitle($ns, $title, $fragment= '', $interwiki= '')
Create a new Title from a namespace index and a DB key.
dieUsageMsg($error)
Output the error message related to a certain array.
selectNamedDB($name, $db, $groups)
Selects the query database connection with the given name.
Allows to change the fields on the form that will be generated $name