31476270b2540f10c253999f63ddeef1c2e7fd64
[lhc/web/wiklou.git] / includes / specials / 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, $wgImplicitGroups, $wgMessageCache;
28 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
29 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
30 $wgMessageCache->loadAllMessages();
31
32 $this->setHeaders();
33 $this->outputHeader();
34
35 $wgOut->addHTML(
36 Xml::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
37 '<tr>' .
38 Xml::element( 'th', null, wfMsg( 'listgrouprights-group' ) ) .
39 Xml::element( 'th', null, wfMsg( 'listgrouprights-rights' ) ) .
40 '</tr>'
41 );
42
43 foreach( $wgGroupPermissions as $group => $permissions ) {
44 $groupname = ( $group == '*' ) ? 'all' : $group; // Replace * with a more descriptive groupname
45
46 $msg = wfMsg( 'group-' . $groupname );
47 if ( wfEmptyMsg( 'group-' . $groupname, $msg ) || $msg == '' ) {
48 $groupnameLocalized = $groupname;
49 } else {
50 $groupnameLocalized = $msg;
51 }
52
53 $msg = wfMsgForContent( 'grouppage-' . $groupname );
54 if ( wfEmptyMsg( 'grouppage-' . $groupname, $msg ) || $msg == '' ) {
55 $grouppageLocalized = MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
56 } else {
57 $grouppageLocalized = $msg;
58 }
59
60 if( $group == '*' ) {
61 // Do not make a link for the generic * group
62 $grouppage = htmlspecialchars($groupnameLocalized);
63 } else {
64 $grouppage = $this->skin->link(
65 Title::newFromText( $grouppageLocalized ),
66 htmlspecialchars($groupnameLocalized)
67 );
68 }
69
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' ),
75 array(),
76 array(),
77 array( 'known', 'noclasses' )
78 );
79 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
80 $grouplink = '<br />' . $this->skin->link(
81 SpecialPage::getTitleFor( 'Listusers' ),
82 wfMsgHtml( 'listgrouprights-members' ),
83 array(),
84 array( 'group' => $group ),
85 array( 'known', 'noclasses' )
86 );
87 } else {
88 // No link to Special:listusers for other implicit groups as they are unlistable
89 $grouplink = '';
90 }
91
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();
97
98 $wgOut->addHTML(
99 '<tr>
100 <td>' .
101 $grouppage . $grouplink .
102 '</td>
103 <td>' .
104 self::formatPermissions( $permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf ) .
105 '</td>
106 </tr>'
107 );
108 }
109 $wgOut->addHTML(
110 Xml::closeElement( 'table' ) . "\n<br /><hr />\n"
111 );
112 $wgOut->addWikiMsg( 'listgrouprights-key' );
113 }
114
115 /**
116 * Create a user-readable list of permissions from the given array.
117 *
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
125 */
126 private static function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
127 global $wgLang;
128 $r = array();
129 foreach( $permissions as $permission => $granted ) {
130 if( $granted ) {
131 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
132 User::getRightDescription( $permission ),
133 $permission
134 );
135 $r[] = $description;
136 }
137 }
138 foreach( $revoke as $permission => $revoked ) {
139 if( $revoked ) {
140 $description = wfMsgExt( 'lisgrouprights-right-revoked', array( 'parseinline' ),
141 User::getRightDescription( $permission ),
142 $permission
143 );
144 $r[] = $description;
145 }
146 }
147 sort( $r );
148 if( $add === true ){
149 $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
150 } else if( is_array( $add ) && count( $add ) ) {
151 $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
152 }
153 if( $remove === true ){
154 $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
155 } else if( is_array( $remove ) && count( $remove ) ) {
156 $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
157 }
158 if( $addSelf === true ){
159 $r[] = wfMsgExt( 'listgrouprights-addgroup-self-all', array( 'escape' ) );
160 } else if( is_array( $addSelf ) && count( $addSelf ) ) {
161 $r[] = wfMsgExt( 'listgrouprights-addgroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), count( $addSelf ) );
162 }
163 if( $removeSelf === true ){
164 $r[] = wfMsgExt( 'listgrouprights-removegroup-self-all', array( 'escape' ) );
165 } else if( is_array( $removeSelf ) && count( $removeSelf ) ) {
166 $r[] = wfMsgExt( 'listgrouprights-removegroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), count( $removeSelf ) );
167 }
168 if( empty( $r ) ) {
169 return '';
170 } else {
171 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
172 }
173 }
174 }