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