4 * This special page lists all defined user groups and the associated rights.
5 * See also @ref $wgGroupPermissions.
8 * @author Petr Kadlec <mormegil@centrum.cz>
10 class SpecialListGroupRights
extends SpecialPage
{
17 function __construct() {
19 parent
::__construct( 'Listgrouprights' );
20 $this->skin
= $wgUser->getSkin();
24 * Show the special page
26 public function execute( $par ) {
27 global $wgOut, $wgImplicitGroups, $wgMessageCache;
28 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
29 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
30 $wgMessageCache->loadAllMessages();
33 $this->outputHeader();
36 Xml
::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
38 Xml
::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
39 Xml
::element( 'th', null, wfMsg( 'listgrouprights-rights' ) ) .
43 foreach( $wgGroupPermissions as $group => $permissions ) {
44 $groupname = ( $group == '*' ) ?
'all' : $group; // Replace * with a more descriptive groupname
46 $msg = wfMsg( 'group-' . $groupname );
47 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) ||
$msg == '' ) {
48 $groupnameLocalized = $groupname;
50 $groupnameLocalized = $msg;
53 $msg = wfMsgForContent( 'grouppage-' . $groupname );
54 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) ||
$msg == '' ) {
55 $grouppageLocalized = MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $groupname;
57 $grouppageLocalized = $msg;
61 // Do not make a link for the generic * group
62 $grouppage = htmlspecialchars($groupnameLocalized);
64 $grouppage = $this->skin
->link(
65 Title
::newFromText( $grouppageLocalized ),
66 htmlspecialchars($groupnameLocalized)
70 if ( $group === 'user' ) {
71 // Link to Special:listusers for implicit group 'user'
72 $grouplink = '<br />' . $this->skin
->link(
73 SpecialPage
::getTitleFor( 'Listusers' ),
74 wfMsgHtml( 'listgrouprights-members' ),
77 array( 'known', 'noclasses' )
79 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
80 $grouplink = '<br />' . $this->skin
->link(
81 SpecialPage
::getTitleFor( 'Listusers' ),
82 wfMsgHtml( 'listgrouprights-members' ),
84 array( 'group' => $group ),
85 array( 'known', 'noclasses' )
88 // No link to Special:listusers for other implicit groups as they are unlistable
92 $revoke = isset( $wgRevokePermissions[$group] ) ?
$wgRevokePermissions[$group] : array();
93 $addgroups = isset( $wgAddGroups[$group] ) ?
$wgAddGroups[$group] : array();
94 $removegroups = isset( $wgRemoveGroups[$group] ) ?
$wgRemoveGroups[$group] : array();
95 $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ?
$wgGroupsAddToSelf[$group] : array();
96 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ?
$wgGroupsRemoveFromSelf[$group] : array();
101 $grouppage . $grouplink .
104 self
::formatPermissions( $permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf ) .
110 Xml
::closeElement( 'table' ) . "\n<br /><hr />\n"
112 $wgOut->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
116 * Create a user-readable list of permissions from the given array.
118 * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
119 * @param $revoke Array of permission => bool (from $wgRevokePermissions items)
120 * @param $add Array of groups this group is allowed to add or true
121 * @param $remove Array of groups this group is allowed to remove or true
122 * @param $addSelf Array of groups this group is allowed to add to self or true
123 * @param $removeSelf Array of group this group is allowed to remove from self or true
124 * @return string List of all granted permissions, separated by comma separator
126 private static function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
130 foreach( $permissions as $permission => $granted ) {
131 //show as granted only if it isn't revoked to prevent duplicate display of permissions
132 if( $granted && ( !isset( $revoke[$permission] ) ||
!$revoke[$permission] ) ) {
133 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
134 User
::getRightDescription( $permission ),
135 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
140 foreach( $revoke as $permission => $revoked ) {
142 $description = wfMsgExt( 'listgrouprights-right-revoked', array( 'parseinline' ),
143 User
::getRightDescription( $permission ),
144 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
151 $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
152 } else if( is_array( $add ) && count( $add ) ) {
153 $add = array_unique( $add );
154 $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
156 if( $remove === true ){
157 $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
158 } else if( is_array( $remove ) && count( $remove ) ) {
159 $remove = array_unique( $remove );
160 $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
162 if( $addSelf === true ){
163 $r[] = wfMsgExt( 'listgrouprights-addgroup-self-all', array( 'escape' ) );
164 } else if( is_array( $addSelf ) && count( $addSelf ) ) {
165 $addSelf = array_unique( $addSelf );
166 $r[] = wfMsgExt( 'listgrouprights-addgroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), count( $addSelf ) );
168 if( $removeSelf === true ){
169 $r[] = wfMsgExt( 'listgrouprights-removegroup-self-all', array( 'escape' ) );
170 } else if( is_array( $removeSelf ) && count( $removeSelf ) ) {
171 $removeSelf = array_unique( $removeSelf );
172 $r[] = wfMsgExt( 'listgrouprights-removegroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), count( $removeSelf ) );
177 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';