Merge "Allow all users to view Special:UserRights"
[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 ) {
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(
441 'editusergroup',
442 $this->mFetchedUser === null ? '[]' : $this->mFetchedUser->getName()
443 )->text()
444 ) .
445 Html::closeElement( 'fieldset' ) .
446 Html::closeElement( 'form' ) . "\n"
447 );
448 }
449
450 /**
451 * Go through used and available groups and return the ones that this
452 * form will be able to manipulate based on the current user's system
453 * permissions.
454 *
455 * @param array $groups List of groups the given user is in
456 * @return array Tuple of addable, then removable groups
457 */
458 protected function splitGroups( $groups ) {
459 list( $addable, $removable, $addself, $removeself ) = array_values( $this->changeableGroups() );
460
461 $removable = array_intersect(
462 array_merge( $this->isself ? $removeself : [], $removable ),
463 $groups
464 ); // Can't remove groups the user doesn't have
465 $addable = array_diff(
466 array_merge( $this->isself ? $addself : [], $addable ),
467 $groups
468 ); // Can't add groups the user does have
469
470 return [ $addable, $removable ];
471 }
472
473 /**
474 * Show the form to edit group memberships.
475 *
476 * @param User|UserRightsProxy $user User or UserRightsProxy you're editing
477 * @param array $groups Array of groups the user is in
478 */
479 protected function showEditUserGroupsForm( $user, $groups ) {
480 $list = [];
481 $membersList = [];
482 foreach ( $groups as $group ) {
483 $list[] = self::buildGroupLink( $group );
484 $membersList[] = self::buildGroupMemberLink( $group );
485 }
486
487 $autoList = [];
488 $autoMembersList = [];
489 if ( $user instanceof User ) {
490 foreach ( Autopromote::getAutopromoteGroups( $user ) as $group ) {
491 $autoList[] = self::buildGroupLink( $group );
492 $autoMembersList[] = self::buildGroupMemberLink( $group );
493 }
494 }
495
496 $language = $this->getLanguage();
497 $displayedList = $this->msg( 'userrights-groupsmember-type' )
498 ->rawParams(
499 $language->listToText( $list ),
500 $language->listToText( $membersList )
501 )->escaped();
502 $displayedAutolist = $this->msg( 'userrights-groupsmember-type' )
503 ->rawParams(
504 $language->listToText( $autoList ),
505 $language->listToText( $autoMembersList )
506 )->escaped();
507
508 $grouplist = '';
509 $count = count( $list );
510 if ( $count > 0 ) {
511 $grouplist = $this->msg( 'userrights-groupsmember' )
512 ->numParams( $count )
513 ->params( $user->getName() )
514 ->parse();
515 $grouplist = '<p>' . $grouplist . ' ' . $displayedList . "</p>\n";
516 }
517
518 $count = count( $autoList );
519 if ( $count > 0 ) {
520 $autogrouplistintro = $this->msg( 'userrights-groupsmember-auto' )
521 ->numParams( $count )
522 ->params( $user->getName() )
523 ->parse();
524 $grouplist .= '<p>' . $autogrouplistintro . ' ' . $displayedAutolist . "</p>\n";
525 }
526
527 $userToolLinks = Linker::userToolLinks(
528 $user->getId(),
529 $user->getName(),
530 false, /* default for redContribsWhenNoEdits */
531 Linker::TOOL_LINKS_EMAIL /* Add "send e-mail" link */
532 );
533
534 list( $groupCheckboxes, $canChangeAny ) = $this->groupCheckboxes( $groups, $user );
535 $this->getOutput()->addHTML(
536 Xml::openElement(
537 'form',
538 [
539 'method' => 'post',
540 'action' => $this->getPageTitle()->getLocalURL(),
541 'name' => 'editGroup',
542 'id' => 'mw-userrights-form2'
543 ]
544 ) .
545 Html::hidden( 'user', $this->mTarget ) .
546 Html::hidden( 'wpEditToken', $this->getUser()->getEditToken( $this->mTarget ) ) .
547 Html::hidden(
548 'conflictcheck-originalgroups',
549 implode( ',', $user->getGroups() )
550 ) . // Conflict detection
551 Xml::openElement( 'fieldset' ) .
552 Xml::element(
553 'legend',
554 [],
555 $this->msg( 'userrights-editusergroup', $user->getName() )->text()
556 ) .
557 $this->msg( 'editinguser' )->params( wfEscapeWikiText( $user->getName() ) )
558 ->rawParams( $userToolLinks )->parse()
559 );
560 if ( $canChangeAny ) {
561 $this->getOutput()->addHTML(
562 $this->msg( 'userrights-groups-help', $user->getName() )->parse() .
563 $grouplist .
564 $groupCheckboxes .
565 Xml::openElement( 'table', [ 'id' => 'mw-userrights-table-outer' ] ) .
566 "<tr>
567 <td class='mw-label'>" .
568 Xml::label( $this->msg( 'userrights-reason' )->text(), 'wpReason' ) .
569 "</td>
570 <td class='mw-input'>" .
571 Xml::input( 'user-reason', 60, $this->getRequest()->getVal( 'user-reason', false ),
572 [ 'id' => 'wpReason', 'maxlength' => 255 ] ) .
573 "</td>
574 </tr>
575 <tr>
576 <td></td>
577 <td class='mw-submit'>" .
578 Xml::submitButton( $this->msg( 'saveusergroups', $user->getName() )->text(),
579 [ 'name' => 'saveusergroups' ] +
580 Linker::tooltipAndAccesskeyAttribs( 'userrights-set' )
581 ) .
582 "</td>
583 </tr>" .
584 Xml::closeElement( 'table' ) . "\n"
585 );
586 } else {
587 $this->getOutput()->addHTML( $grouplist );
588 }
589 $this->getOutput()->addHTML(
590 Xml::closeElement( 'fieldset' ) .
591 Xml::closeElement( 'form' ) . "\n"
592 );
593 }
594
595 /**
596 * Format a link to a group description page
597 *
598 * @param string $group
599 * @return string
600 */
601 private static function buildGroupLink( $group ) {
602 return User::makeGroupLinkHTML( $group, User::getGroupName( $group ) );
603 }
604
605 /**
606 * Format a link to a group member description page
607 *
608 * @param string $group
609 * @return string
610 */
611 private static function buildGroupMemberLink( $group ) {
612 return User::makeGroupLinkHTML( $group, User::getGroupMember( $group ) );
613 }
614
615 /**
616 * Returns an array of all groups that may be edited
617 * @return array Array of groups that may be edited.
618 */
619 protected static function getAllGroups() {
620 return User::getAllGroups();
621 }
622
623 /**
624 * Adds a table with checkboxes where you can select what groups to add/remove
625 *
626 * @todo Just pass the username string?
627 * @param array $usergroups Groups the user belongs to
628 * @param User $user
629 * @return Array with 2 elements: the XHTML table element with checkxboes, and
630 * whether any groups are changeable
631 */
632 private function groupCheckboxes( $usergroups, $user ) {
633 $allgroups = $this->getAllGroups();
634 $ret = '';
635
636 // Put all column info into an associative array so that extensions can
637 // more easily manage it.
638 $columns = [ 'unchangeable' => [], 'changeable' => [] ];
639
640 foreach ( $allgroups as $group ) {
641 $set = in_array( $group, $usergroups );
642 // Should the checkbox be disabled?
643 $disabled = !(
644 ( $set && $this->canRemove( $group ) ) ||
645 ( !$set && $this->canAdd( $group ) ) );
646 // Do we need to point out that this action is irreversible?
647 $irreversible = !$disabled && (
648 ( $set && !$this->canAdd( $group ) ) ||
649 ( !$set && !$this->canRemove( $group ) ) );
650
651 $checkbox = [
652 'set' => $set,
653 'disabled' => $disabled,
654 'irreversible' => $irreversible
655 ];
656
657 if ( $disabled ) {
658 $columns['unchangeable'][$group] = $checkbox;
659 } else {
660 $columns['changeable'][$group] = $checkbox;
661 }
662 }
663
664 // Build the HTML table
665 $ret .= Xml::openElement( 'table', [ 'class' => 'mw-userrights-groups' ] ) .
666 "<tr>\n";
667 foreach ( $columns as $name => $column ) {
668 if ( $column === [] ) {
669 continue;
670 }
671 // Messages: userrights-changeable-col, userrights-unchangeable-col
672 $ret .= Xml::element(
673 'th',
674 null,
675 $this->msg( 'userrights-' . $name . '-col', count( $column ) )->text()
676 );
677 }
678
679 $ret .= "</tr>\n<tr>\n";
680 foreach ( $columns as $column ) {
681 if ( $column === [] ) {
682 continue;
683 }
684 $ret .= "\t<td style='vertical-align:top;'>\n";
685 foreach ( $column as $group => $checkbox ) {
686 $attr = $checkbox['disabled'] ? [ 'disabled' => 'disabled' ] : [];
687
688 $member = User::getGroupMember( $group, $user->getName() );
689 if ( $checkbox['irreversible'] ) {
690 $text = $this->msg( 'userrights-irreversible-marker', $member )->text();
691 } else {
692 $text = $member;
693 }
694 $checkboxHtml = Xml::checkLabel( $text, "wpGroup-" . $group,
695 "wpGroup-" . $group, $checkbox['set'], $attr );
696 $ret .= "\t\t" . ( $checkbox['disabled']
697 ? Xml::tags( 'span', [ 'class' => 'mw-userrights-disabled' ], $checkboxHtml )
698 : $checkboxHtml
699 ) . "<br />\n";
700 }
701 $ret .= "\t</td>\n";
702 }
703 $ret .= Xml::closeElement( 'tr' ) . Xml::closeElement( 'table' );
704
705 return [ $ret, (bool)$columns['changeable'] ];
706 }
707
708 /**
709 * @param string $group The name of the group to check
710 * @return bool Can we remove the group?
711 */
712 private function canRemove( $group ) {
713 // $this->changeableGroups()['remove'] doesn't work, of course. Thanks, PHP.
714 $groups = $this->changeableGroups();
715
716 return in_array(
717 $group,
718 $groups['remove'] ) || ( $this->isself && in_array( $group, $groups['remove-self'] )
719 );
720 }
721
722 /**
723 * @param string $group The name of the group to check
724 * @return bool Can we add the group?
725 */
726 private function canAdd( $group ) {
727 $groups = $this->changeableGroups();
728
729 return in_array(
730 $group,
731 $groups['add'] ) || ( $this->isself && in_array( $group, $groups['add-self'] )
732 );
733 }
734
735 /**
736 * Returns $this->getUser()->changeableGroups()
737 *
738 * @return array Array(
739 * 'add' => array( addablegroups ),
740 * 'remove' => array( removablegroups ),
741 * 'add-self' => array( addablegroups to self ),
742 * 'remove-self' => array( removable groups from self )
743 * )
744 */
745 function changeableGroups() {
746 return $this->getUser()->changeableGroups();
747 }
748
749 /**
750 * Show a rights log fragment for the specified user
751 *
752 * @param User $user User to show log for
753 * @param OutputPage $output OutputPage to use
754 */
755 protected function showLogFragment( $user, $output ) {
756 $rightsLogPage = new LogPage( 'rights' );
757 $output->addHTML( Xml::element( 'h2', null, $rightsLogPage->getName()->text() ) );
758 LogEventsList::showLogExtract( $output, 'rights', $user->getUserPage() );
759 }
760
761 /**
762 * Return an array of subpages beginning with $search that this special page will accept.
763 *
764 * @param string $search Prefix to search for
765 * @param int $limit Maximum number of results to return (usually 10)
766 * @param int $offset Number of results to skip (usually 0)
767 * @return string[] Matching subpages
768 */
769 public function prefixSearchSubpages( $search, $limit, $offset ) {
770 $user = User::newFromName( $search );
771 if ( !$user ) {
772 // No prefix suggestion for invalid user
773 return [];
774 }
775 // Autocomplete subpage as user list - public to allow caching
776 return UserNamePrefixSearch::search( 'public', $search, $limit, $offset );
777 }
778
779 protected function getGroupName() {
780 return 'users';
781 }
782 }
783