46 return User::getAllGroups();
55 $block = $pUser->getBlock();
56 if ( $block && $block->isSitewide() ) {
65 if ( isset( $params[
'expiry'] ) ) {
66 $expiry = (array)$params[
'expiry'];
68 $expiry = [
'infinity' ];
70 $add = (array)$params[
'add'];
73 } elseif ( count( $expiry ) !== count( $add ) ) {
74 if ( count( $expiry ) === 1 ) {
75 $expiry = array_fill( 0, count( $add ), $expiry[0] );
78 'apierror-toofewexpiries',
87 foreach ( $expiry as $index => $expiryValue ) {
88 $group = $add[$index];
91 if ( $groupExpiries[$group] ===
false ) {
96 if ( $groupExpiries[$group] && $groupExpiries[$group] <
wfTimestampNow() ) {
103 $tags = $params[
'tags'];
106 if ( $tags !==
null ) {
108 if ( !$ableToTag->isOK() ) {
116 $r[
'user'] = $user->getName();
117 $r[
'userid'] = $user->getId();
118 list( $r[
'added'], $r[
'removed'] ) = $form->doSaveUserGroups(
120 $user, (array)$add, (array)$params[
'remove'],
121 $params[
'reason'], (array)$tags, $groupExpiries
125 ApiResult::setIndexedTagName( $r[
'added'],
'group' );
126 ApiResult::setIndexedTagName( $r[
'removed'],
'group' );
135 if ( $this->mUser !==
null ) {
141 $user = $params[
'user'] ??
'#' . $params[
'userid'];
145 $status = $form->fetchUser( $user );
146 if ( !$status->isOK() ) {
150 $this->mUser = $status->value;
152 return $status->value;
198 unset( $a[
'expiry'] );
208 return $this->
getUrUser( $params )->getName();
213 'action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
214 =>
'apihelp-userrights-example-user',
215 'action=userrights&userid=123&add=bot&remove=sysop|bureaucrat&token=123ABC'
216 =>
'apihelp-userrights-example-userid',
219 $a[
'action=userrights&user=SometimeSysop&add=sysop&expiry=1%20month&token=123ABC']
220 =
'apihelp-userrights-example-expiry';
226 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:User_group_membership';
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfEscapeWikiText( $text)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This abstract class implements many basic API functions, and is the base of all API classes.
dieWithError( $msg, $code=null, $data=null, $httpCode=null)
Abort execution with an error.
const PARAM_TYPE
(string|string[]) Either an array of allowed value strings, or a string type as described below.
const PARAM_DFLT
(null|boolean|integer|string) Default value of the parameter.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
const PARAM_ALLOW_DUPLICATES
(boolean) Allow the same value to be set more than once when PARAM_ISMULTI is true?
getPermissionManager()
Obtain a PermissionManager instance that subclasses may use in their authorization checks.
dieBlocked(AbstractBlock $block)
Throw an ApiUsageException, which will (if uncaught) call the main module's error handler and die wit...
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.
getHelpUrls()
Return links to more detailed help pages about the module.
execute()
Evaluates the parameters, performs the requested query, and sets up the result.
mustBePosted()
Indicates whether this module must be called with a POST request.
getUserRightsPage()
Get a UserrightsPage object, or subclass.
needsToken()
Returns the token type this module requires in order to execute.
getAllGroups()
Get all available groups.
isWriteMode()
Indicates whether this module requires write mode.
getExamplesMessages()
Returns usage examples for this module.
getAllowedParams()
Returns an array of allowed parameters (parameter name) => (default value) or (parameter name) => (ar...
getWebUITokenSalt(array $params)
Fetch the salt used in the Web UI corresponding to this module.
getContext()
Get the base IContextSource object.
Special page to allow managing user group membership.
static expiryToTimestamp( $expiry)
Converts a user group membership expiry string into a timestamp.