Debian Codegraph @

includes/specials/SpecialUserRights.php

raw symbols SCIP
1 <?php
2 /**
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 * http://www.gnu.org/copyleft/gpl.html
17 *
18 * @file
19 */
20
21 namespace MediaWiki\Specials;
22
23 use LogEventsList;
24 use LogPage;
25 use ManualLogEntry;
26 use MediaWiki\CommentStore\CommentStore;
27 use MediaWiki\Html\Html;
28 use MediaWiki\HTMLForm\Field\HTMLUserTextField;
29 use MediaWiki\HTMLForm\HTMLForm;
30 use MediaWiki\Linker\Linker;
31 use MediaWiki\MainConfigNames;
32 use MediaWiki\MediaWikiServices;
33 use MediaWiki\Output\OutputPage;
34 use MediaWiki\SpecialPage\SpecialPage;
35 use MediaWiki\Status\Status;
36 use MediaWiki\Title\Title;
37 use MediaWiki\User\ActorStoreFactory;
38 use MediaWiki\User\TempUser\TempUserConfig;
39 use MediaWiki\User\UserFactory;
40 use MediaWiki\User\UserGroupManager;
41 use MediaWiki\User\UserGroupManagerFactory;
42 use MediaWiki\User\UserGroupMembership;
43 use MediaWiki\User\UserIdentity;
44 use MediaWiki\User\UserNamePrefixSearch;
45 use MediaWiki\User\UserNameUtils;
46 use MediaWiki\Watchlist\WatchlistManager;
47 use MediaWiki\WikiMap\WikiMap;
48 use MediaWiki\Xml\Xml;
49 use MediaWiki\Xml\XmlSelect;
50 use PermissionsError;
51 use UserBlockedError;
52 use Wikimedia\Rdbms\IDBAccessObject;
53
54 /**
55 * Special page to allow managing user group membership
56 *
57 * @ingroup SpecialPage
58 */
59 class SpecialUserRights extends SpecialPage {
60 /**
61 * The target of the local right-adjuster's interest. Can be gotten from
62 * either a GET parameter or a subpage-style parameter, so have a member
63 * variable for it.
64 * @var null|string
65 */
66 protected $mTarget;
67 /**
68 * @var null|UserIdentity The user object of the target username or null.
69 */
70 protected $mFetchedUser = null;
71 /** @var bool */
72 protected $isself = false;
73
74 private UserGroupManagerFactory $userGroupManagerFactory;
75
76 /** @var UserGroupManager|null The UserGroupManager of the target username or null */
77 private $userGroupManager = null;
78
79 private UserNameUtils $userNameUtils;
80 private UserNamePrefixSearch $userNamePrefixSearch;
81 private UserFactory $userFactory;
82 private ActorStoreFactory $actorStoreFactory;
83 private WatchlistManager $watchlistManager;
84 private TempUserConfig $tempUserConfig;
85
86 /**
87 * @param UserGroupManagerFactory|null $userGroupManagerFactory
88 * @param UserNameUtils|null $userNameUtils
89 * @param UserNamePrefixSearch|null $userNamePrefixSearch
90 * @param UserFactory|null $userFactory
91 * @param ActorStoreFactory|null $actorStoreFactory
92 * @param WatchlistManager|null $watchlistManager
93 * @param TempUserConfig|null $tempUserConfig
94 */
95 public function __construct(
96 ?UserGroupManagerFactory $userGroupManagerFactory = null,
97 ?UserNameUtils $userNameUtils = null,
98 ?UserNamePrefixSearch $userNamePrefixSearch = null,
99 ?UserFactory $userFactory = null,
100 ?ActorStoreFactory $actorStoreFactory = null,
101 ?WatchlistManager $watchlistManager = null,
102 ?TempUserConfig $tempUserConfig = null
103 ) {
104 parent::__construct( 'Userrights' );
105 $services = MediaWikiServices::getInstance();
106 // This class is extended and therefore falls back to global state - T263207
107 $this->userNameUtils = $userNameUtils ?? $services->getUserNameUtils();
108 $this->userNamePrefixSearch = $userNamePrefixSearch ?? $services->getUserNamePrefixSearch();
109 $this->userFactory = $userFactory ?? $services->getUserFactory();
110 $this->userGroupManagerFactory = $userGroupManagerFactory ?? $services->getUserGroupManagerFactory();
111 $this->actorStoreFactory = $actorStoreFactory ?? $services->getActorStoreFactory();
112 $this->watchlistManager = $watchlistManager ?? $services->getWatchlistManager();
113 $this->tempUserConfig = $tempUserConfig ?? $services->getTempUserConfig();
114 }
115
116 public function doesWrites() {
117 return true;
118 }
119
120 /**
121 * Check whether the current user (from context) can change the target user's rights.
122 *
123 * This function can be used without submitting the special page
124 *
125 * @param UserIdentity $targetUser User whose rights are being changed
126 * @param bool $checkIfSelf If false, assume that the current user can add/remove groups defined
127 * in $wgGroupsAddToSelf / $wgGroupsRemoveFromSelf, without checking if it's the same as target
128 * user
129 * @return bool
130 */
131 public function userCanChangeRights( UserIdentity $targetUser, $checkIfSelf = true ) {
132 if (
133 !$targetUser->isRegistered() ||
134 $this->userNameUtils->isTemp( $targetUser->getName() )
135 ) {
136 return false;
137 }
138
139 $userGroupManager = $this->userGroupManagerFactory
140 ->getUserGroupManager( $targetUser->getWikiId() );
141 $available = $userGroupManager->getGroupsChangeableBy( $this->getAuthority() );
142 if ( $available['add'] || $available['remove'] ) {
143 // can change some rights for any user
144 return true;
145 }
146
147 $isself = $this->getUser()->equals( $targetUser );
148 if ( ( $available['add-self'] || $available['remove-self'] )
149 && ( $isself || !$checkIfSelf )
150 ) {
151 // can change some rights for self
152 return true;
153 }
154
155 return false;
156 }
157
158 /**
159 * Manage forms to be shown according to posted data.
160 * Depending on the submit button used, call a form or a save function.
161 *
162 * @param string|null $par String if any subpage provided, else null
163 * @throws UserBlockedError|PermissionsError
164 */
165 public function execute( $par ) {
166 $user = $this->getUser();
167 $request = $this->getRequest();
168 $session = $request->getSession();
169 $out = $this->getOutput();
170
171 $out->addModules( [ 'mediawiki.special.userrights' ] );
172
173 $this->mTarget = $par ?? $request->getVal( 'user' );
174 if ( $this->mTarget === null ) {
175 $fetchedStatus = Status::newFatal( 'nouserspecified' );
176
177 } else {
178 $this->mTarget = trim( $this->mTarget );
179
180 if ( $this->userNameUtils->getCanonical( $this->mTarget ) === $user->getName() ) {
181 $this->isself = true;
182 }
183
184 $fetchedStatus = $this->fetchUser( $this->mTarget, true );
185 }
186
187 if ( $fetchedStatus->isOK() ) {
188 $this->mFetchedUser = $fetchedUser = $fetchedStatus->value;
189 // Phan false positive on Status object - T323205
190 '@phan-var UserIdentity $fetchedUser';
191 $wikiId = $fetchedUser->getWikiId();
192 if ( $wikiId === UserIdentity::LOCAL ) {
193 // Set the 'relevant user' in the skin, so it displays links like Contributions,
194 // User logs, UserRights, etc.
195 $this->getSkin()->setRelevantUser( $this->mFetchedUser );
196 }
197 $this->userGroupManager = $this->userGroupManagerFactory
198 ->getUserGroupManager( $wikiId );
199 }
200
201 // show a successbox, if the user rights was saved successfully
202 if (
203 $session->get( 'specialUserrightsSaveSuccess' ) &&
204 $this->mFetchedUser !== null
205 ) {
206 // Remove session data for the success message
207 $session->remove( 'specialUserrightsSaveSuccess' );
208
209 $out->addModuleStyles( 'mediawiki.notification.convertmessagebox.styles' );
210 $out->addHTML(
211 Html::successBox(
212 Html::element(
213 'p',
214 [],
215 $this->msg( 'savedrights', $this->getDisplayUsername( $this->mFetchedUser ) )->text()
216 ),
217 'mw-notify-success'
218 )
219 );
220 }
221
222 $this->setHeaders();
223 $this->outputHeader();
224
225 $out->addModuleStyles( 'mediawiki.special' );
226 $this->addHelpLink( 'Help:Assigning permissions' );
227
228 $this->switchForm();
229
230 if ( $this->mTarget !== null && !$this->getAuthority()->isAllowed( 'userrights-interwiki' ) ) {
231 $isRedirected = $this->redirectIfRemoteWikiForView( $this->mTarget );
232 if ( $isRedirected ) {
233 return;
234 }
235 }
236
237 if (
238 $request->wasPosted() &&
239 $request->getCheck( 'saveusergroups' ) &&
240 $this->mTarget !== null &&
241 $user->matchEditToken( $request->getVal( 'wpEditToken' ), $this->mTarget )
242 ) {
243 /*
244 * If the user is blocked and they only have "partial" access
245 * (e.g. they don't have the userrights permission), then don't
246 * allow them to change any user rights.
247 */
248 if ( !$this->getAuthority()->isAllowed( 'userrights' ) ) {
249 $block = $user->getBlock();
250 if ( $block && $block->isSitewide() ) {
251 throw new UserBlockedError(
252 $block,
253 $user,
254 $this->getLanguage(),
255 $request->getIP()
256 );
257 }
258 }
259
260 $this->checkReadOnly();
261
262 // save settings
263 if ( !$fetchedStatus->isOK() ) {
264 $this->getOutput()->addWikiTextAsInterface(
265 $fetchedStatus->getWikiText( false, false, $this->getLanguage() )
266 );
267
268 return;
269 }
270
271 $targetUser = $this->mFetchedUser;
272 $conflictCheck = $request->getVal( 'conflictcheck-originalgroups' );
273 $conflictCheck = ( $conflictCheck === '' ) ? [] : explode( ',', $conflictCheck );
274 $userGroups = $this->userGroupManager->getUserGroups( $targetUser, IDBAccessObject::READ_LATEST );
275
276 if ( $userGroups !== $conflictCheck ) {
277 $out->addHTML( Html::errorBox(
278 $this->msg( 'userrights-conflict' )->parse()
279 ) );
280 } else {
281 $status = $this->saveUserGroups(
282 $request->getText( 'user-reason' ),
283 $targetUser
284 );
285
286 if ( $status->isOK() ) {
287 // Set session data for the success message
288 $session->set( 'specialUserrightsSaveSuccess', 1 );
289
290 $out->redirect( $this->getSuccessURL() );
291 return;
292 } else {
293 // Print an error message and redisplay the form
294 $out->wrapWikiTextAsInterface(
295 'error', $status->getWikiText( false, false, $this->getLanguage() )
296 );
297 }
298 }
299 }
300
301 // show some more forms
302 if ( $this->mTarget !== null ) {
303 $this->editUserGroupsForm( $this->mTarget );
304 }
305 }
306
307 /**
308 * If the special page is used for an interwiki user and the performer
309 * has no userrights-interwiki permission, redirect them to the remote wiki,
310 * instead of displaying the groups.
311 *
312 * This helps with appropriate listing of implicit groups and ensures that
313 * the performer has read access to the remote wiki.
314 *
315 * Returns a boolean value, indicating whether the redirect occurred.
316 */
317 private function redirectIfRemoteWikiForView( string $target ): bool {
318 $interwikiDelimiter = $this->getConfig()->get( MainConfigNames::UserrightsInterwikiDelimiter );
319 if ( !str_contains( $target, $interwikiDelimiter ) ) {
320 return false;
321 }
322
323 $targetParts = explode( $interwikiDelimiter, $target );
324 [ $user, $remoteWikiId ] = $targetParts;
325
326 if ( WikiMap::isCurrentWikiId( $remoteWikiId ) ) {
327 // No need for redirect
328 return false;
329 }
330
331 $remoteWiki = WikiMap::getWiki( $remoteWikiId );
332 if ( !$remoteWiki ) {
333 // Nowhere to redirect to
334 return false;
335 }
336
337 $remoteUrl = $remoteWiki->getUrl( 'Special:UserRights' );
338 $remoteUrl = wfAppendQuery( $remoteUrl, [ 'user' => $user ] );
339 $this->getOutput()->redirect( $remoteUrl );
340 return true;
341 }
342
343 private function getSuccessURL() {
344 return $this->getPageTitle( $this->mTarget )->getFullURL();
345 }
346
347 /**
348 * Returns true if this user rights form can set and change user group expiries.
349 * Subclasses may wish to override this to return false.
350 *
351 * @return bool
352 */
353 public function canProcessExpiries() {
354 return true;
355 }
356
357 /**
358 * Converts a user group membership expiry string into a timestamp. Words like
359 * 'existing' or 'other' should have been filtered out before calling this
360 * function.
361 *
362 * @param string $expiry
363 * @return string|null|false A string containing a valid timestamp, or null
364 * if the expiry is infinite, or false if the timestamp is not valid
365 */
366 public static function expiryToTimestamp( $expiry ) {
367 if ( wfIsInfinity( $expiry ) ) {
368 return null;
369 }
370
371 $unix = strtotime( $expiry );
372
373 if ( !$unix || $unix === -1 ) {
374 return false;
375 }
376
377 // @todo FIXME: Non-qualified absolute times are not in users specified timezone
378 // and there isn't notice about it in the ui (see ProtectionForm::getExpiry)
379 return wfTimestamp( TS_MW, $unix );
380 }
381
382 /**
383 * Save user groups changes in the database.
384 * Data comes from the editUserGroupsForm() form function
385 *
386 * @param string $reason Reason for group change
387 * @param UserIdentity $user
388 * @return Status
389 */
390 protected function saveUserGroups( string $reason, UserIdentity $user ) {
391 if ( $this->userNameUtils->isTemp( $user->getName() ) ) {
392 return Status::newFatal( 'userrights-no-tempuser' );
393 }
394
395 // Prevent cross-wiki assignment of groups to temporary accounts on wikis where the feature is not known.
396 if (
397 $user->getWikiId() !== UserIdentity::LOCAL &&
398 !$this->tempUserConfig->isKnown() &&
399 $this->tempUserConfig->isReservedName( $user->getName() )
400 ) {
401 return Status::newFatal( 'userrights-cross-wiki-assignment-for-reserved-name' );
402 }
403
404 $allgroups = $this->userGroupManager->listAllGroups();
405 $addgroup = [];
406 $groupExpiries = []; // associative array of (group name => expiry)
407 $removegroup = [];
408 $existingUGMs = $this->userGroupManager->getUserGroupMemberships( $user );
409
410 // This could possibly create a highly unlikely race condition if permissions are changed between
411 // when the form is loaded and when the form is saved. Ignoring it for the moment.
412 foreach ( $allgroups as $group ) {
413 // We'll tell it to remove all unchecked groups, and add all checked groups.
414 // Later on, this gets filtered for what can actually be removed
415 if ( $this->getRequest()->getCheck( "wpGroup-$group" ) ) {
416 $addgroup[] = $group;
417
418 if ( $this->canProcessExpiries() ) {
419 // read the expiry information from the request
420 $expiryDropdown = $this->getRequest()->getVal( "wpExpiry-$group" );
421 if ( $expiryDropdown === 'existing' ) {
422 continue;
423 }
424
425 if ( $expiryDropdown === 'other' ) {
426 $expiryValue = $this->getRequest()->getVal( "wpExpiry-$group-other" );
427 } else {
428 $expiryValue = $expiryDropdown;
429 }
430
431 // validate the expiry
432 $groupExpiries[$group] = self::expiryToTimestamp( $expiryValue );
433
434 if ( $groupExpiries[$group] === false ) {
435 return Status::newFatal( 'userrights-invalid-expiry', $group );
436 }
437
438 // not allowed to have things expiring in the past
439 if ( $groupExpiries[$group] && $groupExpiries[$group] < wfTimestampNow() ) {
440 return Status::newFatal( 'userrights-expiry-in-past', $group );
441 }
442
443 // if the user can only add this group (not remove it), the expiry time
444 // cannot be brought forward (T156784)
445 if ( !$this->canRemove( $group ) &&
446 isset( $existingUGMs[$group] ) &&
447 ( $existingUGMs[$group]->getExpiry() ?: 'infinity' ) >
448 ( $groupExpiries[$group] ?: 'infinity' )
449 ) {
450 return Status::newFatal( 'userrights-cannot-shorten-expiry', $group );
451 }
452 }
453 } else {
454 $removegroup[] = $group;
455 }
456 }
457
458 $this->doSaveUserGroups( $user, $addgroup, $removegroup, $reason, [], $groupExpiries );
459
460 if ( $user->getWikiId() === UserIdentity::LOCAL && $this->getRequest()->getCheck( 'wpWatch' ) ) {
461 $this->watchlistManager->addWatchIgnoringRights(
462 $this->getUser(),
463 Title::makeTitle( NS_USER, $user->getName() )
464 );
465 }
466
467 return Status::newGood();
468 }
469
470 /**
471 * Save user groups changes in the database. This function does not throw errors;
472 * instead, it ignores groups that the performer does not have permission to set.
473 *
474 * This function can be used without submitting the special page
475 *
476 * @param UserIdentity $user
477 * @param string[] $add Array of groups to add
478 * @param string[] $remove Array of groups to remove
479 * @param string $reason Reason for group change
480 * @param string[] $tags Array of change tags to add to the log entry
481 * @param array<string,?string> $groupExpiries Associative array of (group name => expiry),
482 * containing only those groups that are to have new expiry values set
483 * @return array Tuple of added, then removed groups
484 */
485 public function doSaveUserGroups( $user, array $add, array $remove, string $reason = '',
486 array $tags = [], array $groupExpiries = []
487 ) {
488 // Validate input set...
489 $isself = $user->getName() == $this->getUser()->getName();
490 if ( $this->userGroupManager !== null ) {
491 // Used after form submit
492 $userGroupManager = $this->userGroupManager;
493 } else {
494 // Used as backend-function
495 $userGroupManager = $this->userGroupManagerFactory
496 ->getUserGroupManager( $user->getWikiId() );
497 }
498 $groups = $userGroupManager->getUserGroups( $user );
499 $ugms = $userGroupManager->getUserGroupMemberships( $user );
500 $changeable = $userGroupManager->getGroupsChangeableBy( $this->getAuthority() );
501 $addable = array_merge( $changeable['add'], $isself ? $changeable['add-self'] : [] );
502 $removable = array_merge( $changeable['remove'], $isself ? $changeable['remove-self'] : [] );
503
504 $remove = array_unique( array_intersect( $remove, $removable, $groups ) );
505 $add = array_intersect( $add, $addable );
506
507 // add only groups that are not already present or that need their expiry updated,
508 // UNLESS the user can only add this group (not remove it) and the expiry time
509 // is being brought forward (T156784)
510 $add = array_filter( $add,
511 static function ( $group ) use ( $groups, $groupExpiries, $removable, $ugms ) {
512 if ( isset( $groupExpiries[$group] ) &&
513 !in_array( $group, $removable ) &&
514 isset( $ugms[$group] ) &&
515 ( $ugms[$group]->getExpiry() ?: 'infinity' ) >
516 ( $groupExpiries[$group] ?: 'infinity' )
517 ) {
518 return false;
519 }
520 return !in_array( $group, $groups ) || array_key_exists( $group, $groupExpiries );
521 } );
522
523 if ( $user->getWikiId() === UserIdentity::LOCAL ) {
524 // For compatibility local changes are provided as User object to the hook
525 $hookUser = $this->userFactory->newFromUserIdentity( $user );
526 } else {
527 // Interwiki changes are provided as UserIdentity since 1.41, was UserRightsProxy before
528 $hookUser = $user;
529 }
530 $this->getHookRunner()->onChangeUserGroups( $this->getUser(), $hookUser, $add, $remove );
531
532 $oldGroups = $groups;
533 $oldUGMs = $userGroupManager->getUserGroupMemberships( $user );
534 $newGroups = $oldGroups;
535
536 // Remove groups, then add new ones/update expiries of existing ones
537 if ( $remove ) {
538 foreach ( $remove as $index => $group ) {
539 if ( !$userGroupManager->removeUserFromGroup( $user, $group ) ) {
540 unset( $remove[$index] );
541 }
542 }
543 $newGroups = array_diff( $newGroups, $remove );
544 }
545 if ( $add ) {
546 foreach ( $add as $index => $group ) {
547 $expiry = $groupExpiries[$group] ?? null;
548 if ( !$userGroupManager->addUserToGroup( $user, $group, $expiry, true ) ) {
549 unset( $add[$index] );
550 }
551 }
552 $newGroups = array_merge( $newGroups, $add );
553 }
554 $newGroups = array_unique( $newGroups );
555 $newUGMs = $userGroupManager->getUserGroupMemberships( $user );
556
557 // Ensure that caches are cleared
558 $this->userFactory->invalidateCache( $user );
559
560 // update groups in external authentication database
561 $this->getHookRunner()->onUserGroupsChanged( $hookUser, $add, $remove,
562 $this->getUser(), $reason, $oldUGMs, $newUGMs );
563
564 wfDebug( 'oldGroups: ' . print_r( $oldGroups, true ) );
565 wfDebug( 'newGroups: ' . print_r( $newGroups, true ) );
566 wfDebug( 'oldUGMs: ' . print_r( $oldUGMs, true ) );
567 wfDebug( 'newUGMs: ' . print_r( $newUGMs, true ) );
568
569 // Only add a log entry if something actually changed
570 if ( $newGroups != $oldGroups || $newUGMs != $oldUGMs ) {
571 $this->addLogEntry( $user, $oldGroups, $newGroups, $reason, $tags, $oldUGMs, $newUGMs );
572 }
573
574 return [ $add, $remove ];
575 }
576
577 /**
578 * Serialise a UserGroupMembership object for storage in the log_params section
579 * of the logging table. Only keeps essential data, removing redundant fields.
580 *
581 * @param UserGroupMembership|null $ugm May be null if things get borked
582 * @return array|null
583 */
584 protected static function serialiseUgmForLog( $ugm ) {
585 if ( !$ugm instanceof UserGroupMembership ) {
586 return null;
587 }
588 return [ 'expiry' => $ugm->getExpiry() ];
589 }
590
591 /**
592 * Add a rights log entry for an action.
593 * @param UserIdentity $user
594 * @param array $oldGroups
595 * @param array $newGroups
596 * @param string $reason
597 * @param string[] $tags Change tags for the log entry
598 * @param array $oldUGMs Associative array of (group name => UserGroupMembership)
599 * @param array $newUGMs Associative array of (group name => UserGroupMembership)
600 */
601 protected function addLogEntry( $user, array $oldGroups, array $newGroups, string $reason,
602 array $tags, array $oldUGMs, array $newUGMs
603 ) {
604 // make sure $oldUGMs and $newUGMs are in the same order, and serialise
605 // each UGM object to a simplified array
606 $oldUGMs = array_map( static function ( $group ) use ( $oldUGMs ) {
607 return isset( $oldUGMs[$group] ) ?
608 self::serialiseUgmForLog( $oldUGMs[$group] ) :
609 null;
610 }, $oldGroups );
611 $newUGMs = array_map( static function ( $group ) use ( $newUGMs ) {
612 return isset( $newUGMs[$group] ) ?
613 self::serialiseUgmForLog( $newUGMs[$group] ) :
614 null;
615 }, $newGroups );
616
617 $logEntry = new ManualLogEntry( 'rights', 'rights' );
618 $logEntry->setPerformer( $this->getUser() );
619 $logEntry->setTarget( Title::makeTitle( NS_USER, $this->getDisplayUsername( $user ) ) );
620 $logEntry->setComment( $reason );
621 $logEntry->setParameters( [
622 '4::oldgroups' => $oldGroups,
623 '5::newgroups' => $newGroups,
624 'oldmetadata' => $oldUGMs,
625 'newmetadata' => $newUGMs,
626 ] );
627 $logid = $logEntry->insert();
628 if ( count( $tags ) ) {
629 $logEntry->addTags( $tags );
630 }
631 $logEntry->publish( $logid );
632 }
633
634 /**
635 * Edit user groups membership
636 * @param string $username Name of the user.
637 */
638 private function editUserGroupsForm( $username ) {
639 $status = $this->fetchUser( $username, true );
640 if ( !$status->isOK() ) {
641 $this->getOutput()->addWikiTextAsInterface(
642 $status->getWikiText( false, false, $this->getLanguage() )
643 );
644
645 return;
646 }
647
648 /** @var UserIdentity $user */
649 $user = $status->value;
650 '@phan-var UserIdentity $user';
651
652 $groups = $this->userGroupManager->getUserGroups( $user );
653 $groupMemberships = $this->userGroupManager->getUserGroupMemberships( $user );
654 $this->showEditUserGroupsForm( $user, $groups, $groupMemberships );
655
656 // This isn't really ideal logging behavior, but let's not hide the
657 // interwiki logs if we're using them as is.
658 $this->showLogFragment( $user, $this->getOutput() );
659 }
660
661 /**
662 * Normalize the input username, which may be local or remote, and
663 * return a user identity object, use it on other services for manipulating rights
664 *
665 * Side effects: error output for invalid access
666 * @param string $username
667 * @param bool $writing
668 * @return Status
669 */
670 public function fetchUser( $username, $writing = true ) {
671 $parts = explode( $this->getConfig()->get( MainConfigNames::UserrightsInterwikiDelimiter ),
672 $username );
673 if ( count( $parts ) < 2 ) {
674 $name = trim( $username );
675 $wikiId = UserIdentity::LOCAL;
676 } else {
677 [ $name, $wikiId ] = array_map( 'trim', $parts );
678
679 if ( WikiMap::isCurrentWikiId( $wikiId ) ) {
680 $wikiId = UserIdentity::LOCAL;
681 } else {
682 if ( $writing &&
683 !$this->getAuthority()->isAllowed( 'userrights-interwiki' )
684 ) {
685 return Status::newFatal( 'userrights-no-interwiki' );
686 }
687 $localDatabases = $this->getConfig()->get( MainConfigNames::LocalDatabases );
688 if ( !in_array( $wikiId, $localDatabases ) ) {
689 return Status::newFatal( 'userrights-nodatabase', $wikiId );
690 }
691 }
692 }
693
694 if ( $name === '' ) {
695 return Status::newFatal( 'nouserspecified' );
696 }
697
698 $userIdentityLookup = $this->actorStoreFactory->getUserIdentityLookup( $wikiId );
699 if ( $name[0] == '#' ) {
700 // Numeric ID can be specified...
701 $id = intval( substr( $name, 1 ) );
702
703 $user = $userIdentityLookup->getUserIdentityByUserId( $id );
704 if ( !$user ) {
705 // Different error message for compatibility
706 return Status::newFatal( 'noname' );
707 }
708 $name = $user->getName();
709 } else {
710 $name = $this->userNameUtils->getCanonical( $name );
711 if ( $name === false ) {
712 // invalid name
713 return Status::newFatal( 'nosuchusershort', $username );
714 }
715 $user = $userIdentityLookup->getUserIdentityByName( $name );
716 }
717
718 if ( $this->userNameUtils->isTemp( $name ) ) {
719 return Status::newFatal( 'userrights-no-group' );
720 }
721
722 if ( !$user || !$user->isRegistered() ) {
723 return Status::newFatal( 'nosuchusershort', $username );
724 }
725
726 // Prevent cross-wiki assignment of groups to temporary accounts on wikis where the feature is not known.
727 // We have to check this here, as ApiUserrights uses this to validate before assigning user rights.
728 if (
729 $user->getWikiId() !== UserIdentity::LOCAL &&
730 !$this->tempUserConfig->isKnown() &&
731 $this->tempUserConfig->isReservedName( $name )
732 ) {
733 return Status::newFatal( 'userrights-no-group' );
734 }
735
736 if ( $user->getWikiId() === UserIdentity::LOCAL &&
737 $this->userFactory->newFromUserIdentity( $user )->isHidden() &&
738 !$this->getAuthority()->isAllowed( 'hideuser' )
739 ) {
740 // Cannot see hidden users, pretend they don't exist
741 return Status::newFatal( 'nosuchusershort', $username );
742 }
743
744 return Status::newGood( $user );
745 }
746
747 /**
748 * @since 1.15
749 *
750 * @param array $ids
751 *
752 * @return string
753 */
754 public function makeGroupNameList( $ids ) {
755 if ( !$ids ) {
756 return $this->msg( 'rightsnone' )->inContentLanguage()->text();
757 } else {
758 return implode( ', ', $ids );
759 }
760 }
761
762 /**
763 * Display a HTMLUserTextField form to allow searching for a named user only
764 */
765 protected function switchForm() {
766 $formDescriptor = [
767 'user' => [
768 'class' => HTMLUserTextField::class,
769 'label-message' => 'userrights-user-editname',
770 'name' => 'user',
771 'ipallowed' => true,
772 'iprange' => true,
773 'excludetemp' => true, // Do not show temp users: T341684
774 'autofocus' => $this->mFetchedUser === null,
775 'default' => $this->mTarget,
776 ]
777 ];
778
779 $htmlForm = HTMLForm::factory( 'ooui', $formDescriptor, $this->getContext() );
780 $htmlForm
781 ->setMethod( 'GET' )
782 ->setAction( wfScript() )
783 ->setName( 'uluser' )
784 ->setTitle( SpecialPage::getTitleFor( 'Userrights' ) )
785 ->setWrapperLegendMsg( 'userrights-lookup-user' )
786 ->setId( 'mw-userrights-form1' )
787 ->setSubmitTextMsg( 'editusergroup' )
788 ->prepareForm()
789 ->displayForm( true );
790 }
791
792 /**
793 * Show the form to edit group memberships.
794 *
795 * @param UserIdentity $user
796 * @param string[] $groups Array of groups the user is in. Not used by this implementation
797 * anymore, but kept for backward compatibility with subclasses
798 * @param UserGroupMembership[] $groupMemberships Associative array of (group name => UserGroupMembership
799 * object) containing the groups the user is in
800 */
801 protected function showEditUserGroupsForm( $user, $groups, $groupMemberships ) {
802 $list = $membersList = $tempList = $tempMembersList = [];
803 foreach ( $groupMemberships as $ugm ) {
804 $linkG = UserGroupMembership::getLinkHTML( $ugm, $this->getContext() );
805 $linkM = UserGroupMembership::getLinkHTML( $ugm, $this->getContext(), $user->getName() );
806 if ( $ugm->getExpiry() ) {
807 $tempList[] = $linkG;
808 $tempMembersList[] = $linkM;
809 } else {
810 $list[] = $linkG;
811 $membersList[] = $linkM;
812
813 }
814 }
815
816 $autoList = [];
817 $autoMembersList = [];
818
819 if ( $user->getWikiId() === UserIdentity::LOCAL ) {
820 // Listing autopromote groups works only on the local wiki
821 foreach ( $this->userGroupManager->getUserAutopromoteGroups( $user ) as $group ) {
822 $autoList[] = UserGroupMembership::getLinkHTML( $group, $this->getContext() );
823 $autoMembersList[] = UserGroupMembership::getLinkHTML( $group, $this->getContext(), $user->getName() );
824 }
825 }
826
827 $language = $this->getLanguage();
828 $displayedList = $this->msg( 'userrights-groupsmember-type' )
829 ->rawParams(
830 $language->commaList( array_merge( $tempList, $list ) ),
831 $language->commaList( array_merge( $tempMembersList, $membersList ) )
832 )->escaped();
833 $displayedAutolist = $this->msg( 'userrights-groupsmember-type' )
834 ->rawParams(
835 $language->commaList( $autoList ),
836 $language->commaList( $autoMembersList )
837 )->escaped();
838
839 $grouplist = '';
840 $count = count( $list ) + count( $tempList );
841 if ( $count > 0 ) {
842 $grouplist = $this->msg( 'userrights-groupsmember' )
843 ->numParams( $count )
844 ->params( $user->getName() )
845 ->parse();
846 $grouplist = '<p>' . $grouplist . ' ' . $displayedList . "</p>\n";
847 }
848
849 $count = count( $autoList );
850 if ( $count > 0 ) {
851 $autogrouplistintro = $this->msg( 'userrights-groupsmember-auto' )
852 ->numParams( $count )
853 ->params( $user->getName() )
854 ->parse();
855 $grouplist .= '<p>' . $autogrouplistintro . ' ' . $displayedAutolist . "</p>\n";
856 }
857
858 $systemUser = $user->getWikiId() === UserIdentity::LOCAL
859 && $this->userFactory->newFromUserIdentity( $user )->isSystemUser();
860 if ( $systemUser ) {
861 $systemusernote = $this->msg( 'userrights-systemuser' )
862 ->params( $user->getName() )
863 ->parse();
864 $grouplist .= '<p>' . $systemusernote . "</p>\n";
865 }
866
867 // Only add an email link if the user is not a system user
868 $flags = $systemUser ? 0 : Linker::TOOL_LINKS_EMAIL;
869 $userToolLinks = Linker::userToolLinks(
870 $user->getId( $user->getWikiId() ),
871 $this->getDisplayUsername( $user ),
872 false, /* default for redContribsWhenNoEdits */
873 $flags
874 );
875
876 [ $groupCheckboxes, $canChangeAny ] =
877 $this->groupCheckboxes( $groupMemberships, $user );
878 $this->getOutput()->addHTML(
879 Html::openElement(
880 'form',
881 [
882 'method' => 'post',
883 'action' => $this->getPageTitle()->getLocalURL(),
884 'name' => 'editGroup',
885 'id' => 'mw-userrights-form2'
886 ]
887 ) .
888 Html::hidden( 'user', $this->mTarget ) .
889 Html::hidden( 'wpEditToken', $this->getUser()->getEditToken( $this->mTarget ) ) .
890 Html::hidden(
891 'conflictcheck-originalgroups',
892 implode( ',', $this->userGroupManager->getUserGroups( $user ) )
893 ) . // Conflict detection
894 Html::openElement( 'fieldset' ) .
895 Html::element(
896 'legend',
897 [],
898 $this->msg(
899 $canChangeAny ? 'userrights-editusergroup' : 'userrights-viewusergroup',
900 $user->getName()
901 )->text()
902 ) .
903 $this->msg(
904 $canChangeAny ? 'editinguser' : 'viewinguserrights'
905 )->params( wfEscapeWikiText( $this->getDisplayUsername( $user ) ) )
906 ->rawParams( $userToolLinks )->parse()
907 );
908 if ( $canChangeAny ) {
909 $this->getOutput()->addHTML(
910 $this->msg( 'userrights-groups-help', $user->getName() )->parse() .
911 $grouplist .
912 $groupCheckboxes .
913 Html::openElement( 'table', [ 'id' => 'mw-userrights-table-outer' ] ) .
914 "<tr>
915 <td class='mw-label'>" .
916 Html::label( $this->msg( 'userrights-reason' )->text(), 'wpReason' ) .
917 "</td>
918 <td class='mw-input'>" .
919 Xml::input( 'user-reason', 60, $this->getRequest()->getVal( 'user-reason' ) ?? false, [
920 'id' => 'wpReason',
921 // HTML maxlength uses "UTF-16 code units", which means that characters outside BMP
922 // (e.g. emojis) count for two each. This limit is overridden in JS to instead count
923 // Unicode codepoints.
924 'maxlength' => CommentStore::COMMENT_CHARACTER_LIMIT,
925 ] ) .
926 "</td>
927 </tr>
928 <tr>
929 <td></td>
930 <td class='mw-submit'>" .
931 Html::submitButton( $this->msg( 'saveusergroups', $user->getName() )->text(),
932 [ 'name' => 'saveusergroups' ] +
933 Linker::tooltipAndAccesskeyAttribs( 'userrights-set' )
934 ) .
935 "</td>
936 </tr>
937 <tr>
938 <td></td>
939 <td class='mw-input'>" .
940 Html::check( 'wpWatch', false, [ 'id' => 'wpWatch' ] ) .
941 '&nbsp;' . Html::label( $this->msg( 'userrights-watchuser' )->text(), 'wpWatch' ) .
942 "</td>
943 </tr>" .
944 Xml::closeElement( 'table' ) . "\n"
945 );
946 } else {
947 $this->getOutput()->addHTML( $grouplist );
948 }
949 $this->getOutput()->addHTML(
950 Xml::closeElement( 'fieldset' ) .
951 Xml::closeElement( 'form' ) . "\n"
952 );
953 }
954
955 /**
956 * Adds a table with checkboxes where you can select what groups to add/remove
957 *
958 * @param UserGroupMembership[] $usergroups Associative array of (group name as string =>
959 * UserGroupMembership object) for groups the user belongs to
960 * @param UserIdentity $user
961 * @return array Array with 2 elements: the XHTML table element with checkxboes, and
962 * whether any groups are changeable
963 */
964 private function groupCheckboxes( $usergroups, UserIdentity $user ) {
965 $allgroups = $this->userGroupManager->listAllGroups();
966 $ret = '';
967
968 // Get the list of preset expiry times from the system message
969 $expiryOptionsMsg = $this->msg( 'userrights-expiry-options' )->inContentLanguage();
970 $expiryOptions = $expiryOptionsMsg->isDisabled()
971 ? []
972 : XmlSelect::parseOptionsMessage( $expiryOptionsMsg->text() );
973
974 // Put all column info into an associative array so that extensions can
975 // more easily manage it.
976 $columns = [ 'unchangeable' => [], 'changeable' => [] ];
977
978 foreach ( $allgroups as $group ) {
979 $set = isset( $usergroups[$group] );
980 // Users who can add the group, but not remove it, can only lengthen
981 // expiries, not shorten them. So they should only see the expiry
982 // dropdown if the group currently has a finite expiry
983 $canOnlyLengthenExpiry = ( $set && $this->canAdd( $group ) &&
984 !$this->canRemove( $group ) && $usergroups[$group]->getExpiry() );
985 // Should the checkbox be disabled?
986 $disabledCheckbox = !(
987 ( $set && $this->canRemove( $group ) ) ||
988 ( !$set && $this->canAdd( $group ) ) );
989 // Should the expiry elements be disabled?
990 $disabledExpiry = $disabledCheckbox && !$canOnlyLengthenExpiry;
991 // Do we need to point out that this action is irreversible?
992 $irreversible = !$disabledCheckbox && (
993 ( $set && !$this->canAdd( $group ) ) ||
994 ( !$set && !$this->canRemove( $group ) ) );
995
996 $checkbox = [
997 'set' => $set,
998 'disabled' => $disabledCheckbox,
999 'disabled-expiry' => $disabledExpiry,
1000 'irreversible' => $irreversible
1001 ];
1002
1003 if ( $disabledCheckbox && $disabledExpiry ) {
1004 $columns['unchangeable'][$group] = $checkbox;
1005 } else {
1006 $columns['changeable'][$group] = $checkbox;
1007 }
1008 }
1009
1010 // Build the HTML table
1011 $ret .= Xml::openElement( 'table', [ 'class' => 'mw-userrights-groups' ] ) .
1012 "<tr>\n";
1013 foreach ( $columns as $name => $column ) {
1014 if ( $column === [] ) {
1015 continue;
1016 }
1017 // Messages: userrights-changeable-col, userrights-unchangeable-col
1018 $ret .= Xml::element(
1019 'th',
1020 null,
1021 $this->msg( 'userrights-' . $name . '-col', count( $column ) )->text()
1022 );
1023 }
1024
1025 $ret .= "</tr>\n<tr>\n";
1026 $uiLanguage = $this->getLanguage();
1027 $userName = $user->getName();
1028 foreach ( $columns as $column ) {
1029 if ( $column === [] ) {
1030 continue;
1031 }
1032 $ret .= "\t<td style='vertical-align:top;'>\n";
1033 foreach ( $column as $group => $checkbox ) {
1034 $member = $uiLanguage->getGroupMemberName( $group, $userName );
1035 if ( $checkbox['irreversible'] ) {
1036 $text = $this->msg( 'userrights-irreversible-marker', $member )->text();
1037 } elseif ( $checkbox['disabled'] && !$checkbox['disabled-expiry'] ) {
1038 $text = $this->msg( 'userrights-no-shorten-expiry-marker', $member )->text();
1039 } else {
1040 $text = $member;
1041 }
1042 $checkboxHtml = Html::element( 'input', [
1043 'type' => 'checkbox', 'name' => "wpGroup-$group", 'value' => '1',
1044 'id' => "wpGroup-$group", 'checked' => $checkbox['set'],
1045 'class' => 'mw-userrights-groupcheckbox',
1046 'disabled' => $checkbox['disabled'],
1047 ] ) . '&nbsp;' . Html::label( $text, "wpGroup-$group" );
1048
1049 if ( $this->canProcessExpiries() ) {
1050 $uiUser = $this->getUser();
1051
1052 $currentExpiry = isset( $usergroups[$group] ) ?
1053 $usergroups[$group]->getExpiry() :
1054 null;
1055
1056 // If the user can't modify the expiry, print the current expiry below
1057 // it in plain text. Otherwise provide UI to set/change the expiry
1058 if ( $checkbox['set'] &&
1059 ( $checkbox['irreversible'] || $checkbox['disabled-expiry'] )
1060 ) {
1061 if ( $currentExpiry ) {
1062 $expiryFormatted = $uiLanguage->userTimeAndDate( $currentExpiry, $uiUser );
1063 $expiryFormattedD = $uiLanguage->userDate( $currentExpiry, $uiUser );
1064 $expiryFormattedT = $uiLanguage->userTime( $currentExpiry, $uiUser );
1065 $expiryHtml = Xml::element( 'span', null,
1066 $this->msg( 'userrights-expiry-current' )->params(
1067 $expiryFormatted, $expiryFormattedD, $expiryFormattedT )->text() );
1068 } else {
1069 $expiryHtml = Xml::element( 'span', null,
1070 $this->msg( 'userrights-expiry-none' )->text() );
1071 }
1072 // T171345: Add a hidden form element so that other groups can still be manipulated,
1073 // otherwise saving errors out with an invalid expiry time for this group.
1074 $expiryHtml .= Html::hidden( "wpExpiry-$group",
1075 $currentExpiry ? 'existing' : 'infinite' );
1076 $expiryHtml .= "<br />\n";
1077 } else {
1078 $expiryHtml = Html::element( 'span', [],
1079 $this->msg( 'userrights-expiry' )->text() );
1080 $expiryHtml .= Html::openElement( 'span' );
1081
1082 // add a form element to set the expiry date
1083 $expiryFormOptions = new XmlSelect(
1084 "wpExpiry-$group",
1085 "mw-input-wpExpiry-$group", // forward compatibility with HTMLForm
1086 $currentExpiry ? 'existing' : 'infinite'
1087 );
1088 if ( $checkbox['disabled-expiry'] ) {
1089 $expiryFormOptions->setAttribute( 'disabled', 'disabled' );
1090 }
1091
1092 if ( $currentExpiry ) {
1093 $timestamp = $uiLanguage->userTimeAndDate( $currentExpiry, $uiUser );
1094 $d = $uiLanguage->userDate( $currentExpiry, $uiUser );
1095 $t = $uiLanguage->userTime( $currentExpiry, $uiUser );
1096 $existingExpiryMessage = $this->msg( 'userrights-expiry-existing',
1097 $timestamp, $d, $t );
1098 $expiryFormOptions->addOption( $existingExpiryMessage->text(), 'existing' );
1099 }
1100
1101 $expiryFormOptions->addOption(
1102 $this->msg( 'userrights-expiry-none' )->text(),
1103 'infinite'
1104 );
1105 $expiryFormOptions->addOption(
1106 $this->msg( 'userrights-expiry-othertime' )->text(),
1107 'other'
1108 );
1109
1110 $expiryFormOptions->addOptions( $expiryOptions );
1111
1112 // Add expiry dropdown
1113 $expiryHtml .= $expiryFormOptions->getHTML() . '<br />';
1114
1115 // Add custom expiry field
1116 $expiryHtml .= Html::element( 'input', [
1117 'name' => "wpExpiry-$group-other", 'size' => 30, 'value' => '',
1118 'id' => "mw-input-wpExpiry-$group-other",
1119 'class' => 'mw-userrights-expiryfield',
1120 'disabled' => $checkbox['disabled-expiry'],
1121 ] );
1122
1123 // If the user group is set but the checkbox is disabled, mimic a
1124 // checked checkbox in the form submission
1125 if ( $checkbox['set'] && $checkbox['disabled'] ) {
1126 $expiryHtml .= Html::hidden( "wpGroup-$group", 1 );
1127 }
1128
1129 $expiryHtml .= Html::closeElement( 'span' );
1130 }
1131
1132 $divAttribs = [
1133 'id' => "mw-userrights-nested-wpGroup-$group",
1134 'class' => 'mw-userrights-nested',
1135 ];
1136 $checkboxHtml .= "\t\t\t" . Html::rawElement( 'div', $divAttribs, $expiryHtml ) . "\n";
1137 }
1138 $ret .= "\t\t" . ( ( $checkbox['disabled'] && $checkbox['disabled-expiry'] )
1139 ? Html::rawElement( 'div', [ 'class' => 'mw-userrights-disabled' ], $checkboxHtml )
1140 : Html::rawElement( 'div', [], $checkboxHtml )
1141 ) . "\n";
1142 }
1143 $ret .= "\t</td>\n";
1144 }
1145 $ret .= Html::closeElement( 'tr' ) . Html::closeElement( 'table' );
1146
1147 return [ $ret, (bool)$columns['changeable'] ];
1148 }
1149
1150 /**
1151 * @param string $group The name of the group to check
1152 * @return bool Can we remove the group?
1153 */
1154 private function canRemove( $group ) {
1155 $groups = $this->changeableGroups();
1156
1157 return in_array(
1158 $group,
1159 $groups['remove'] ) || ( $this->isself && in_array( $group, $groups['remove-self'] )
1160 );
1161 }
1162
1163 /**
1164 * @param string $group The name of the group to check
1165 * @return bool Can we add the group?
1166 */
1167 private function canAdd( $group ) {
1168 $groups = $this->changeableGroups();
1169
1170 return in_array(
1171 $group,
1172 $groups['add'] ) || ( $this->isself && in_array( $group, $groups['add-self'] )
1173 );
1174 }
1175
1176 /**
1177 * @return array [
1178 * 'add' => [ addablegroups ],
1179 * 'remove' => [ removablegroups ],
1180 * 'add-self' => [ addablegroups to self ],
1181 * 'remove-self' => [ removable groups from self ]
1182 * ]
1183 * @phan-return array{add:list<string>,remove:list<string>,add-self:list<string>,remove-self:list<string>}
1184 */
1185 protected function changeableGroups() {
1186 return $this->userGroupManager->getGroupsChangeableBy( $this->getContext()->getAuthority() );
1187 }
1188
1189 /**
1190 * Get a display user name. This includes the {@}domain part for interwiki users.
1191 * Use UserIdentity::getName for {{GENDER:}} in messages and
1192 * use the "display user name" for visible user names in logs or messages
1193 *
1194 * @param UserIdentity $user
1195 * @return string
1196 */
1197 private function getDisplayUsername( UserIdentity $user ) {
1198 $userName = $user->getName();
1199 if ( $user->getWikiId() !== UserIdentity::LOCAL ) {
1200 $userName .= $this->getConfig()->get( MainConfigNames::UserrightsInterwikiDelimiter )
1201 . $user->getWikiId();
1202 }
1203 return $userName;
1204 }
1205
1206 /**
1207 * Show a rights log fragment for the specified user
1208 *
1209 * @param UserIdentity $user User to show log for
1210 * @param OutputPage $output OutputPage to use
1211 */
1212 protected function showLogFragment( $user, $output ) {
1213 $rightsLogPage = new LogPage( 'rights' );
1214 $output->addHTML( Html::element( 'h2', [], $rightsLogPage->getName()->text() ) );
1215 LogEventsList::showLogExtract( $output, 'rights',
1216 Title::makeTitle( NS_USER, $this->getDisplayUsername( $user ) ) );
1217 }
1218
1219 /**
1220 * Return an array of subpages beginning with $search that this special page will accept.
1221 *
1222 * @param string $search Prefix to search for
1223 * @param int $limit Maximum number of results to return (usually 10)
1224 * @param int $offset Number of results to skip (usually 0)
1225 * @return string[] Matching subpages
1226 */
1227 public function prefixSearchSubpages( $search, $limit, $offset ) {
1228 $search = $this->userNameUtils->getCanonical( $search );
1229 if ( !$search ) {
1230 // No prefix suggestion for invalid user
1231 return [];
1232 }
1233 // Autocomplete subpage as user list - public to allow caching
1234 return $this->userNamePrefixSearch
1235 ->search( UserNamePrefixSearch::AUDIENCE_PUBLIC, $search, $limit, $offset );
1236 }
1237
1238 protected function getGroupName() {
1239 return 'users';
1240 }
1241 }
1242
1243 /**
1244 * Retain the old class name for backwards compatibility.
1245 * @deprecated since 1.40
1246 */
1247 class_alias( SpecialUserRights::class, 'UserrightsPage' );