3 * Implements Special:Listgrouprights
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.
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.
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
21 * @ingroup SpecialPage
25 * This special page lists all defined user groups and the associated rights.
26 * See also @ref $wgGroupPermissions.
28 * @ingroup SpecialPage
29 * @author Petr Kadlec <mormegil@centrum.cz>
31 class SpecialListGroupRights
extends SpecialPage
{
38 function __construct() {
40 parent
::__construct( 'Listgrouprights' );
41 $this->skin
= $wgUser->getSkin();
45 * Show the special page
47 public function execute( $par ) {
48 global $wgOut, $wgImplicitGroups;
49 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
50 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
53 $this->outputHeader();
56 Xml
::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
58 Xml
::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
59 Xml
::element( 'th', null, wfMsg( 'listgrouprights-rights' ) ) .
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 )
73 foreach ( $allGroups as $group ) {
74 $permissions = isset( $wgGroupPermissions[$group] )
75 ?
$wgGroupPermissions[$group]
77 $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
81 $msg = wfMsg( 'group-' . $groupname );
82 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) ||
$msg == '' ) {
83 $groupnameLocalized = $groupname;
85 $groupnameLocalized = $msg;
88 $msg = wfMsgForContent( 'grouppage-' . $groupname );
89 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) ||
$msg == '' ) {
90 $grouppageLocalized = MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $groupname;
92 $grouppageLocalized = $msg;
96 // Do not make a link for the generic * group
97 $grouppage = htmlspecialchars( $groupnameLocalized );
99 $grouppage = $this->skin
->link(
100 Title
::newFromText( $grouppageLocalized ),
101 htmlspecialchars( $groupnameLocalized )
105 if ( $group === 'user' ) {
106 // Link to Special:listusers for implicit group 'user'
107 $grouplink = '<br />' . $this->skin
->link(
108 SpecialPage
::getTitleFor( 'Listusers' ),
109 wfMsgHtml( 'listgrouprights-members' ),
112 array( 'known', 'noclasses' )
114 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
115 $grouplink = '<br />' . $this->skin
->link(
116 SpecialPage
::getTitleFor( 'Listusers' ),
117 wfMsgHtml( 'listgrouprights-members' ),
119 array( 'group' => $group ),
120 array( 'known', 'noclasses' )
123 // No link to Special:listusers for other implicit groups as they are unlistable
127 $revoke = isset( $wgRevokePermissions[$group] ) ?
$wgRevokePermissions[$group] : array();
128 $addgroups = isset( $wgAddGroups[$group] ) ?
$wgAddGroups[$group] : array();
129 $removegroups = isset( $wgRemoveGroups[$group] ) ?
$wgRemoveGroups[$group] : array();
130 $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ?
$wgGroupsAddToSelf[$group] : array();
131 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ?
$wgGroupsRemoveFromSelf[$group] : array();
133 $id = $group == '*' ?
false : Sanitizer
::escapeId( $group );
134 $wgOut->addHTML( Html
::rawElement( 'tr', array( 'id' => $id ),
136 <td>$grouppage$grouplink</td>
138 self
::formatPermissions( $permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf ) .
144 Xml
::closeElement( 'table' ) . "\n<br /><hr />\n"
146 $wgOut->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
150 * Create a user-readable list of permissions from the given array.
152 * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
153 * @param $revoke Array of permission => bool (from $wgRevokePermissions items)
154 * @param $add Array of groups this group is allowed to add or true
155 * @param $remove Array of groups this group is allowed to remove or true
156 * @param $addSelf Array of groups this group is allowed to add to self or true
157 * @param $removeSelf Array of group this group is allowed to remove from self or true
158 * @return string List of all granted permissions, separated by comma separator
160 private static function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
164 foreach( $permissions as $permission => $granted ) {
165 //show as granted only if it isn't revoked to prevent duplicate display of permissions
166 if( $granted && ( !isset( $revoke[$permission] ) ||
!$revoke[$permission] ) ) {
167 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
168 User
::getRightDescription( $permission ),
169 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
174 foreach( $revoke as $permission => $revoked ) {
176 $description = wfMsgExt( 'listgrouprights-right-revoked', array( 'parseinline' ),
177 User
::getRightDescription( $permission ),
178 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
185 $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
186 } else if( is_array( $add ) && count( $add ) ) {
187 $add = array_values( array_unique( $add ) );
188 $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
190 if( $remove === true ){
191 $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
192 } else if( is_array( $remove ) && count( $remove ) ) {
193 $remove = array_values( array_unique( $remove ) );
194 $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
196 if( $addSelf === true ){
197 $r[] = wfMsgExt( 'listgrouprights-addgroup-self-all', array( 'escape' ) );
198 } else if( is_array( $addSelf ) && count( $addSelf ) ) {
199 $addSelf = array_values( array_unique( $addSelf ) );
200 $r[] = wfMsgExt( 'listgrouprights-addgroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), count( $addSelf ) );
202 if( $removeSelf === true ){
203 $r[] = wfMsgExt( 'listgrouprights-removegroup-self-all', array( 'escape' ) );
204 } else if( is_array( $removeSelf ) && count( $removeSelf ) ) {
205 $removeSelf = array_values( array_unique( $removeSelf ) );
206 $r[] = wfMsgExt( 'listgrouprights-removegroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), count( $removeSelf ) );
211 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';