2007-12-06 16:06:22 +00:00
|
|
|
<?php
|
2010-02-21 12:32:46 +00:00
|
|
|
/**
|
2010-12-22 20:52:06 +00:00
|
|
|
*
|
2007-12-06 16:06:22 +00:00
|
|
|
*
|
2010-08-07 19:59:42 +00:00
|
|
|
* Created on Sep 4, 2007
|
|
|
|
|
*
|
2012-07-15 20:13:02 +00:00
|
|
|
* Copyright © 2007 Roan Kattouw "<Firstname>.<Lastname>@gmail.com"
|
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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
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
|
|
|
/**
|
|
|
|
|
* 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() {
|
2011-10-26 23:27:01 +00:00
|
|
|
$user = $this->getUser();
|
2007-12-06 16:06:22 +00:00
|
|
|
$params = $this->extractRequestParams();
|
|
|
|
|
|
2010-02-21 12:32:46 +00:00
|
|
|
if ( $params['gettoken'] ) {
|
2012-04-02 18:11:50 +00:00
|
|
|
$res['blocktoken'] = $user->getEditToken();
|
2010-01-11 15:55:52 +00:00
|
|
|
$this->getResult()->addValue( null, $this->getModuleName(), $res );
|
2007-12-06 16:06:22 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 23:27:01 +00:00
|
|
|
if ( !$user->isAllowed( 'block' ) ) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'cantblock' );
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
2012-12-22 19:33:05 +00:00
|
|
|
|
2010-03-26 23:02:10 +00:00
|
|
|
# bug 15810: blocked admins should have limited access here
|
2011-10-26 23:27:01 +00:00
|
|
|
if ( $user->isBlocked() ) {
|
2011-11-13 07:25:56 +00:00
|
|
|
$status = SpecialBlock::checkUnblockSelf( $params['user'], $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
|
|
|
}
|
2012-12-22 19:33:05 +00:00
|
|
|
|
|
|
|
|
$target = User::newFromName( $params['user'] );
|
|
|
|
|
// Bug 38633 - if the target is a user (not an IP address), but it doesn't exist or is unusable, error.
|
|
|
|
|
if ( $target instanceof User && ( $target->isAnon() /* doesn't exist */ || !User::isUsableName( $target->getName() ) ) ) {
|
|
|
|
|
$this->dieUsageMsg( array( 'nosuchuser', $params['user'] ) );
|
|
|
|
|
}
|
|
|
|
|
|
2011-10-26 23:27:01 +00:00
|
|
|
if ( $params['hidename'] && !$user->isAllowed( 'hideuser' ) ) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'canthide' );
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
2011-10-26 23:27:01 +00:00
|
|
|
if ( $params['noemail'] && !SpecialBlock::canBlockEmail( $user ) ) {
|
2011-05-19 17:51:16 +00:00
|
|
|
$this->dieUsageMsg( 'cantblock-email' );
|
2010-02-21 12:32:46 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2011-03-12 21:54:35 +00:00
|
|
|
$data = array(
|
2012-04-14 21:43:49 +00:00
|
|
|
'PreviousTarget' => $params['user'],
|
2011-03-12 21:54:35 +00:00
|
|
|
'Target' => $params['user'],
|
|
|
|
|
'Reason' => array(
|
2012-07-07 07:12:04 +00:00
|
|
|
$params['reason'],
|
2011-03-12 21:54:35 +00:00
|
|
|
'other',
|
2012-07-07 07:12:04 +00:00
|
|
|
$params['reason']
|
2011-03-12 21:54:35 +00:00
|
|
|
),
|
|
|
|
|
'Expiry' => $params['expiry'] == 'never' ? 'infinite' : $params['expiry'],
|
|
|
|
|
'HardBlock' => !$params['anononly'],
|
|
|
|
|
'CreateAccount' => $params['nocreate'],
|
|
|
|
|
'AutoBlock' => $params['autoblock'],
|
|
|
|
|
'DisableEmail' => $params['noemail'],
|
|
|
|
|
'HideUser' => $params['hidename'],
|
2011-10-13 22:23:13 +00:00
|
|
|
'DisableUTEdit' => !$params['allowusertalk'],
|
2012-04-14 21:43:49 +00:00
|
|
|
'Reblock' => $params['reblock'],
|
2011-03-12 21:54:35 +00:00
|
|
|
'Watch' => $params['watchuser'],
|
2011-04-07 14:54:38 +00:00
|
|
|
'Confirm' => true,
|
2011-03-12 21:54:35 +00:00
|
|
|
);
|
2007-12-06 16:06:22 +00:00
|
|
|
|
2011-11-13 07:25:56 +00:00
|
|
|
$retval = SpecialBlock::processForm( $data, $this->getContext() );
|
2011-03-12 21:54:35 +00:00
|
|
|
if ( $retval !== true ) {
|
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
|
|
|
|
2011-03-21 19:12:41 +00:00
|
|
|
list( $target, /*...*/ ) = SpecialBlock::getTargetAndType( $params['user'] );
|
2007-12-06 16:06:22 +00:00
|
|
|
$res['user'] = $params['user'];
|
2011-03-12 21:54:35 +00:00
|
|
|
$res['userID'] = $target instanceof User ? $target->getId() : 0;
|
|
|
|
|
|
2011-03-21 19:12:41 +00:00
|
|
|
$block = Block::newFromTarget( $target );
|
2013-01-26 21:11:09 +00:00
|
|
|
if( $block instanceof Block ) {
|
2012-05-16 17:22:36 +00:00
|
|
|
$res['expiry'] = $block->mExpiry == $this->getDB()->getInfinity()
|
2011-03-12 21:54:35 +00:00
|
|
|
? 'infinite'
|
|
|
|
|
: wfTimestamp( TS_ISO_8601, $block->mExpiry );
|
2012-04-22 12:20:46 +00:00
|
|
|
$res['id'] = $block->getId();
|
2011-03-12 21:54:35 +00:00
|
|
|
} else {
|
|
|
|
|
# should be unreachable
|
|
|
|
|
$res['expiry'] = '';
|
2012-04-22 12:20:46 +00:00
|
|
|
$res['id'] = '';
|
2011-03-12 21:54:35 +00:00
|
|
|
}
|
|
|
|
|
|
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
|
|
|
}
|
2011-01-02 19:58:27 +00:00
|
|
|
if ( $params['watchuser'] ) {
|
|
|
|
|
$res['watchuser'] = '';
|
|
|
|
|
}
|
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(
|
2010-08-04 14:15:33 +00:00
|
|
|
'user' => array(
|
|
|
|
|
ApiBase::PARAM_TYPE => 'string',
|
2010-08-04 14:29:39 +00:00
|
|
|
ApiBase::PARAM_REQUIRED => true
|
2010-08-04 14:15:33 +00:00
|
|
|
),
|
2007-12-06 16:06:22 +00:00
|
|
|
'token' => null,
|
2012-05-06 14:43:09 +00:00
|
|
|
'gettoken' => array(
|
|
|
|
|
ApiBase::PARAM_DFLT => false,
|
|
|
|
|
ApiBase::PARAM_DEPRECATED => true,
|
|
|
|
|
),
|
2007-12-06 16:06:22 +00:00
|
|
|
'expiry' => 'never',
|
2012-07-07 07:12:04 +00:00
|
|
|
'reason' => '',
|
2007-12-06 16:06:22 +00:00
|
|
|
'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,
|
2011-01-02 19:58:27 +00:00
|
|
|
'watchuser' => 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',
|
2012-05-06 14:43:09 +00:00
|
|
|
'token' => 'A block token previously obtained through 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.',
|
2012-07-07 07:12:04 +00:00
|
|
|
'reason' => 'Reason for block',
|
2007-12-06 16:06:22 +00:00
|
|
|
'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',
|
2013-03-02 18:13:54 +00:00
|
|
|
'noemail' => 'Prevent user from sending email 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',
|
2011-01-02 19:58:27 +00:00
|
|
|
'watchuser' => 'Watch the user/IP\'s user and talk pages',
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
Added result properties to action=paraminfo
Added information about the properties of the results of API calls
to action=paraminfo, including information about "property groups":
what should the prop parameter be set to to get that property.
Uses the same format for types as parameters already do.
The output format of some modules doesn't fit this, so the result
properties for them weren't added, or only partially.
Partially implemented modules:
* expandtemplates:
parsetree is in its own tag
* protect, allusers, backlinks, deletedrevs, info, imageinfo,
logevents, querypage, recentchanges, revisions, searchinfo,
usercontribs, userinfo, users, watchlist, upload:
response with partially complex structure
Not implemented modules:
* feedcontributions, feedwatchlist, opensearch, rds:
non-standard reponse
* help:
error is normal response; not very useful for automated tools anyway
* paraminfo, parse, pageprops, siteinfo, userrights:
response with complex structure
Change-Id: Iff2a9bef79f994e73eef3062b4dd5461bff968ab
2012-05-02 15:00:30 +00:00
|
|
|
public function getResultProperties() {
|
|
|
|
|
return array(
|
|
|
|
|
'' => array(
|
|
|
|
|
'blocktoken' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'string',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'user' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'string',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'userID' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'integer',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'expiry' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'string',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'id' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'integer',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'reason' => array(
|
|
|
|
|
ApiBase::PROP_TYPE => 'string',
|
|
|
|
|
ApiBase::PROP_NULLABLE => true
|
|
|
|
|
),
|
|
|
|
|
'anononly' => 'boolean',
|
|
|
|
|
'nocreate' => 'boolean',
|
|
|
|
|
'autoblock' => 'boolean',
|
|
|
|
|
'noemail' => 'boolean',
|
|
|
|
|
'hidename' => 'boolean',
|
|
|
|
|
'allowusertalk' => 'boolean',
|
|
|
|
|
'watchuser' => 'boolean'
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
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-07-23 07:33:40 +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( '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-07-23 07:33:40 +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
|
|
|
|
2011-08-17 22:24:21 +00:00
|
|
|
public 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',
|
2010-11-23 22:05:27 +00:00
|
|
|
'api.php?action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate=&autoblock=&noemail='
|
2007-12-06 16:06:22 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-17 16:38:24 +00:00
|
|
|
public function getHelpUrls() {
|
2011-11-28 15:43:11 +00:00
|
|
|
return 'https://www.mediawiki.org/wiki/API:Block';
|
2011-07-17 16:38:24 +00:00
|
|
|
}
|
2007-12-06 16:06:22 +00:00
|
|
|
}
|