Merge "(bug 19195) Make user IDs more readily available with the API"
[lhc/web/wiklou.git] / includes / api / ApiUnblock.php
index 4115727..49353b6 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( "ApiBase.php" );
-}
-
 /**
  * API module that facilitates the unblocking of users. Requires API write mode
  * to be enabled.
@@ -49,7 +44,7 @@ class ApiUnblock extends ApiBase {
                $params = $this->extractRequestParams();
 
                if ( $params['gettoken'] ) {
-                       $res['unblocktoken'] = $user->getEditToken( '', $this->getMain()->getRequest() );
+                       $res['unblocktoken'] = $user->getEditToken();
                        $this->getResult()->addValue( null, $this->getModuleName(), $res );
                        return;
                }
@@ -66,7 +61,7 @@ class ApiUnblock extends ApiBase {
                }
                # bug 15810: blocked admins should have limited access here
                if ( $user->isBlocked() ) {
-                       $status = SpecialBlock::checkUnblockSelf( $params['user'] );
+                       $status = SpecialBlock::checkUnblockSelf( $params['user'], $user );
                        if ( $status !== true ) {
                                $this->dieUsageMsg( $status );
                        }
@@ -77,13 +72,15 @@ class ApiUnblock extends ApiBase {
                        'Reason' => is_null( $params['reason'] ) ? '' : $params['reason']
                );
                $block = Block::newFromTarget( $data['Target'] );
-               $retval = SpecialUnblock::processUnblock( $data );
+               $retval = SpecialUnblock::processUnblock( $data, $this->getContext() );
                if ( $retval !== true ) {
                        $this->dieUsageMsg( $retval[0] );
                }
 
                $res['id'] = $block->getId();
-               $res['user'] = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
+               $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
+               $res['user'] = $target;
+               $res['userid'] = $target instanceof User ? $target->getId() : 0;
                $res['reason'] = $params['reason'];
                $this->getResult()->addValue( null, $this->getModuleName(), $res );
        }
@@ -103,7 +100,10 @@ class ApiUnblock extends ApiBase {
                        ),
                        'user' => null,
                        'token' => null,
-                       'gettoken' => false,
+                       'gettoken' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
                        'reason' => null,
                );
        }
@@ -113,7 +113,7 @@ class ApiUnblock extends ApiBase {
                return array(
                        'id' => "ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with {$p}user",
                        'user' => "Username, IP address or IP range you want to unblock. Cannot be used together with {$p}id",
-                       'token' => "An unblock token previously obtained through the gettoken parameter or {$p}prop=info",
+                       'token' => "An unblock token previously obtained through prop=info",
                        'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
                        'reason' => 'Reason for unblock (optional)',
                );
@@ -149,7 +149,7 @@ class ApiUnblock extends ApiBase {
        }
 
        public function getHelpUrls() {
-               return 'http://www.mediawiki.org/wiki/API:Block';
+               return 'https://www.mediawiki.org/wiki/API:Block';
        }
 
        public function getVersion() {