]> scripts.mit.edu Git - autoinstalls/mediawiki.git/blob - includes/api/ApiUnblock.php
MediaWiki 1.17.4
[autoinstalls/mediawiki.git] / includes / api / ApiUnblock.php
1 <?php
2 /**
3  * API for MediaWiki 1.8+
4  *
5  * Created on Sep 7, 2007
6  *
7  * Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
8  *
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.
13  *
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.
18  *
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
23  *
24  * @file
25  */
26
27 if ( !defined( 'MEDIAWIKI' ) ) {
28         // Eclipse helper - will be ignored in production
29         require_once( "ApiBase.php" );
30 }
31
32 /**
33  * API module that facilitates the unblocking of users. Requires API write mode
34  * to be enabled.
35  *
36  * @ingroup API
37  */
38 class ApiUnblock extends ApiBase {
39
40         public function __construct( $main, $action ) {
41                 parent::__construct( $main, $action );
42         }
43
44         /**
45          * Unblocks the specified user or provides the reason the unblock failed.
46          */
47         public function execute() {
48                 global $wgUser;
49                 $params = $this->extractRequestParams();
50
51                 if ( $params['gettoken'] ) {
52                         $res['unblocktoken'] = $wgUser->editToken();
53                         $this->getResult()->addValue( null, $this->getModuleName(), $res );
54                         return;
55                 }
56
57                 if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) {
58                         $this->dieUsageMsg( array( 'unblock-notarget' ) );
59                 }
60                 if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) {
61                         $this->dieUsageMsg( array( 'unblock-idanduser' ) );
62                 }
63
64                 if ( !$wgUser->isAllowed( 'block' ) ) {
65                         $this->dieUsageMsg( array( 'cantunblock' ) );
66                 }
67                 # bug 15810: blocked admins should have limited access here
68                 if ( $wgUser->isBlocked() ) {
69                         $status = IPBlockForm::checkUnblockSelf( $params['user'] );
70                         if ( $status !== true ) {
71                                 $this->dieUsageMsg( array( $status ) );
72                         }
73                 }
74
75                 $id = $params['id'];
76                 $user = $params['user'];
77                 $reason = ( is_null( $params['reason'] ) ? '' : $params['reason'] );
78                 $retval = IPUnblockForm::doUnblock( $id, $user, $reason, $range );
79                 if ( $retval ) {
80                         $this->dieUsageMsg( $retval );
81                 }
82
83                 $res['id'] = intval( $id );
84                 $res['user'] = $user;
85                 $res['reason'] = $reason;
86                 $this->getResult()->addValue( null, $this->getModuleName(), $res );
87         }
88
89         public function mustBePosted() {
90                 return true;
91         }
92
93         public function isWriteMode() {
94                 return true;
95         }
96
97         public function getAllowedParams() {
98                 return array(
99                         'id' => null,
100                         'user' => null,
101                         'token' => null,
102                         'gettoken' => false,
103                         'reason' => null,
104                 );
105         }
106
107         public function getParamDescription() {
108                 $p = $this->getModulePrefix();
109                 return array(
110                         'id' => "ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with {$p}user",
111                         'user' => "Username, IP address or IP range you want to unblock. Cannot be used together with {$p}id",
112                         'token' => "An unblock token previously obtained through the gettoken parameter or {$p}prop=info",
113                         'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
114                         'reason' => 'Reason for unblock (optional)',
115                 );
116         }
117
118         public function getDescription() {
119                 return 'Unblock a user';
120         }
121
122         public function getPossibleErrors() {
123                 return array_merge( parent::getPossibleErrors(), array(
124                         array( 'unblock-notarget' ),
125                         array( 'unblock-idanduser' ),
126                         array( 'cantunblock' ),
127                         array( 'ipbblocked' ),
128                         array( 'ipbnounblockself' ),
129                 ) );
130         }
131
132         public function needsToken() {
133                 return true;
134         }
135
136         public function getTokenSalt() {
137                 return '';
138         }
139
140         protected function getExamples() {
141                 return array(
142                         'api.php?action=unblock&id=105',
143                         'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
144                 );
145         }
146
147         public function getVersion() {
148                 return __CLASS__ . ': $Id$';
149         }
150 }