50 # T17810: blocked admins should have limited access here
51 $block = $user->getBlock();
53 $status = SpecialBlock::checkUnblockSelf( $params[
'user'], $user );
54 if ( $status !==
true ) {
58 [
'blockinfo' => $this->getBlockDetails( $block ) ]
63 $editingRestriction = $params[
'partial'] ?
'partial' :
'sitewide';
64 $pageRestrictions = implode(
"\n", (array)$params[
'pagerestrictions'] );
65 $namespaceRestrictions = implode(
"\n", (array)$params[
'namespacerestrictions'] );
67 if ( $params[
'userid'] !==
null ) {
70 if ( $username ===
false ) {
71 $this->
dieWithError( [
'apierror-nosuchuserid', $params[
'userid'] ],
'nosuchuserid' );
73 $params[
'user'] = $username;
76 list( $target,
$type ) = SpecialBlock::getTargetAndType( $params[
'user'] );
80 if (
$type === DatabaseBlock::TYPE_USER &&
83 $this->
dieWithError( [
'nosuchusershort', $params[
'user'] ],
'nosuchuser' );
87 if ( $params[
'tags'] ) {
89 if ( !$ableToTag->isOK() ) {
94 if ( $params[
'hidename'] &&
98 if ( $params[
'noemail'] && !SpecialBlock::canBlockEmail( $user ) ) {
103 'PreviousTarget' => $params[
'user'],
104 'Target' => $params[
'user'],
110 'Expiry' => $params[
'expiry'],
111 'HardBlock' => !$params[
'anononly'],
112 'CreateAccount' => $params[
'nocreate'],
113 'AutoBlock' => $params[
'autoblock'],
114 'DisableEmail' => $params[
'noemail'],
115 'HideUser' => $params[
'hidename'],
116 'DisableUTEdit' => !$params[
'allowusertalk'],
117 'Reblock' => $params[
'reblock'],
118 'Watch' => $params[
'watchuser'],
120 'Tags' => $params[
'tags'],
121 'EditingRestriction' => $editingRestriction,
122 'PageRestrictions' => $pageRestrictions,
123 'NamespaceRestrictions' => $namespaceRestrictions,
126 $status = SpecialBlock::validateTarget( $params[
'user'], $user );
127 if ( !$status->isOK() ) {
131 $retval = SpecialBlock::processForm( $data, $this->
getContext() );
132 if ( $retval !==
true ) {
138 $res[
'user'] = $params[
'user'];
139 list( $target, ) = SpecialBlock::getTargetAndType( $params[
'user'] );
140 $res[
'userID'] = $target instanceof
User ? $target->
getId() : 0;
142 $block = DatabaseBlock::newFromTarget( $target,
null,
true );
144 $res[
'expiry'] = ApiResult::formatExpiry( $block->getExpiry(),
'infinite' );
145 $res[
'id'] = $block->getId();
147 # should be unreachable
152 $res[
'reason'] = $params[
'reason'];
153 $res[
'anononly'] = $params[
'anononly'];
154 $res[
'nocreate'] = $params[
'nocreate'];
155 $res[
'autoblock'] = $params[
'autoblock'];
156 $res[
'noemail'] = $params[
'noemail'];
157 $res[
'hidename'] = $params[
'hidename'];
158 $res[
'allowusertalk'] = $params[
'allowusertalk'];
159 $res[
'watchuser'] = $params[
'watchuser'];
160 $res[
'partial'] = $params[
'partial'];
161 $res[
'pagerestrictions'] = $params[
'pagerestrictions'];
162 $res[
'namespacerestrictions'] = $params[
'namespacerestrictions'];
179 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'ip',
'cidr',
'id' ],
189 'autoblock' =>
false,
192 'allowusertalk' =>
false,
194 'watchuser' =>
false,
200 'pagerestrictions' => [
205 'namespacerestrictions' => [
219 'action=block&user=192.0.2.5&expiry=3%20days&reason=First%20strike&token=123ABC'
220 =>
'apihelp-block-example-ip-simple',
221 'action=block&user=Vandal&expiry=never&reason=Vandalism&nocreate=&autoblock=&noemail=&token=123ABC'
222 =>
'apihelp-block-example-user-complex',
228 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.
dieWithError( $msg, $code=null, $data=null, $httpCode=0)
Abort execution with an error.
checkUserRightsAny( $rights, $user=null)
Helper function for permission-denied errors.
const PARAM_ISMULTI_LIMIT1
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.
requireOnlyOneParameter( $params,... $required)
Die if none or more than one of a certain set of parameters is set and not false.
const PARAM_ISMULTI_LIMIT2
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.
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 Stable to override.
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.
getUser()
Stable to override.
getContext()
Get the base IContextSource object.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
getId()
Get the user's ID.
static isUsableName( $name)
Usernames which fail to pass this function will be blocked from user login and new account registrati...
static whoIs( $id)
Get the username corresponding to a given user ID.