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