Add $wgGroupsAddToSelf and $wgGroupsRemoveFromSelf in Special:ListGroupRights (bug...
[lhc/web/wiklou.git] / includes / specials / SpecialListgrouprights.php
1 <?php
2
3 /**
4 * This special page lists all defined user groups and the associated rights.
5 * See also @ref $wgGroupPermissions.
6 *
7 * @ingroup SpecialPage
8 * @author Petr Kadlec <mormegil@centrum.cz>
9 */
10 class SpecialListGroupRights extends SpecialPage {
11
12 var $skin;
13
14 /**
15 * Constructor
16 */
17 function __construct() {
18 global $wgUser;
19 parent::__construct( 'Listgrouprights' );
20 $this->skin = $wgUser->getSkin();
21 }
22
23 /**
24 * Show the special page
25 */
26 public function execute( $par ) {
27 global $wgOut, $wgImplicitGroups, $wgMessageCache;
28 global $wgGroupPermissions, $wgAddGroups, $wgRemoveGroups;
29 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
30 $wgMessageCache->loadAllMessages();
31
32 $this->setHeaders();
33 $this->outputHeader();
34
35 $wgOut->addHTML(
36 Xml::openElement( 'table', array( 'class' => 'mw-listgrouprights-table' ) ) .
37 '<tr>' .
38 Xml::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
39 Xml::element( 'th', null, wfMsg( 'listgrouprights-rights' ) ) .
40 '</tr>'
41 );
42
43 foreach( $wgGroupPermissions as $group => $permissions ) {
44 $groupname = ( $group == '*' ) ? 'all' : htmlspecialchars( $group ); // Replace * with a more descriptive groupname
45
46 $msg = wfMsg( 'group-' . $groupname );
47 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) || $msg == '' ) {
48 $groupnameLocalized = $groupname;
49 } else {
50 $groupnameLocalized = $msg;
51 }
52
53 $msg = wfMsgForContent( 'grouppage-' . $groupname );
54 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) || $msg == '' ) {
55 $grouppageLocalized = MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
56 } else {
57 $grouppageLocalized = $msg;
58 }
59
60 if( $group == '*' ) {
61 // Do not make a link for the generic * group
62 $grouppage = $groupnameLocalized;
63 } else {
64 $grouppage = $this->skin->makeLink( $grouppageLocalized, $groupnameLocalized );
65 }
66
67 if ( $group === 'user' ) {
68 // Link to Special:listusers for implicit group 'user'
69 $grouplink = '<br />' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Listusers' ), wfMsgHtml( 'listgrouprights-members' ), '' );
70 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
71 $grouplink = '<br />' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Listusers' ), wfMsgHtml( 'listgrouprights-members' ), 'group=' . $group );
72 } else {
73 // No link to Special:listusers for other implicit groups as they are unlistable
74 $grouplink = '';
75 }
76
77 $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
78 $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
79
80 $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
81 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
82
83 $wgOut->addHTML(
84 '<tr>
85 <td>' .
86 $grouppage . $grouplink .
87 '</td>
88 <td>' .
89 self::formatPermissions( $permissions, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf ) .
90 '</td>
91 </tr>'
92 );
93 }
94 $wgOut->addHTML(
95 Xml::closeElement( 'table' ) . "\n"
96 );
97 }
98
99 /**
100 * Create a user-readable list of permissions from the given array.
101 *
102 * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
103 * @return string List of all granted permissions, separated by comma separator
104 */
105 private static function formatPermissions( $permissions, $add, $remove, $addSelf, $removeSelf ) {
106 global $wgLang;
107 $r = array();
108 foreach( $permissions as $permission => $granted ) {
109 if ( $granted ) {
110 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
111 User::getRightDescription( $permission ),
112 $permission
113 );
114 $r[] = $description;
115 }
116 }
117 sort( $r );
118 if( $add === true ){
119 $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
120 } else if( is_array( $add ) && count( $add ) ) {
121 $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
122 }
123 if( $remove === true ){
124 $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
125 } else if( is_array( $remove ) && count( $remove ) ) {
126 $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
127 }
128 if( $addSelf === true ){
129 $r[] = wfMsgExt( 'listgrouprights-addgroup-self-all', array( 'escape' ) );
130 } else if( is_array( $addSelf ) && count( $addSelf ) ) {
131 $r[] = wfMsgExt( 'listgrouprights-addgroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), count( $addSelf ) );
132 }
133 if( $removeSelf === true ){
134 $r[] = wfMsgExt( 'listgrouprights-removegroup-self-all', array( 'escape' ) );
135 } else if( is_array( $removeSelf ) && count( $removeSelf ) ) {
136 $r[] = wfMsgExt( 'listgrouprights-removegroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), count( $removeSelf ) );
137 }
138 if( empty( $r ) ) {
139 return '';
140 } else {
141 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
142 }
143 }
144 }