36 private $mUser =
null;
39 private $userGroupManager;
51 parent::__construct( $mainModule, $moduleName );
52 $this->userGroupManager = $userGroupManager;
60 if ( !$this->
getAuthority()->isAllowed(
'userrights' ) ) {
61 $block = $pUser->getBlock( Authority::READ_LATEST );
62 if ( $block && $block->isSitewide() ) {
71 if ( isset( $params[
'expiry'] ) ) {
72 $expiry = (array)$params[
'expiry'];
74 $expiry = [
'infinity' ];
76 $add = (array)$params[
'add'];
79 } elseif ( count( $expiry ) !== count( $add ) ) {
80 if ( count( $expiry ) === 1 ) {
81 $expiry = array_fill( 0, count( $add ), $expiry[0] );
84 'apierror-toofewexpiries',
93 foreach ( $expiry as $index => $expiryValue ) {
94 $group = $add[$index];
97 if ( $groupExpiries[$group] ===
false ) {
102 if ( $groupExpiries[$group] && $groupExpiries[$group] <
wfTimestampNow() ) {
107 $user = $this->getUrUser( $params );
109 $tags = $params[
'tags'];
112 if ( $tags !==
null ) {
114 if ( !$ableToTag->isOK() ) {
122 $r[
'user'] = $user->getName();
123 $r[
'userid'] = $user->getId();
124 list( $r[
'added'], $r[
'removed'] ) = $form->doSaveUserGroups(
126 $user, $add, (array)$params[
'remove'],
127 $params[
'reason'], (array)$tags, $groupExpiries
131 ApiResult::setIndexedTagName( $r[
'added'],
'group' );
132 ApiResult::setIndexedTagName( $r[
'removed'],
'group' );
140 private function getUrUser( array $params ) {
141 if ( $this->mUser !==
null ) {
147 $user = $params[
'user'] ??
'#' . $params[
'userid'];
151 $status = $form->fetchUser( $user );
152 if ( !$status->isOK() ) {
156 $this->mUser = $status->value;
158 return $status->value;
170 $allGroups = $this->userGroupManager->listAllGroups();
178 ParamValidator::PARAM_TYPE =>
'user',
179 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'id' ],
182 ParamValidator::PARAM_TYPE =>
'integer',
183 ParamValidator::PARAM_DEPRECATED =>
true,
186 ParamValidator::PARAM_TYPE => $allGroups,
187 ParamValidator::PARAM_ISMULTI =>
true
190 ParamValidator::PARAM_ISMULTI =>
true,
191 ParamValidator::PARAM_ALLOW_DUPLICATES =>
true,
192 ParamValidator::PARAM_DEFAULT =>
'infinite',
195 ParamValidator::PARAM_TYPE => $allGroups,
196 ParamValidator::PARAM_ISMULTI =>
true
199 ParamValidator::PARAM_DEFAULT =>
''
206 ParamValidator::PARAM_TYPE =>
'tags',
207 ParamValidator::PARAM_ISMULTI =>
true
217 return $this->getUrUser( $params )->getName();
222 'action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
223 =>
'apihelp-userrights-example-user',
224 'action=userrights&userid=123&add=bot&remove=sysop|bureaucrat&token=123ABC'
225 =>
'apihelp-userrights-example-userid',
226 'action=userrights&user=SometimeSysop&add=sysop&expiry=1%20month&token=123ABC'
227 =>
'apihelp-userrights-example-expiry',
232 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=0)
Abort execution with an error.
const PARAM_HELP_MSG_APPEND
((string|array|Message)[]) Specify additional i18n messages to append to the normal message for this ...
requireOnlyOneParameter( $params,... $required)
Die if none or more than one of a certain set of parameters is set and not false.
getResult()
Get the result object.
extractRequestParams( $options=[])
Using getAllowedParams(), this function makes an array of the values provided by the user,...
const GET_VALUES_FOR_HELP
getAllowedParams() flag: When set, the result could take longer to generate, but should be more thoro...
getModuleName()
Get the name of the module being executed by this instance.
dieStatus(StatusValue $status)
Throw an ApiUsageException based on the Status object.
dieBlocked(Block $block)
Throw an ApiUsageException, which will (if uncaught) call the main module's error handler and die wit...
This is the main API class, used for both external and internal processing.
getHelpUrls()
Return links to more detailed help pages about the module.
getAllowedParams( $flags=0)
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.
needsToken()
Returns the token type this module requires in order to execute.
isWriteMode()
Indicates whether this module requires write mode.
__construct(ApiMain $mainModule, $moduleName, UserGroupManager $userGroupManager)
getExamplesMessages()
Returns usage examples for this module.
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.