Merge "registration: Don't let extensions load late"
[lhc/web/wiklou.git] / includes / specials / SpecialUserrights.php
1 <?php
2 /**
3 * Implements Special:Userrights
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
19 *
20 * @file
21 * @ingroup SpecialPage
22 */
23
24 /**
25 * Special page to allow managing user group membership
26 *
27 * @ingroup SpecialPage
28 */
29 class UserrightsPage extends SpecialPage {
30 /**
31 * The target of the local right-adjuster's interest. Can be gotten from
32 * either a GET parameter or a subpage-style parameter, so have a member
33 * variable for it.
34 * @var null|string $mTarget
35 */
36 protected $mTarget;
37 /*
38 * @var null|User $mFetchedUser The user object of the target username or null.
39 */
40 protected $mFetchedUser = null;
41 protected $isself = false;
42
43 public function __construct() {
44 parent::__construct( 'Userrights' );
45 }
46
47 public function doesWrites() {
48 return true;
49 }
50
51 /**
52 * @param User $user
53 * @param bool $checkIfSelf
54 * @return bool
55 */
56 public function userCanChangeRights( $user, $checkIfSelf = true ) {
57 $available = $this->changeableGroups();
58 if ( $user->getId() == 0 ) {
59 return false;
60 }
61
62 return !empty( $available['add'] )
63 || !empty( $available['remove'] )
64 || ( ( $this->isself || !$checkIfSelf ) &&
65 ( !empty( $available['add-self'] )
66 || !empty( $available['remove-self'] ) ) );
67 }
68
69 /**
70 * Manage forms to be shown according to posted data.
71 * Depending on the submit button used, call a form or a save function.
72 *
73 * @param string|null $par String if any subpage provided, else null
74 * @throws UserBlockedError|PermissionsError
75 */
76 public function execute( $par ) {
77 $user = $this->getUser();
78 $request = $this->getRequest();
79 $out = $this->getOutput();
80
81 if ( $par !== null ) {
82 $this->mTarget = $par;
83 } else {
84 $this->mTarget = $request->getVal( 'user' );
85 }
86
87 if ( is_string( $this->mTarget ) ) {
88 $this->mTarget = trim( $this->mTarget );
89 }
90
91 $fetchedStatus = $this->fetchUser( $this->mTarget, true );
92 if ( $fetchedStatus->isOK() ) {
93 $this->mFetchedUser = $fetchedStatus->value;
94 if ( $this->mFetchedUser instanceof User ) {
95 // Set the 'relevant user' in the skin, so it displays links like Contributions,
96 // User logs, UserRights, etc.
97 $this->getSkin()->setRelevantUser( $this->mFetchedUser );
98 }
99 }
100
101 // show a successbox, if the user rights was saved successfully
102 if ( $request->getCheck( 'success' ) && $this->mFetchedUser !== null ) {
103 $out->addModules( [ 'mediawiki.special.userrights' ] );
104 $out->addModuleStyles( 'mediawiki.notification.convertmessagebox.styles' );
105 $out->addHTML(
106 Html::rawElement(
107 'div',
108 [
109 'class' => 'mw-notify-success successbox',
110 'id' => 'mw-preferences-success',
111 'data-mw-autohide' => 'false',
112 ],
113 Html::element(
114 'p',
115 [],
116 $this->msg( 'savedrights', $this->mFetchedUser->getName() )->text()
117 )
118 )
119 );
120 }
121
122 $this->setHeaders();
123 $this->outputHeader();
124
125 $out->addModuleStyles( 'mediawiki.special' );
126 $this->addHelpLink( 'Help:Assigning permissions' );
127
128 $this->switchForm();
129
130 if (
131 $request->wasPosted() &&
132 $request->getCheck( 'saveusergroups' ) &&
133 $this->mTarget !== null &&
134 $user->matchEditToken( $request->getVal( 'wpEditToken' ), $this->mTarget )
135 ) {
136 /*
137 * If the user is blocked and they only have "partial" access
138 * (e.g. they don't have the userrights permission), then don't
139 * allow them to change any user rights.
140 */
141 if ( $user->isBlocked() && !$user->isAllowed( 'userrights' ) ) {
142 throw new UserBlockedError( $user->getBlock() );
143 }
144
145 $this->checkReadOnly();
146
147 // save settings
148 if ( !$fetchedStatus->isOK() ) {
149 $this->getOutput()->addWikiText( $fetchedStatus->getWikiText() );
150
151 return;
152 }
153
154 $targetUser = $this->mFetchedUser;
155 if ( $targetUser instanceof User ) { // UserRightsProxy doesn't have this method (bug 61252)
156 $targetUser->clearInstanceCache(); // bug 38989
157 }
158
159 if ( $request->getVal( 'conflictcheck-originalgroups' )
160 !== implode( ',', $targetUser->getGroups() )
161 ) {
162 $out->addWikiMsg( 'userrights-conflict' );
163 } else {
164 $this->saveUserGroups(
165 $this->mTarget,
166 $request->getVal( 'user-reason' ),
167 $targetUser
168 );
169
170 $out->redirect( $this->getSuccessURL() );
171
172 return;
173 }
174 }
175
176 // show some more forms
177 if ( $this->mTarget !== null ) {
178 $this->editUserGroupsForm( $this->mTarget );
179 }
180 }
181
182 function getSuccessURL() {
183 return $this->getPageTitle( $this->mTarget )->getFullURL( [ 'success' => 1 ] );
184 }
185
186 /**
187 * Save user groups changes in the database.
188 * Data comes from the editUserGroupsForm() form function
189 *
190 * @param string $username Username to apply changes to.
191 * @param string $reason Reason for group change
192 * @param User|UserRightsProxy $user Target user object.
193 * @return null
194 */
195 function saveUserGroups( $username, $reason, $user ) {
196 $allgroups = $this->getAllGroups();
197 $addgroup = [];
198 $removegroup = [];
199
200 // This could possibly create a highly unlikely race condition if permissions are changed between
201 // when the form is loaded and when the form is saved. Ignoring it for the moment.
202 foreach ( $allgroups as $group ) {
203 // We'll tell it to remove all unchecked groups, and add all checked groups.
204 // Later on, this gets filtered for what can actually be removed
205 if ( $this->getRequest()->getCheck( "wpGroup-$group" ) ) {
206 $addgroup[] = $group;
207 } else {
208 $removegroup[] = $group;
209 }
210 }
211
212 $this->doSaveUserGroups( $user, $addgroup, $removegroup, $reason );
213 }
214
215 /**
216 * Save user groups changes in the database.
217 *
218 * @param User|UserRightsProxy $user
219 * @param array $add Array of groups to add
220 * @param array $remove Array of groups to remove
221 * @param string $reason Reason for group change
222 * @return array Tuple of added, then removed groups
223 */
224 function doSaveUserGroups( $user, $add, $remove, $reason = '' ) {
225 // Validate input set...
226 $isself = $user->getName() == $this->getUser()->getName();
227 $groups = $user->getGroups();
228 $changeable = $this->changeableGroups();
229 $addable = array_merge( $changeable['add'], $isself ? $changeable['add-self'] : [] );
230 $removable = array_merge( $changeable['remove'], $isself ? $changeable['remove-self'] : [] );
231
232 $remove = array_unique(
233 array_intersect( (array)$remove, $removable, $groups ) );
234 $add = array_unique( array_diff(
235 array_intersect( (array)$add, $addable ),
236 $groups )
237 );
238
239 $oldGroups = $user->getGroups();
240 $newGroups = $oldGroups;
241
242 // Remove then add groups
243 if ( $remove ) {
244 foreach ( $remove as $index => $group ) {
245 if ( !$user->removeGroup( $group ) ) {
246 unset( $remove[$index] );
247 }
248 }
249 $newGroups = array_diff( $newGroups, $remove );
250 }
251 if ( $add ) {
252 foreach ( $add as $index => $group ) {
253 if ( !$user->addGroup( $group ) ) {
254 unset( $add[$index] );
255 }
256 }
257 $newGroups = array_merge( $newGroups, $add );
258 }
259 $newGroups = array_unique( $newGroups );
260
261 // Ensure that caches are cleared
262 $user->invalidateCache();
263
264 // update groups in external authentication database
265 Hooks::run( 'UserGroupsChanged', [ $user, $add, $remove, $this->getUser(), $reason ] );
266 MediaWiki\Auth\AuthManager::callLegacyAuthPlugin(
267 'updateExternalDBGroups', [ $user, $add, $remove ]
268 );
269
270 wfDebug( 'oldGroups: ' . print_r( $oldGroups, true ) . "\n" );
271 wfDebug( 'newGroups: ' . print_r( $newGroups, true ) . "\n" );
272 // Deprecated in favor of UserGroupsChanged hook
273 Hooks::run( 'UserRights', [ &$user, $add, $remove ], '1.26' );
274
275 if ( $newGroups != $oldGroups ) {
276 $this->addLogEntry( $user, $oldGroups, $newGroups, $reason );
277 }
278
279 return [ $add, $remove ];
280 }
281
282 /**
283 * Add a rights log entry for an action.
284 * @param User $user
285 * @param array $oldGroups
286 * @param array $newGroups
287 * @param array $reason
288 */
289 function addLogEntry( $user, $oldGroups, $newGroups, $reason ) {
290 $logEntry = new ManualLogEntry( 'rights', 'rights' );
291 $logEntry->setPerformer( $this->getUser() );
292 $logEntry->setTarget( $user->getUserPage() );
293 $logEntry->setComment( $reason );
294 $logEntry->setParameters( [
295 '4::oldgroups' => $oldGroups,
296 '5::newgroups' => $newGroups,
297 ] );
298 $logid = $logEntry->insert();
299 $logEntry->publish( $logid );
300 }
301
302 /**
303 * Edit user groups membership
304 * @param string $username Name of the user.
305 */
306 function editUserGroupsForm( $username ) {
307 $status = $this->fetchUser( $username, true );
308 if ( !$status->isOK() ) {
309 $this->getOutput()->addWikiText( $status->getWikiText() );
310
311 return;
312 } else {
313 $user = $status->value;
314 }
315
316 $groups = $user->getGroups();
317
318 $this->showEditUserGroupsForm( $user, $groups );
319
320 // This isn't really ideal logging behavior, but let's not hide the
321 // interwiki logs if we're using them as is.
322 $this->showLogFragment( $user, $this->getOutput() );
323 }
324
325 /**
326 * Normalize the input username, which may be local or remote, and
327 * return a user (or proxy) object for manipulating it.
328 *
329 * Side effects: error output for invalid access
330 * @param string $username
331 * @param bool $writing
332 * @return Status
333 */
334 public function fetchUser( $username, $writing = true ) {
335 $parts = explode( $this->getConfig()->get( 'UserrightsInterwikiDelimiter' ), $username );
336 if ( count( $parts ) < 2 ) {
337 $name = trim( $username );
338 $database = '';
339 } else {
340 list( $name, $database ) = array_map( 'trim', $parts );
341
342 if ( $database == wfWikiID() ) {
343 $database = '';
344 } else {
345 if ( $writing && !$this->getUser()->isAllowed( 'userrights-interwiki' ) ) {
346 return Status::newFatal( 'userrights-no-interwiki' );
347 }
348 if ( !UserRightsProxy::validDatabase( $database ) ) {
349 return Status::newFatal( 'userrights-nodatabase', $database );
350 }
351 }
352 }
353
354 if ( $name === '' ) {
355 return Status::newFatal( 'nouserspecified' );
356 }
357
358 if ( $name[0] == '#' ) {
359 // Numeric ID can be specified...
360 // We'll do a lookup for the name internally.
361 $id = intval( substr( $name, 1 ) );
362
363 if ( $database == '' ) {
364 $name = User::whoIs( $id );
365 } else {
366 $name = UserRightsProxy::whoIs( $database, $id );
367 }
368
369 if ( !$name ) {
370 return Status::newFatal( 'noname' );
371 }
372 } else {
373 $name = User::getCanonicalName( $name );
374 if ( $name === false ) {
375 // invalid name
376 return Status::newFatal( 'nosuchusershort', $username );
377 }
378 }
379
380 if ( $database == '' ) {
381 $user = User::newFromName( $name );
382 } else {
383 $user = UserRightsProxy::newFromName( $database, $name );
384 }
385
386 if ( !$user || $user->isAnon() ) {
387 return Status::newFatal( 'nosuchusershort', $username );
388 }
389
390 return Status::newGood( $user );
391 }
392
393 /**
394 * @since 1.15
395 *
396 * @param array $ids
397 *
398 * @return string
399 */
400 public function makeGroupNameList( $ids ) {
401 if ( empty( $ids ) ) {
402 return $this->msg( 'rightsnone' )->inContentLanguage()->text();
403 } else {
404 return implode( ', ', $ids );
405 }
406 }
407
408 /**
409 * Output a form to allow searching for a user
410 */
411 function switchForm() {
412 $this->getOutput()->addModules( 'mediawiki.userSuggest' );
413
414 $this->getOutput()->addHTML(
415 Html::openElement(
416 'form',
417 [
418 'method' => 'get',
419 'action' => wfScript(),
420 'name' => 'uluser',
421 'id' => 'mw-userrights-form1'
422 ]
423 ) .
424 Html::hidden( 'title', $this->getPageTitle()->getPrefixedText() ) .
425 Xml::fieldset( $this->msg( 'userrights-lookup-user' )->text() ) .
426 Xml::inputLabel(
427 $this->msg( 'userrights-user-editname' )->text(),
428 'user',
429 'username',
430 30,
431 str_replace( '_', ' ', $this->mTarget ),
432 [
433 'class' => 'mw-autocomplete-user', // used by mediawiki.userSuggest
434 ] + (
435 // Set autofocus on blank input and error input
436 $this->mFetchedUser === null ? [ 'autofocus' => '' ] : []
437 )
438 ) . ' ' .
439 Xml::submitButton(
440 $this->msg( 'editusergroup' )->text()
441 ) .
442 Html::closeElement( 'fieldset' ) .
443 Html::closeElement( 'form' ) . "\n"
444 );
445 }
446
447 /**
448 * Go through used and available groups and return the ones that this
449 * form will be able to manipulate based on the current user's system
450 * permissions.
451 *
452 * @param array $groups List of groups the given user is in
453 * @return array Tuple of addable, then removable groups
454 */
455 protected function splitGroups( $groups ) {
456 list( $addable, $removable, $addself, $removeself ) = array_values( $this->changeableGroups() );
457
458 $removable = array_intersect(
459 array_merge( $this->isself ? $removeself : [], $removable ),
460 $groups
461 ); // Can't remove groups the user doesn't have
462 $addable = array_diff(
463 array_merge( $this->isself ? $addself : [], $addable ),
464 $groups
465 ); // Can't add groups the user does have
466
467 return [ $addable, $removable ];
468 }
469
470 /**
471 * Show the form to edit group memberships.
472 *
473 * @param User|UserRightsProxy $user User or UserRightsProxy you're editing
474 * @param array $groups Array of groups the user is in
475 */
476 protected function showEditUserGroupsForm( $user, $groups ) {
477 $list = [];
478 $membersList = [];
479 foreach ( $groups as $group ) {
480 $list[] = self::buildGroupLink( $group );
481 $membersList[] = self::buildGroupMemberLink( $group );
482 }
483
484 $autoList = [];
485 $autoMembersList = [];
486 if ( $user instanceof User ) {
487 foreach ( Autopromote::getAutopromoteGroups( $user ) as $group ) {
488 $autoList[] = self::buildGroupLink( $group );
489 $autoMembersList[] = self::buildGroupMemberLink( $group );
490 }
491 }
492
493 $language = $this->getLanguage();
494 $displayedList = $this->msg( 'userrights-groupsmember-type' )
495 ->rawParams(
496 $language->listToText( $list ),
497 $language->listToText( $membersList )
498 )->escaped();
499 $displayedAutolist = $this->msg( 'userrights-groupsmember-type' )
500 ->rawParams(
501 $language->listToText( $autoList ),
502 $language->listToText( $autoMembersList )
503 )->escaped();
504
505 $grouplist = '';
506 $count = count( $list );
507 if ( $count > 0 ) {
508 $grouplist = $this->msg( 'userrights-groupsmember' )
509 ->numParams( $count )
510 ->params( $user->getName() )
511 ->parse();
512 $grouplist = '<p>' . $grouplist . ' ' . $displayedList . "</p>\n";
513 }
514
515 $count = count( $autoList );
516 if ( $count > 0 ) {
517 $autogrouplistintro = $this->msg( 'userrights-groupsmember-auto' )
518 ->numParams( $count )
519 ->params( $user->getName() )
520 ->parse();
521 $grouplist .= '<p>' . $autogrouplistintro . ' ' . $displayedAutolist . "</p>\n";
522 }
523
524 $userToolLinks = Linker::userToolLinks(
525 $user->getId(),
526 $user->getName(),
527 false, /* default for redContribsWhenNoEdits */
528 Linker::TOOL_LINKS_EMAIL /* Add "send e-mail" link */
529 );
530
531 list( $groupCheckboxes, $canChangeAny ) = $this->groupCheckboxes( $groups, $user );
532 $this->getOutput()->addHTML(
533 Xml::openElement(
534 'form',
535 [
536 'method' => 'post',
537 'action' => $this->getPageTitle()->getLocalURL(),
538 'name' => 'editGroup',
539 'id' => 'mw-userrights-form2'
540 ]
541 ) .
542 Html::hidden( 'user', $this->mTarget ) .
543 Html::hidden( 'wpEditToken', $this->getUser()->getEditToken( $this->mTarget ) ) .
544 Html::hidden(
545 'conflictcheck-originalgroups',
546 implode( ',', $user->getGroups() )
547 ) . // Conflict detection
548 Xml::openElement( 'fieldset' ) .
549 Xml::element(
550 'legend',
551 [],
552 $this->msg(
553 $canChangeAny ? 'userrights-editusergroup' : 'userrights-viewusergroup',
554 $user->getName()
555 )->text()
556 ) .
557 $this->msg(
558 $canChangeAny ? 'editinguser' : 'viewinguserrights'
559 )->params( wfEscapeWikiText( $user->getName() ) )
560 ->rawParams( $userToolLinks )->parse()
561 );
562 if ( $canChangeAny ) {
563 $this->getOutput()->addHTML(
564 $this->msg( 'userrights-groups-help', $user->getName() )->parse() .
565 $grouplist .
566 $groupCheckboxes .
567 Xml::openElement( 'table', [ 'id' => 'mw-userrights-table-outer' ] ) .
568 "<tr>
569 <td class='mw-label'>" .
570 Xml::label( $this->msg( 'userrights-reason' )->text(), 'wpReason' ) .
571 "</td>
572 <td class='mw-input'>" .
573 Xml::input( 'user-reason', 60, $this->getRequest()->getVal( 'user-reason', false ),
574 [ 'id' => 'wpReason', 'maxlength' => 255 ] ) .
575 "</td>
576 </tr>
577 <tr>
578 <td></td>
579 <td class='mw-submit'>" .
580 Xml::submitButton( $this->msg( 'saveusergroups', $user->getName() )->text(),
581 [ 'name' => 'saveusergroups' ] +
582 Linker::tooltipAndAccesskeyAttribs( 'userrights-set' )
583 ) .
584 "</td>
585 </tr>" .
586 Xml::closeElement( 'table' ) . "\n"
587 );
588 } else {
589 $this->getOutput()->addHTML( $grouplist );
590 }
591 $this->getOutput()->addHTML(
592 Xml::closeElement( 'fieldset' ) .
593 Xml::closeElement( 'form' ) . "\n"
594 );
595 }
596
597 /**
598 * Format a link to a group description page
599 *
600 * @param string $group
601 * @return string
602 */
603 private static function buildGroupLink( $group ) {
604 return User::makeGroupLinkHTML( $group, User::getGroupName( $group ) );
605 }
606
607 /**
608 * Format a link to a group member description page
609 *
610 * @param string $group
611 * @return string
612 */
613 private static function buildGroupMemberLink( $group ) {
614 return User::makeGroupLinkHTML( $group, User::getGroupMember( $group ) );
615 }
616
617 /**
618 * Returns an array of all groups that may be edited
619 * @return array Array of groups that may be edited.
620 */
621 protected static function getAllGroups() {
622 return User::getAllGroups();
623 }
624
625 /**
626 * Adds a table with checkboxes where you can select what groups to add/remove
627 *
628 * @todo Just pass the username string?
629 * @param array $usergroups Groups the user belongs to
630 * @param User $user
631 * @return Array with 2 elements: the XHTML table element with checkxboes, and
632 * whether any groups are changeable
633 */
634 private function groupCheckboxes( $usergroups, $user ) {
635 $allgroups = $this->getAllGroups();
636 $ret = '';
637
638 // Put all column info into an associative array so that extensions can
639 // more easily manage it.
640 $columns = [ 'unchangeable' => [], 'changeable' => [] ];
641
642 foreach ( $allgroups as $group ) {
643 $set = in_array( $group, $usergroups );
644 // Should the checkbox be disabled?
645 $disabled = !(
646 ( $set && $this->canRemove( $group ) ) ||
647 ( !$set && $this->canAdd( $group ) ) );
648 // Do we need to point out that this action is irreversible?
649 $irreversible = !$disabled && (
650 ( $set && !$this->canAdd( $group ) ) ||
651 ( !$set && !$this->canRemove( $group ) ) );
652
653 $checkbox = [
654 'set' => $set,
655 'disabled' => $disabled,
656 'irreversible' => $irreversible
657 ];
658
659 if ( $disabled ) {
660 $columns['unchangeable'][$group] = $checkbox;
661 } else {
662 $columns['changeable'][$group] = $checkbox;
663 }
664 }
665
666 // Build the HTML table
667 $ret .= Xml::openElement( 'table', [ 'class' => 'mw-userrights-groups' ] ) .
668 "<tr>\n";
669 foreach ( $columns as $name => $column ) {
670 if ( $column === [] ) {
671 continue;
672 }
673 // Messages: userrights-changeable-col, userrights-unchangeable-col
674 $ret .= Xml::element(
675 'th',
676 null,
677 $this->msg( 'userrights-' . $name . '-col', count( $column ) )->text()
678 );
679 }
680
681 $ret .= "</tr>\n<tr>\n";
682 foreach ( $columns as $column ) {
683 if ( $column === [] ) {
684 continue;
685 }
686 $ret .= "\t<td style='vertical-align:top;'>\n";
687 foreach ( $column as $group => $checkbox ) {
688 $attr = $checkbox['disabled'] ? [ 'disabled' => 'disabled' ] : [];
689
690 $member = User::getGroupMember( $group, $user->getName() );
691 if ( $checkbox['irreversible'] ) {
692 $text = $this->msg( 'userrights-irreversible-marker', $member )->text();
693 } else {
694 $text = $member;
695 }
696 $checkboxHtml = Xml::checkLabel( $text, "wpGroup-" . $group,
697 "wpGroup-" . $group, $checkbox['set'], $attr );
698 $ret .= "\t\t" . ( $checkbox['disabled']
699 ? Xml::tags( 'span', [ 'class' => 'mw-userrights-disabled' ], $checkboxHtml )
700 : $checkboxHtml
701 ) . "<br />\n";
702 }
703 $ret .= "\t</td>\n";
704 }
705 $ret .= Xml::closeElement( 'tr' ) . Xml::closeElement( 'table' );
706
707 return [ $ret, (bool)$columns['changeable'] ];
708 }
709
710 /**
711 * @param string $group The name of the group to check
712 * @return bool Can we remove the group?
713 */
714 private function canRemove( $group ) {
715 $groups = $this->changeableGroups();
716
717 return in_array(
718 $group,
719 $groups['remove'] ) || ( $this->isself && in_array( $group, $groups['remove-self'] )
720 );
721 }
722
723 /**
724 * @param string $group The name of the group to check
725 * @return bool Can we add the group?
726 */
727 private function canAdd( $group ) {
728 $groups = $this->changeableGroups();
729
730 return in_array(
731 $group,
732 $groups['add'] ) || ( $this->isself && in_array( $group, $groups['add-self'] )
733 );
734 }
735
736 /**
737 * Returns $this->getUser()->changeableGroups()
738 *
739 * @return array Array(
740 * 'add' => array( addablegroups ),
741 * 'remove' => array( removablegroups ),
742 * 'add-self' => array( addablegroups to self ),
743 * 'remove-self' => array( removable groups from self )
744 * )
745 */
746 function changeableGroups() {
747 return $this->getUser()->changeableGroups();
748 }
749
750 /**
751 * Show a rights log fragment for the specified user
752 *
753 * @param User $user User to show log for
754 * @param OutputPage $output OutputPage to use
755 */
756 protected function showLogFragment( $user, $output ) {
757 $rightsLogPage = new LogPage( 'rights' );
758 $output->addHTML( Xml::element( 'h2', null, $rightsLogPage->getName()->text() ) );
759 LogEventsList::showLogExtract( $output, 'rights', $user->getUserPage() );
760 }
761
762 /**
763 * Return an array of subpages beginning with $search that this special page will accept.
764 *
765 * @param string $search Prefix to search for
766 * @param int $limit Maximum number of results to return (usually 10)
767 * @param int $offset Number of results to skip (usually 0)
768 * @return string[] Matching subpages
769 */
770 public function prefixSearchSubpages( $search, $limit, $offset ) {
771 $user = User::newFromName( $search );
772 if ( !$user ) {
773 // No prefix suggestion for invalid user
774 return [];
775 }
776 // Autocomplete subpage as user list - public to allow caching
777 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
778 }
779
780 protected function getGroupName() {
781 return 'users';
782 }
783 }
784