65 parent::__construct( $query, $moduleName,
'bk' );
77 $prop = array_fill_keys( $params[
'prop'],
true );
78 $fld_id = isset( $prop[
'id'] );
79 $fld_user = isset( $prop[
'user'] );
80 $fld_userid = isset( $prop[
'userid'] );
81 $fld_by = isset( $prop[
'by'] );
82 $fld_byid = isset( $prop[
'byid'] );
83 $fld_timestamp = isset( $prop[
'timestamp'] );
84 $fld_expiry = isset( $prop[
'expiry'] );
85 $fld_reason = isset( $prop[
'reason'] );
86 $fld_range = isset( $prop[
'range'] );
87 $fld_flags = isset( $prop[
'flags'] );
88 $fld_restrictions = isset( $prop[
'restrictions'] );
93 $this->
addFields( [
'ipb_auto',
'ipb_id',
'ipb_timestamp' ] );
95 $this->
addFieldsIf( [
'ipb_address',
'ipb_user' ], $fld_user || $fld_userid );
96 if ( $fld_by || $fld_byid ) {
98 $this->
addFields( [
'actor_user',
'actor_name' ] );
99 $this->
addJoinConds( [
'actor' => [
'JOIN',
'actor_id=ipb_by_actor' ] ] );
102 $this->
addFieldsIf( [
'ipb_range_start',
'ipb_range_end' ], $fld_range );
103 $this->
addFieldsIf( [
'ipb_anon_only',
'ipb_create_account',
'ipb_enable_autoblock',
104 'ipb_block_email',
'ipb_deleted',
'ipb_allow_usertalk',
'ipb_sitewide' ],
106 $this->
addFieldsIf(
'ipb_sitewide', $fld_restrictions );
109 $commentQuery = $this->commentStore->getJoin(
'ipb_reason' );
110 $this->
addTables( $commentQuery[
'tables'] );
111 $this->
addFields( $commentQuery[
'fields'] );
115 $this->
addOption(
'LIMIT', $params[
'limit'] + 1 );
123 $this->
addWhereRange(
'ipb_id', $params[
'dir'],
null,
null );
125 if ( $params[
'continue'] !==
null ) {
126 $cont = explode(
'|', $params[
'continue'] );
128 $op = ( $params[
'dir'] ==
'newer' ?
'>' :
'<' );
129 $continueTimestamp = $db->addQuotes( $db->timestamp( $cont[0] ) );
130 $continueId = (int)$cont[1];
132 $this->
addWhere(
"ipb_timestamp $op $continueTimestamp OR " .
133 "(ipb_timestamp = $continueTimestamp AND " .
134 "ipb_id $op= $continueId)"
138 if ( isset( $params[
'ids'] ) ) {
141 if ( isset( $params[
'users'] ) ) {
143 foreach ( (array)$params[
'users'] as $u ) {
149 if ( isset( $params[
'ip'] ) ) {
150 $blockCIDRLimit = $this->
getConfig()->get(
'BlockCIDRLimit' );
151 if ( IPUtils::isIPv4( $params[
'ip'] ) ) {
153 $cidrLimit = $blockCIDRLimit[
'IPv4'];
155 } elseif ( IPUtils::isIPv6( $params[
'ip'] ) ) {
157 $cidrLimit = $blockCIDRLimit[
'IPv6'];
163 # Check range validity, if it's a CIDR
164 list( $ip, $range ) = IPUtils::parseCIDR( $params[
'ip'] );
165 if ( $ip !==
false && $range !==
false && $range < $cidrLimit ) {
169 # Let IPUtils::parseRange handle calculating $upper, instead of duplicating the logic here.
170 list( $lower, $upper ) = IPUtils::parseRange( $params[
'ip'] );
172 # Extract the common prefix to any rangeblock affecting this IP/CIDR
173 $prefix = substr( $lower, 0, $prefixLen + floor( $cidrLimit / 4 ) );
175 # Fairly hard to make a malicious SQL statement out of hex characters,
176 # but it is good practice to add quotes
177 $lower = $db->addQuotes( $lower );
178 $upper = $db->addQuotes( $upper );
181 'ipb_range_start' . $db->buildLike( $prefix, $db->anyString() ),
182 'ipb_range_start <= ' . $lower,
183 'ipb_range_end >= ' . $upper,
188 if ( $params[
'show'] !==
null ) {
189 $show = array_fill_keys( $params[
'show'],
true );
192 if ( ( isset( $show[
'account'] ) && isset( $show[
'!account'] ) )
193 || ( isset( $show[
'ip'] ) && isset( $show[
'!ip'] ) )
194 || ( isset( $show[
'range'] ) && isset( $show[
'!range'] ) )
195 || ( isset( $show[
'temp'] ) && isset( $show[
'!temp'] ) )
200 $this->
addWhereIf(
'ipb_user = 0', isset( $show[
'!account'] ) );
201 $this->
addWhereIf(
'ipb_user != 0', isset( $show[
'account'] ) );
202 $this->
addWhereIf(
'ipb_user != 0 OR ipb_range_end > ipb_range_start', isset( $show[
'!ip'] ) );
203 $this->
addWhereIf(
'ipb_user = 0 AND ipb_range_end = ipb_range_start', isset( $show[
'ip'] ) );
205 $db->addQuotes( $db->getInfinity() ), isset( $show[
'!temp'] ) );
207 $db->addQuotes( $db->getInfinity() ), isset( $show[
'temp'] ) );
208 $this->
addWhereIf(
'ipb_range_end = ipb_range_start', isset( $show[
'!range'] ) );
209 $this->
addWhereIf(
'ipb_range_end > ipb_range_start', isset( $show[
'range'] ) );
212 if ( !$this->
getAuthority()->isAllowed(
'hideuser' ) ) {
216 # Filter out expired rows
217 $this->
addWhere(
'ipb_expiry > ' . $db->addQuotes( $db->timestamp() ) );
222 if ( $fld_restrictions ) {
227 foreach (
$res as $row ) {
228 if ( ++$count > $params[
'limit'] ) {
234 ApiResult::META_TYPE =>
'assoc',
237 $block[
'id'] = (int)$row->ipb_id;
239 if ( $fld_user && !$row->ipb_auto ) {
240 $block[
'user'] = $row->ipb_address;
242 if ( $fld_userid && !$row->ipb_auto ) {
243 $block[
'userid'] = (int)$row->ipb_user;
246 $block[
'by'] = $row->actor_name;
249 $block[
'byid'] = (int)$row->actor_user;
251 if ( $fld_timestamp ) {
252 $block[
'timestamp'] =
wfTimestamp( TS_ISO_8601, $row->ipb_timestamp );
255 $block[
'expiry'] = ApiResult::formatExpiry( $row->ipb_expiry );
258 $block[
'reason'] = $this->commentStore->getComment(
'ipb_reason', $row )->text;
260 if ( $fld_range && !$row->ipb_auto ) {
261 $block[
'rangestart'] = IPUtils::formatHex( $row->ipb_range_start );
262 $block[
'rangeend'] = IPUtils::formatHex( $row->ipb_range_end );
266 $block[
'automatic'] = (bool)$row->ipb_auto;
267 $block[
'anononly'] = (bool)$row->ipb_anon_only;
268 $block[
'nocreate'] = (bool)$row->ipb_create_account;
269 $block[
'autoblock'] = (bool)$row->ipb_enable_autoblock;
270 $block[
'noemail'] = (bool)$row->ipb_block_email;
271 $block[
'hidden'] = (bool)$row->ipb_deleted;
272 $block[
'allowusertalk'] = (bool)$row->ipb_allow_usertalk;
273 $block[
'partial'] = !(bool)$row->ipb_sitewide;
276 if ( $fld_restrictions ) {
277 $block[
'restrictions'] = [];
278 if ( !$row->ipb_sitewide && isset( $restrictions[$row->ipb_id] ) ) {
279 $block[
'restrictions'] = $restrictions[$row->ipb_id];
283 $fit = $result->addValue( [
'query', $this->
getModuleName() ],
null, $block );
289 $result->addIndexedTagName( [
'query', $this->
getModuleName() ],
'block' );
296 "baduser_{$encParamName}"
299 $name = $this->userNameUtils->isIP( $user ) || IPUtils::isIPv6( $user )
301 : $this->userNameUtils->getCanonical( $user );
302 if ( $name ===
false ) {
305 "baduser_{$encParamName}"
322 foreach ( $result as $row ) {
323 if ( ++$count <= $limit && !$row->ipb_sitewide ) {
324 $partialIds[] = (int)$row->ipb_id;
328 $restrictions = $this->blockRestrictionStore->loadByBlockId( $partialIds );
333 'ns' =>
'namespaces',
335 if ( $this->
getConfig()->
get(
'EnablePartialActionBlocks' ) ) {
336 $keys[
'action'] =
'actions';
339 foreach ( $restrictions as $restriction ) {
340 $key =
$keys[$restriction->getType()];
341 $id = $restriction->getBlockId();
342 switch ( $restriction->getType() ) {
345 '@phan-var \MediaWiki\Block\Restriction\PageRestriction $restriction';
346 $value = [
'id' => $restriction->getValue() ];
347 if ( $restriction->getTitle() ) {
352 $value = $this->blockActionInfo->getActionFromId( $restriction->getValue() );
355 $value = $restriction->getValue();
358 if ( !isset( $data[$id][$key] ) ) {
359 $data[$id][$key] = [];
360 ApiResult::setIndexedTagName( $data[$id][$key], $restriction->getType() );
362 $data[$id][$key][] = $value;
369 $blockCIDRLimit = $this->
getConfig()->get(
'BlockCIDRLimit' );
392 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'cidr' ],
397 'apihelp-query+blocks-param-ip',
398 $blockCIDRLimit[
'IPv4'],
399 $blockCIDRLimit[
'IPv6'],
448 'action=query&list=blocks'
449 =>
'apihelp-query+blocks-example-simple',
450 'action=query&list=blocks&bkusers=Alice|Bob'
451 =>
'apihelp-query+blocks-example-users',
456 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Blocks';
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,...
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
encodeParamName( $paramName)
This method mangles parameter name based on the prefix supplied to the constructor.
dieContinueUsageIf( $condition)
Die with the 'badcontinue' error.
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 LIMIT_BIG1
Fast query, standard limit.
requireMaxOneParameter( $params,... $required)
Die if more than one of a certain set of parameters is set and not false.
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.
This is a base class for all Query modules.
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.
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)
select( $method, $extraQuery=[], array &$hookData=null)
Execute a SELECT query based on the values in the internal arrays.
addFieldsIf( $value, $condition)
Same as addFields(), but add the fields only if a condition is met.
addWhereIDsFld( $table, $field, $ids)
Like addWhereFld for an integer list of IDs.
addJoinConds( $join_conds)
Add a set of JOIN conditions to the internal array.
addWhereFld( $field, $value)
Equivalent to addWhere( [ $field => $value ] )
addWhere( $value)
Add a set of WHERE clauses to the internal array.
Query module to enumerate all user blocks.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
BlockActionInfo $blockActionInfo
BlockRestrictionStore $blockRestrictionStore
getRestrictionData(IResultWrapper $result, $limit)
Retrieves the restrictions based on the query result.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
__construct(ApiQuery $query, $moduleName, BlockActionInfo $blockActionInfo, BlockRestrictionStore $blockRestrictionStore, CommentStore $commentStore, UserNameUtils $userNameUtils)
CommentStore $commentStore
UserNameUtils $userNameUtils
getExamplesMessages()
Returns usage examples for this module.
getHelpUrls()
Return links to more detailed help pages about the module.
This is the main query class.