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