api: Replace UserCache in ApiUnblock
Inject and use the new UserIdentityLookup service Change-Id: I1e5cbae12115423a82316d7234b5cfc02d27dd3b
This commit is contained in:
parent
f39b88ed7b
commit
fdc64ef20c
2 changed files with 9 additions and 10 deletions
|
|
@ -249,7 +249,7 @@ class ApiMain extends ApiBase {
|
|||
'services' => [
|
||||
'BlockPermissionCheckerFactory',
|
||||
'UnblockUserFactory',
|
||||
'UserCache',
|
||||
'UserIdentityLookup',
|
||||
]
|
||||
],
|
||||
'move' => [
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ use MediaWiki\Block\BlockPermissionCheckerFactory;
|
|||
use MediaWiki\Block\DatabaseBlock;
|
||||
use MediaWiki\Block\UnblockUserFactory;
|
||||
use MediaWiki\ParamValidator\TypeDef\UserDef;
|
||||
use MediaWiki\User\UserIdentityLookup;
|
||||
|
||||
/**
|
||||
* API module that facilitates the unblocking of users. Requires API write mode
|
||||
|
|
@ -41,21 +42,21 @@ class ApiUnblock extends ApiBase {
|
|||
/** @var UnblockUserFactory */
|
||||
private $unblockUserFactory;
|
||||
|
||||
/** @var UserCache */
|
||||
private $userCache;
|
||||
/** @var UserIdentityLookup */
|
||||
private $userIdentityLookup;
|
||||
|
||||
public function __construct(
|
||||
ApiMain $main,
|
||||
$action,
|
||||
BlockPermissionCheckerFactory $permissionCheckerFactory,
|
||||
UnblockUserFactory $unblockUserFactory,
|
||||
UserCache $userCache
|
||||
UserIdentityLookup $userIdentityLookup
|
||||
) {
|
||||
parent::__construct( $main, $action );
|
||||
|
||||
$this->permissionCheckerFactory = $permissionCheckerFactory;
|
||||
$this->unblockUserFactory = $unblockUserFactory;
|
||||
$this->userCache = $userCache;
|
||||
$this->userIdentityLookup = $userIdentityLookup;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -72,13 +73,11 @@ class ApiUnblock extends ApiBase {
|
|||
}
|
||||
|
||||
if ( $params['userid'] !== null ) {
|
||||
$username = $this->userCache->getProp( $params['userid'], 'name' );
|
||||
|
||||
if ( $username === false ) {
|
||||
$identity = $this->userIdentityLookup->getUserIdentityByUserId( $params['userid'] );
|
||||
if ( !$identity ) {
|
||||
$this->dieWithError( [ 'apierror-nosuchuserid', $params['userid'] ], 'nosuchuserid' );
|
||||
} else {
|
||||
$params['user'] = $username;
|
||||
}
|
||||
$params['user'] = $identity->getName();
|
||||
}
|
||||
|
||||
$target = $params['id'] === null ? $params['user'] : "#{$params['id']}";
|
||||
|
|
|
|||
Loading…
Reference in a new issue