00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 if ( !defined( 'MEDIAWIKI' ) ) {
00026
00027 require_once ( "ApiBase.php" );
00028 }
00029
00036 class ApiUnblock extends ApiBase {
00037
00038 public function __construct( $main, $action ) {
00039 parent :: __construct( $main, $action );
00040 }
00041
00045 public function execute() {
00046 global $wgUser;
00047 $params = $this->extractRequestParams();
00048
00049 if ( $params['gettoken'] )
00050 {
00051 $res['unblocktoken'] = $wgUser->editToken();
00052 $this->getResult()->addValue( null, $this->getModuleName(), $res );
00053 return;
00054 }
00055
00056 if ( is_null( $params['id'] ) && is_null( $params['user'] ) )
00057 $this->dieUsageMsg( array( 'unblock-notarget' ) );
00058 if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) )
00059 $this->dieUsageMsg( array( 'unblock-idanduser' ) );
00060
00061 if ( !$wgUser->isAllowed( 'block' ) )
00062 $this->dieUsageMsg( array( 'cantunblock' ) );
00063
00064 $id = $params['id'];
00065 $user = $params['user'];
00066 $reason = ( is_null( $params['reason'] ) ? '' : $params['reason'] );
00067 $retval = IPUnblockForm::doUnblock( $id, $user, $reason, $range );
00068 if ( $retval )
00069 $this->dieUsageMsg( $retval );
00070
00071 $res['id'] = intval( $id );
00072 $res['user'] = $user;
00073 $res['reason'] = $reason;
00074 $this->getResult()->addValue( null, $this->getModuleName(), $res );
00075 }
00076
00077 public function mustBePosted() {
00078 return true;
00079 }
00080
00081 public function isWriteMode() {
00082 return true;
00083 }
00084
00085 public function getAllowedParams() {
00086 return array (
00087 'id' => null,
00088 'user' => null,
00089 'token' => null,
00090 'gettoken' => false,
00091 'reason' => null,
00092 );
00093 }
00094
00095 public function getParamDescription() {
00096 return array (
00097 'id' => 'ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with user',
00098 'user' => 'Username, IP address or IP range you want to unblock. Cannot be used together with id',
00099 'token' => 'An unblock token previously obtained through the gettoken parameter or prop=info',
00100 'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
00101 'reason' => 'Reason for unblock (optional)',
00102 );
00103 }
00104
00105 public function getDescription() {
00106 return array(
00107 'Unblock a user.'
00108 );
00109 }
00110
00111 public function getPossibleErrors() {
00112 return array_merge( parent::getPossibleErrors(), array(
00113 array( 'unblock-notarget' ),
00114 array( 'unblock-idanduser' ),
00115 array( 'cantunblock' ),
00116 ) );
00117 }
00118
00119 public function needsToken() {
00120 return true;
00121 }
00122
00123 public function getTokenSalt() {
00124 return '';
00125 }
00126
00127 protected function getExamples() {
00128 return array (
00129 'api.php?action=unblock&id=105',
00130 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
00131 );
00132 }
00133
00134 public function getVersion() {
00135 return __CLASS__ . ': $Id: ApiUnblock.php 74217 2010-10-03 15:53:07Z reedy $';
00136 }
00137 }