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 ( $group === 'user' ) {
67 // Link to Special:listusers for implicit group 'user'
68 $grouplink = '<br />' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Listusers' ), wfMsgHtml( 'listgrouprights-members' ), '' );
69 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
70 $grouplink = '<br />' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Listusers' ), wfMsgHtml( 'listgrouprights-members' ), 'group=' . $group );
72 // No link to Special:listusers for other implicit groups as they are unlistable
76 $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
77 $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
82 $grouppage . $grouplink .
85 self::formatPermissions( $permissions, $addgroups, $removegroups ) .
91 Xml::closeElement( 'table' ) . "\n"
96 * Create a user-readable list of permissions from the given array.
98 * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
99 * @return string List of all granted permissions, separated by comma separator
101 private static function formatPermissions( $permissions, $add, $remove ) {
104 foreach( $permissions as $permission => $granted ) {
106 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
107 User::getRightDescription( $permission ),
115 $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
116 } else if( is_array( $add ) && count( $add ) ) {
117 $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
119 if( $remove === true ){
120 $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
121 } else if( is_array( $remove ) && count( $remove ) ) {
122 $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
127 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';