Add the other existing $skin.css/.js to the message files too to be consistent
[lhc/web/wiklou.git] / includes / SpecialListgrouprights.php
1 <?php
2
3 /**
4 * This special page lists all defined user groups and the associated rights.
5 * See also @ref $wgGroupPermissions.
6 *
7 * @ingroup SpecialPage
8 * @author Petr Kadlec <mormegil@centrum.cz>
9 */
10 class SpecialListGroupRights extends SpecialPage {
11
12 var $skin;
13
14 /**
15 * Constructor
16 */
17 function __construct() {
18 global $wgUser;
19 parent::__construct( 'Listgrouprights' );
20 $this->skin = $wgUser->getSkin();
21 }
22
23 /**
24 * Show the special page
25 */
26 public function execute( $par ) {
27 global $wgOut, $wgGroupPermissions, $wgImplicitGroups, $wgMessageCache;
28 $wgMessageCache->loadAllMessages();
29
30 $this->setHeaders();
31 $this->outputHeader();
32
33 $wgOut->addHTML(
34 Xml::openElement( 'table', array( 'class' => 'mw-listgrouprights-table' ) ) .
35 '<tr>' .
36 Xml::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
37 Xml::element( 'th', null, wfMsg( 'listgrouprights-rights' ) ) .
38 '</tr>'
39 );
40
41 foreach( $wgGroupPermissions as $group => $permissions ) {
42 $groupname = ( $group == '*' ) ? 'all' : htmlspecialchars( $group ); // Replace * with a more descriptive groupname
43
44 $msg = wfMsg( 'group-' . $groupname );
45 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) || $msg == '' ) {
46 $groupnameLocalized = $groupname;
47 } else {
48 $groupnameLocalized = $msg;
49 }
50
51 $msg = wfMsgForContent( 'grouppage-' . $groupname );
52 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) || $msg == '' ) {
53 $grouppageLocalized = MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
54 } else {
55 $grouppageLocalized = $msg;
56 }
57
58 if( $group == '*' ) {
59 // Do not make a link for the generic * group
60 $grouppage = $groupnameLocalized;
61 } else {
62 $grouppage = $this->skin->makeLink( $grouppageLocalized, $groupnameLocalized );
63 }
64
65 if ( !in_array( $group, $wgImplicitGroups ) ) {
66 $grouplink = '<br />' . $this->skin->makeKnownLinkObj( SpecialPage::getTitleFor( 'Listusers' ), wfMsgHtml( 'listgrouprights-members' ), 'group=' . $group );
67 } else {
68 // No link to Special:listusers for implicit groups as they are unlistable
69 $grouplink = '';
70 }
71
72 $wgOut->addHTML(
73 '<tr>
74 <td>' .
75 $grouppage . $grouplink .
76 '</td>
77 <td>' .
78 self::formatPermissions( $permissions ) .
79 '</td>
80 </tr>'
81 );
82 }
83 $wgOut->addHTML(
84 Xml::closeElement( 'table' ) . "\n"
85 );
86 }
87
88 /**
89 * Create a user-readable list of permissions from the given array.
90 *
91 * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
92 * @return string List of all granted permissions, separated by comma separator
93 */
94 private static function formatPermissions( $permissions ) {
95 $r = array();
96 foreach( $permissions as $permission => $granted ) {
97 if ( $granted ) {
98 $description = wfMsgHTML( 'listgrouprights-right-display',
99 User::getRightDescription($permission),
100 $permission
101 );
102 $r[] = $description;
103 }
104 }
105 sort( $r );
106 if( empty( $r ) ) {
107 return '';
108 } else {
109 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
110 }
111 }
112 }