* API module that facilitates the blocking of users. Requires API write mode
* to be enabled.
*
- * @addtogroup API
+ * @ingroup API
*/
class ApiBlock extends ApiBase {
* of success. If it fails, the result will specify the nature of the error.
*/
public function execute() {
- global $wgUser;
- $this->getMain()->requestWriteMode();
+ global $wgUser, $wgBlockAllowsUTEdit;
$params = $this->extractRequestParams();
if($params['gettoken'])
$this->dieUsageMsg(array('cantblock'));
if($params['hidename'] && !$wgUser->isAllowed('hideuser'))
$this->dieUsageMsg(array('canthide'));
- if($params['noemail'] && !$wgUser->isAllowed('blockemail'))
+ if($params['noemail'] && !IPBlockForm::canBlockEmail($wgUser) )
$this->dieUsageMsg(array('cantblock-email'));
- if(wfReadOnly())
- $this->dieUsageMsg(array('readonlytext'));
$form = new IPBlockForm('');
$form->BlockAddress = $params['user'];
$form->BlockOther = '';
$form->BlockAnonOnly = $params['anononly'];
$form->BlockCreateAccount = $params['nocreate'];
- $form->BlockEnableAutoBlock = $params['autoblock'];
+ $form->BlockEnableAutoblock = $params['autoblock'];
$form->BlockEmail = $params['noemail'];
$form->BlockHideName = $params['hidename'];
+ $form->BlockAllowUsertalk = $params['allowusertalk'] && $wgBlockAllowsUTEdit;
+ $form->BlockReblock = $params['reblock'];
- $dbw = wfGetDb(DB_MASTER);
- $dbw->begin();
+ $userID = $expiry = null;
$retval = $form->doBlock($userID, $expiry);
- if(!empty($retval))
+ if(count($retval))
// We don't care about multiple errors, just report one of them
$this->dieUsageMsg($retval);
- $dbw->commit();
$res['user'] = $params['user'];
- $res['userID'] = $userID;
- $res['expiry'] = ($expiry == Block::infinity() ? 'infinite' : $expiry);
+ $res['userID'] = intval($userID);
+ $res['expiry'] = ($expiry == Block::infinity() ? 'infinite' : wfTimestamp(TS_ISO_8601, $expiry));
$res['reason'] = $params['reason'];
if($params['anononly'])
$res['anononly'] = '';
$res['noemail'] = '';
if($params['hidename'])
$res['hidename'] = '';
+ if($params['allowusertalk'])
+ $res['allowusertalk'] = '';
$this->getResult()->addValue(null, $this->getModuleName(), $res);
}
public function mustBePosted() { return true; }
- protected function getAllowedParams() {
+ public function isWriteMode() {
+ return true;
+ }
+
+ public function getAllowedParams() {
return array (
'user' => null,
'token' => null,
'autoblock' => false,
'noemail' => false,
'hidename' => false,
+ 'allowusertalk' => false,
+ 'reblock' => false,
);
}
- protected function getParamDescription() {
+ public function getParamDescription() {
return array (
'user' => 'Username, IP address or IP range you want to block',
- 'token' => 'A block token previously obtained through the gettoken parameter',
+ 'token' => 'A block token previously obtained through the gettoken parameter or prop=info',
'gettoken' => 'If set, a block token will be returned, and no other action will be taken',
'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.',
'reason' => 'Reason for block (optional)',
'nocreate' => 'Prevent account creation',
'autoblock' => 'Automatically block the last used IP address, and any subsequent IP addresses they try to login from',
'noemail' => 'Prevent user from sending e-mail through the wiki. (Requires the "blockemail" right.)',
- 'hidename' => 'Hide the username from the block log. (Requires the "hideuser" right.)'
+ 'hidename' => 'Hide the username from the block log. (Requires the "hideuser" right.)',
+ 'allowusertalk' => 'Allow the user to edit their own talk page (depends on $wgBlockAllowsUTEdit)',
+ 'reblock' => 'If the user is already blocked, overwrite the existing block',
);
}
- protected function getDescription() {
+ public function getDescription() {
return array(
'Block a user.'
);