Remove term from search results info
[mediawiki.git] / includes / specials / SpecialListgrouprights.php
blobb5818eab453ecfc6fd71f55913e5baf76a11f48b
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 function __construct() {
33 parent::__construct( 'Listgrouprights' );
36 /**
37 * Show the special page
38 * @param string|null $par
40 public function execute( $par ) {
41 global $wgImplicitGroups;
42 global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
43 global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
45 $this->setHeaders();
46 $this->outputHeader();
48 $out = $this->getOutput();
49 $out->addModuleStyles( 'mediawiki.special' );
51 $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
53 $out->addHTML(
54 Xml::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
55 '<tr>' .
56 Xml::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
57 Xml::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
58 '</tr>'
61 $allGroups = array_unique( array_merge(
62 array_keys( $wgGroupPermissions ),
63 array_keys( $wgRevokePermissions ),
64 array_keys( $wgAddGroups ),
65 array_keys( $wgRemoveGroups ),
66 array_keys( $wgGroupsAddToSelf ),
67 array_keys( $wgGroupsRemoveFromSelf )
68 ) );
69 asort( $allGroups );
71 foreach ( $allGroups as $group ) {
72 $permissions = isset( $wgGroupPermissions[$group] )
73 ? $wgGroupPermissions[$group]
74 : array();
75 $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
76 ? 'all'
77 : $group;
79 $msg = $this->msg( 'group-' . $groupname );
80 $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
82 $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
83 $grouppageLocalized = !$msg->isBlank() ?
84 $msg->text() :
85 MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
87 if ( $group == '*' ) {
88 // Do not make a link for the generic * group
89 $grouppage = htmlspecialchars( $groupnameLocalized );
90 } else {
91 $grouppage = Linker::link(
92 Title::newFromText( $grouppageLocalized ),
93 htmlspecialchars( $groupnameLocalized )
97 if ( $group === 'user' ) {
98 // Link to Special:listusers for implicit group 'user'
99 $grouplink = '<br />' . Linker::linkKnown(
100 SpecialPage::getTitleFor( 'Listusers' ),
101 $this->msg( 'listgrouprights-members' )->escaped()
103 } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
104 $grouplink = '<br />' . Linker::linkKnown(
105 SpecialPage::getTitleFor( 'Listusers' ),
106 $this->msg( 'listgrouprights-members' )->escaped(),
107 array(),
108 array( 'group' => $group )
110 } else {
111 // No link to Special:listusers for other implicit groups as they are unlistable
112 $grouplink = '';
115 $revoke = isset( $wgRevokePermissions[$group] ) ? $wgRevokePermissions[$group] : array();
116 $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
117 $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
118 $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
119 $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] )
120 ? $wgGroupsRemoveFromSelf[$group]
121 : array();
123 $id = $group == '*' ? false : Sanitizer::escapeId( $group );
124 $out->addHTML( Html::rawElement( 'tr', array( 'id' => $id ), "
125 <td>$grouppage$grouplink</td>
126 <td>" .
127 $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
128 $addgroupsSelf, $removegroupsSelf ) .
129 '</td>
131 ) );
133 $out->addHTML( Xml::closeElement( 'table' ) );
134 $this->outputNamespaceProtectionInfo();
137 private function outputNamespaceProtectionInfo() {
138 global $wgNamespaceProtection, $wgParser, $wgContLang;
139 $out = $this->getOutput();
141 if ( count( $wgNamespaceProtection ) == 0 ) {
142 return;
145 $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse();
146 $out->addHTML(
147 Html::rawElement( 'h2', array(), Html::element( 'span', array(
148 'class' => 'mw-headline',
149 'id' => $wgParser->guessSectionNameFromWikiText( $header )
150 ), $header ) ) .
151 Xml::openElement( 'table', array( 'class' => 'wikitable' ) ) .
152 Html::element(
153 'th',
154 array(),
155 $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text()
157 Html::element(
158 'th',
159 array(),
160 $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text()
164 ksort( $wgNamespaceProtection );
165 foreach ( $wgNamespaceProtection as $namespace => $rights ) {
166 if ( !in_array( $namespace, MWNamespace::getValidNamespaces() ) ) {
167 continue;
170 if ( $namespace == NS_MAIN ) {
171 $namespaceText = $this->msg( 'blanknamespace' )->text();
172 } else {
173 $namespaceText = $wgContLang->convertNamespace( $namespace );
176 $out->addHTML(
177 Xml::openElement( 'tr' ) .
178 Html::rawElement(
179 'td',
180 array(),
181 Linker::link(
182 SpecialPage::getTitleFor( 'Allpages' ),
183 $namespaceText,
184 array(),
185 array( 'namespace' => $namespace )
188 Xml::openElement( 'td' ) . Xml::openElement( 'ul' )
191 if ( !is_array( $rights ) ) {
192 $rights = array( $rights );
195 foreach ( $rights as $right ) {
196 $out->addHTML(
197 Html::rawElement( 'li', array(), $this->msg(
198 'listgrouprights-right-display',
199 User::getRightDescription( $right ),
200 Html::element(
201 'span',
202 array( 'class' => 'mw-listgrouprights-right-name' ),
203 $right
205 )->parse() )
209 $out->addHTML(
210 Xml::closeElement( 'ul' ) .
211 Xml::closeElement( 'td' ) .
212 Xml::closeElement( 'tr' )
215 $out->addHTML( Xml::closeElement( 'table' ) );
219 * Create a user-readable list of permissions from the given array.
221 * @param array $permissions Array of permission => bool (from $wgGroupPermissions items)
222 * @param array $revoke Array of permission => bool (from $wgRevokePermissions items)
223 * @param array $add Array of groups this group is allowed to add or true
224 * @param array $remove Array of groups this group is allowed to remove or true
225 * @param array $addSelf Array of groups this group is allowed to add to self or true
226 * @param array $removeSelf Array of group this group is allowed to remove from self or true
227 * @return string List of all granted permissions, separated by comma separator
229 private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
230 $r = array();
231 foreach ( $permissions as $permission => $granted ) {
232 //show as granted only if it isn't revoked to prevent duplicate display of permissions
233 if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
234 $description = $this->msg( 'listgrouprights-right-display',
235 User::getRightDescription( $permission ),
236 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
237 )->parse();
238 $r[] = $description;
241 foreach ( $revoke as $permission => $revoked ) {
242 if ( $revoked ) {
243 $description = $this->msg( 'listgrouprights-right-revoked',
244 User::getRightDescription( $permission ),
245 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
246 )->parse();
247 $r[] = $description;
251 sort( $r );
253 $lang = $this->getLanguage();
255 if ( $add === true ) {
256 $r[] = $this->msg( 'listgrouprights-addgroup-all' )->escaped();
257 } elseif ( is_array( $add ) && count( $add ) ) {
258 $add = array_values( array_unique( $add ) );
259 $r[] = $this->msg( 'listgrouprights-addgroup',
260 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ),
261 count( $add )
262 )->parse();
265 if ( $remove === true ) {
266 $r[] = $this->msg( 'listgrouprights-removegroup-all' )->escaped();
267 } elseif ( is_array( $remove ) && count( $remove ) ) {
268 $remove = array_values( array_unique( $remove ) );
269 $r[] = $this->msg( 'listgrouprights-removegroup',
270 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
271 count( $remove )
272 )->parse();
275 if ( $addSelf === true ) {
276 $r[] = $this->msg( 'listgrouprights-addgroup-self-all' )->escaped();
277 } elseif ( is_array( $addSelf ) && count( $addSelf ) ) {
278 $addSelf = array_values( array_unique( $addSelf ) );
279 $r[] = $this->msg( 'listgrouprights-addgroup-self',
280 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
281 count( $addSelf )
282 )->parse();
285 if ( $removeSelf === true ) {
286 $r[] = $this->msg( 'listgrouprights-removegroup-self-all' )->parse();
287 } elseif ( is_array( $removeSelf ) && count( $removeSelf ) ) {
288 $removeSelf = array_values( array_unique( $removeSelf ) );
289 $r[] = $this->msg( 'listgrouprights-removegroup-self',
290 $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
291 count( $removeSelf )
292 )->parse();
295 if ( empty( $r ) ) {
296 return '';
297 } else {
298 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
302 protected function getGroupName() {
303 return 'users';