33 use ApiBlockInfoTrait;
49 # T17810: blocked admins should have limited access here
50 $block = $user->getBlock();
53 if ( $status !==
true ) {
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 ) {
75 $username = User::whoIs( $params[
'userid'] );
77 if ( $username ===
false ) {
78 $this->
dieWithError( [
'apierror-nosuchuserid', $params[
'userid'] ],
'nosuchuserid' );
80 $params[
'user'] = $username;
87 if (
$type === DatabaseBlock::TYPE_USER &&
88 ( $target->isAnon() || !User::isUsableName( $params[
'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,
134 if ( !$status->isOK() ) {
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 );
151 $res[
'expiry'] = ApiResult::formatExpiry( $block->getExpiry(),
'infinite' );
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';
This abstract class implements many basic API functions, and is the base of all API classes.
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_ISMULTI_LIMIT1
(integer) Maximum number of values, for normal users.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
errorArrayToStatus(array $errors, User $user=null)
Turn an array of message keys or key+param arrays into a Status.
const PARAM_ISMULTI_LIMIT2
(integer) Maximum number of values, for users with the apihighimits right.
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.
requireOnlyOneParameter( $params, $required)
Die if none or more than one of a certain set of parameters is set and not false.
const PARAM_ISMULTI
(boolean) Accept multiple pipe-separated values for this parameter (e.g.
API module that facilitates the blocking of users.
needsToken()
Returns the token type this module requires in order to execute.
getExamplesMessages()
Returns usage examples for this module.
isWriteMode()
Indicates whether this module requires write mode.
mustBePosted()
Indicates whether this module must be called with a POST request.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
execute()
Blocks the user specified in the parameters for the given expiry, with the given reason,...
getHelpUrls()
Return links to more detailed help pages about the module.
getContext()
Get the base IContextSource object.
static processForm(array $data, IContextSource $context)
Given the form data, actually implement a block.
static validateTarget( $value, User $user)
Validate a block target.
static getTargetAndType( $par, WebRequest $request=null)
Determine the target of the block, and the type of target.
static checkUnblockSelf( $target, User $performer)
T17810: blocked admins should not be able to block/unblock others, and probably shouldn't be able to ...
static canBlockEmail(UserIdentity $user)
Can we do an email block?
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getId()
Get the user's ID.