2007-12-06 16:06:22 +00:00
|
|
|
<?php
|
2010-02-26 13:18:56 +00:00
|
|
|
/**
|
2007-12-06 16:06:22 +00:00
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Sep 7, 2007
|
|
|
|
|
*
|
2010-02-26 13:18:56 +00:00
|
|
|
* Copyright © 2007 Roan Kattouw <Firstname>.<Lastname>@home.nl
|
2007-12-06 16:06:22 +00:00
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
2010-06-21 13:13:32 +00:00
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2007-12-06 16:06:22 +00:00
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
2010-08-07 19:59:42 +00:00
|
|
|
*
|
|
|
|
|
* @file
|
2007-12-06 16:06:22 +00:00
|
|
|
*/
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
if ( !defined( 'MEDIAWIKI' ) ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
// Eclipse helper - will be ignored in production
|
2010-02-26 13:18:56 +00:00
|
|
|
require_once( "ApiBase.php" );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2008-01-12 07:08:17 +00:00
|
|
|
* API module that facilitates the unblocking of users. Requires API write mode
|
|
|
|
|
* to be enabled.
|
|
|
|
|
*
|
WARNING: HUGE COMMIT
Doxygen documentation update:
* Changed alls @addtogroup to @ingroup. @addtogroup adds the comment to the group description, but doesn't add the file, class, function, ... to the group like @ingroup does. See for example http://svn.wikimedia.org/doc/group__SpecialPage.html where it's impossible to see related files, classes, ... that should belong to that group.
* Added @file to file description, it seems that it should be explicitely decalred for file descriptions, otherwise doxygen will think that the comment document the first class, variabled, function, ... that is in that file.
* Removed some empty comments
* Removed some ?>
Added following groups:
* ExternalStorage
* JobQueue
* MaintenanceLanguage
One more thing: there are still a lot of warnings when generating the doc.
2008-05-20 17:13:28 +00:00
|
|
|
* @ingroup API
|
2007-12-06 16:06:22 +00:00
|
|
|
*/
|
|
|
|
|
class ApiUnblock extends ApiBase {
|
|
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $main, $action ) {
|
2010-02-26 13:18:56 +00:00
|
|
|
parent::__construct( $main, $action );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-12 07:08:17 +00:00
|
|
|
/**
|
|
|
|
|
* Unblocks the specified user or provides the reason the unblock failed.
|
2008-04-14 07:45:50 +00:00
|
|
|
*/
|
2007-12-06 16:06:22 +00:00
|
|
|
public function execute() {
|
|
|
|
|
global $wgUser;
|
|
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( $params['gettoken'] ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['unblocktoken'] = $wgUser->editToken();
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $res );
|
2007-12-06 16:06:22 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( is_null( $params['id'] ) && is_null( $params['user'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'unblock-notarget' ) );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
|
|
|
|
if ( !is_null( $params['id'] ) && !is_null( $params['user'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'unblock-idanduser' ) );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2010-02-15 23:53:43 +00:00
|
|
|
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( !$wgUser->isAllowed( 'block' ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'cantunblock' ) );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2010-03-26 23:02:10 +00:00
|
|
|
# bug 15810: blocked admins should have limited access here
|
2010-03-27 21:31:10 +00:00
|
|
|
if ( $wgUser->isBlocked() ) {
|
2010-03-27 15:05:56 +00:00
|
|
|
$status = IPBlockForm::checkUnblockSelf( $params['user'] );
|
2010-03-27 21:31:10 +00:00
|
|
|
if ( $status !== true ) {
|
2010-03-27 15:05:56 +00:00
|
|
|
$this->dieUsageMsg( array( $status ) );
|
2010-03-27 21:31:10 +00:00
|
|
|
}
|
2010-03-26 23:02:10 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
|
|
|
|
$id = $params['id'];
|
|
|
|
|
$user = $params['user'];
|
2010-01-11 15:55:52 +00:00
|
|
|
$reason = ( is_null( $params['reason'] ) ? '' : $params['reason'] );
|
|
|
|
|
$retval = IPUnblockForm::doUnblock( $id, $user, $reason, $range );
|
2010-02-26 13:18:56 +00:00
|
|
|
if ( $retval ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( $retval );
|
2010-02-26 13:18:56 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$res['id'] = intval( $id );
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['user'] = $user;
|
|
|
|
|
$res['reason'] = $reason;
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $res );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2008-04-14 07:45:50 +00:00
|
|
|
|
2010-02-14 21:12:11 +00:00
|
|
|
public function mustBePosted() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2009-03-06 13:49:44 +00:00
|
|
|
public function isWriteMode() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getAllowedParams() {
|
2010-02-26 13:18:56 +00:00
|
|
|
return array(
|
2007-12-06 16:06:22 +00:00
|
|
|
'id' => null,
|
|
|
|
|
'user' => null,
|
|
|
|
|
'token' => null,
|
|
|
|
|
'gettoken' => false,
|
|
|
|
|
'reason' => null,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getParamDescription() {
|
2010-05-11 22:30:18 +00:00
|
|
|
$p = $this->getModulePrefix();
|
2010-02-26 13:18:56 +00:00
|
|
|
return array(
|
2010-05-11 22:30:18 +00:00
|
|
|
'id' => "ID of the block you want to unblock (obtained through list=blocks). Cannot be used together with {$p}user",
|
|
|
|
|
'user' => "Username, IP address or IP range you want to unblock. Cannot be used together with {$p}id",
|
|
|
|
|
'token' => "An unblock token previously obtained through the gettoken parameter or {$p}prop=info",
|
2007-12-06 16:06:22 +00:00
|
|
|
'gettoken' => 'If set, an unblock token will be returned, and no other action will be taken',
|
|
|
|
|
'reason' => 'Reason for unblock (optional)',
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getDescription() {
|
2010-05-25 20:46:09 +00:00
|
|
|
return 'Unblock a user';
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
|
|
|
|
|
public function getPossibleErrors() {
|
2010-02-13 00:09:05 +00:00
|
|
|
return array_merge( parent::getPossibleErrors(), array(
|
|
|
|
|
array( 'unblock-notarget' ),
|
|
|
|
|
array( 'unblock-idanduser' ),
|
|
|
|
|
array( 'cantunblock' ),
|
2010-03-26 23:02:10 +00:00
|
|
|
array( 'ipbblocked' ),
|
|
|
|
|
array( 'ipbnounblockself' ),
|
2010-02-26 13:18:56 +00:00
|
|
|
) );
|
2010-02-13 00:09:05 +00:00
|
|
|
}
|
2010-02-26 13:18:56 +00:00
|
|
|
|
2010-10-01 20:12:50 +00:00
|
|
|
public function needsToken() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-02-15 23:53:43 +00:00
|
|
|
public function getTokenSalt() {
|
2010-02-16 21:59:16 +00:00
|
|
|
return '';
|
2010-02-14 22:20:27 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
|
|
|
|
protected function getExamples() {
|
2010-02-26 13:18:56 +00:00
|
|
|
return array(
|
2007-12-06 16:06:22 +00:00
|
|
|
'api.php?action=unblock&id=105',
|
|
|
|
|
'api.php?action=unblock&user=Bob&reason=Sorry%20Bob'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion() {
|
2007-12-06 18:33:18 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
}
|