Merge "DatabaseMssql: Don't duplicate body of makeList()"
[mediawiki.git] / includes / api / ApiUnblock.php
blob1af83ba3f030013a18b32532474251358d1a7432
1 <?php
2 /**
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
24 * @file
27 /**
28 * API module that facilitates the unblocking of users. Requires API write mode
29 * to be enabled.
31 * @ingroup API
33 class ApiUnblock extends ApiBase {
35 /**
36 * Unblocks the specified user or provides the reason the unblock failed.
38 public function execute() {
39 $user = $this->getUser();
40 $params = $this->extractRequestParams();
42 if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) {
43 $this->dieUsageMsg( 'unblock-notarget' );
45 if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) {
46 $this->dieUsageMsg( 'unblock-idanduser' );
49 if ( !$user->isAllowed( 'block' ) ) {
50 $this->dieUsageMsg( 'cantunblock' );
52 # bug 15810: blocked admins should have limited access here
53 if ( $user->isBlocked() ) {
54 $status = SpecialBlock::checkUnblockSelf( $params['user'], $user );
55 if ( $status !== true ) {
56 $this->dieUsageMsg( $status );
60 $data = array(
61 'Target' => is_null( $params['id'] ) ? $params['user'] : "#{$params['id']}",
62 'Reason' => $params['reason']
64 $block = Block::newFromTarget( $data['Target'] );
65 $retval = SpecialUnblock::processUnblock( $data, $this->getContext() );
66 if ( $retval !== true ) {
67 $this->dieUsageMsg( $retval[0] );
70 $res['id'] = $block->getId();
71 $target = $block->getType() == Block::TYPE_AUTO ? '' : $block->getTarget();
72 $res['user'] = $target instanceof User ? $target->getName() : $target;
73 $res['userid'] = $target instanceof User ? $target->getId() : 0;
74 $res['reason'] = $params['reason'];
75 $this->getResult()->addValue( null, $this->getModuleName(), $res );
78 public function mustBePosted() {
79 return true;
82 public function isWriteMode() {
83 return true;
86 public function getAllowedParams() {
87 return array(
88 'id' => array(
89 ApiBase::PARAM_TYPE => 'integer',
91 'user' => null,
92 'reason' => '',
96 public function needsToken() {
97 return 'csrf';
100 protected function getExamplesMessages() {
101 return array(
102 'action=unblock&id=105'
103 => 'apihelp-unblock-example-id',
104 'action=unblock&user=Bob&reason=Sorry%20Bob'
105 => 'apihelp-unblock-example-user',
109 public function getHelpUrls() {
110 return 'https://www.mediawiki.org/wiki/API:Block';