2007-12-06 16:06:22 +00:00
|
|
|
<?php
|
|
|
|
|
|
2010-02-21 12:32:46 +00:00
|
|
|
/**
|
2007-12-06 16:06:22 +00:00
|
|
|
* Created on Sep 4, 2007
|
|
|
|
|
* API for MediaWiki 1.8+
|
|
|
|
|
*
|
2010-02-21 12:32:46 +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.,
|
|
|
|
|
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
|
* http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
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-21 12:32:46 +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 blocking 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 ApiBlock extends ApiBase {
|
|
|
|
|
|
2008-01-12 07:08:17 +00:00
|
|
|
/**
|
|
|
|
|
* Std ctor.
|
|
|
|
|
*/
|
2010-01-11 15:55:52 +00:00
|
|
|
public function __construct( $main, $action ) {
|
2010-02-21 12:32:46 +00:00
|
|
|
parent::__construct( $main, $action );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
2008-01-12 07:08:17 +00:00
|
|
|
/**
|
|
|
|
|
* Blocks the user specified in the parameters for the given expiry, with the
|
|
|
|
|
* given reason, and with all other settings provided in the params. If the block
|
|
|
|
|
* succeeds, produces a result containing the details of the block and notice
|
|
|
|
|
* of success. If it fails, the result will specify the nature of the error.
|
|
|
|
|
*/
|
2007-12-06 16:06:22 +00:00
|
|
|
public function execute() {
|
2009-05-23 00:05:40 +00:00
|
|
|
global $wgUser, $wgBlockAllowsUTEdit;
|
2007-12-06 16:06:22 +00:00
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
|
2010-02-21 12:32:46 +00:00
|
|
|
if ( $params['gettoken'] ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['blocktoken'] = $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-21 12:32:46 +00:00
|
|
|
if ( is_null( $params['user'] ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'missingparam', 'user' ) );
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
|
|
|
|
if ( !$wgUser->isAllowed( 'block' ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'cantblock' ) );
|
2010-02-21 12:32:46 +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
|
|
|
}
|
2010-02-21 12:32:46 +00:00
|
|
|
if ( $params['hidename'] && !$wgUser->isAllowed( 'hideuser' ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'canthide' ) );
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
|
|
|
|
if ( $params['noemail'] && !IPBlockForm::canBlockEmail( $wgUser ) ) {
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( array( 'cantblock-email' ) );
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$form = new IPBlockForm( '' );
|
2007-12-06 16:06:22 +00:00
|
|
|
$form->BlockAddress = $params['user'];
|
2010-01-11 15:55:52 +00:00
|
|
|
$form->BlockReason = ( is_null( $params['reason'] ) ? '' : $params['reason'] );
|
2007-12-06 16:06:22 +00:00
|
|
|
$form->BlockReasonList = 'other';
|
2010-01-11 15:55:52 +00:00
|
|
|
$form->BlockExpiry = ( $params['expiry'] == 'never' ? 'infinite' : $params['expiry'] );
|
2007-12-06 16:06:22 +00:00
|
|
|
$form->BlockOther = '';
|
|
|
|
|
$form->BlockAnonOnly = $params['anononly'];
|
|
|
|
|
$form->BlockCreateAccount = $params['nocreate'];
|
2008-09-05 15:05:57 +00:00
|
|
|
$form->BlockEnableAutoblock = $params['autoblock'];
|
2007-12-06 16:06:22 +00:00
|
|
|
$form->BlockEmail = $params['noemail'];
|
|
|
|
|
$form->BlockHideName = $params['hidename'];
|
2008-10-02 09:34:29 +00:00
|
|
|
$form->BlockAllowUsertalk = $params['allowusertalk'] && $wgBlockAllowsUTEdit;
|
2008-11-18 15:21:04 +00:00
|
|
|
$form->BlockReblock = $params['reblock'];
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2008-05-24 20:44:49 +00:00
|
|
|
$userID = $expiry = null;
|
2010-01-11 15:55:52 +00:00
|
|
|
$retval = $form->doBlock( $userID, $expiry );
|
2010-02-21 12:32:46 +00:00
|
|
|
if ( count( $retval ) ) {
|
2008-01-18 17:48:03 +00:00
|
|
|
// We don't care about multiple errors, just report one of them
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->dieUsageMsg( $retval );
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
2008-01-18 17:48:03 +00:00
|
|
|
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['user'] = $params['user'];
|
2010-01-11 15:55:52 +00:00
|
|
|
$res['userID'] = intval( $userID );
|
|
|
|
|
$res['expiry'] = ( $expiry == Block::infinity() ? 'infinite' : wfTimestamp( TS_ISO_8601, $expiry ) );
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['reason'] = $params['reason'];
|
2010-02-21 12:32:46 +00:00
|
|
|
if ( $params['anononly'] ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['anononly'] = '';
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
|
|
|
|
if ( $params['nocreate'] ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['nocreate'] = '';
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
|
|
|
|
if ( $params['autoblock'] ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['autoblock'] = '';
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
|
|
|
|
if ( $params['noemail'] ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['noemail'] = '';
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
|
|
|
|
if ( $params['hidename'] ) {
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['hidename'] = '';
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
|
|
|
|
if ( $params['allowusertalk'] ) {
|
2008-10-02 09:34:29 +00:00
|
|
|
$res['allowusertalk'] = '';
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $res );
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
|
2010-02-14 21:12:11 +00:00
|
|
|
public function mustBePosted() {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2008-01-18 20:43:59 +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-21 12:32:46 +00:00
|
|
|
return array(
|
2007-12-06 16:06:22 +00:00
|
|
|
'user' => null,
|
|
|
|
|
'token' => null,
|
|
|
|
|
'gettoken' => false,
|
|
|
|
|
'expiry' => 'never',
|
|
|
|
|
'reason' => null,
|
|
|
|
|
'anononly' => false,
|
|
|
|
|
'nocreate' => false,
|
|
|
|
|
'autoblock' => false,
|
|
|
|
|
'noemail' => false,
|
|
|
|
|
'hidename' => false,
|
2008-10-26 10:47:13 +00:00
|
|
|
'allowusertalk' => false,
|
2008-11-18 15:21:04 +00:00
|
|
|
'reblock' => false,
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getParamDescription() {
|
2010-02-21 12:32:46 +00:00
|
|
|
return array(
|
2007-12-06 16:06:22 +00:00
|
|
|
'user' => 'Username, IP address or IP range you want to block',
|
2008-10-27 12:06:49 +00:00
|
|
|
'token' => 'A block token previously obtained through the gettoken parameter or prop=info',
|
2007-12-06 16:06:22 +00:00
|
|
|
'gettoken' => 'If set, a block token will be returned, and no other action will be taken',
|
|
|
|
|
'expiry' => 'Relative expiry time, e.g. \'5 months\' or \'2 weeks\'. If set to \'infinite\', \'indefinite\' or \'never\', the block will never expire.',
|
|
|
|
|
'reason' => 'Reason for block (optional)',
|
|
|
|
|
'anononly' => 'Block anonymous users only (i.e. disable anonymous edits for this IP)',
|
|
|
|
|
'nocreate' => 'Prevent account creation',
|
|
|
|
|
'autoblock' => 'Automatically block the last used IP address, and any subsequent IP addresses they try to login from',
|
2008-01-18 17:48:03 +00:00
|
|
|
'noemail' => 'Prevent user from sending e-mail through the wiki. (Requires the "blockemail" right.)',
|
2008-10-02 09:34:29 +00:00
|
|
|
'hidename' => 'Hide the username from the block log. (Requires the "hideuser" right.)',
|
2008-11-18 15:21:04 +00:00
|
|
|
'allowusertalk' => 'Allow the user to edit their own talk page (depends on $wgBlockAllowsUTEdit)',
|
|
|
|
|
'reblock' => 'If the user is already blocked, overwrite the existing block',
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2008-01-28 19:05:26 +00:00
|
|
|
public function getDescription() {
|
2010-05-25 20:46:09 +00:00
|
|
|
return 'Block a user';
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
2010-02-11 01:13:45 +00:00
|
|
|
|
2010-02-11 21:53:57 +00:00
|
|
|
public function getPossibleErrors() {
|
|
|
|
|
return array_merge( parent::getPossibleErrors(), array(
|
2010-02-11 21:34:35 +00:00
|
|
|
array( 'missingparam', 'user' ),
|
|
|
|
|
array( 'cantblock' ),
|
|
|
|
|
array( 'canthide' ),
|
|
|
|
|
array( 'cantblock-email' ),
|
2010-03-26 23:02:10 +00:00
|
|
|
array( 'ipbblocked' ),
|
|
|
|
|
array( 'ipbnounblockself' ),
|
2010-02-21 12:32:46 +00:00
|
|
|
) );
|
2010-02-11 01:13:45 +00:00
|
|
|
}
|
2010-02-14 22:20:27 +00:00
|
|
|
|
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-21 12:32:46 +00:00
|
|
|
return array(
|
2007-12-06 16:06:22 +00:00
|
|
|
'api.php?action=block&user=123.5.5.12&expiry=3%20days&reason=First%20strike',
|
|
|
|
|
'api.php?action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate&autoblock&noemail'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function getVersion() {
|
2007-12-06 18:33:18 +00:00
|
|
|
return __CLASS__ . ': $Id$';
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|
|
|
|
|
}
|