71 parent::__construct( $main, $action );
73 $this->permissionCheckerFactory = $permissionCheckerFactory;
74 $this->unblockUserFactory = $unblockUserFactory;
75 $this->userIdentityLookup = $userIdentityLookup;
76 $this->watchedItemStore = $watchedItemStore;
80 $this->watchlistMaxDuration =
82 $this->watchlistManager = $watchlistManager;
83 $this->userOptionsLookup = $userOptionsLookup;
84 $this->blockStore = $blockStore;
85 $this->blockTargetFactory = $blockTargetFactory;
98 $this->
dieWithError(
'apierror-permissiondenied-unblock',
'permissiondenied' );
101 if ( $params[
'userid'] !==
null ) {
102 $identity = $this->userIdentityLookup->getUserIdentityByUserId( $params[
'userid'] );
104 $this->
dieWithError( [
'apierror-nosuchuserid', $params[
'userid'] ],
'nosuchuserid' );
106 $params[
'user'] = $identity;
109 $blockToRemove =
null;
110 if ( $params[
'id'] !==
null ) {
111 $blockToRemove = $this->blockStore->newFromID( $params[
'id'],
true );
112 if ( !$blockToRemove ) {
114 [
'apierror-nosuchblockid', $params[
'id'] ],
117 $target = $blockToRemove->getRedactedTarget();
119 throw new RuntimeException(
'Block has no target' );
122 $target = $this->blockTargetFactory->newFromUser( $params[
'user'] );
125 # T17810: blocked admins should have limited access here
126 $status = $this->permissionCheckerFactory
129 )->checkBlockPermissions( $target );
131 if ( $status !==
true ) {
136 [
'blockinfo' => $this->getBlockDetails( $performer->getBlock() ) ]
140 if ( $blockToRemove !==
null ) {
141 $status = $this->unblockUserFactory->newRemoveBlock(
145 $params[
'tags'] ?? []
148 $status = $this->unblockUserFactory->newUnblockUser(
152 $params[
'tags'] ?? []
156 if ( !$status->isOK() ) {
160 $block = $status->getValue();
161 $targetType = $block->getType();
162 $targetName = $targetType === Block::TYPE_AUTO ?
'' : $block->getTargetName();
163 $targetUserId = $block->getTargetUserIdentity() ? $block->getTargetUserIdentity()->getId() : 0;
166 $watchuser = $params[
'watchuser'];
167 $userPage = Title::makeTitle(
NS_USER, $targetName );
168 if ( $watchuser && $targetType !== Block::TYPE_RANGE && $targetType !== Block::TYPE_AUTO ) {
169 $this->
setWatch(
'watch', $userPage, $this->
getUser(),
null, $watchlistExpiry );
172 $watchlistExpiry =
null;
176 'id' => $block->getId(),
177 'user' => $targetName,
178 'userid' => $targetUserId,
179 'reason' => $params[
'reason'],
180 'watchuser' => $watchuser,
183 if ( $watchlistExpiry !==
null ) {
185 $this->watchedItemStore,
205 ParamValidator::PARAM_TYPE =>
'integer',
208 ParamValidator::PARAM_TYPE =>
'user',
209 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'cidr',
'id' ],
210 UserDef::PARAM_RETURN_OBJECT =>
true,
213 ParamValidator::PARAM_TYPE =>
'integer',
214 ParamValidator::PARAM_DEPRECATED =>
true,
218 ParamValidator::PARAM_TYPE =>
'tags',
219 ParamValidator::PARAM_ISMULTI =>
true,
221 'watchuser' =>
false,
227 if ( $this->watchlistExpiryEnabled ) {
229 'watchlistexpiry' => [
230 ParamValidator::PARAM_TYPE =>
'expiry',
231 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
232 ExpiryDef::PARAM_USE_MAX =>
true,
246 'action=unblock&id=105'
247 =>
'apihelp-unblock-example-id',
248 'action=unblock&user=Bob&reason=Sorry%20Bob'
249 =>
'apihelp-unblock-example-user',
254 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Block';
259class_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...