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, $wgAddGroups, $wgRemoveGroups;
29 $wgMessageCache->loadAllMessages();
32 $this->outputHeader();
35 Xml
::openElement( 'table', array( 'class' => 'mw-listgrouprights-table' ) ) .
37 Xml
::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
38 Xml
::element( 'th', null, wfMsg( 'listgrouprights-rights' ) ) .
42 foreach( $wgGroupPermissions as $group => $permissions ) {
43 $groupname = ( $group == '*' ) ?
'all' : htmlspecialchars( $group ); // Replace * with a more descriptive groupname
45 $msg = wfMsg( 'group-' . $groupname );
46 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) ||
$msg == '' ) {
47 $groupnameLocalized = $groupname;
49 $groupnameLocalized = $msg;
52 $msg = wfMsgForContent( 'grouppage-' . $groupname );
53 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) ||
$msg == '' ) {
54 $grouppageLocalized = MWNamespace
::getCanonicalName( NS_PROJECT
) . ':' . $groupname;
56 $grouppageLocalized = $msg;
60 // Do not make a link for the generic * group
61 $grouppage = $groupnameLocalized;
63 $grouppage = $this->skin
->makeLink( $grouppageLocalized, $groupnameLocalized );
66 if ( !in_array( $group, $wgImplicitGroups ) ) {
67 $grouplink = '<br />' . $this->skin
->makeKnownLinkObj( SpecialPage
::getTitleFor( 'Listusers' ), wfMsgHtml( 'listgrouprights-members' ), 'group=' . $group );
69 // No link to Special:listusers for implicit groups as they are unlistable
73 $addgroups = isset( $wgAddGroups[$group] ) ?
$wgAddGroups[$group] : array();
74 $removegroups = isset( $wgRemoveGroups[$group] ) ?
$wgRemoveGroups[$group] : array();
79 $grouppage . $grouplink .
82 self
::formatPermissions( $permissions, $addgroups, $removegroups ) .
88 Xml
::closeElement( 'table' ) . "\n"
93 * Create a user-readable list of permissions from the given array.
95 * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
96 * @return string List of all granted permissions, separated by comma separator
98 private static function formatPermissions( $permissions, $add, $remove ) {
101 foreach( $permissions as $permission => $granted ) {
103 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
104 User
::getRightDescription( $permission ),
112 $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
113 } else if( is_array( $add ) && count( $add ) ) {
114 $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
116 if( $remove === true ){
117 $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
118 } else if( is_array( $remove ) && count( $remove ) ) {
119 $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
124 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';