38 private $mUser =
null;
50 parent::__construct( $mainModule, $moduleName );
51 $this->watchedItemStore = $watchedItemStore;
55 $this->watchlistMaxDuration =
57 $this->watchlistManager = $watchlistManager;
58 $this->userOptionsLookup = $userOptionsLookup;
66 if ( !$this->
getAuthority()->isAllowed(
'userrights' ) ) {
67 $block = $pUser->getBlock( IDBAccessObject::READ_LATEST );
68 if ( $block && $block->isSitewide() ) {
76 $expiry = (array)$params[
'expiry'];
77 $add = (array)$params[
'add'];
80 } elseif ( count( $expiry ) !== count( $add ) ) {
81 if ( count( $expiry ) === 1 ) {
82 $expiry = array_fill( 0, count( $add ), $expiry[0] );
85 'apierror-toofewexpiries',
94 foreach ( $expiry as $index => $expiryValue ) {
95 $group = $add[$index];
96 $groupExpiries[$group] = UserGroupAssignmentService::expiryToTimestamp( $expiryValue );
98 if ( $groupExpiries[$group] ===
false ) {
103 if ( $groupExpiries[$group] && $groupExpiries[$group] <
wfTimestampNow() ) {
108 $user = $this->getUrUser( $params );
110 $tags = $params[
'tags'];
113 if ( $tags !==
null ) {
114 $ableToTag = ChangeTags::canAddTagsAccompanyingChange( $tags, $this->
getAuthority() );
115 if ( !$ableToTag->isOK() ) {
121 $r[
'user'] = $user->getName();
122 $r[
'userid'] = $user->getId( $user->getWikiId() );
123 [ $r[
'added'], $r[
'removed'] ] = $this->userGroupAssignmentService->saveChangesToUserGroups(
128 (array)$params[
'remove'],
136 $watchuser = $params[
'watchuser'];
137 if ( $watchuser && $user->getWikiId() === UserIdentity::LOCAL ) {
138 $this->
setWatch(
'watch', $userPage, $this->
getUser(),
null, $watchlistExpiry );
141 $watchlistExpiry =
null;
143 $r[
'watchuser'] = $watchuser;
144 if ( $watchlistExpiry !==
null ) {
146 $this->watchedItemStore,
162 private function getUrUser( array $params ) {
163 if ( $this->mUser !==
null ) {
169 $userDesignator = $params[
'user'] ??
'#' . $params[
'userid'];
174 if ( isset( $params[
'user'] ) ) {
176 if ( str_contains( $userDesignator, $interwikiDelimiter ) ) {
177 $targetParts = explode( $interwikiDelimiter, $userDesignator );
178 $remoteWikiId = $targetParts[1] ??
'';
180 $remoteWikiId !==
'' &&
181 !WikiMap::isCurrentWikiId( $remoteWikiId ) &&
182 !$this->
getAuthority()->isAllowed(
'userrights-interwiki' )
184 $this->
dieWithError(
'apierror-permissiondenied-userrights-interwiki',
'permissiondenied' );
189 $status = $this->multiFormatUserIdentityLookup->getUserIdentity( $userDesignator, $this->
getAuthority() );
190 if ( !$status->isOK() ) {
194 $user = $status->value;
195 $canHaveRights = $this->userGroupAssignmentService->targetCanHaveUserGroups( $user );
196 if ( !$canHaveRights ) {
199 $user->isRegistered() ? [
'userrights-no-group', $user->getName() ] :
'nosuchusershort'
203 $this->mUser = $user;
220 $allGroups = $this->userGroupManager->listAllGroups();
228 ParamValidator::PARAM_TYPE =>
'user',
229 UserDef::PARAM_ALLOWED_USER_TYPES => [
'name',
'id' ],
232 ParamValidator::PARAM_TYPE =>
'integer',
233 ParamValidator::PARAM_DEPRECATED =>
true,
236 ParamValidator::PARAM_TYPE => $allGroups,
237 ParamValidator::PARAM_ISMULTI => true
240 ParamValidator::PARAM_ISMULTI =>
true,
241 ParamValidator::PARAM_ALLOW_DUPLICATES =>
true,
242 ParamValidator::PARAM_DEFAULT =>
'infinite',
245 ParamValidator::PARAM_TYPE => $allGroups,
246 ParamValidator::PARAM_ISMULTI => true
249 ParamValidator::PARAM_DEFAULT =>
''
256 ParamValidator::PARAM_TYPE =>
'tags',
257 ParamValidator::PARAM_ISMULTI => true
259 'watchuser' =>
false,
265 if ( $this->watchlistExpiryEnabled ) {
267 'watchlistexpiry' => [
268 ParamValidator::PARAM_TYPE =>
'expiry',
269 ExpiryDef::PARAM_MAX => $this->watchlistMaxDuration,
270 ExpiryDef::PARAM_USE_MAX =>
true,
285 return $this->getUrUser( $params )->getName();
291 'action=userrights&user=FooBot&add=bot&remove=sysop|bureaucrat&token=123ABC'
292 =>
'apihelp-userrights-example-user',
293 'action=userrights&userid=123&add=bot&remove=sysop|bureaucrat&token=123ABC'
294 =>
'apihelp-userrights-example-userid',
295 'action=userrights&user=SometimeSysop&add=sysop&expiry=1%20month&token=123ABC'
296 =>
'apihelp-userrights-example-expiry',
302 return 'https://www.mediawiki.org/wiki/Special:MyLanguage/API:User_group_membership';
307class_alias( ApiUserrights::class,
'ApiUserrights' );
wfTimestampNow()
Convenience function; returns MediaWiki timestamp for the present time.
wfEscapeWikiText( $input)
Escapes the given text so that it may be output using addWikiText() without any linking,...
This is the main API class, used for both external and internal processing.
A class containing constants representing the names of configuration variables.
const WatchlistExpiry
Name constant for the WatchlistExpiry setting, for use with Config::get()
const UserrightsInterwikiDelimiter
Name constant for the UserrightsInterwikiDelimiter setting, for use with Config::get()
const WatchlistExpiryMaxDuration
Name constant for the WatchlistExpiryMaxDuration setting, for use with Config::get()
trait ApiWatchlistTrait
An ApiWatchlistTrait adds class properties and convenience methods for APIs that allow you to watch a...