MediaWiki REL1_29
SpecialListgrouprights.php
Go to the documentation of this file.
1<?php
32 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 $msg = $this->msg( 'group-' . $groupname );
85 $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
86
87 $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
88 $grouppageLocalized = !$msg->isBlank() ?
89 $msg->text() :
90 MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
91 $grouppageLocalizedTitle = Title::newFromText( $grouppageLocalized );
92
93 if ( $group == '*' || !$grouppageLocalizedTitle ) {
94 // Do not make a link for the generic * group or group with invalid group page
95 $grouppage = htmlspecialchars( $groupnameLocalized );
96 } else {
97 $grouppage = $linkRenderer->makeLink(
98 $grouppageLocalizedTitle,
99 $groupnameLocalized
100 );
101 }
102
103 if ( $group === 'user' ) {
104 // Link to Special:listusers for implicit group 'user'
105 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
106 SpecialPage::getTitleFor( 'Listusers' ),
107 $this->msg( 'listgrouprights-members' )->text()
108 );
109 } elseif ( !in_array( $group, $config->get( 'ImplicitGroups' ) ) ) {
110 $grouplink = '<br />' . $linkRenderer->makeKnownLink(
111 SpecialPage::getTitleFor( 'Listusers' ),
112 $this->msg( 'listgrouprights-members' )->text(),
113 [],
114 [ 'group' => $group ]
115 );
116 } else {
117 // No link to Special:listusers for other implicit groups as they are unlistable
118 $grouplink = '';
119 }
120
121 $revoke = isset( $revokePermissions[$group] ) ? $revokePermissions[$group] : [];
122 $addgroups = isset( $addGroups[$group] ) ? $addGroups[$group] : [];
123 $removegroups = isset( $removeGroups[$group] ) ? $removeGroups[$group] : [];
124 $addgroupsSelf = isset( $groupsAddToSelf[$group] ) ? $groupsAddToSelf[$group] : [];
125 $removegroupsSelf = isset( $groupsRemoveFromSelf[$group] )
126 ? $groupsRemoveFromSelf[$group]
127 : [];
128
129 $id = $group == '*' ? false : Sanitizer::escapeId( $group );
130 $out->addHTML( Html::rawElement( 'tr', [ 'id' => $id ], "
131 <td>$grouppage$grouplink</td>
132 <td>" .
133 $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
134 $addgroupsSelf, $removegroupsSelf ) .
135 '</td>
136 '
137 ) );
138 }
139 $out->addHTML( Xml::closeElement( 'table' ) );
141 }
142
143 private function outputNamespaceProtectionInfo() {
145 $out = $this->getOutput();
146 $namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
147
148 if ( count( $namespaceProtection ) == 0 ) {
149 return;
150 }
151
152 $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse();
153 $out->addHTML(
154 Html::rawElement( 'h2', [], Html::element( 'span', [
155 'class' => 'mw-headline',
156 'id' => $wgParser->guessSectionNameFromWikiText( $header )
157 ], $header ) ) .
158 Xml::openElement( 'table', [ 'class' => 'wikitable' ] ) .
159 Html::element(
160 'th',
161 [],
162 $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text()
163 ) .
164 Html::element(
165 'th',
166 [],
167 $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text()
168 )
169 );
171 ksort( $namespaceProtection );
172 foreach ( $namespaceProtection as $namespace => $rights ) {
173 if ( !in_array( $namespace, MWNamespace::getValidNamespaces() ) ) {
174 continue;
175 }
176
177 if ( $namespace == NS_MAIN ) {
178 $namespaceText = $this->msg( 'blanknamespace' )->text();
179 } else {
180 $namespaceText = $wgContLang->convertNamespace( $namespace );
181 }
182
183 $out->addHTML(
184 Xml::openElement( 'tr' ) .
185 Html::rawElement(
186 'td',
187 [],
188 $linkRenderer->makeLink(
189 SpecialPage::getTitleFor( 'Allpages' ),
190 $namespaceText,
191 [],
192 [ 'namespace' => $namespace ]
193 )
194 ) .
195 Xml::openElement( 'td' ) . Xml::openElement( 'ul' )
196 );
197
198 if ( !is_array( $rights ) ) {
199 $rights = [ $rights ];
200 }
201
202 foreach ( $rights as $right ) {
203 $out->addHTML(
204 Html::rawElement( 'li', [], $this->msg(
205 'listgrouprights-right-display',
206 User::getRightDescription( $right ),
207 Html::element(
208 'span',
209 [ 'class' => 'mw-listgrouprights-right-name' ],
210 $right
211 )
212 )->parse() )
213 );
214 }
215
216 $out->addHTML(
217 Xml::closeElement( 'ul' ) .
218 Xml::closeElement( 'td' ) .
219 Xml::closeElement( 'tr' )
220 );
221 }
222 $out->addHTML( Xml::closeElement( 'table' ) );
223 }
224
236 private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
237 $r = [];
238 foreach ( $permissions as $permission => $granted ) {
239 // show as granted only if it isn't revoked to prevent duplicate display of permissions
240 if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
241 $r[] = $this->msg( 'listgrouprights-right-display',
242 User::getRightDescription( $permission ),
243 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
244 )->parse();
245 }
246 }
247 foreach ( $revoke as $permission => $revoked ) {
248 if ( $revoked ) {
249 $r[] = $this->msg( 'listgrouprights-right-revoked',
250 User::getRightDescription( $permission ),
251 '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
252 )->parse();
253 }
254 }
255
256 sort( $r );
257
258 $lang = $this->getLanguage();
259 $allGroups = User::getAllGroups();
260
261 $changeGroups = [
262 'addgroup' => $add,
263 'removegroup' => $remove,
264 'addgroup-self' => $addSelf,
265 'removegroup-self' => $removeSelf
266 ];
267
268 foreach ( $changeGroups as $messageKey => $changeGroup ) {
269 if ( $changeGroup === true ) {
270 // For grep: listgrouprights-addgroup-all, listgrouprights-removegroup-all,
271 // listgrouprights-addgroup-self-all, listgrouprights-removegroup-self-all
272 $r[] = $this->msg( 'listgrouprights-' . $messageKey . '-all' )->escaped();
273 } elseif ( is_array( $changeGroup ) ) {
274 $changeGroup = array_intersect( array_values( array_unique( $changeGroup ) ), $allGroups );
275 if ( count( $changeGroup ) ) {
276 $groupLinks = [];
277 foreach ( $changeGroup as $group ) {
278 $groupLinks[] = UserGroupMembership::getLink( $group, $this->getContext(), 'wiki' );
279 }
280 // For grep: listgrouprights-addgroup, listgrouprights-removegroup,
281 // listgrouprights-addgroup-self, listgrouprights-removegroup-self
282 $r[] = $this->msg( 'listgrouprights-' . $messageKey,
283 $lang->listToText( $groupLinks ), count( $changeGroup ) )->parse();
284 }
285 }
286 }
287
288 if ( empty( $r ) ) {
289 return '';
290 } else {
291 return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
292 }
293 }
294
295 protected function getGroupName() {
296 return 'users';
297 }
298}
$wgParser
Definition Setup.php:796
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.
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
msg()
Wrapper around wfMessage that sets the current context.
MediaWiki Linker LinkRenderer null $linkRenderer
static getLink( $ugm, IContextSource $context, $format, $userName=null)
Gets a link for a user group, possibly including the expiry date if relevant.
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
when a variable name is used in a it is silently declared as a new local masking the global
Definition design.txt:95
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 document is intended to provide useful advice for parties seeking to redistribute MediaWiki to end users It s targeted particularly at maintainers for Linux since it s been observed that distribution packages of MediaWiki often break We ve consistently had to recommend that users seeking support use official tarballs instead of their distribution s and this often solves whatever problem the user is having It would be nice if this could such as
const NS_MAIN
Definition Defines.php:62
const NS_PROJECT
Definition Defines.php:66
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:189
injection txt This is an overview of how MediaWiki makes use of dependency injection The design described here grew from the discussion of RFC T384 The term dependency this means that anything an object needs to operate should be injected from the the object itself should only know narrow no concrete implementation of the logic it relies on The requirement to inject everything typically results in an architecture that based on two main types of and essentially stateless service objects that use other service objects to operate on the value objects As of the beginning MediaWiki is only starting to use the DI approach Much of the code still relies on global state or direct resulting in a highly cyclical dependency which acts as the top level factory for services in MediaWiki which can be used to gain access to default instances of various services MediaWikiServices however also allows new services to be defined and default services to be redefined Services are defined or redefined by providing a callback the instantiator that will return a new instance of the service When it will create an instance of MediaWikiServices and populate it with the services defined in the files listed by thereby bootstrapping the DI framework Per $wgServiceWiringFiles lists includes ServiceWiring php
Definition injection.txt:37
if(!isset( $args[0])) $lang
$header