Go to the documentation of this file.
33 use ApiBlockInfoTrait;
49 # T17810: blocked admins should have limited access here
50 $block = $user->getBlock();
57 [
'blockinfo' => $this->getBlockDetails( $block ) ]
62 $editingRestriction =
'sitewide';
63 $pageRestrictions =
'';
64 $namespaceRestrictions =
'';
65 if ( $this->
getConfig()->
get(
'EnablePartialBlocks' ) ) {
66 if ( $params[
'partial'] ) {
67 $editingRestriction =
'partial';
70 $pageRestrictions = implode(
"\n", (array)$params[
'pagerestrictions'] );
71 $namespaceRestrictions = implode(
"\n", (array)$params[
'namespacerestrictions'] );
74 if ( $params[
'userid'] !==
null ) {
77 if ( $username ===
false ) {
78 $this->
dieWithError( [
'apierror-nosuchuserid', $params[
'userid'] ],
'nosuchuserid' );
80 $params[
'user'] = $username;
87 if (
$type === DatabaseBlock::TYPE_USER &&
90 $this->
dieWithError( [
'nosuchusershort', $params[
'user'] ],
'nosuchuser' );
94 if ( $params[
'tags'] ) {
96 if ( !$ableToTag->isOK() ) {
101 if ( $params[
'hidename'] &&
110 'PreviousTarget' => $params[
'user'],
111 'Target' => $params[
'user'],
117 'Expiry' => $params[
'expiry'],
118 'HardBlock' => !$params[
'anononly'],
119 'CreateAccount' => $params[
'nocreate'],
120 'AutoBlock' => $params[
'autoblock'],
121 'DisableEmail' => $params[
'noemail'],
122 'HideUser' => $params[
'hidename'],
123 'DisableUTEdit' => !$params[
'allowusertalk'],
124 'Reblock' => $params[
'reblock'],
125 'Watch' => $params[
'watchuser'],
127 'Tags' => $params[
'tags'],
128 'EditingRestriction' => $editingRestriction,
129 'PageRestrictions' => $pageRestrictions,
130 'NamespaceRestrictions' => $namespaceRestrictions,
139 if ( $retval !==
true ) {
145 $res[
'user'] = $params[
'user'];
147 $res[
'userID'] = $target instanceof
User ? $target->
getId() : 0;
149 $block = DatabaseBlock::newFromTarget( $target,
null,
true );
152 $res[
'id'] = $block->getId();
154 # should be unreachable
159 $res[
'reason'] = $params[
'reason'];
160 $res[
'anononly'] = $params[
'anononly'];
161 $res[
'nocreate'] = $params[
'nocreate'];
162 $res[
'autoblock'] = $params[
'autoblock'];
163 $res[
'noemail'] = $params[
'noemail'];
164 $res[
'hidename'] = $params[
'hidename'];
165 $res[
'allowusertalk'] = $params[
'allowusertalk'];
166 $res[
'watchuser'] = $params[
'watchuser'];
168 if ( $this->
getConfig()->
get(
'EnablePartialBlocks' ) ) {
169 $res[
'partial'] = $params[
'partial'];
170 $res[
'pagerestrictions'] = $params[
'pagerestrictions'];
171 $res[
'namespacerestrictions'] = $params[
'namespacerestrictions'];
197 'autoblock' =>
false,
200 'allowusertalk' =>
false,
202 'watchuser' =>
false,
209 if ( $this->
getConfig()->
get(
'EnablePartialBlocks' ) ) {
210 $params[
'partial'] =
false;
211 $params[
'pagerestrictions'] = [
216 $params[
'namespacerestrictions'] = [
232 'action=block&user=192.0.2.5&expiry=3%20days&reason=First%20strike&token=123ABC'
233 =>
'apihelp-block-example-ip-simple',
234 'action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate=&autoblock=&noemail=&token=123ABC'
235 =>
'apihelp-block-example-user-complex',
241 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:Block';
getContext()
Get the base IContextSource object.
static canBlockEmail(UserIdentity $user)
Can we do an email block?
getId()
Get the user's ID.
static checkUnblockSelf( $target, User $performer)
T17810: blocked admins should not be able to block/unblock others, and probably shouldn't be able to ...
getExamplesMessages()
Returns usage examples for this module.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
static processForm(array $data, IContextSource $context)
Given the form data, actually implement a block.
mustBePosted()
Indicates whether this module must be called with a POST request.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getResult()
Get the result object.
isWriteMode()
Indicates whether this module requires write mode.
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
const PARAM_ISMULTI_LIMIT1
(integer) Maximum number of values, for normal users.
needsToken()
Returns the token type this module requires in order to execute.
This abstract class implements many basic API functions, and is the base of all API classes.
const PARAM_ISMULTI_LIMIT2
(integer) Maximum number of values, for users with the apihighimits right.
API module that facilitates the blocking of users.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
static whoIs( $id)
Get the username corresponding to a given user ID.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
getHelpUrls()
Return links to more detailed help pages about the module.
requireOnlyOneParameter( $params, $required)
Die if none or more than one of a certain set of parameters is set and not false.
execute()
Blocks the user specified in the parameters for the given expiry, with the given reason,...
static validateTarget( $value, User $user)
Validate a block target.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
getModuleName()
Get the name of the module being executed by this instance.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
static formatExpiry( $expiry, $infinity='infinity')
Format an expiry timestamp for API output.
static getTargetAndType( $par, WebRequest $request=null)
Determine the target of the block, and the type of target.
static isUsableName( $name)
Usernames which fail to pass this function will be blocked from user login and new account registrati...
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
errorArrayToStatus(array $errors, User $user=null)
Turn an array of message keys or key+param arrays into a Status.