$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['hidename'] && !$user->isAllowed( 'hideuser' ) ) {
return [
'user' => [
ApiBase::PARAM_TYPE => 'user',
- ApiBase::PARAM_REQUIRED => true
+ ],
+ 'userid' => [
+ ApiBase::PARAM_TYPE => 'integer',
],
'expiry' => 'never',
'reason' => '',
$user = $this->getUser();
$params = $this->extractRequestParams();
- $this->requireOnlyOneParameter( $params, 'id', 'user' );
+ $this->requireOnlyOneParameter( $params, 'id', 'user', 'userid' );
if ( !$user->isAllowed( 'block' ) ) {
$this->dieWithError( 'apierror-permissiondenied-unblock', 'permissiondenied' );
}
}
+ if ( $params['userid'] !== null ) {
+ $username = User::whoIs( $params['userid'] );
+
+ if ( $username === false ) {
+ $this->dieWithError( [ 'apierror-nosuchuserid', $params['userid'] ], 'nosuchuserid' );
+ } else {
+ $params['user'] = $username;
+ }
+ }
+
$data = [
'Target' => is_null( $params['id'] ) ? $params['user'] : "#{$params['id']}",
'Reason' => $params['reason'],
ApiBase::PARAM_TYPE => 'integer',
],
'user' => null,
+ 'userid' => [
+ ApiBase::PARAM_TYPE => 'integer'
+ ],
'reason' => '',
'tags' => [
ApiBase::PARAM_TYPE => 'tags',
"apihelp-main-param-errorsuselocal": "If given, error texts will use locally-customized messages from the {{ns:MediaWiki}} namespace.",
"apihelp-block-description": "Block a user.",
- "apihelp-block-param-user": "Username, IP address, or IP address range to block.",
+ "apihelp-block-param-user": "Username, IP address, or IP address range to block. Cannot be used together with <var>$1userid</var>",
+ "apihelp-block-param-userid": "User ID to block. Cannot be used together with <var>$1user</var>.",
"apihelp-block-param-expiry": "Expiry time. May be relative (e.g. <kbd>5 months</kbd> or <kbd>2 weeks</kbd>) or absolute (e.g. <kbd>2014-09-18T12:34:56Z</kbd>). If set to <kbd>infinite</kbd>, <kbd>indefinite</kbd>, or <kbd>never</kbd>, the block will never expire.",
"apihelp-block-param-reason": "Reason for block.",
"apihelp-block-param-anononly": "Block anonymous users only (i.e. disable anonymous edits for this IP address).",
"apihelp-tokens-example-emailmove": "Retrieve an email token and a move token.",
"apihelp-unblock-description": "Unblock a user.",
- "apihelp-unblock-param-id": "ID of the block to unblock (obtained through <kbd>list=blocks</kbd>). Cannot be used together with <var>$1user</var>.",
- "apihelp-unblock-param-user": "Username, IP address or IP address range to unblock. Cannot be used together with <var>$1id</var>.",
+ "apihelp-unblock-param-id": "ID of the block to unblock (obtained through <kbd>list=blocks</kbd>). Cannot be used together with <var>$1user</var> or <var>$luserid</var>.",
+ "apihelp-unblock-param-user": "Username, IP address or IP address range to unblock. Cannot be used together with <var>$1id</var> or <var>$luserid</var>.",
+ "apihelp-unblock-param-userid": "User ID to unblock. Cannot be used together with <var>$1id</var> or <var>$1user</var>.",
"apihelp-unblock-param-reason": "Reason for unblock.",
"apihelp-unblock-param-tags": "Change tags to apply to the entry in the block log.",
"apihelp-unblock-example-id": "Unblock block ID #<kbd>105</kbd>.",
"apierror-nosuchrevid": "There is no revision with ID $1.",
"apierror-nosuchsection": "There is no section $1.",
"apierror-nosuchsection-what": "There is no section $1 in $2.",
+ "apierror-nosuchuserid": "There is no user with ID $1.",
"apierror-notarget": "You have not specified a valid target for this action.",
"apierror-notpatrollable": "The revision r$1 can't be patrolled as it's too old.",
"apierror-nouploadmodule": "No upload module set.",
"apihelp-main-param-errorsuselocal": "{{doc-apihelp-param|main|errorsuselocal}}",
"apihelp-block-description": "{{doc-apihelp-description|block}}",
"apihelp-block-param-user": "{{doc-apihelp-param|block|user}}",
+ "apihelp-block-param-userid": "{{doc-apihelp-param|block|userid}}",
"apihelp-block-param-expiry": "{{doc-apihelp-param|block|expiry}}\n{{doc-important|Do not translate \"5 months\", \"2 weeks\", \"infinite\", \"indefinite\" or \"never\"!}}",
"apihelp-block-param-reason": "{{doc-apihelp-param|block|reason}}",
"apihelp-block-param-anononly": "{{doc-apihelp-param|block|anononly}}\n* See also {{msg-mw|ipb-hardblock}}",
"apihelp-unblock-description": "{{doc-apihelp-description|unblock}}",
"apihelp-unblock-param-id": "{{doc-apihelp-param|unblock|id}}",
"apihelp-unblock-param-user": "{{doc-apihelp-param|unblock|user}}",
+ "apihelp-unblock-param-userid": "{{doc-apihelp-param|unblock|userid}}",
"apihelp-unblock-param-reason": "{{doc-apihelp-param|unblock|reason}}",
"apihelp-unblock-param-tags": "{{doc-apihelp-param|unblock|tags}}",
"apihelp-unblock-example-id": "{{doc-apihelp-example|unblock}}",
"apierror-nosuchrevid": "{{doc-apierror}}\n\nParameters:\n* $1 - Revision ID number.",
"apierror-nosuchsection": "{{doc-apierror}}\n\nParameters:\n* $1 - Section identifier. Probably a number or \"T-\" followed by a number.",
"apierror-nosuchsection-what": "{{doc-apierror}}\n\nParameters:\n* $1 - Section identifier. Probably a number or \"T-\" followed by a number.\n* $2 - Page title, revision ID formatted with {{msg-mw|revid}}, or page ID formatted with {{msg-mw|pageid}}.",
+ "apierror-nosuchuserid": "{{doc-apierror}}",
"apierror-notarget": "{{doc-apierror}}",
"apierror-notpatrollable": "{{doc-apierror}}\n\nParameters:\n* $1 - Revision ID number.",
"apierror-nouploadmodule": "{{doc-apierror}}",
$this->doLogin();
}
+ protected function tearDown() {
+ $block = Block::newFromTarget( 'UTApiBlockee' );
+ if ( !is_null( $block ) ) {
+ $block->delete();
+ }
+ parent::tearDown();
+ }
+
protected function getTokens() {
return $this->getTokenList( self::$users['sysop'] );
}
$this->assertEquals( 'infinity', $block->mExpiry );
}
+ /**
+ * Block by user ID
+ */
+ public function testMakeNormalBlockId() {
+ $tokens = $this->getTokens();
+ $user = User::newFromName( 'UTApiBlockee' );
+
+ if ( !$user->getId() ) {
+ $this->markTestIncomplete( "The user UTApiBlockee does not exist." );
+ }
+
+ if ( !array_key_exists( 'blocktoken', $tokens ) ) {
+ $this->markTestIncomplete( "No block token found" );
+ }
+
+ $data = $this->doApiRequest( [
+ 'action' => 'block',
+ 'userid' => $user->getId(),
+ 'reason' => 'Some reason',
+ 'token' => $tokens['blocktoken'] ], null, false, self::$users['sysop']->getUser() );
+
+ $block = Block::newFromTarget( 'UTApiBlockee' );
+
+ $this->assertTrue( !is_null( $block ), 'Block is valid.' );
+ $this->assertEquals( 'UTApiBlockee', (string)$block->getTarget() );
+ $this->assertEquals( 'Some reason', $block->mReason );
+ $this->assertEquals( 'infinity', $block->mExpiry );
+ }
+
/**
* @expectedException ApiUsageException
* @expectedExceptionMessage The "token" parameter must be set