rm unused class variable
[lhc/web/wiklou.git] / includes / specials / SpecialListgrouprights.php
1 <?php
2 /**
3 * Implements Special:Listgrouprights
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 * This special page lists all defined user groups and the associated rights.
26 * See also @ref $wgGroupPermissions.
27 *
28 * @ingroup SpecialPage
29 * @author Petr Kadlec <mormegil@centrum.cz>
30 */
31 class SpecialListGroupRights extends SpecialPage {
32
33 var $skin;
34
35 /**
36 * Constructor
37 */
38 function __construct() {
39 global $wgUser;
40 parent::__construct( 'Listgrouprights' );
41 $this->skin = $wgUser->getSkin();
42 }
43
44 /**
45 * Show the special page
46 */
47 public function execute( $par ) {
48 global $wgOut, $wgImplicitGroups;
49 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
50 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
51
52 $this->setHeaders();
53 $this->outputHeader();
54
55 $wgOut->addHTML(
56 Xml::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
57 '<tr>' .
58 Xml::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
59 Xml::element( 'th', null, wfMsg( 'listgrouprights-rights' ) ) .
60 '</tr>'
61 );
62
63 $allGroups = array_unique( array_merge(
64 array_keys( $wgGroupPermissions ),
65 array_keys( $wgRevokePermissions ),
66 array_keys( $wgAddGroups ),
67 array_keys( $wgRemoveGroups ),
68 array_keys( $wgGroupsAddToSelf ),
69 array_keys( $wgGroupsRemoveFromSelf )
70 ) );
71 asort( $allGroups );
72
73 foreach ( $allGroups as $group ) {
74 $permissions = isset( $wgGroupPermissions[$group] )
75 ? $wgGroupPermissions[$group]
76 : array();
77 $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
78 ? 'all'
79 : $group;
80
81 $msg = wfMessage( 'group-' . $groupname );
82 $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
83
84 $msg = wfMessage( 'grouppage-' . $groupname )->inContentLanguage();
85 $grouppageLocalized = !$msg->isBlank() ?
86 $msg->text() :
87 MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
88
89 if( $group == '*' ) {
90 // Do not make a link for the generic * group
91 $grouppage = htmlspecialchars( $groupnameLocalized );
92 } else {
93 $grouppage = $this->skin->link(
94 Title::newFromText( $grouppageLocalized ),
95 htmlspecialchars( $groupnameLocalized )
96 );
97 }
98
99 if ( $group === 'user' ) {
100 // Link to Special:listusers for implicit group 'user'
101 $grouplink = '<br />' . $this->skin->link(
102 SpecialPage::getTitleFor( 'Listusers' ),
103 wfMsgHtml( 'listgrouprights-members' ),
104 array(),
105 array(),
106 array( 'known', 'noclasses' )
107 );
108 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
109 $grouplink = '<br />' . $this->skin->link(
110 SpecialPage::getTitleFor( 'Listusers' ),
111 wfMsgHtml( 'listgrouprights-members' ),
112 array(),
113 array( 'group' => $group ),
114 array( 'known', 'noclasses' )
115 );
116 } else {
117 // No link to Special:listusers for other implicit groups as they are unlistable
118 $grouplink = '';
119 }
120
121 $revoke = isset( $wgRevokePermissions[$group] ) ? $wgRevokePermissions[$group] : array();
122 $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
123 $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
124 $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
125 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
126
127 $id = $group == '*' ? false : Sanitizer::escapeId( $group );
128 $wgOut->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
129 "
130 <td>$grouppage$grouplink</td>
131 <td>" .
132 self::formatPermissions( $permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf ) .
133 '</td>
134 '
135 ) );
136 }
137 $wgOut->addHTML(
138 Xml::closeElement( 'table' ) . "\n<br /><hr />\n"
139 );
140 $wgOut->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
141 }
142
143 /**
144 * Create a user-readable list of permissions from the given array.
145 *
146 * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
147 * @param $revoke Array of permission => bool (from $wgRevokePermissions items)
148 * @param $add Array of groups this group is allowed to add or true
149 * @param $remove Array of groups this group is allowed to remove or true
150 * @param $addSelf Array of groups this group is allowed to add to self or true
151 * @param $removeSelf Array of group this group is allowed to remove from self or true
152 * @return string List of all granted permissions, separated by comma separator
153 */
154 private static function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
155 global $wgLang;
156
157 $r = array();
158 foreach( $permissions as $permission => $granted ) {
159 //show as granted only if it isn't revoked to prevent duplicate display of permissions
160 if( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
161 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
162 User::getRightDescription( $permission ),
163 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
164 );
165 $r[] = $description;
166 }
167 }
168 foreach( $revoke as $permission => $revoked ) {
169 if( $revoked ) {
170 $description = wfMsgExt( 'listgrouprights-right-revoked', array( 'parseinline' ),
171 User::getRightDescription( $permission ),
172 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
173 );
174 $r[] = $description;
175 }
176 }
177 sort( $r );
178 if( $add === true ){
179 $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
180 } else if( is_array( $add ) && count( $add ) ) {
181 $add = array_values( array_unique( $add ) );
182 $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
183 }
184 if( $remove === true ){
185 $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
186 } else if( is_array( $remove ) && count( $remove ) ) {
187 $remove = array_values( array_unique( $remove ) );
188 $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
189 }
190 if( $addSelf === true ){
191 $r[] = wfMsgExt( 'listgrouprights-addgroup-self-all', array( 'escape' ) );
192 } else if( is_array( $addSelf ) && count( $addSelf ) ) {
193 $addSelf = array_values( array_unique( $addSelf ) );
194 $r[] = wfMsgExt( 'listgrouprights-addgroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), count( $addSelf ) );
195 }
196 if( $removeSelf === true ){
197 $r[] = wfMsgExt( 'listgrouprights-removegroup-self-all', array( 'escape' ) );
198 } else if( is_array( $removeSelf ) && count( $removeSelf ) ) {
199 $removeSelf = array_values( array_unique( $removeSelf ) );
200 $r[] = wfMsgExt( 'listgrouprights-removegroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), count( $removeSelf ) );
201 }
202 if( empty( $r ) ) {
203 return '';
204 } else {
205 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
206 }
207 }
208 }