* Remove the two hooks introduced in r52082
[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 //show as granted only if it isn't revoked to prevent duplicate display of permissions
131 if( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
132 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
133 User::getRightDescription( $permission ),
134 $permission
135 );
136 $r[] = $description;
137 }
138 }
139 foreach( $revoke as $permission => $revoked ) {
140 if( $revoked ) {
141 $description = wfMsgExt( 'listgrouprights-right-revoked', array( 'parseinline' ),
142 User::getRightDescription( $permission ),
143 $permission
144 );
145 $r[] = $description;
146 }
147 }
148 sort( $r );
149 if( $add === true ){
150 $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
151 } else if( is_array( $add ) && count( $add ) ) {
152 $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
153 }
154 if( $remove === true ){
155 $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
156 } else if( is_array( $remove ) && count( $remove ) ) {
157 $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
158 }
159 if( $addSelf === true ){
160 $r[] = wfMsgExt( 'listgrouprights-addgroup-self-all', array( 'escape' ) );
161 } else if( is_array( $addSelf ) && count( $addSelf ) ) {
162 $r[] = wfMsgExt( 'listgrouprights-addgroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), count( $addSelf ) );
163 }
164 if( $removeSelf === true ){
165 $r[] = wfMsgExt( 'listgrouprights-removegroup-self-all', array( 'escape' ) );
166 } else if( is_array( $removeSelf ) && count( $removeSelf ) ) {
167 $r[] = wfMsgExt( 'listgrouprights-removegroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), count( $removeSelf ) );
168 }
169 if( empty( $r ) ) {
170 return '';
171 } else {
172 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
173 }
174 }
175 }