MediaWiki REL1_31
SpecialListgrouprights.php
Go to the documentation of this file.
1<?php
32 public function __construct() {
33 parent::__construct( 'Listgrouprights' );
34 }
35
40 public function execute( $par ) {
41 $this->setHeaders();
42 $this->outputHeader();
43
44 $out = $this->getOutput();
45 $out->addModuleStyles( 'mediawiki.special' );
46
47 $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
48
49 $out->addHTML(
50 Xml::openElement( 'table', [ 'class' => 'wikitable mw-listgrouprights-table' ] ) .
51 '<tr>' .
52 Xml::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
53 Xml::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
54 '</tr>'
55 );
56
57 $config = $this->getConfig();
58 $groupPermissions = $config->get( 'GroupPermissions' );
59 $revokePermissions = $config->get( 'RevokePermissions' );
60 $addGroups = $config->get( 'AddGroups' );
61 $removeGroups = $config->get( 'RemoveGroups' );
62 $groupsAddToSelf = $config->get( 'GroupsAddToSelf' );
63 $groupsRemoveFromSelf = $config->get( 'GroupsRemoveFromSelf' );
64 $allGroups = array_unique( array_merge(
65 array_keys( $groupPermissions ),
66 array_keys( $revokePermissions ),
67 array_keys( $addGroups ),
68 array_keys( $removeGroups ),
69 array_keys( $groupsAddToSelf ),
70 array_keys( $groupsRemoveFromSelf )
71 ) );
72 asort( $allGroups );
73
75
76 foreach ( $allGroups as $group ) {
77 $permissions = isset( $groupPermissions[$group] )
78 ? $groupPermissions[$group]
79 : [];
80 $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
81 ? 'all'
82 : $group;
83
84 $groupnameLocalized = UserGroupMembership::getGroupName( $groupname );
85
86 $grouppageLocalizedTitle = UserGroupMembership::getGroupPage( $groupname )
87 ?: Title::newFromText( MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname );
88
89 if ( $group == '*' || !$grouppageLocalizedTitle ) {
90 // Do not make a link for the generic * group or group with invalid group page
91 $grouppage = htmlspecialchars( $groupnameLocalized );
92 } else {
93 $grouppage = $linkRenderer->makeLink(
94 $grouppageLocalizedTitle,
95 $groupnameLocalized
96 );
97 }
98
99 if ( $group === 'user' ) {
100 // Link to Special:listusers for implicit group 'user'
101 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
102 SpecialPage::getTitleFor( 'Listusers' ),
103 $this->msg( 'listgrouprights-members' )->text()
104 );
105 } elseif ( !in_array( $group, $config->get( 'ImplicitGroups' ) ) ) {
106 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
107 SpecialPage::getTitleFor( 'Listusers' ),
108 $this->msg( 'listgrouprights-members' )->text(),
109 [],
110 [ 'group' => $group ]
111 );
112 } else {
113 // No link to Special:listusers for other implicit groups as they are unlistable
114 $grouplink = '';
115 }
116
117 $revoke = isset( $revokePermissions[$group] ) ? $revokePermissions[$group] : [];
118 $addgroups = isset( $addGroups[$group] ) ? $addGroups[$group] : [];
119 $removegroups = isset( $removeGroups[$group] ) ? $removeGroups[$group] : [];
120 $addgroupsSelf = isset( $groupsAddToSelf[$group] ) ? $groupsAddToSelf[$group] : [];
121 $removegroupsSelf = isset( $groupsRemoveFromSelf[$group] )
122 ? $groupsRemoveFromSelf[$group]
123 : [];
124
125 $id = $group == '*' ? false : Sanitizer::escapeIdForAttribute( $group );
126 $out->addHTML( Html::rawElement( 'tr', [ 'id' => $id ], "
127 <td>$grouppage$grouplink</td>
128 <td>" .
129 $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
130 $addgroupsSelf, $removegroupsSelf ) .
131 '</td>
132 '
133 ) );
134 }
135 $out->addHTML( Xml::closeElement( 'table' ) );
137 }
138
139 private function outputNamespaceProtectionInfo() {
140 global $wgContLang;
141 $out = $this->getOutput();
142 $namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
143
144 if ( count( $namespaceProtection ) == 0 ) {
145 return;
146 }
147
148 $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->text();
149 $out->addHTML(
150 Html::rawElement( 'h2', [], Html::element( 'span', [
151 'class' => 'mw-headline',
152 'id' => substr( Parser::guessSectionNameFromStrippedText( $header ), 1 )
153 ], $header ) ) .
154 Xml::openElement( 'table', [ 'class' => 'wikitable' ] ) .
155 Html::element(
156 'th',
157 [],
158 $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text()
159 ) .
160 Html::element(
161 'th',
162 [],
163 $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text()
164 )
165 );
167 ksort( $namespaceProtection );
168 foreach ( $namespaceProtection as $namespace => $rights ) {
169 if ( !in_array( $namespace, MWNamespace::getValidNamespaces() ) ) {
170 continue;
171 }
172
173 if ( $namespace == NS_MAIN ) {
174 $namespaceText = $this->msg( 'blanknamespace' )->text();
175 } else {
176 $namespaceText = $wgContLang->convertNamespace( $namespace );
177 }
178
179 $out->addHTML(
180 Xml::openElement( 'tr' ) .
181 Html::rawElement(
182 'td',
183 [],
184 $linkRenderer->makeLink(
185 SpecialPage::getTitleFor( 'Allpages' ),
186 $namespaceText,
187 [],
188 [ 'namespace' => $namespace ]
189 )
190 ) .
191 Xml::openElement( 'td' ) . Xml::openElement( 'ul' )
192 );
193
194 if ( !is_array( $rights ) ) {
195 $rights = [ $rights ];
196 }
197
198 foreach ( $rights as $right ) {
199 $out->addHTML(
200 Html::rawElement( 'li', [], $this->msg(
201 'listgrouprights-right-display',
203 Html::element(
204 'span',
205 [ 'class' => 'mw-listgrouprights-right-name' ],
206 $right
207 )
208 )->parse() )
209 );
210 }
211
212 $out->addHTML(
213 Xml::closeElement( 'ul' ) .
214 Xml::closeElement( 'td' ) .
215 Xml::closeElement( 'tr' )
216 );
217 }
218 $out->addHTML( Xml::closeElement( 'table' ) );
219 }
220
232 private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
233 $r = [];
234 foreach ( $permissions as $permission => $granted ) {
235 // show as granted only if it isn't revoked to prevent duplicate display of permissions
236 if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
237 $r[] = $this->msg( 'listgrouprights-right-display',
238 User::getRightDescription( $permission ),
239 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
240 )->parse();
241 }
242 }
243 foreach ( $revoke as $permission => $revoked ) {
244 if ( $revoked ) {
245 $r[] = $this->msg( 'listgrouprights-right-revoked',
246 User::getRightDescription( $permission ),
247 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
248 )->parse();
249 }
250 }
251
252 sort( $r );
253
254 $lang = $this->getLanguage();
255 $allGroups = User::getAllGroups();
256
257 $changeGroups = [
258 'addgroup' => $add,
259 'removegroup' => $remove,
260 'addgroup-self' => $addSelf,
261 'removegroup-self' => $removeSelf
262 ];
263
264 foreach ( $changeGroups as $messageKey => $changeGroup ) {
265 if ( $changeGroup === true ) {
266 // For grep: listgrouprights-addgroup-all, listgrouprights-removegroup-all,
267 // listgrouprights-addgroup-self-all, listgrouprights-removegroup-self-all
268 $r[] = $this->msg( 'listgrouprights-' . $messageKey . '-all' )->escaped();
269 } elseif ( is_array( $changeGroup ) ) {
270 $changeGroup = array_intersect( array_values( array_unique( $changeGroup ) ), $allGroups );
271 if ( count( $changeGroup ) ) {
272 $groupLinks = [];
273 foreach ( $changeGroup as $group ) {
274 $groupLinks[] = UserGroupMembership::getLink( $group, $this->getContext(), 'wiki' );
275 }
276 // For grep: listgrouprights-addgroup, listgrouprights-removegroup,
277 // listgrouprights-addgroup-self, listgrouprights-removegroup-self
278 $r[] = $this->msg( 'listgrouprights-' . $messageKey,
279 $lang->listToText( $groupLinks ), count( $changeGroup ) )->parse();
280 }
281 }
282 }
283
284 if ( empty( $r ) ) {
285 return '';
286 } else {
287 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
288 }
289 }
290
291 protected function getGroupName() {
292 return 'users';
293 }
294}
This special page lists all defined user groups and the associated rights.
execute( $par)
Show the special page.
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf)
Create a user-readable list of permissions from the given array.
Parent class for all special pages.
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
getOutput()
Get the OutputPage being used for this instance.
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name If you don't need a full Title object,...
getContext()
Gets the context this SpecialPage is executed in.
msg( $key)
Wrapper around wfMessage that sets the current context.
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
MediaWiki Linker LinkRenderer null $linkRenderer
static getAllGroups()
Return the set of defined explicit groups.
Definition User.php:5099
static getRightDescription( $right)
Get the description of a given right.
Definition User.php:5418
this class mediates it Skin Encapsulates a look and feel for the wiki All of the functions that render HTML and make choices about how to render it are here and are called from various other places when and is meant to be subclassed with other skins that may override some of its functions The User object contains a reference to a and so rather than having a global skin object we just rely on the global User and get the skin with $wgUser and also has some character encoding functions and other locale stuff The current user interface language is instantiated as and the local content language as $wgContLang
Definition design.txt:57
design txt This is a brief overview of the new design More thorough and up to date information is available on the documentation wiki at etc Handles the details of getting and saving to the user table of the and dealing with sessions and cookies OutputPage Encapsulates the entire HTML page that will be sent in response to any server request It is used by calling its functions to add text
Definition design.txt:18
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that probably a stub it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
Definition hooks.txt:864
processing should stop and the error should be shown to the user * false
Definition hooks.txt:187
const NS_MAIN
Definition Defines.php:74
const NS_PROJECT
Definition Defines.php:78
if(!isset( $args[0])) $lang
$header