global $wgUser;
$params = $this->extractRequestParams();
+ if(isset($params['users']) && isset($params['ip']))
+ $this->dieUsage('bkusers and bkip cannot be used together', 'usersandip');
+
$prop = array_flip($params['prop']);
$fld_id = isset($prop['id']);
$fld_user = isset($prop['user']);
$this->prepareUsername($u);
$this->addWhere(array('ipb_address' => $this->usernames));
}
+ if(isset($params['ip']))
+ {
+ list($ip, $range) = IP::parseCIDR($params['ip']);
+ if($ip && $range)
+ {
+ # We got a CIDR range
+ if($range < 16)
+ $this->dieUsage('CIDR ranges broader than /16 are not accepted', 'cidrtoobroad');
+ $lower = wfBaseConvert($ip, 10, 16, 8, false);
+ $upper = wfBaseConvert($ip + pow(2, 32 - $range) - 1, 10, 16, 8, false);
+ }
+ else
+ $lower = $upper = IP::toHex($params['ip']);
+ $prefix = substr($lower, 0, 4);
+ $this->addWhere(array(
+ "ipb_range_start LIKE '$prefix%'",
+ "ipb_range_start <= '$lower'",
+ "ipb_range_end >= '$upper'"
+ ));
+ }
if(!$wgUser->isAllowed('suppress'))
$this->addWhere(array('ipb_deleted' => 0));
$result->addValue('query', $this->getModuleName(), $data);
}
- protected function prepareUsername($user) {
- if( $user ) {
- $name = User::isIP( $user )
- ? $user
- : User::getCanonicalName( $user, 'valid' );
- if( $name === false ) {
- $this->dieUsage( "User name {$user} is not valid", 'param_user' );
- } else {
- $this->usernames[] = $name;
- }
- } else {
- $this->dieUsage( 'User parameter may not be empty', 'param_user' );
- }
+ protected function prepareUsername($user)
+ {
+ if(!$user)
+ $this->dieUsage('User parameter may not be empty', 'param_user');
+ $name = User::isIP($user)
+ ? $user
+ : User::getCanonicalName($user, 'valid');
+ if($name === false)
+ $this->dieUsage("User name {$user} is not valid", 'param_user');
+ $this->usernames[] = $name;
}
protected function convertHexIP($ip)
'users' => array(
ApiBase :: PARAM_ISMULTI => true
),
+ 'ip' => null,
'limit' => array(
ApiBase :: PARAM_DFLT => 10,
ApiBase :: PARAM_TYPE => 'limit',
'dir' => 'The direction in which to enumerate',
'ids' => 'Pipe-separated list of block IDs to list (optional)',
'users' => 'Pipe-separated list of users to search for (optional)',
+ 'ip' => array( 'Get all blocks applying to this IP or CIDR range, including range blocks.',
+ 'Cannot be used together with bkusers. CIDR ranges broader than /16 are not accepted.'),
'limit' => 'The maximum amount of blocks to list',
'prop' => 'Which properties to get',
);