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 );
117 if ( $this->fld_sizediff ) {
119 foreach (
$res as $row ) {
120 if ( $row->rev_parent_id ) {
121 $revIds[] = $row->rev_parent_id;
130 $limit = $this->params[
'limit'];
133 foreach (
$res as $row ) {
163 $tables = [
'page',
'revision' ];
164 $this->
addWhere(
'page_id=rev_page' );
167 if ( !is_null( $this->params[
'continue'] ) ) {
168 $continue = explode(
'|', $this->params[
'continue'] );
169 $db = $this->
getDB();
170 if ( $this->multiUserMode ) {
172 $modeFlag = array_shift( $continue );
174 if ( $this->idMode && $modeFlag ===
'name' ) {
178 $this->idMode =
false;
181 $userField = $this->idMode ?
'rev_user' :
'rev_user_text';
182 $encUser = $db->addQuotes( array_shift( $continue ) );
186 $encTS = $db->addQuotes( $db->timestamp( $continue[0] ) );
187 $encId = (int)$continue[1];
189 $op = ( $this->params[
'dir'] ==
'older' ?
'<' :
'>' );
190 if ( $this->multiUserMode ) {
192 "$userField $op $encUser OR " .
193 "($userField = $encUser AND " .
194 "(rev_timestamp $op $encTS OR " .
195 "(rev_timestamp = $encTS AND " .
196 "rev_id $op= $encId)))"
200 "rev_timestamp $op $encTS OR " .
201 "(rev_timestamp = $encTS AND " .
202 "rev_id $op= $encId)"
209 if ( !
$user->isAllowed(
'deletedhistory' ) ) {
211 } elseif ( !
$user->isAllowedAny(
'suppressrevision',
'viewsuppressed' ) ) {
217 $this->
addWhere( $this->
getDB()->bitAnd(
'rev_deleted', $bitmask ) .
" != $bitmask" );
221 if ( $this->prefixMode ) {
223 $this->
getDB()->buildLike( $this->userprefix, $this->
getDB()->anyString() ) );
224 } elseif ( $this->idMode ) {
227 $this->
addWhereFld(
'rev_user_text', $this->usernames );
232 if ( $this->multiUserMode ) {
233 $this->
addWhereRange( $this->idMode ?
'rev_user' :
'rev_user_text',
234 $this->params[
'dir'], null, null );
237 $this->params[
'dir'], $this->params[
'start'], $this->params[
'end'] );
239 $this->
addWhereRange(
'rev_id', $this->params[
'dir'], null, null );
241 $this->
addWhereFld(
'page_namespace', $this->params[
'namespace'] );
243 $show = $this->params[
'show'];
244 if ( $this->params[
'toponly'] ) {
247 if ( !is_null( $show ) ) {
248 $show = array_flip( $show );
250 if ( ( isset( $show[
'minor'] ) && isset( $show[
'!minor'] ) )
251 || ( isset( $show[
'patrolled'] ) && isset( $show[
'!patrolled'] ) )
252 || ( isset( $show[
'top'] ) && isset( $show[
'!top'] ) )
253 || ( isset( $show[
'new'] ) && isset( $show[
'!new'] ) )
258 $this->
addWhereIf(
'rev_minor_edit = 0', isset( $show[
'!minor'] ) );
259 $this->
addWhereIf(
'rev_minor_edit != 0', isset( $show[
'minor'] ) );
260 $this->
addWhereIf(
'rc_patrolled = 0', isset( $show[
'!patrolled'] ) );
261 $this->
addWhereIf(
'rc_patrolled != 0', isset( $show[
'patrolled'] ) );
262 $this->
addWhereIf(
'rev_id != page_latest', isset( $show[
'!top'] ) );
263 $this->
addWhereIf(
'rev_id = page_latest', isset( $show[
'top'] ) );
264 $this->
addWhereIf(
'rev_parent_id != 0', isset( $show[
'!new'] ) );
265 $this->
addWhereIf(
'rev_parent_id = 0', isset( $show[
'new'] ) );
267 $this->
addOption(
'LIMIT', $this->params[
'limit'] + 1 );
282 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ||
285 if ( !
$user->useRCPatrol() && !
$user->useNPPatrol() ) {
287 'You need the patrol right to request the patrolled flag',
295 $index[
'recentchanges'] =
'rc_user_text';
296 if ( isset( $show[
'patrolled'] ) || isset( $show[
'!patrolled'] ) ) {
299 $tables = [
'revision',
'recentchanges',
'page' ];
301 $this->
addWhere(
'rc_user_text=rev_user_text' );
302 $this->
addWhere(
'rc_timestamp=rev_timestamp' );
303 $this->
addWhere(
'rc_this_oldid=rev_id' );
308 'rc_user_text=rev_user_text',
309 'rc_timestamp=rev_timestamp',
310 'rc_this_oldid=rev_id' ] ] ] );
316 $this->
addFieldsIf(
'page_latest', $this->fld_flags );
318 $this->
addFieldsIf(
'rev_comment', $this->fld_comment || $this->fld_parsedcomment );
319 $this->
addFieldsIf(
'rev_len', $this->fld_size || $this->fld_sizediff );
320 $this->
addFieldsIf(
'rev_minor_edit', $this->fld_flags );
321 $this->
addFieldsIf(
'rev_parent_id', $this->fld_flags || $this->fld_sizediff || $this->fld_ids );
322 $this->
addFieldsIf(
'rc_patrolled', $this->fld_patrolled );
324 if ( $this->fld_tags ) {
327 [
'tag_summary' => [
'LEFT JOIN', [
'rev_id=ts_rev_id' ] ] ]
332 if ( isset( $this->params[
'tag'] ) ) {
335 [
'change_tag' => [
'INNER JOIN', [
'rev_id=ct_rev_id' ] ] ]
337 $this->
addWhereFld(
'ct_tag', $this->params[
'tag'] );
340 if ( isset( $index ) ) {
356 $vals[
'texthidden'] =
true;
361 $vals[
'userid'] = (int)$row->rev_user;
362 $vals[
'user'] = $row->rev_user_text;
364 $vals[
'userhidden'] =
true;
367 if ( $this->fld_ids ) {
368 $vals[
'pageid'] = intval( $row->rev_page );
369 $vals[
'revid'] = intval( $row->rev_id );
372 if ( !is_null( $row->rev_parent_id ) ) {
373 $vals[
'parentid'] = intval( $row->rev_parent_id );
379 if ( $this->fld_title ) {
383 if ( $this->fld_timestamp ) {
387 if ( $this->fld_flags ) {
388 $vals[
'new'] = $row->rev_parent_id == 0 && !is_null( $row->rev_parent_id );
389 $vals[
'minor'] = (bool)$row->rev_minor_edit;
390 $vals[
'top'] = $row->page_latest == $row->rev_id;
393 if ( ( $this->fld_comment || $this->fld_parsedcomment ) && isset( $row->rev_comment ) ) {
395 $vals[
'commenthidden'] =
true;
404 if ( $userCanView ) {
405 if ( $this->fld_comment ) {
406 $vals[
'comment'] = $row->rev_comment;
409 if ( $this->fld_parsedcomment ) {
415 if ( $this->fld_patrolled ) {
416 $vals[
'patrolled'] = (bool)$row->rc_patrolled;
419 if ( $this->fld_size && !is_null( $row->rev_len ) ) {
420 $vals[
'size'] = intval( $row->rev_len );
423 if ( $this->fld_sizediff
424 && !is_null( $row->rev_len )
425 && !is_null( $row->rev_parent_id )
427 $parentLen = isset( $this->parentLens[$row->rev_parent_id] )
428 ? $this->parentLens[$row->rev_parent_id]
430 $vals[
'sizediff'] = intval( $row->rev_len - $parentLen );
433 if ( $this->fld_tags ) {
434 if ( $row->ts_tags ) {
435 $tags = explode(
',', $row->ts_tags );
437 $vals[
'tags'] = $tags;
444 $vals[
'suppressed'] =
true;
451 if ( $this->multiUserMode ) {
452 if ( $this->idMode ) {
453 return "id|$row->rev_user|$row->rev_timestamp|$row->rev_id";
455 return "name|$row->rev_user_text|$row->rev_timestamp|$row->rev_id";
458 return "$row->rev_timestamp|$row->rev_id";
465 return 'anon-public-user-private';
490 'userprefix' => null,
533 'apihelp-query+usercontribs-param-show',
547 'action=query&list=usercontribs&ucuser=Example'
548 =>
'apihelp-query+usercontribs-example-user',
549 'action=query&list=usercontribs&ucuserprefix=192.0.2.'
550 =>
'apihelp-query+usercontribs-example-ipprefix',
555 return 'https://www.mediawiki.org/wiki/API:Usercontribs';
select($method, $extraQuery=[])
Execute a SELECT query based on the values in the internal arrays.
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...
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.
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.
const TS_ISO_8601
ISO 8601 format with no timezone: 1986-02-09T20:00:00Z.
addWhereIf($value, $condition)
Same as addWhere(), but add the WHERE clauses only if a condition is met.
getConfig()
Get the Config object.
addOption($name, $value=null)
Add an option such as LIMIT or USE INDEX.
static isIP($name)
Does the string match an anonymous IP address?
Allows to change the fields on the form that will be generated are created Can be used to omit specific feeds from being outputted You must not use this hook to add use OutputPage::addFeedLink() instead.&$feedLinks conditions will AND in the final query as a Content object as a Content object $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