Remove useless comments from search output
[mediawiki.git] / includes / specials / SpecialListgrouprights.php
blob31034f9cb2026a596fbd03309eaa5348372ee628
1 <?php
2 /**
3 * Implements Special:Listgrouprights
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 * http://www.gnu.org/copyleft/gpl.html
20 * @file
21 * @ingroup SpecialPage
24 /**
25 * This special page lists all defined user groups and the associated rights.
26 * See also @ref $wgGroupPermissions.
28 * @ingroup SpecialPage
29 * @author Petr Kadlec <mormegil@centrum.cz>
31 class SpecialListGroupRights extends SpecialPage {
32 /**
33 * Constructor
35 function __construct() {
36 parent::__construct( 'Listgrouprights' );
39 /**
40 * Show the special page
42 public function execute( $par ) {
43 global $wgImplicitGroups;
44 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
45 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
47 $this->setHeaders();
48 $this->outputHeader();
50 $out = $this->getOutput();
51 $out->addModuleStyles( 'mediawiki.special' );
53 $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
55 $out->addHTML(
56 Xml::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
57 '<tr>' .
58 Xml::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
59 Xml::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
60 '</tr>'
63 $allGroups = array_unique( array_merge(
64 array_keys( $wgGroupPermissions ),
65 array_keys( $wgRevokePermissions ),
66 array_keys( $wgAddGroups ),
67 array_keys( $wgRemoveGroups ),
68 array_keys( $wgGroupsAddToSelf ),
69 array_keys( $wgGroupsRemoveFromSelf )
70 ) );
71 asort( $allGroups );
73 foreach ( $allGroups as $group ) {
74 $permissions = isset( $wgGroupPermissions[$group] )
75 ? $wgGroupPermissions[$group]
76 : array();
77 $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
78 ? 'all'
79 : $group;
81 $msg = $this->msg( 'group-' . $groupname );
82 $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
84 $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
85 $grouppageLocalized = !$msg->isBlank() ?
86 $msg->text() :
87 MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
89 if ( $group == '*' ) {
90 // Do not make a link for the generic * group
91 $grouppage = htmlspecialchars( $groupnameLocalized );
92 } else {
93 $grouppage = Linker::link(
94 Title::newFromText( $grouppageLocalized ),
95 htmlspecialchars( $groupnameLocalized )
99 if ( $group === 'user' ) {
100 // Link to Special:listusers for implicit group 'user'
101 $grouplink = '<br />' . Linker::linkKnown(
102 SpecialPage::getTitleFor( 'Listusers' ),
103 $this->msg( 'listgrouprights-members' )->escaped()
105 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
106 $grouplink = '<br />' . Linker::linkKnown(
107 SpecialPage::getTitleFor( 'Listusers' ),
108 $this->msg( 'listgrouprights-members' )->escaped(),
109 array(),
110 array( 'group' => $group )
112 } else {
113 // No link to Special:listusers for other implicit groups as they are unlistable
114 $grouplink = '';
117 $revoke = isset( $wgRevokePermissions[$group] ) ? $wgRevokePermissions[$group] : array();
118 $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
119 $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
120 $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
121 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
123 $id = $group == '*' ? false : Sanitizer::escapeId( $group );
124 $out->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
126 <td>$grouppage$grouplink</td>
127 <td>" .
128 $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
129 $addgroupsSelf, $removegroupsSelf ) .
130 '</td>
132 ) );
134 $out->addHTML( Xml::closeElement( 'table' ) );
135 $this->outputNamespaceProtectionInfo();
138 private function outputNamespaceProtectionInfo() {
139 global $wgNamespaceProtection, $wgParser, $wgContLang;
140 $out = $this->getOutput();
142 if ( count( $wgNamespaceProtection ) == 0 ) {
143 return;
146 $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse();
147 $out->addHTML(
148 Html::rawElement( 'h2', array(), Html::element( 'span', array(
149 'class' => 'mw-headline',
150 'id' => $wgParser->guessSectionNameFromWikiText( $header )
151 ), $header ) ) .
152 Xml::openElement( 'table', array( 'class' => 'wikitable' ) ) .
153 Html::element(
154 'th',
155 array(),
156 $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text()
158 Html::element(
159 'th',
160 array(),
161 $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text()
165 ksort( $wgNamespaceProtection );
166 foreach ( $wgNamespaceProtection as $namespace => $rights ) {
167 if ( !in_array( $namespace, MWNamespace::getValidNamespaces() ) ) {
168 continue;
171 if ( $namespace == NS_MAIN ) {
172 $namespaceText = $this->msg( 'blanknamespace' )->text();
173 } else {
174 $namespaceText = $wgContLang->convertNamespace( $namespace );
177 $out->addHTML(
178 Xml::openElement( 'tr' ) .
179 Html::rawElement(
180 'td',
181 array(),
182 Linker::link(
183 SpecialPage::getTitleFor( 'Allpages' ),
184 $namespaceText,
185 array(),
186 array( 'namespace' => $namespace )
189 Xml::openElement( 'td' ) . Xml::openElement( 'ul' )
192 if ( !is_array( $rights ) ) {
193 $rights = array( $rights );
196 foreach ( $rights as $right ) {
197 $out->addHTML(
198 Html::rawElement( 'li', array(), $this->msg(
199 'listgrouprights-right-display',
200 User::getRightDescription( $right ),
201 Html::element(
202 'span',
203 array( 'class' => 'mw-listgrouprights-right-name' ),
204 $right
206 )->parse() )
210 $out->addHTML(
211 Xml::closeElement( 'ul' ) .
212 Xml::closeElement( 'td' ) .
213 Xml::closeElement( 'tr' )
216 $out->addHTML( Xml::closeElement( 'table' ) );
220 * Create a user-readable list of permissions from the given array.
222 * @param array $permissions of permission => bool (from $wgGroupPermissions items)
223 * @param array $revoke of permission => bool (from $wgRevokePermissions items)
224 * @param array $add of groups this group is allowed to add or true
225 * @param array $remove of groups this group is allowed to remove or true
226 * @param array $addSelf of groups this group is allowed to add to self or true
227 * @param array $removeSelf of group this group is allowed to remove from self or true
228 * @return string List of all granted permissions, separated by comma separator
230 private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
231 $r = array();
232 foreach ( $permissions as $permission => $granted ) {
233 //show as granted only if it isn't revoked to prevent duplicate display of permissions
234 if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
235 $description = $this->msg( 'listgrouprights-right-display',
236 User::getRightDescription( $permission ),
237 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
238 )->parse();
239 $r[] = $description;
242 foreach ( $revoke as $permission => $revoked ) {
243 if ( $revoked ) {
244 $description = $this->msg( 'listgrouprights-right-revoked',
245 User::getRightDescription( $permission ),
246 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
247 )->parse();
248 $r[] = $description;
252 sort( $r );
254 $lang = $this->getLanguage();
256 if ( $add === true ) {
257 $r[] = $this->msg( 'listgrouprights-addgroup-all' )->escaped();
258 } elseif ( is_array( $add ) && count( $add ) ) {
259 $add = array_values( array_unique( $add ) );
260 $r[] = $this->msg( 'listgrouprights-addgroup',
261 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ),
262 count( $add )
263 )->parse();
266 if ( $remove === true ) {
267 $r[] = $this->msg( 'listgrouprights-removegroup-all' )->escaped();
268 } elseif ( is_array( $remove ) && count( $remove ) ) {
269 $remove = array_values( array_unique( $remove ) );
270 $r[] = $this->msg( 'listgrouprights-removegroup',
271 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
272 count( $remove )
273 )->parse();
276 if ( $addSelf === true ) {
277 $r[] = $this->msg( 'listgrouprights-addgroup-self-all' )->escaped();
278 } elseif ( is_array( $addSelf ) && count( $addSelf ) ) {
279 $addSelf = array_values( array_unique( $addSelf ) );
280 $r[] = $this->msg( 'listgrouprights-addgroup-self',
281 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
282 count( $addSelf )
283 )->parse();
286 if ( $removeSelf === true ) {
287 $r[] = $this->msg( 'listgrouprights-removegroup-self-all' )->parse();
288 } elseif ( is_array( $removeSelf ) && count( $removeSelf ) ) {
289 $removeSelf = array_values( array_unique( $removeSelf ) );
290 $r[] = $this->msg( 'listgrouprights-removegroup-self',
291 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
292 count( $removeSelf )
293 )->parse();
296 if ( empty( $r ) ) {
297 return '';
298 } else {
299 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
303 protected function getGroupName() {
304 return 'users';