62 parent::__construct( $main, $action );
64 $this->permissionCheckerFactory = $permissionCheckerFactory;
65 $this->unblockUserFactory = $unblockUserFactory;
66 $this->userIdentityLookup = $userIdentityLookup;
67 $this->watchedItemStore = $watchedItemStore;
70 $this->watchlistExpiryEnabled = $this->
getConfig()->get( MainConfigNames::WatchlistExpiry );
71 $this->watchlistMaxDuration =
72 $this->
getConfig()->get( MainConfigNames::WatchlistExpiryMaxDuration );
73 $this->watchlistManager = $watchlistManager;
74 $this->userOptionsLookup = $userOptionsLookup;
87 $this->
dieWithError(
'apierror-permissiondenied-unblock',
'permissiondenied' );
90 if (
$params[
'userid'] !==
null ) {
91 $identity = $this->userIdentityLookup->getUserIdentityByUserId(
$params[
'userid'] );
95 $params[
'user'] = $identity->getName();
98 $target =
$params[
'id'] ===
null ?
$params[
'user'] :
"#{$params['id']}";
100 # T17810: blocked admins should have limited access here
101 $status = $this->permissionCheckerFactory
102 ->newBlockPermissionChecker(
105 )->checkBlockPermissions();
106 if ( $status !==
true ) {
111 [
'blockinfo' => $this->getBlockDetails( $performer->getBlock() ) ]
115 $status = $this->unblockUserFactory->newUnblockUser(
122 if ( !$status->isOK() ) {
126 $block = $status->getValue();
127 $targetType = $block->getType();
128 $targetName = $targetType === Block::TYPE_AUTO ?
'' : $block->getTargetName();
129 $targetUserId = $block->getTargetUserIdentity() ? $block->getTargetUserIdentity()->getId() : 0;
132 $watchuser =
$params[
'watchuser'];
133 $userPage = Title::makeTitle(
NS_USER, $targetName );
134 if ( $watchuser && $targetType !== Block::TYPE_RANGE && $targetType !== Block::TYPE_AUTO ) {
135 $this->
setWatch(
'watch', $userPage, $this->
getUser(),
null, $watchlistExpiry );
138 $watchlistExpiry =
null;
142 'id' => $block->getId(),
143 'user' => $targetName,
144 'userid' => $targetUserId,
146 'watchuser' => $watchuser,
148 if ( $watchlistExpiry !==
null ) {
150 $this->watchedItemStore,
169 ParamValidator::PARAM_TYPE =>
'integer',
172 ParamValidator::PARAM_TYPE =>
'user',
173 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'cidr',
'id' ],
176 ParamValidator::PARAM_TYPE =>
'integer',
177 ParamValidator::PARAM_DEPRECATED =>
true,
181 ParamValidator::PARAM_TYPE =>
'tags',
182 ParamValidator::PARAM_ISMULTI =>
true,
184 'watchuser' =>
false,
190 if ( $this->watchlistExpiryEnabled ) {
192 'watchlistexpiry' => [
193 ParamValidator::PARAM_TYPE =>
'expiry',
194 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
195 ExpiryDef::PARAM_USE_MAX =>
true,
209 'action=unblock&id=105'
210 =>
'apihelp-unblock-example-id',
211 'action=unblock&user=Bob&reason=Sorry%20Bob'
212 =>
'apihelp-unblock-example-user',
217 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, PageIdentity $page, User $user, ?string $userOption=null, ?string $expiry=null)
Set a watch (or unwatch) based the based on a watchlist parameter.
getWatchlistExpiry(WatchedItemStoreInterface $store, PageIdentity $page, UserIdentity $user)
Get existing expiry from the database.
array $params
The job parameters.
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...