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