* of success. If it fails, the result will specify the nature of the error.
*/
public function execute() {
- global $wgContLang;
-
$this->checkUserRightsAny( 'block' );
$user = $this->getUser();
$params = $this->extractRequestParams();
+ $this->requireOnlyOneParameter( $params, 'user', 'userid' );
+
# bug 15810: blocked admins should have limited access here
if ( $user->isBlocked() ) {
$status = SpecialBlock::checkUnblockSelf( $params['user'], $user );
}
}
- $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->dieWithError( [ 'nosuchusershort', $params['user'] ], 'nosuchuser' );
+ if ( $params['userid'] !== null ) {
+ $username = User::whoIs( $params['userid'] );
+
+ if ( $username === false ) {
+ $this->dieWithError( [ 'apierror-nosuchuserid', $params['userid'] ], 'nosuchuserid' );
+ } else {
+ $params['user'] = $username;
+ }
+ } else {
+ $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->dieWithError( [ 'nosuchusershort', $params['user'] ], 'nosuchuser' );
+ }
+ }
+
+ if ( $params['tags'] ) {
+ $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $params['tags'], $user );
+ if ( !$ableToTag->isOK() ) {
+ $this->dieStatus( $ableToTag );
+ }
}
if ( $params['hidename'] && !$user->isAllowed( 'hideuser' ) ) {
'Reblock' => $params['reblock'],
'Watch' => $params['watchuser'],
'Confirm' => true,
+ 'Tags' => $params['tags'],
];
$retval = SpecialBlock::processForm( $data, $this->getContext() );
$block = Block::newFromTarget( $target, null, true );
if ( $block instanceof Block ) {
- $res['expiry'] = $wgContLang->formatExpiry( $block->mExpiry, TS_ISO_8601, 'infinite' );
+ $res['expiry'] = ApiResult::formatExpiry( $block->mExpiry, 'infinite' );
$res['id'] = $block->getId();
} else {
# should be unreachable
return [
'user' => [
ApiBase::PARAM_TYPE => 'user',
- ApiBase::PARAM_REQUIRED => true
+ ],
+ 'userid' => [
+ ApiBase::PARAM_TYPE => 'integer',
],
'expiry' => 'never',
'reason' => '',
'allowusertalk' => false,
'reblock' => false,
'watchuser' => false,
+ 'tags' => [
+ ApiBase::PARAM_TYPE => 'tags',
+ ApiBase::PARAM_ISMULTI => true,
+ ],
];
}