fixes #22501 follow up r61101 remove superfluous, buggy code that was over-rideing...
[lhc/web/wiklou.git] / includes / api / ApiUnblock.php
index b262df2..595dcc7 100644 (file)
@@ -22,9 +22,9 @@
  * http://www.gnu.org/copyleft/gpl.html
  */
 
-if (!defined('MEDIAWIKI')) {
+if ( !defined( 'MEDIAWIKI' ) ) {
        // Eclipse helper - will be ignored in production
-       require_once ("ApiBase.php");
+       require_once ( "ApiBase.php" );
 }
 
 /**
@@ -35,8 +35,8 @@ if (!defined('MEDIAWIKI')) {
  */
 class ApiUnblock extends ApiBase {
 
-       public function __construct($main, $action) {
-               parent :: __construct($main, $action);
+       public function __construct( $main, $action ) {
+               parent :: __construct( $main, $action );
        }
 
        /**
@@ -44,41 +44,44 @@ class ApiUnblock extends ApiBase {
         */
        public function execute() {
                global $wgUser;
-               $this->getMain()->requestWriteMode();
                $params = $this->extractRequestParams();
 
-               if($params['gettoken'])
+               if ( $params['gettoken'] )
                {
                        $res['unblocktoken'] = $wgUser->editToken();
-                       $this->getResult()->addValue(null, $this->getModuleName(), $res);
+                       $this->getResult()->addValue( null, $this->getModuleName(), $res );
                        return;
                }
 
-               if(is_null($params['id']) && is_null($params['user']))
-                       $this->dieUsageMsg(array('unblock-notarget'));
-               if(!is_null($params['id']) && !is_null($params['user']))
-                       $this->dieUsageMsg(array('unblock-idanduser'));
-               if(is_null($params['token']))
-                       $this->dieUsageMsg(array('missingparam', 'token'));
-               if(!$wgUser->matchEditToken($params['token']))
-                       $this->dieUsageMsg(array('sessionfailure'));
-               if(!$wgUser->isAllowed('block'))
-                       $this->dieUsageMsg(array('cantunblock'));
+               if ( is_null( $params['id'] ) && is_null( $params['user'] ) )
+                       $this->dieUsageMsg( array( 'unblock-notarget' ) );
+               if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) )
+                       $this->dieUsageMsg( array( 'unblock-idanduser' ) );
+               if ( !$wgUser->matchEditToken( $params['token'] ) )
+                       $this->dieUsageMsg( array( 'sessionfailure' ) );
+               if ( !$wgUser->isAllowed( 'block' ) )
+                       $this->dieUsageMsg( array( 'cantunblock' ) );
 
                $id = $params['id'];
                $user = $params['user'];
-               $reason = (is_null($params['reason']) ? '' : $params['reason']);
-               $retval = IPUnblockForm::doUnblock($id, $user, $reason, $range);
-               if($retval)
-                       $this->dieUsageMsg($retval);
+               $reason = ( is_null( $params['reason'] ) ? '' : $params['reason'] );
+               $retval = IPUnblockForm::doUnblock( $id, $user, $reason, $range );
+               if ( $retval )
+                       $this->dieUsageMsg( $retval );
 
-               $res['id'] = $id;
+               $res['id'] = intval( $id );
                $res['user'] = $user;
                $res['reason'] = $reason;
-               $this->getResult()->addValue(null, $this->getModuleName(), $res);
+               $this->getResult()->addValue( null, $this->getModuleName(), $res );
        }
 
-       public function mustBePosted() { return true; }
+       public function mustBePosted() {
+               return true;
+       }
+
+       public function isWriteMode() {
+               return true;
+       }
 
        public function getAllowedParams() {
                return array (
@@ -105,6 +108,19 @@ class ApiUnblock extends ApiBase {
                        'Unblock a user.'
                );
        }
+       
+    public function getPossibleErrors() {
+               return array_merge( parent::getPossibleErrors(), array(
+                       array( 'unblock-notarget' ),
+                       array( 'unblock-idanduser' ),
+                       array( 'sessionfailure' ),
+                       array( 'cantunblock' ),
+        ) );
+       }
+       
+       public function requiresToken() {
+               return true;
+       }
 
        protected function getExamples() {
                return array (