Merge "Revert "Adding sanity check to Title::isRedirect().""
[lhc/web/wiklou.git] / includes / api / ApiBlock.php
index f77fdf4..e229ef0 100644 (file)
  * @file
  */
 
-if ( !defined( 'MEDIAWIKI' ) ) {
-       // Eclipse helper - will be ignored in production
-       require_once( "ApiBase.php" );
-}
-
 /**
 * API module that facilitates the blocking of users. Requires API write mode
 * to be enabled.
@@ -48,29 +43,29 @@ class ApiBlock extends ApiBase {
         * of success. If it fails, the result will specify the nature of the error.
         */
        public function execute() {
-               global $wgUser;
+               $user = $this->getUser();
                $params = $this->extractRequestParams();
 
                if ( $params['gettoken'] ) {
-                       $res['blocktoken'] = $wgUser->editToken( '', $this->getMain()->getRequest() );
+                       $res['blocktoken'] = $user->getEditToken();
                        $this->getResult()->addValue( null, $this->getModuleName(), $res );
                        return;
                }
 
-               if ( !$wgUser->isAllowed( 'block' ) ) {
+               if ( !$user->isAllowed( 'block' ) ) {
                        $this->dieUsageMsg( 'cantblock' );
                }
                # bug 15810: blocked admins should have limited access here
-               if ( $wgUser->isBlocked() ) {
-                       $status = SpecialBlock::checkUnblockSelf( $params['user'] );
+               if ( $user->isBlocked() ) {
+                       $status = SpecialBlock::checkUnblockSelf( $params['user'], $user );
                        if ( $status !== true ) {
                                $this->dieUsageMsg( array( $status ) );
                        }
                }
-               if ( $params['hidename'] && !$wgUser->isAllowed( 'hideuser' ) ) {
+               if ( $params['hidename'] && !$user->isAllowed( 'hideuser' ) ) {
                        $this->dieUsageMsg( 'canthide' );
                }
-               if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $wgUser ) ) {
+               if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $user ) ) {
                        $this->dieUsageMsg( 'cantblock-email' );
                }
 
@@ -93,7 +88,7 @@ class ApiBlock extends ApiBase {
                        'Confirm' => true,
                );
 
-               $retval = SpecialBlock::processForm( $data );
+               $retval = SpecialBlock::processForm( $data, $this->getContext() );
                if ( $retval !== true ) {
                        // We don't care about multiple errors, just report one of them
                        $this->dieUsageMsg( $retval );
@@ -105,12 +100,14 @@ class ApiBlock extends ApiBase {
 
                $block = Block::newFromTarget( $target );
                if( $block instanceof Block ){
-                       $res['expiry'] = $block->mExpiry == wfGetDB( DB_SLAVE )->getInfinity()
+                       $res['expiry'] = $block->mExpiry == $this->getDB()->getInfinity()
                                ? 'infinite'
                                : wfTimestamp( TS_ISO_8601, $block->mExpiry );
+                       $res['id'] = $block->getId();
                } else {
                        # should be unreachable
                        $res['expiry'] = '';
+                       $res['id'] = '';
                }
 
                $res['reason'] = $params['reason'];
@@ -154,7 +151,10 @@ class ApiBlock extends ApiBase {
                                ApiBase::PARAM_REQUIRED => true
                        ),
                        'token' => null,
-                       'gettoken' => false,
+                       'gettoken' => array(
+                               ApiBase::PARAM_DFLT => false,
+                               ApiBase::PARAM_DEPRECATED => true,
+                       ),
                        'expiry' => 'never',
                        'reason' => null,
                        'anononly' => false,
@@ -171,7 +171,7 @@ class ApiBlock extends ApiBase {
        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 or prop=info',
+                       'token' => 'A block token previously obtained through 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)',
@@ -216,7 +216,7 @@ class ApiBlock extends ApiBase {
        }
 
        public function getHelpUrls() {
-               return 'http://www.mediawiki.org/wiki/API:Block';
+               return 'https://www.mediawiki.org/wiki/API:Block';
        }
 
        public function getVersion() {