50 parent::__construct( $main, $action );
52 $this->watchedItemStore = $watchedItemStore;
56 $this->watchlistMaxDuration =
58 $this->watchlistManager = $watchlistManager;
59 $this->userOptionsLookup = $userOptionsLookup;
72 $this->
dieWithError(
'apierror-permissiondenied-unblock',
'permissiondenied' );
75 if ( $params[
'userid'] !==
null ) {
76 $identity = $this->userIdentityLookup->getUserIdentityByUserId( $params[
'userid'] );
78 $this->
dieWithError( [
'apierror-nosuchuserid', $params[
'userid'] ],
'nosuchuserid' );
80 $params[
'user'] = $identity;
83 $blockToRemove =
null;
84 if ( $params[
'id'] !==
null ) {
85 $blockToRemove = $this->blockStore->newFromID( $params[
'id'],
true );
86 if ( !$blockToRemove ) {
88 [
'apierror-nosuchblockid', $params[
'id'] ],
91 $target = $blockToRemove->getRedactedTarget();
93 throw new RuntimeException(
'Block has no target' );
96 $target = $this->blockTargetFactory->newFromUser( $params[
'user'] );
99 # T17810: blocked admins should have limited access here
100 $status = $this->permissionCheckerFactory
103 )->checkBlockPermissions( $target );
105 if ( $status !==
true ) {
110 [
'blockinfo' => $this->getBlockDetails( $performer->getBlock() ) ]
114 if ( $blockToRemove !==
null ) {
115 $status = $this->unblockUserFactory->newRemoveBlock(
119 $params[
'tags'] ?? []
122 $status = $this->unblockUserFactory->newUnblockUser(
126 $params[
'tags'] ?? []
130 if ( !$status->isOK() ) {
134 $block = $status->getValue();
135 $targetType = $block->getType();
136 $targetName = $targetType === Block::TYPE_AUTO ?
'' : $block->getTargetName();
137 $targetUserId = $block->getTargetUserIdentity() ? $block->getTargetUserIdentity()->getId() : 0;
141 $watchuser = $params[
'watchuser'];
142 if ( $watchuser && $targetType !== Block::TYPE_RANGE && $targetType !== Block::TYPE_AUTO ) {
143 $this->
setWatch(
'watch', $userPage, $this->
getUser(),
null, $watchlistExpiry );
146 $watchlistExpiry =
null;
150 'id' => $block->getId(),
151 'user' => $targetName,
152 'userid' => $targetUserId,
153 'reason' => $params[
'reason'],
154 'watchuser' => $watchuser,
157 if ( $watchlistExpiry !==
null ) {
159 $this->watchedItemStore,
182 ParamValidator::PARAM_TYPE =>
'integer',
185 ParamValidator::PARAM_TYPE =>
'user',
186 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'cidr',
'id' ],
187 UserDef::PARAM_RETURN_OBJECT =>
true,
190 ParamValidator::PARAM_TYPE =>
'integer',
191 ParamValidator::PARAM_DEPRECATED =>
true,
195 ParamValidator::PARAM_TYPE =>
'tags',
196 ParamValidator::PARAM_ISMULTI =>
true,
198 'watchuser' =>
false,
204 if ( $this->watchlistExpiryEnabled ) {
206 'watchlistexpiry' => [
207 ParamValidator::PARAM_TYPE =>
'expiry',
208 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
209 ExpiryDef::PARAM_USE_MAX =>
true,
225 'action=unblock&id=105'
226 =>
'apihelp-unblock-example-id',
227 'action=unblock&user=Bob&reason=Sorry%20Bob'
228 =>
'apihelp-unblock-example-user',
234 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Block';
239class_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...