MediaWiki  1.33.0
SpecialListgrouprights.php
Go to the documentation of this file.
1 <?php
25 
34  public function __construct() {
35  parent::__construct( 'Listgrouprights' );
36  }
37 
42  public function execute( $par ) {
43  $this->setHeaders();
44  $this->outputHeader();
45 
46  $out = $this->getOutput();
47  $out->addModuleStyles( 'mediawiki.special' );
48 
49  $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
50 
51  $out->addHTML(
52  Xml::openElement( 'table', [ 'class' => 'wikitable mw-listgrouprights-table' ] ) .
53  '<tr>' .
54  Xml::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
55  Xml::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
56  '</tr>'
57  );
58 
59  $config = $this->getConfig();
60  $groupPermissions = $config->get( 'GroupPermissions' );
61  $revokePermissions = $config->get( 'RevokePermissions' );
62  $addGroups = $config->get( 'AddGroups' );
63  $removeGroups = $config->get( 'RemoveGroups' );
64  $groupsAddToSelf = $config->get( 'GroupsAddToSelf' );
65  $groupsRemoveFromSelf = $config->get( 'GroupsRemoveFromSelf' );
66  $allGroups = array_unique( array_merge(
67  array_keys( $groupPermissions ),
68  array_keys( $revokePermissions ),
69  array_keys( $addGroups ),
70  array_keys( $removeGroups ),
71  array_keys( $groupsAddToSelf ),
72  array_keys( $groupsRemoveFromSelf )
73  ) );
74  asort( $allGroups );
75 
76  $linkRenderer = $this->getLinkRenderer();
77 
78  foreach ( $allGroups as $group ) {
79  $permissions = $groupPermissions[$group] ?? [];
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 )
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 = $revokePermissions[$group] ?? [];
118  $addgroups = $addGroups[$group] ?? [];
119  $removegroups = $removeGroups[$group] ?? [];
120  $addgroupsSelf = $groupsAddToSelf[$group] ?? [];
121  $removegroupsSelf = $groupsRemoveFromSelf[$group] ?? [];
122 
123  $id = $group == '*' ? false : Sanitizer::escapeIdForAttribute( $group );
124  $out->addHTML( Html::rawElement( 'tr', [ 'id' => $id ], "
125  <td>$grouppage$grouplink</td>
126  <td>" .
127  $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
128  $addgroupsSelf, $removegroupsSelf ) .
129  '</td>
130  '
131  ) );
132  }
133  $out->addHTML( Xml::closeElement( 'table' ) );
135  }
136 
137  private function outputNamespaceProtectionInfo() {
138  $out = $this->getOutput();
139  $namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
140 
141  if ( count( $namespaceProtection ) == 0 ) {
142  return;
143  }
144 
145  $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->text();
146  $out->addHTML(
147  Html::rawElement( 'h2', [], Html::element( 'span', [
148  'class' => 'mw-headline',
149  'id' => substr( Parser::guessSectionNameFromStrippedText( $header ), 1 )
150  ], $header ) ) .
151  Xml::openElement( 'table', [ 'class' => 'wikitable' ] ) .
152  Html::element(
153  'th',
154  [],
155  $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text()
156  ) .
157  Html::element(
158  'th',
159  [],
160  $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text()
161  )
162  );
163  $linkRenderer = $this->getLinkRenderer();
164  ksort( $namespaceProtection );
165  $validNamespaces = MWNamespace::getValidNamespaces();
166  $contLang = MediaWikiServices::getInstance()->getContentLanguage();
167  foreach ( $namespaceProtection as $namespace => $rights ) {
168  if ( !in_array( $namespace, $validNamespaces ) ) {
169  continue;
170  }
171 
172  if ( $namespace == NS_MAIN ) {
173  $namespaceText = $this->msg( 'blanknamespace' )->text();
174  } else {
175  $namespaceText = $contLang->convertNamespace( $namespace );
176  }
177 
178  $out->addHTML(
179  Xml::openElement( 'tr' ) .
180  Html::rawElement(
181  'td',
182  [],
183  $linkRenderer->makeLink(
184  SpecialPage::getTitleFor( 'Allpages' ),
185  $namespaceText,
186  [],
187  [ 'namespace' => $namespace ]
188  )
189  ) .
190  Xml::openElement( 'td' ) . Xml::openElement( 'ul' )
191  );
192 
193  if ( !is_array( $rights ) ) {
194  $rights = [ $rights ];
195  }
196 
197  foreach ( $rights as $right ) {
198  $out->addHTML(
199  Html::rawElement( 'li', [], $this->msg(
200  'listgrouprights-right-display',
201  User::getRightDescription( $right ),
202  Html::element(
203  'span',
204  [ 'class' => 'mw-listgrouprights-right-name' ],
205  $right
206  )
207  )->parse() )
208  );
209  }
210 
211  $out->addHTML(
212  Xml::closeElement( 'ul' ) .
213  Xml::closeElement( 'td' ) .
214  Xml::closeElement( 'tr' )
215  );
216  }
217  $out->addHTML( Xml::closeElement( 'table' ) );
218  }
219 
231  private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
232  $r = [];
233  foreach ( $permissions as $permission => $granted ) {
234  // show as granted only if it isn't revoked to prevent duplicate display of permissions
235  if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
236  $r[] = $this->msg( 'listgrouprights-right-display',
237  User::getRightDescription( $permission ),
238  '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
239  )->parse();
240  }
241  }
242  foreach ( $revoke as $permission => $revoked ) {
243  if ( $revoked ) {
244  $r[] = $this->msg( 'listgrouprights-right-revoked',
245  User::getRightDescription( $permission ),
246  '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
247  )->parse();
248  }
249  }
250 
251  sort( $r );
252 
253  $lang = $this->getLanguage();
254  $allGroups = User::getAllGroups();
255 
256  $changeGroups = [
257  'addgroup' => $add,
258  'removegroup' => $remove,
259  'addgroup-self' => $addSelf,
260  'removegroup-self' => $removeSelf
261  ];
262 
263  foreach ( $changeGroups as $messageKey => $changeGroup ) {
264  if ( $changeGroup === true ) {
265  // For grep: listgrouprights-addgroup-all, listgrouprights-removegroup-all,
266  // listgrouprights-addgroup-self-all, listgrouprights-removegroup-self-all
267  $r[] = $this->msg( 'listgrouprights-' . $messageKey . '-all' )->escaped();
268  } elseif ( is_array( $changeGroup ) ) {
269  $changeGroup = array_intersect( array_values( array_unique( $changeGroup ) ), $allGroups );
270  if ( count( $changeGroup ) ) {
271  $groupLinks = [];
272  foreach ( $changeGroup as $group ) {
273  $groupLinks[] = UserGroupMembership::getLink( $group, $this->getContext(), 'wiki' );
274  }
275  // For grep: listgrouprights-addgroup, listgrouprights-removegroup,
276  // listgrouprights-addgroup-self, listgrouprights-removegroup-self
277  $r[] = $this->msg( 'listgrouprights-' . $messageKey,
278  $lang->listToText( $groupLinks ), count( $changeGroup ) )->parse();
279  }
280  }
281  }
282 
283  if ( empty( $r ) ) {
284  return '';
285  } else {
286  return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
287  }
288  }
289 
290  protected function getGroupName() {
291  return 'users';
292  }
293 }
SpecialListGroupRights\execute
execute( $par)
Show the special page.
Definition: SpecialListgrouprights.php:42
Title\newFromText
static newFromText( $text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:306
SpecialPage\msg
msg( $key)
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:796
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:187
MWNamespace\getValidNamespaces
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
Definition: MWNamespace.php:287
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:725
$lang
if(!isset( $args[0])) $lang
Definition: testCompression.php:33
captcha-old.count
count
Definition: captcha-old.py:249
UserGroupMembership\getGroupName
static getGroupName( $group)
Gets the localized friendly name for a group, if it exists.
Definition: UserGroupMembership.php:432
$out
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password 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:780
SpecialPage\getTitleFor
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,...
Definition: SpecialPage.php:82
SpecialListGroupRights\outputNamespaceProtectionInfo
outputNamespaceProtectionInfo()
Definition: SpecialListgrouprights.php:137
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:755
UserGroupMembership\getGroupPage
static getGroupPage( $group)
Gets the title of a page describing a particular user group.
Definition: UserGroupMembership.php:457
SpecialListGroupRights\__construct
__construct()
Definition: SpecialListgrouprights.php:34
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:108
php
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:35
NS_MAIN
const NS_MAIN
Definition: Defines.php:64
SpecialPage\getConfig
getConfig()
Shortcut to get main config object.
Definition: SpecialPage.php:764
NS_PROJECT
const NS_PROJECT
Definition: Defines.php:68
SpecialListGroupRights\formatPermissions
formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf)
Create a user-readable list of permissions from the given array.
Definition: SpecialListgrouprights.php:231
UserGroupMembership\getLink
static getLink( $ugm, IContextSource $context, $format, $userName=null)
Gets a link for a user group, possibly including the expiry date if relevant.
Definition: UserGroupMembership.php:374
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:41
use
as see the revision history and available at free of to any person obtaining a copy of this software and associated documentation to deal in the Software without including without limitation the rights to use
Definition: MIT-LICENSE.txt:10
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:531
SpecialPage\getContext
getContext()
Gets the context this SpecialPage is executed in.
Definition: SpecialPage.php:698
$header
$header
Definition: updateCredits.php:41
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:36
User\getAllGroups
static getAllGroups()
Return the set of defined explicit groups.
Definition: User.php:5134
SpecialPage\getLinkRenderer
getLinkRenderer()
Definition: SpecialPage.php:908
text
This list may contain false positives That usually means there is additional text with links below the first Each row contains links to the first and second as well as the first line of the second redirect text
Definition: All_system_messages.txt:1267
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:117
User\getRightDescription
static getRightDescription( $right)
Get the description of a given right.
Definition: User.php:5415
as
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
Definition: distributors.txt:9
SpecialListGroupRights\getGroupName
getGroupName()
Under which header this special page is listed in Special:SpecialPages See messages 'specialpages-gro...
Definition: SpecialListgrouprights.php:290
SpecialListGroupRights
This special page lists all defined user groups and the associated rights.
Definition: SpecialListgrouprights.php:33
SpecialPage\$linkRenderer
MediaWiki Linker LinkRenderer null $linkRenderer
Definition: SpecialPage.php:66
MediaWikiServices
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 MediaWikiServices
Definition: injection.txt:23
SpecialPage\outputHeader
outputHeader( $summaryMessageKey='')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
Definition: SpecialPage.php:633
MWNamespace\getCanonicalName
static getCanonicalName( $index)
Returns the canonical (English) name for a given index.
Definition: MWNamespace.php:256