61 parent::__construct( $main, $action );
63 $this->permissionCheckerFactory = $permissionCheckerFactory;
64 $this->unblockUserFactory = $unblockUserFactory;
65 $this->userIdentityLookup = $userIdentityLookup;
66 $this->watchedItemStore = $watchedItemStore;
69 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
70 $this->watchlistMaxDuration =
71 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
72 $this->watchlistManager = $watchlistManager;
73 $this->userOptionsLookup = $userOptionsLookup;
86 $this->
dieWithError(
'apierror-permissiondenied-unblock',
'permissiondenied' );
89 if ( $params[
'userid'] !==
null ) {
90 $identity = $this->userIdentityLookup->getUserIdentityByUserId( $params[
'userid'] );
92 $this->
dieWithError( [
'apierror-nosuchuserid', $params[
'userid'] ],
'nosuchuserid' );
94 $params[
'user'] = $identity->getName();
97 $target = $params[
'id'] ===
null ? $params[
'user'] :
"#{$params['id']}";
99 # T17810: blocked admins should have limited access here
100 $status = $this->permissionCheckerFactory
101 ->newBlockPermissionChecker(
104 )->checkBlockPermissions();
105 if ( $status !==
true ) {
110 [
'blockinfo' => $this->getBlockDetails( $performer->getBlock() ) ]
114 $status = $this->unblockUserFactory->newUnblockUser(
118 $params[
'tags'] ?? []
121 if ( !$status->isOK() ) {
125 $block = $status->getValue();
126 $targetType = $block->getType();
127 $targetName = $targetType === DatabaseBlock::TYPE_AUTO ?
'' : $block->getTargetName();
128 $targetUserId = $block->getTargetUserIdentity() ? $block->getTargetUserIdentity()->getId() : 0;
131 $watchuser = $params[
'watchuser'];
132 $userPage = Title::makeTitle(
NS_USER, $targetName );
133 if ( $watchuser && $targetType !== DatabaseBlock::TYPE_RANGE && $targetType !== DatabaseBlock::TYPE_AUTO ) {
134 $this->
setWatch(
'watch', $userPage, $this->
getUser(),
null, $watchlistExpiry );
137 $watchlistExpiry =
null;
141 'id' => $block->getId(),
142 'user' => $targetName,
143 'userid' => $targetUserId,
144 'reason' => $params[
'reason'],
145 'watchuser' => $watchuser,
147 if ( $watchlistExpiry !==
null ) {
149 $this->watchedItemStore,
168 ParamValidator::PARAM_TYPE =>
'integer',
171 ParamValidator::PARAM_TYPE =>
'user',
172 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'cidr',
'id' ],
175 ParamValidator::PARAM_TYPE =>
'integer',
176 ParamValidator::PARAM_DEPRECATED =>
true,
180 ParamValidator::PARAM_TYPE =>
'tags',
181 ParamValidator::PARAM_ISMULTI =>
true,
183 'watchuser' =>
false,
189 if ( $this->watchlistExpiryEnabled ) {
191 'watchlistexpiry' => [
192 ParamValidator::PARAM_TYPE =>
'expiry',
193 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
194 ExpiryDef::PARAM_USE_MAX =>
true,
208 'action=unblock&id=105'
209 =>
'apihelp-unblock-example-id',
210 'action=unblock&user=Bob&reason=Sorry%20Bob'
211 =>
'apihelp-unblock-example-user',
216 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Block';
getExpiryFromParams(array $params)
Get formatted expiry from the given parameters, or null if no expiry was provided.
setWatch(string $watch, Title $title, User $user, ?string $userOption=null, ?string $expiry=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
getWatchlistExpiry(WatchedItemStoreInterface $store, Title $title, UserIdentity $user)
Get existing expiry from the database.
This abstract class implements many basic API functions, and is the base of all API classes.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
requireOnlyOneParameter( $params,... $required)
Die if 0 or more than one of a certain set of parameters is set and not false.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
getModuleName()
Get the name of the module being executed by this instance.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
This is the main API class, used for both external and internal processing.
API module that facilitates the unblocking of users.
isWriteMode()
Indicates whether this module requires write mode.
needsToken()
Returns the token type this module requires in order to execute.
execute()
Unblocks the specified user or provides the reason the unblock failed.
getHelpUrls()
Return links to more detailed help pages about the module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
mustBePosted()
Indicates whether this module must be called with a POST request.
__construct(ApiMain $main, $action, BlockPermissionCheckerFactory $permissionCheckerFactory, UnblockUserFactory $unblockUserFactory, UserIdentityLookup $userIdentityLookup, WatchedItemStoreInterface $watchedItemStore, WatchlistManager $watchlistManager, UserOptionsLookup $userOptionsLookup)
getExamplesMessages()
Returns usage examples for this module.
A class containing constants representing the names of configuration variables.
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...