* (bug 20131) PHP Notice: Undfined index: page_latest in includes/ChangesList.php...
[lhc/web/wiklou.git] / includes / api / ApiBlock.php
index 43103d0..9220d54 100644 (file)
@@ -31,7 +31,7 @@ if (!defined('MEDIAWIKI')) {
 * API module that facilitates the blocking of users. Requires API write mode
 * to be enabled.
 *
- * @addtogroup API
+ * @ingroup API
  */
 class ApiBlock extends ApiBase {
 
@@ -49,8 +49,7 @@ 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'])
@@ -70,10 +69,8 @@ class ApiBlock extends ApiBase {
                        $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'];
@@ -83,21 +80,21 @@ class ApiBlock extends ApiBase {
                $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'] = '';
@@ -109,13 +106,19 @@ class ApiBlock extends ApiBase {
                        $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,
@@ -127,13 +130,15 @@ class ApiBlock extends ApiBase {
                        '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)',
@@ -141,11 +146,13 @@ class ApiBlock extends ApiBase {
                        '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.'
                );