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
28 * API module that facilitates the unblocking of users. Requires API write mode
33 class ApiUnblock
extends ApiBase
{
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 $this->requireOnlyOneParameter( $params, 'id', 'user' );
44 if ( !$user->isAllowed( 'block' ) ) {
45 $this->dieWithError( 'apierror-permissiondenied-unblock', 'permissiondenied' );
47 # bug 15810: blocked admins should have limited access here
48 if ( $user->isBlocked() ) {
49 $status = SpecialBlock
::checkUnblockSelf( $params['user'], $user );
50 if ( $status !== true ) {
54 [ 'blockinfo' => ApiQueryUserInfo
::getBlockInfo( $user->getBlock() ) ]
59 // Check if user can add tags
60 if ( !is_null( $params['tags'] ) ) {
61 $ableToTag = ChangeTags
::canAddTagsAccompanyingChange( $params['tags'], $user );
62 if ( !$ableToTag->isOK() ) {
63 $this->dieStatus( $ableToTag );
68 'Target' => is_null( $params['id'] ) ?
$params['user'] : "#{$params['id']}",
69 'Reason' => $params['reason'],
70 'Tags' => $params['tags']
72 $block = Block
::newFromTarget( $data['Target'] );
73 $retval = SpecialUnblock
::processUnblock( $data, $this->getContext() );
74 if ( $retval !== true ) {
75 $this->dieStatus( $this->errorArrayToStatus( $retval ) );
78 $res['id'] = $block->getId();
79 $target = $block->getType() == Block
::TYPE_AUTO ?
'' : $block->getTarget();
80 $res['user'] = $target instanceof User ?
$target->getName() : $target;
81 $res['userid'] = $target instanceof User ?
$target->getId() : 0;
82 $res['reason'] = $params['reason'];
83 $this->getResult()->addValue( null, $this->getModuleName(), $res );
86 public function mustBePosted() {
90 public function isWriteMode() {
94 public function getAllowedParams() {
97 ApiBase
::PARAM_TYPE
=> 'integer',
102 ApiBase
::PARAM_TYPE
=> 'tags',
103 ApiBase
::PARAM_ISMULTI
=> true,
108 public function needsToken() {
112 protected function getExamplesMessages() {
114 'action=unblock&id=105'
115 => 'apihelp-unblock-example-id',
116 'action=unblock&user=Bob&reason=Sorry%20Bob'
117 => 'apihelp-unblock-example-user',
121 public function getHelpUrls() {
122 return 'https://www.mediawiki.org/wiki/API:Block';