X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2Fapi%2FApiBlock.php;h=7d3a40bb5f5e054c6baa645a3d17e205d1278474;hb=364be04f3f194094ca08c098ac4cae53da2f4e74;hp=a7197320ca804ffc3601201407768ecf9e29914a;hpb=78059976086f0ce02cdc328868b5b6ba0e88e576;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/api/ApiBlock.php b/includes/api/ApiBlock.php index a7197320ca..7d3a40bb5f 100644 --- a/includes/api/ApiBlock.php +++ b/includes/api/ApiBlock.php @@ -24,11 +24,6 @@ * @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,30 +43,30 @@ class ApiBlock extends ApiBase { * of success. If it fails, the result will specify the nature of the error. */ public function execute() { - global $wgUser, $wgBlockAllowsUTEdit; + $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' ) ) { - $this->dieUsageMsg( array( 'cantblock' ) ); + 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' ) ) { - $this->dieUsageMsg( array( 'canthide' ) ); + if ( $params['hidename'] && !$user->isAllowed( 'hideuser' ) ) { + $this->dieUsageMsg( 'canthide' ); } - if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $wgUser ) ) { - $this->dieUsageMsg( array( 'cantblock-email' ) ); + if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $user ) ) { + $this->dieUsageMsg( 'cantblock-email' ); } $data = array( @@ -87,24 +82,25 @@ class ApiBlock extends ApiBase { 'AutoBlock' => $params['autoblock'], 'DisableEmail' => $params['noemail'], 'HideUser' => $params['hidename'], - 'DisableUTEdit' => $params['allowusertalk'], + 'DisableUTEdit' => !$params['allowusertalk'], 'AlreadyBlocked' => $params['reblock'], 'Watch' => $params['watchuser'], + '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 ); } - list( $target, $type ) = SpecialBlock::getTargetAndType( $params['user'] ); + list( $target, /*...*/ ) = SpecialBlock::getTargetAndType( $params['user'] ); $res['user'] = $params['user']; $res['userID'] = $target instanceof User ? $target->getId() : 0; - $block = SpecialBlock::getBlockFromTargetAndType( $target, $type ); + $block = Block::newFromTarget( $target ); if( $block instanceof Block ){ - $res['expiry'] = $block->mExpiry == Block::infinity() + $res['expiry'] = $block->mExpiry == wfGetDB( DB_SLAVE )->getInfinity() ? 'infinite' : wfTimestamp( TS_ISO_8601, $block->mExpiry ); } else { @@ -207,13 +203,17 @@ class ApiBlock extends ApiBase { return ''; } - protected function getExamples() { + public function getExamples() { return array( 'api.php?action=block&user=123.5.5.12&expiry=3%20days&reason=First%20strike', 'api.php?action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate=&autoblock=&noemail=' ); } + public function getHelpUrls() { + return 'https://www.mediawiki.org/wiki/API:Block'; + } + public function getVersion() { return __CLASS__ . ': $Id$'; }