Follow-up r67045. Delete it from the English message file too.
[mediawiki.git] / includes / api / ApiUnblock.php
blob31d0beff3d640d815d8d93471f009ece60096648
1 <?php
3 /**
4 * Created on Sep 7, 2007
5 * API for MediaWiki 1.8+
7 * Copyright © 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" );
30 /**
31 * API module that facilitates the unblocking of users. Requires API write mode
32 * to be enabled.
34 * @ingroup API
36 class ApiUnblock extends ApiBase {
38 public function __construct( $main, $action ) {
39 parent::__construct( $main, $action );
42 /**
43 * Unblocks the specified user or provides the reason the unblock failed.
45 public function execute() {
46 global $wgUser;
47 $params = $this->extractRequestParams();
49 if ( $params['gettoken'] ) {
50 $res['unblocktoken'] = $wgUser->editToken();
51 $this->getResult()->addValue( null, $this->getModuleName(), $res );
52 return;
55 if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) {
56 $this->dieUsageMsg( array( 'unblock-notarget' ) );
58 if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) {
59 $this->dieUsageMsg( array( 'unblock-idanduser' ) );
62 if ( !$wgUser->isAllowed( 'block' ) ) {
63 $this->dieUsageMsg( array( 'cantunblock' ) );
65 # bug 15810: blocked admins should have limited access here
66 if ( $wgUser->isBlocked() ) {
67 $status = IPBlockForm::checkUnblockSelf( $params['user'] );
68 if ( $status !== true ) {
69 $this->dieUsageMsg( array( $status ) );
73 $id = $params['id'];
74 $user = $params['user'];
75 $reason = ( is_null( $params['reason'] ) ? '' : $params['reason'] );
76 $retval = IPUnblockForm::doUnblock( $id, $user, $reason, $range );
77 if ( $retval ) {
78 $this->dieUsageMsg( $retval );
81 $res['id'] = intval( $id );
82 $res['user'] = $user;
83 $res['reason'] = $reason;
84 $this->getResult()->addValue( null, $this->getModuleName(), $res );
87 public function mustBePosted() {
88 return true;
91 public function isWriteMode() {
92 return true;
95 public function getAllowedParams() {
96 return array(
97 'id' => null,
98 'user' => null,
99 'token' => null,
100 'gettoken' => false,
101 'reason' => null,
105 public function getParamDescription() {
106 $p = $this->getModulePrefix();
107 return array(
108 'id' => "ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with {$p}user",
109 'user' => "Username, IP address or IP range you want to unblock. Cannot be used together with {$p}id",
110 'token' => "An unblock token previously obtained through the gettoken parameter or {$p}prop=info",
111 'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
112 'reason' => 'Reason for unblock (optional)',
116 public function getDescription() {
117 return 'Unblock a user';
120 public function getPossibleErrors() {
121 return array_merge( parent::getPossibleErrors(), array(
122 array( 'unblock-notarget' ),
123 array( 'unblock-idanduser' ),
124 array( 'cantunblock' ),
125 array( 'ipbblocked' ),
126 array( 'ipbnounblockself' ),
127 ) );
130 public function getTokenSalt() {
131 return '';
134 protected function getExamples() {
135 return array(
136 'api.php?action=unblock&id=105',
137 'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
141 public function getVersion() {
142 return __CLASS__ . ': $Id$';