79 parent::__construct( $main, $action );
81 $this->blockPermissionCheckerFactory = $blockPermissionCheckerFactory;
82 $this->blockUserFactory = $blockUserFactory;
83 $this->titleFactory = $titleFactory;
84 $this->userIdentityLookup = $userIdentityLookup;
85 $this->watchedItemStore = $watchedItemStore;
86 $this->blockUtils = $blockUtils;
87 $this->blockActionInfo = $blockActionInfo;
91 $this->watchlistMaxDuration =
93 $this->watchlistManager = $watchlistManager;
94 $this->userOptionsLookup = $userOptionsLookup;
109 if (
$params[
'user'] !==
null ) {
112 $target = $this->userIdentityLookup->getUserIdentityByUserId(
$params[
'userid'] );
117 [ $target, $targetType ] = $this->blockUtils->parseBlockTarget( $target );
121 !$this->blockPermissionCheckerFactory
122 ->newBlockPermissionChecker(
126 ->checkEmailPermissions()
133 $pageRestrictions = array_map(
134 [ PageRestriction::class,
'newFromTitle' ],
135 (array)
$params[
'pagerestrictions']
138 $namespaceRestrictions = array_map(
static function ( $id ) {
140 }, (array)
$params[
'namespacerestrictions'] );
141 $restrictions = array_merge( $pageRestrictions, $namespaceRestrictions );
144 $actionRestrictions = array_map(
function ( $action ) {
145 return new ActionRestriction( 0, $this->blockActionInfo->getIdFromAction( $action ) );
146 }, (array)
$params[
'actionrestrictions'] );
147 $restrictions = array_merge( $restrictions, $actionRestrictions );
151 $status = $this->blockUserFactory->newBlockUser(
157 'isCreateAccountBlocked' =>
$params[
'nocreate'],
158 'isEmailBlocked' =>
$params[
'noemail'],
159 'isHardBlock' => !
$params[
'anononly'],
160 'isAutoblocking' =>
$params[
'autoblock'],
161 'isUserTalkEditBlocked' => !
$params[
'allowusertalk'],
162 'isHideUser' =>
$params[
'hidename'],
163 'isPartial' =>
$params[
'partial'],
167 )->placeBlock(
$params[
'reblock'] );
169 if ( !$status->isOK() ) {
173 $block = $status->value;
176 $userPage = Title::makeTitle(
NS_USER, $block->getTargetName() );
178 if (
$params[
'watchuser'] && $targetType !== AbstractBlock::TYPE_RANGE ) {
179 $this->
setWatch(
'watch', $userPage, $this->
getUser(),
null, $watchlistExpiry );
184 $res[
'user'] = $block->getTargetName();
189 $res[
'id'] = $block->getId();
191 # should be unreachable
196 $res[
'reason'] =
$params[
'reason'];
197 $res[
'anononly'] =
$params[
'anononly'];
198 $res[
'nocreate'] =
$params[
'nocreate'];
199 $res[
'autoblock'] =
$params[
'autoblock'];
200 $res[
'noemail'] =
$params[
'noemail'];
201 $res[
'hidename'] = $block->getHideName();
202 $res[
'allowusertalk'] =
$params[
'allowusertalk'];
203 $res[
'watchuser'] =
$params[
'watchuser'];
204 if ( $watchlistExpiry ) {
206 $this->watchedItemStore,
210 $res[
'watchlistexpiry'] = $expiry;
212 $res[
'partial'] =
$params[
'partial'];
213 $res[
'pagerestrictions'] =
$params[
'pagerestrictions'];
214 $res[
'namespacerestrictions'] =
$params[
'namespacerestrictions'];
216 $res[
'actionrestrictions'] =
$params[
'actionrestrictions'];
233 ParamValidator::PARAM_TYPE =>
'user',
234 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'temp',
'cidr',
'id' ],
237 ParamValidator::PARAM_TYPE =>
'integer',
238 ParamValidator::PARAM_DEPRECATED =>
true,
244 'autoblock' =>
false,
247 'allowusertalk' =>
false,
249 'watchuser' =>
false,
255 if ( $this->watchlistExpiryEnabled ) {
257 'watchlistexpiry' => [
258 ParamValidator::PARAM_TYPE =>
'expiry',
259 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
260 ExpiryDef::PARAM_USE_MAX =>
true,
267 ParamValidator::PARAM_TYPE =>
'tags',
268 ParamValidator::PARAM_ISMULTI =>
true,
271 'pagerestrictions' => [
272 ParamValidator::PARAM_TYPE =>
'title',
273 TitleDef::PARAM_MUST_EXIST =>
true,
281 ParamValidator::PARAM_ISMULTI =>
true,
282 ParamValidator::PARAM_ISMULTI_LIMIT1 => 10,
283 ParamValidator::PARAM_ISMULTI_LIMIT2 => 10,
285 'namespacerestrictions' => [
286 ParamValidator::PARAM_ISMULTI =>
true,
287 ParamValidator::PARAM_TYPE =>
'namespace',
293 'actionrestrictions' => [
294 ParamValidator::PARAM_ISMULTI =>
true,
295 ParamValidator::PARAM_TYPE => array_keys(
296 $this->blockActionInfo->getAllBlockActions()
312 'action=block&user=192.0.2.5&expiry=3%20days&reason=First%20strike&token=123ABC'
313 =>
'apihelp-block-example-ip-simple',
314 'action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate=&autoblock=&noemail=&token=123ABC'
315 =>
'apihelp-block-example-user-complex',
321 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Block';
326class_alias( ApiBlock::class,
'ApiBlock' );
array $params
The job parameters.
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()
const EnablePartialActionBlocks
Name constant for the EnablePartialActionBlocks setting, for use with Config::get()
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...