]> scripts.mit.edu Git - autoinstallsdev/mediawiki.git/blob - includes/api/ApiUnblock.php
MediaWiki 1.16.0
[autoinstallsdev/mediawiki.git] / includes / api / ApiUnblock.php
1 <?php
2
3 /*
4  * Created on Sep 7, 2007
5  * API for MediaWiki 1.8+
6  *
7  * Copyright (C) 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  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  * http://www.gnu.org/copyleft/gpl.html
23  */
24
25 if ( !defined( 'MEDIAWIKI' ) ) {
26         // Eclipse helper - will be ignored in production
27         require_once ( "ApiBase.php" );
28 }
29
30 /**
31  * API module that facilitates the unblocking of users. Requires API write mode
32  * to be enabled.
33  *
34  * @ingroup API
35  */
36 class ApiUnblock extends ApiBase {
37
38         public function __construct( $main, $action ) {
39                 parent :: __construct( $main, $action );
40         }
41
42         /**
43          * Unblocks the specified user or provides the reason the unblock failed.
44          */
45         public function execute() {
46                 global $wgUser;
47                 $params = $this->extractRequestParams();
48
49                 if ( $params['gettoken'] )
50                 {
51                         $res['unblocktoken'] = $wgUser->editToken();
52                         $this->getResult()->addValue( null, $this->getModuleName(), $res );
53                         return;
54                 }
55
56                 if ( is_null( $params['id'] ) && is_null( $params['user'] ) )
57                         $this->dieUsageMsg( array( 'unblock-notarget' ) );
58                 if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) )
59                         $this->dieUsageMsg( array( 'unblock-idanduser' ) );
60
61                 if ( !$wgUser->isAllowed( 'block' ) )
62                         $this->dieUsageMsg( array( 'cantunblock' ) );
63
64                 $id = $params['id'];
65                 $user = $params['user'];
66                 $reason = ( is_null( $params['reason'] ) ? '' : $params['reason'] );
67                 $retval = IPUnblockForm::doUnblock( $id, $user, $reason, $range );
68                 if ( $retval )
69                         $this->dieUsageMsg( $retval );
70
71                 $res['id'] = intval( $id );
72                 $res['user'] = $user;
73                 $res['reason'] = $reason;
74                 $this->getResult()->addValue( null, $this->getModuleName(), $res );
75         }
76
77         public function mustBePosted() {
78                 return true;
79         }
80
81         public function isWriteMode() {
82                 return true;
83         }
84
85         public function getAllowedParams() {
86                 return array (
87                         'id' => null,
88                         'user' => null,
89                         'token' => null,
90                         'gettoken' => false,
91                         'reason' => null,
92                 );
93         }
94
95         public function getParamDescription() {
96                 return array (
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 or prop=info',
100                         'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
101                         'reason' => 'Reason for unblock (optional)',
102                 );
103         }
104
105         public function getDescription() {
106                 return array(
107                         'Unblock a user.'
108                 );
109         }
110         
111     public function getPossibleErrors() {
112                 return array_merge( parent::getPossibleErrors(), array(
113                         array( 'unblock-notarget' ),
114                         array( 'unblock-idanduser' ),
115                         array( 'cantunblock' ),
116         ) );
117         }
118         
119         public function getTokenSalt() {
120                 return '';
121         }
122
123         protected function getExamples() {
124                 return array (
125                         'api.php?action=unblock&id=105',
126                         'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
127                 );
128         }
129
130         public function getVersion() {
131                 return __CLASS__ . ': $Id: ApiUnblock.php 62599 2010-02-16 21:59:16Z reedy $';
132         }
133 }