5 * Created on Sep 7, 2007
7 * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@gmail.com
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 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * http://www.gnu.org/copyleft/gpl.html
27 if ( !defined( 'MEDIAWIKI' ) ) {
28 // Eclipse helper - will be ignored in production
29 require_once( "ApiBase.php" );
33 * API module that facilitates the unblocking of users. Requires API write mode
38 class ApiUnblock
extends ApiBase
{
40 public function __construct( $main, $action ) {
41 parent
::__construct( $main, $action );
45 * Unblocks the specified user or provides the reason the unblock failed.
47 public function execute() {
48 $user = $this->getUser();
49 $params = $this->extractRequestParams();
51 if ( $params['gettoken'] ) {
52 $res['unblocktoken'] = $user->getEditToken( '', $this->getMain()->getRequest() );
53 $this->getResult()->addValue( null, $this->getModuleName(), $res );
57 if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) {
58 $this->dieUsageMsg( 'unblock-notarget' );
60 if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) {
61 $this->dieUsageMsg( 'unblock-idanduser' );
64 if ( !$user->isAllowed( 'block' ) ) {
65 $this->dieUsageMsg( 'cantunblock' );
67 # bug 15810: blocked admins should have limited access here
68 if ( $user->isBlocked() ) {
69 $status = SpecialBlock
::checkUnblockSelf( $params['user'], $user );
70 if ( $status !== true ) {
71 $this->dieUsageMsg( $status );
76 'Target' => is_null( $params['id'] ) ?
$params['user'] : "#{$params['id']}",
77 'Reason' => is_null( $params['reason'] ) ?
'' : $params['reason']
79 $block = Block
::newFromTarget( $data['Target'] );
80 $retval = SpecialUnblock
::processUnblock( $data, $this->getContext() );
81 if ( $retval !== true ) {
82 $this->dieUsageMsg( $retval[0] );
85 $res['id'] = $block->getId();
86 $res['user'] = $block->getType() == Block
::TYPE_AUTO ?
'' : $block->getTarget();
87 $res['reason'] = $params['reason'];
88 $this->getResult()->addValue( null, $this->getModuleName(), $res );
91 public function mustBePosted() {
95 public function isWriteMode() {
99 public function getAllowedParams() {
102 ApiBase
::PARAM_TYPE
=> 'integer',
111 public function getParamDescription() {
112 $p = $this->getModulePrefix();
114 'id' => "ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with {$p}user",
115 'user' => "Username, IP address or IP range you want to unblock. Cannot be used together with {$p}id",
116 'token' => "An unblock token previously obtained through the gettoken parameter or {$p}prop=info",
117 'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
118 'reason' => 'Reason for unblock (optional)',
122 public function getDescription() {
123 return 'Unblock a user';
126 public function getPossibleErrors() {
127 return array_merge( parent
::getPossibleErrors(), array(
128 array( 'unblock-notarget' ),
129 array( 'unblock-idanduser' ),
130 array( 'cantunblock' ),
131 array( 'ipbblocked' ),
132 array( 'ipbnounblockself' ),
136 public function needsToken() {
140 public function getTokenSalt() {
144 public function getExamples() {
146 'api.php?action=unblock&id=105',
147 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
151 public function getHelpUrls() {
152 return 'http://www.mediawiki.org/wiki/API:Block';
155 public function getVersion() {
156 return __CLASS__
. ': $Id$';