Add support for Number grouping(commafy) based on CLDR number grouping patterns like...
[lhc/web/wiklou.git] / includes / api / ApiUnblock.php
index f8d4909..6fd9816 100644 (file)
@@ -49,40 +49,42 @@ class ApiUnblock extends ApiBase {
                $params = $this->extractRequestParams();
 
                if ( $params['gettoken'] ) {
-                       $res['unblocktoken'] = $wgUser->editToken();
+                       $res['unblocktoken'] = $wgUser->editToken( '', $this->getMain()->getRequest() );
                        $this->getResult()->addValue( null, $this->getModuleName(), $res );
                        return;
                }
 
                if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) {
-                       $this->dieUsageMsg( array( 'unblock-notarget' ) );
+                       $this->dieUsageMsg( 'unblock-notarget' );
                }
                if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) {
-                       $this->dieUsageMsg( array( 'unblock-idanduser' ) );
+                       $this->dieUsageMsg( 'unblock-idanduser' );
                }
 
                if ( !$wgUser->isAllowed( 'block' ) ) {
-                       $this->dieUsageMsg( array( 'cantunblock' ) );
+                       $this->dieUsageMsg( 'cantunblock' );
                }
                # bug 15810: blocked admins should have limited access here
                if ( $wgUser->isBlocked() ) {
-                       $status = IPBlockForm::checkUnblockSelf( $params['user'] );
+                       $status = SpecialBlock::checkUnblockSelf( $params['user'] );
                        if ( $status !== true ) {
-                               $this->dieUsageMsg( array( $status ) );
+                               $this->dieUsageMsg( $status );
                        }
                }
 
-               $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 );
+               $data = array(
+                       'Target' => is_null( $params['id'] ) ? $params['user'] : "#{$params['id']}",
+                       'Reason' => is_null( $params['reason'] ) ? '' : $params['reason']
+               );
+               $block = Block::newFromTarget( $data['Target'] );
+               $retval = SpecialUnblock::processUnblock( $data );
+               if ( $retval !== true ) {
+                       $this->dieUsageMsg( $retval[0] );
                }
 
-               $res['id'] = intval( $id );
-               $res['user'] = $user;
-               $res['reason'] = $reason;
+               $res['id'] = $block->getId();
+               $res['user'] = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
+               $res['reason'] = $params['reason'];
                $this->getResult()->addValue( null, $this->getModuleName(), $res );
        }
 
@@ -96,7 +98,9 @@ class ApiUnblock extends ApiBase {
 
        public function getAllowedParams() {
                return array(
-                       'id' => null,
+                       'id' => array(
+                               ApiBase::PARAM_TYPE => 'integer',
+                       ),
                        'user' => null,
                        'token' => null,
                        'gettoken' => false,
@@ -137,13 +141,17 @@ class ApiUnblock extends ApiBase {
                return '';
        }
 
-       protected function getExamples() {
+       public function getExamples() {
                return array(
                        'api.php?action=unblock&id=105',
                        'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
                );
        }
 
+       public function getHelpUrls() {
+               return 'http://www.mediawiki.org/wiki/API:Block';
+       }
+
        public function getVersion() {
                return __CLASS__ . ': $Id$';
        }