* (bug 22748) Add anchors on Special:ListGroupRights
[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 array( 'name' => $group )
68 );
69 }
70
71 if ( $group === 'user' ) {
72 // Link to Special:listusers for implicit group 'user'
73 $grouplink = '<br />' . $this->skin->link(
74 SpecialPage::getTitleFor( 'Listusers' ),
75 wfMsgHtml( 'listgrouprights-members' ),
76 array(),
77 array(),
78 array( 'known', 'noclasses' )
79 );
80 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
81 $grouplink = '<br />' . $this->skin->link(
82 SpecialPage::getTitleFor( 'Listusers' ),
83 wfMsgHtml( 'listgrouprights-members' ),
84 array(),
85 array( 'group' => $group ),
86 array( 'known', 'noclasses' )
87 );
88 } else {
89 // No link to Special:listusers for other implicit groups as they are unlistable
90 $grouplink = '';
91 }
92
93 $revoke = isset( $wgRevokePermissions[$group] ) ? $wgRevokePermissions[$group] : array();
94 $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
95 $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
96 $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
97 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
98
99 $wgOut->addHTML(
100 '<tr>
101 <td>' .
102 $grouppage . $grouplink .
103 '</td>
104 <td>' .
105 self::formatPermissions( $permissions, $revoke, $addgroups, $removegroups, $addgroupsSelf, $removegroupsSelf ) .
106 '</td>
107 </tr>'
108 );
109 }
110 $wgOut->addHTML(
111 Xml::closeElement( 'table' ) . "\n<br /><hr />\n"
112 );
113 $wgOut->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
114 }
115
116 /**
117 * Create a user-readable list of permissions from the given array.
118 *
119 * @param $permissions Array of permission => bool (from $wgGroupPermissions items)
120 * @param $revoke Array of permission => bool (from $wgRevokePermissions items)
121 * @param $add Array of groups this group is allowed to add or true
122 * @param $remove Array of groups this group is allowed to remove or true
123 * @param $addSelf Array of groups this group is allowed to add to self or true
124 * @param $removeSelf Array of group this group is allowed to remove from self or true
125 * @return string List of all granted permissions, separated by comma separator
126 */
127 private static function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
128 global $wgLang;
129
130 $r = array();
131 foreach( $permissions as $permission => $granted ) {
132 //show as granted only if it isn't revoked to prevent duplicate display of permissions
133 if( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
134 $description = wfMsgExt( 'listgrouprights-right-display', array( 'parseinline' ),
135 User::getRightDescription( $permission ),
136 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
137 );
138 $r[] = $description;
139 }
140 }
141 foreach( $revoke as $permission => $revoked ) {
142 if( $revoked ) {
143 $description = wfMsgExt( 'listgrouprights-right-revoked', array( 'parseinline' ),
144 User::getRightDescription( $permission ),
145 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
146 );
147 $r[] = $description;
148 }
149 }
150 sort( $r );
151 if( $add === true ){
152 $r[] = wfMsgExt( 'listgrouprights-addgroup-all', array( 'escape' ) );
153 } else if( is_array( $add ) && count( $add ) ) {
154 $add = array_values( array_unique( $add ) );
155 $r[] = wfMsgExt( 'listgrouprights-addgroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ), count( $add ) );
156 }
157 if( $remove === true ){
158 $r[] = wfMsgExt( 'listgrouprights-removegroup-all', array( 'escape' ) );
159 } else if( is_array( $remove ) && count( $remove ) ) {
160 $remove = array_values( array_unique( $remove ) );
161 $r[] = wfMsgExt( 'listgrouprights-removegroup', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ), count( $remove ) );
162 }
163 if( $addSelf === true ){
164 $r[] = wfMsgExt( 'listgrouprights-addgroup-self-all', array( 'escape' ) );
165 } else if( is_array( $addSelf ) && count( $addSelf ) ) {
166 $addSelf = array_values( array_unique( $addSelf ) );
167 $r[] = wfMsgExt( 'listgrouprights-addgroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ), count( $addSelf ) );
168 }
169 if( $removeSelf === true ){
170 $r[] = wfMsgExt( 'listgrouprights-removegroup-self-all', array( 'escape' ) );
171 } else if( is_array( $removeSelf ) && count( $removeSelf ) ) {
172 $removeSelf = array_values( array_unique( $removeSelf ) );
173 $r[] = wfMsgExt( 'listgrouprights-removegroup-self', array( 'parseinline' ), $wgLang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ), count( $removeSelf ) );
174 }
175 if( empty( $r ) ) {
176 return '';
177 } else {
178 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
179 }
180 }
181 }