9f707822e9330955dce6c62a6c0a08d1ef42f7db
4 * Created on Sep 7, 2007
5 * API for MediaWiki 1.8+
7 * Copyright (C) 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * http://www.gnu.org/copyleft/gpl.html
25 if (!defined('MEDIAWIKI')) {
26 // Eclipse helper - will be ignored in production
27 require_once ("ApiBase.php");
31 * API module that facilitates the unblocking of users. Requires API write mode
36 class ApiUnblock
extends ApiBase
{
38 public function __construct($main, $action) {
39 parent
:: __construct($main, $action);
43 * Unblocks the specified user or provides the reason the unblock failed.
45 public function execute() {
47 $this->getMain()->requestWriteMode();
48 $params = $this->extractRequestParams();
50 if($params['gettoken'])
52 $res['unblocktoken'] = $wgUser->editToken();
53 $this->getResult()->addValue(null, $this->getModuleName(), $res);
57 if(is_null($params['id']) && is_null($params['user']))
58 $this->dieUsageMsg(array('unblock-notarget'));
59 if(!is_null($params['id']) && !is_null($params['user']))
60 $this->dieUsageMsg(array('unblock-idanduser'));
61 if(is_null($params['token']))
62 $this->dieUsageMsg(array('missingparam', 'token'));
63 if(!$wgUser->matchEditToken($params['token']))
64 $this->dieUsageMsg(array('sessionfailure'));
65 if(!$wgUser->isAllowed('block'))
66 $this->dieUsageMsg(array('cantunblock'));
68 $this->dieUsageMsg(array('readonlytext'));
71 $user = $params['user'];
72 $reason = (is_null($params['reason']) ?
'' : $params['reason']);
73 $retval = IPUnblockForm
::doUnblock($id, $user, $reason, $range);
75 $this->dieUsageMsg($retval);
79 $res['reason'] = $reason;
80 $this->getResult()->addValue(null, $this->getModuleName(), $res);
83 public function mustBePosted() { return true; }
85 public function getAllowedParams() {
95 public function getParamDescription() {
97 'id' => 'ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with user',
98 'user' => 'Username, IP address or IP range you want to unblock. Cannot be used together with id',
99 'token' => 'An unblock token previously obtained through the gettoken parameter',
100 'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
101 'reason' => 'Reason for unblock (optional)',
105 public function getDescription() {
111 protected function getExamples() {
113 'api.php?action=unblock&id=105',
114 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
118 public function getVersion() {
119 return __CLASS__
. ': $Id$';