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 if(is_null($params['token']))
00061 $this->dieUsageMsg(array('missingparam', 'token'));
00062 if(!$wgUser->matchEditToken($params['token']))
00063 $this->dieUsageMsg(array('sessionfailure'));
00064 if(!$wgUser->isAllowed('block'))
00065 $this->dieUsageMsg(array('cantunblock'));
00066
00067 $id = $params['id'];
00068 $user = $params['user'];
00069 $reason = (is_null($params['reason']) ? '' : $params['reason']);
00070 $retval = IPUnblockForm::doUnblock($id, $user, $reason, $range);
00071 if($retval)
00072 $this->dieUsageMsg($retval);
00073
00074 $res['id'] = intval($id);
00075 $res['user'] = $user;
00076 $res['reason'] = $reason;
00077 $this->getResult()->addValue(null, $this->getModuleName(), $res);
00078 }
00079
00080 public function mustBePosted() { return true; }
00081
00082 public function isWriteMode() {
00083 return true;
00084 }
00085
00086 public function getAllowedParams() {
00087 return array (
00088 'id' => null,
00089 'user' => null,
00090 'token' => null,
00091 'gettoken' => false,
00092 'reason' => null,
00093 );
00094 }
00095
00096 public function getParamDescription() {
00097 return array (
00098 'id' => 'ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with user',
00099 'user' => 'Username, IP address or IP range you want to unblock. Cannot be used together with id',
00100 'token' => 'An unblock token previously obtained through the gettoken parameter or prop=info',
00101 'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
00102 'reason' => 'Reason for unblock (optional)',
00103 );
00104 }
00105
00106 public function getDescription() {
00107 return array(
00108 'Unblock a user.'
00109 );
00110 }
00111
00112 protected function getExamples() {
00113 return array (
00114 'api.php?action=unblock&id=105',
00115 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
00116 );
00117 }
00118
00119 public function getVersion() {
00120 return __CLASS__ . ': $Id: ApiUnblock.php 48091 2009-03-06 13:49:44Z catrope $';
00121 }
00122 }