3 * Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
24 * API module that facilitates the unblocking of users. Requires API write mode
29 class ApiUnblock
extends ApiBase
{
32 * Unblocks the specified user or provides the reason the unblock failed.
34 public function execute() {
35 $user = $this->getUser();
36 $params = $this->extractRequestParams();
38 $this->requireOnlyOneParameter( $params, 'id', 'user', 'userid' );
40 if ( !$user->isAllowed( 'block' ) ) {
41 $this->dieWithError( 'apierror-permissiondenied-unblock', 'permissiondenied' );
43 # T17810: blocked admins should have limited access here
44 if ( $user->isBlocked() ) {
45 $status = SpecialBlock
::checkUnblockSelf( $params['user'], $user );
46 if ( $status !== true ) {
50 [ 'blockinfo' => ApiQueryUserInfo
::getBlockInfo( $user->getBlock() ) ]
55 // Check if user can add tags
56 if ( !is_null( $params['tags'] ) ) {
57 $ableToTag = ChangeTags
::canAddTagsAccompanyingChange( $params['tags'], $user );
58 if ( !$ableToTag->isOK() ) {
59 $this->dieStatus( $ableToTag );
63 if ( $params['userid'] !== null ) {
64 $username = User
::whoIs( $params['userid'] );
66 if ( $username === false ) {
67 $this->dieWithError( [ 'apierror-nosuchuserid', $params['userid'] ], 'nosuchuserid' );
69 $params['user'] = $username;
74 'Target' => is_null( $params['id'] ) ?
$params['user'] : "#{$params['id']}",
75 'Reason' => $params['reason'],
76 'Tags' => $params['tags']
78 $block = Block
::newFromTarget( $data['Target'] );
79 $retval = SpecialUnblock
::processUnblock( $data, $this->getContext() );
80 if ( $retval !== true ) {
81 $this->dieStatus( $this->errorArrayToStatus( $retval ) );
84 $res['id'] = $block->getId();
85 $target = $block->getType() == Block
::TYPE_AUTO ?
'' : $block->getTarget();
86 $res['user'] = $target instanceof User ?
$target->getName() : $target;
87 $res['userid'] = $target instanceof User ?
$target->getId() : 0;
88 $res['reason'] = $params['reason'];
89 $this->getResult()->addValue( null, $this->getModuleName(), $res );
92 public function mustBePosted() {
96 public function isWriteMode() {
100 public function getAllowedParams() {
103 ApiBase
::PARAM_TYPE
=> 'integer',
107 ApiBase
::PARAM_TYPE
=> 'integer'
111 ApiBase
::PARAM_TYPE
=> 'tags',
112 ApiBase
::PARAM_ISMULTI
=> true,
117 public function needsToken() {
121 protected function getExamplesMessages() {
123 'action=unblock&id=105'
124 => 'apihelp-unblock-example-id',
125 'action=unblock&user=Bob&reason=Sorry%20Bob'
126 => 'apihelp-unblock-example-user',
130 public function getHelpUrls() {
131 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Block';