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 $block = $user->getBlock();
46 $status = SpecialBlock
::checkUnblockSelf( $params['user'], $user );
47 if ( $status !== true ) {
51 [ 'blockinfo' => ApiQueryUserInfo
::getBlockInfo( $block ) ]
56 // Check if user can add tags
57 if ( !is_null( $params['tags'] ) ) {
58 $ableToTag = ChangeTags
::canAddTagsAccompanyingChange( $params['tags'], $user );
59 if ( !$ableToTag->isOK() ) {
60 $this->dieStatus( $ableToTag );
64 if ( $params['userid'] !== null ) {
65 $username = User
::whoIs( $params['userid'] );
67 if ( $username === false ) {
68 $this->dieWithError( [ 'apierror-nosuchuserid', $params['userid'] ], 'nosuchuserid' );
70 $params['user'] = $username;
75 'Target' => is_null( $params['id'] ) ?
$params['user'] : "#{$params['id']}",
76 'Reason' => $params['reason'],
77 'Tags' => $params['tags']
79 $block = Block
::newFromTarget( $data['Target'] );
80 $retval = SpecialUnblock
::processUnblock( $data, $this->getContext() );
81 if ( $retval !== true ) {
82 $this->dieStatus( $this->errorArrayToStatus( $retval ) );
85 $res['id'] = $block->getId();
86 $target = $block->getType() == Block
::TYPE_AUTO ?
'' : $block->getTarget();
87 $res['user'] = $target instanceof User ?
$target->getName() : $target;
88 $res['userid'] = $target instanceof User ?
$target->getId() : 0;
89 $res['reason'] = $params['reason'];
90 $this->getResult()->addValue( null, $this->getModuleName(), $res );
93 public function mustBePosted() {
97 public function isWriteMode() {
101 public function getAllowedParams() {
104 ApiBase
::PARAM_TYPE
=> 'integer',
108 ApiBase
::PARAM_TYPE
=> 'integer'
112 ApiBase
::PARAM_TYPE
=> 'tags',
113 ApiBase
::PARAM_ISMULTI
=> true,
118 public function needsToken() {
122 protected function getExamplesMessages() {
124 'action=unblock&id=105'
125 => 'apihelp-unblock-example-id',
126 'action=unblock&user=Bob&reason=Sorry%20Bob'
127 => 'apihelp-unblock-example-user',
131 public function getHelpUrls() {
132 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Block';