57 parent::__construct( $main, $action );
59 $this->permissionCheckerFactory = $permissionCheckerFactory;
60 $this->unblockUserFactory = $unblockUserFactory;
61 $this->userIdentityLookup = $userIdentityLookup;
62 $this->watchedItemStore = $watchedItemStore;
66 $this->watchlistMaxDuration =
68 $this->watchlistManager = $watchlistManager;
69 $this->userOptionsLookup = $userOptionsLookup;
70 $this->blockStore = $blockStore;
71 $this->blockTargetFactory = $blockTargetFactory;
84 $this->
dieWithError(
'apierror-permissiondenied-unblock',
'permissiondenied' );
87 if ( $params[
'userid'] !==
null ) {
88 $identity = $this->userIdentityLookup->getUserIdentityByUserId( $params[
'userid'] );
90 $this->
dieWithError( [
'apierror-nosuchuserid', $params[
'userid'] ],
'nosuchuserid' );
92 $params[
'user'] = $identity;
95 $blockToRemove =
null;
96 if ( $params[
'id'] !==
null ) {
97 $blockToRemove = $this->blockStore->newFromID( $params[
'id'],
true );
98 if ( !$blockToRemove ) {
100 [
'apierror-nosuchblockid', $params[
'id'] ],
103 $target = $blockToRemove->getRedactedTarget();
105 throw new RuntimeException(
'Block has no target' );
108 $target = $this->blockTargetFactory->newFromUser( $params[
'user'] );
111 # T17810: blocked admins should have limited access here
112 $status = $this->permissionCheckerFactory
115 )->checkBlockPermissions( $target );
117 if ( $status !==
true ) {
122 [
'blockinfo' => $this->getBlockDetails( $performer->getBlock() ) ]
126 if ( $blockToRemove !==
null ) {
127 $status = $this->unblockUserFactory->newRemoveBlock(
131 $params[
'tags'] ?? []
134 $status = $this->unblockUserFactory->newUnblockUser(
138 $params[
'tags'] ?? []
142 if ( !$status->isOK() ) {
146 $block = $status->getValue();
147 $targetType = $block->getType();
148 $targetName = $targetType === Block::TYPE_AUTO ?
'' : $block->getTargetName();
149 $targetUserId = $block->getTargetUserIdentity() ? $block->getTargetUserIdentity()->getId() : 0;
153 $watchuser = $params[
'watchuser'];
154 if ( $watchuser && $targetType !== Block::TYPE_RANGE && $targetType !== Block::TYPE_AUTO ) {
155 $this->
setWatch(
'watch', $userPage, $this->
getUser(),
null, $watchlistExpiry );
158 $watchlistExpiry =
null;
162 'id' => $block->getId(),
163 'user' => $targetName,
164 'userid' => $targetUserId,
165 'reason' => $params[
'reason'],
166 'watchuser' => $watchuser,
169 if ( $watchlistExpiry !==
null ) {
171 $this->watchedItemStore,
194 ParamValidator::PARAM_TYPE =>
'integer',
197 ParamValidator::PARAM_TYPE =>
'user',
198 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'cidr',
'id' ],
199 UserDef::PARAM_RETURN_OBJECT =>
true,
202 ParamValidator::PARAM_TYPE =>
'integer',
203 ParamValidator::PARAM_DEPRECATED =>
true,
207 ParamValidator::PARAM_TYPE =>
'tags',
208 ParamValidator::PARAM_ISMULTI =>
true,
210 'watchuser' =>
false,
216 if ( $this->watchlistExpiryEnabled ) {
218 'watchlistexpiry' => [
219 ParamValidator::PARAM_TYPE =>
'expiry',
220 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
221 ExpiryDef::PARAM_USE_MAX =>
true,
237 'action=unblock&id=105'
238 =>
'apihelp-unblock-example-id',
239 'action=unblock&user=Bob&reason=Sorry%20Bob'
240 =>
'apihelp-unblock-example-user',
246 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Block';
251class_alias( ApiUnblock::class,
'ApiUnblock' );
This is the main API class, used for both external and internal processing.
A class containing constants representing the names of configuration variables.
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config::get()
const WatchlistExpiryMaxDuration
Name constant for the WatchlistExpiryMaxDuration setting, for use with Config::get()
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...