MediaWiki  1.27.2
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 
74  foreach ( $allGroups as $group ) {
75  $permissions = isset( $groupPermissions[$group] )
76  ? $groupPermissions[$group]
77  : [];
78  $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
79  ? 'all'
80  : $group;
81 
82  $msg = $this->msg( 'group-' . $groupname );
83  $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
84 
85  $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
86  $grouppageLocalized = !$msg->isBlank() ?
87  $msg->text() :
88  MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
89  $grouppageLocalizedTitle = Title::newFromText( $grouppageLocalized );
90 
91  if ( $group == '*' || !$grouppageLocalizedTitle ) {
92  // Do not make a link for the generic * group or group with invalid group page
93  $grouppage = htmlspecialchars( $groupnameLocalized );
94  } else {
95  $grouppage = Linker::link(
96  $grouppageLocalizedTitle,
97  htmlspecialchars( $groupnameLocalized )
98  );
99  }
100 
101  if ( $group === 'user' ) {
102  // Link to Special:listusers for implicit group 'user'
103  $grouplink = '<br />' . Linker::linkKnown(
104  SpecialPage::getTitleFor( 'Listusers' ),
105  $this->msg( 'listgrouprights-members' )->escaped()
106  );
107  } elseif ( !in_array( $group, $config->get( 'ImplicitGroups' ) ) ) {
108  $grouplink = '<br />' . Linker::linkKnown(
109  SpecialPage::getTitleFor( 'Listusers' ),
110  $this->msg( 'listgrouprights-members' )->escaped(),
111  [],
112  [ 'group' => $group ]
113  );
114  } else {
115  // No link to Special:listusers for other implicit groups as they are unlistable
116  $grouplink = '';
117  }
118 
119  $revoke = isset( $revokePermissions[$group] ) ? $revokePermissions[$group] : [];
120  $addgroups = isset( $addGroups[$group] ) ? $addGroups[$group] : [];
121  $removegroups = isset( $removeGroups[$group] ) ? $removeGroups[$group] : [];
122  $addgroupsSelf = isset( $groupsAddToSelf[$group] ) ? $groupsAddToSelf[$group] : [];
123  $removegroupsSelf = isset( $groupsRemoveFromSelf[$group] )
124  ? $groupsRemoveFromSelf[$group]
125  : [];
126 
127  $id = $group == '*' ? false : Sanitizer::escapeId( $group );
128  $out->addHTML( Html::rawElement( 'tr', [ 'id' => $id ], "
129  <td>$grouppage$grouplink</td>
130  <td>" .
131  $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
132  $addgroupsSelf, $removegroupsSelf ) .
133  '</td>
134  '
135  ) );
136  }
137  $out->addHTML( Xml::closeElement( 'table' ) );
139  }
140 
141  private function outputNamespaceProtectionInfo() {
143  $out = $this->getOutput();
144  $namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
145 
146  if ( count( $namespaceProtection ) == 0 ) {
147  return;
148  }
149 
150  $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse();
151  $out->addHTML(
152  Html::rawElement( 'h2', [], Html::element( 'span', [
153  'class' => 'mw-headline',
154  'id' => $wgParser->guessSectionNameFromWikiText( $header )
155  ], $header ) ) .
156  Xml::openElement( 'table', [ 'class' => 'wikitable' ] ) .
158  'th',
159  [],
160  $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text()
161  ) .
163  'th',
164  [],
165  $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text()
166  )
167  );
168 
169  ksort( $namespaceProtection );
170  foreach ( $namespaceProtection as $namespace => $rights ) {
171  if ( !in_array( $namespace, MWNamespace::getValidNamespaces() ) ) {
172  continue;
173  }
174 
175  if ( $namespace == NS_MAIN ) {
176  $namespaceText = $this->msg( 'blanknamespace' )->text();
177  } else {
178  $namespaceText = $wgContLang->convertNamespace( $namespace );
179  }
180 
181  $out->addHTML(
182  Xml::openElement( 'tr' ) .
184  'td',
185  [],
186  Linker::link(
187  SpecialPage::getTitleFor( 'Allpages' ),
188  htmlspecialchars( $namespaceText ),
189  [],
190  [ 'namespace' => $namespace ]
191  )
192  ) .
193  Xml::openElement( 'td' ) . Xml::openElement( 'ul' )
194  );
195 
196  if ( !is_array( $rights ) ) {
197  $rights = [ $rights ];
198  }
199 
200  foreach ( $rights as $right ) {
201  $out->addHTML(
202  Html::rawElement( 'li', [], $this->msg(
203  'listgrouprights-right-display',
204  User::getRightDescription( $right ),
206  'span',
207  [ 'class' => 'mw-listgrouprights-right-name' ],
208  $right
209  )
210  )->parse() )
211  );
212  }
213 
214  $out->addHTML(
215  Xml::closeElement( 'ul' ) .
216  Xml::closeElement( 'td' ) .
217  Xml::closeElement( 'tr' )
218  );
219  }
220  $out->addHTML( Xml::closeElement( 'table' ) );
221  }
222 
234  private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
235  $r = [];
236  foreach ( $permissions as $permission => $granted ) {
237  // show as granted only if it isn't revoked to prevent duplicate display of permissions
238  if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
239  $r[] = $this->msg( 'listgrouprights-right-display',
240  User::getRightDescription( $permission ),
241  '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
242  )->parse();
243  }
244  }
245  foreach ( $revoke as $permission => $revoked ) {
246  if ( $revoked ) {
247  $r[] = $this->msg( 'listgrouprights-right-revoked',
248  User::getRightDescription( $permission ),
249  '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
250  )->parse();
251  }
252  }
253 
254  sort( $r );
255 
256  $lang = $this->getLanguage();
257  $allGroups = User::getAllGroups();
258 
259  $changeGroups = [
260  'addgroup' => $add,
261  'removegroup' => $remove,
262  'addgroup-self' => $addSelf,
263  'removegroup-self' => $removeSelf
264  ];
265 
266  foreach ( $changeGroups as $messageKey => $changeGroup ) {
267  if ( $changeGroup === true ) {
268  // For grep: listgrouprights-addgroup-all, listgrouprights-removegroup-all,
269  // listgrouprights-addgroup-self-all, listgrouprights-removegroup-self-all
270  $r[] = $this->msg( 'listgrouprights-' . $messageKey . '-all' )->escaped();
271  } elseif ( is_array( $changeGroup ) ) {
272  $changeGroup = array_intersect( array_values( array_unique( $changeGroup ) ), $allGroups );
273  if ( count( $changeGroup ) ) {
274  // For grep: listgrouprights-addgroup, listgrouprights-removegroup,
275  // listgrouprights-addgroup-self, listgrouprights-removegroup-self
276  $r[] = $this->msg( 'listgrouprights-' . $messageKey,
277  $lang->listToText( array_map( [ 'User', 'makeGroupLinkWiki' ], $changeGroup ) ),
278  count( $changeGroup )
279  )->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 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:762
static linkKnown($target, $html=null, $customAttribs=[], $query=[], $options=[ 'known', 'noclasses'])
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
const NS_MAIN
Definition: Defines.php:69
static element($element, $attribs=null, $contents= '', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
static getTitleFor($name, $subpage=false, $fragment= '')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:75
$wgParser
Definition: Setup.php:809
static rawElement($element, $attribs=[], $contents= '')
Returns an HTML element in a string.
Definition: Html.php:210
if(!isset($args[0])) $lang
msg()
Wrapper around wfMessage that sets the current context.
getOutput()
Get the OutputPage being used for this instance.
static newFromText($text, $defaultNamespace=NS_MAIN)
Create a new Title from text, such as what one would find in a link.
Definition: Title.php:277
when a variable name is used in a it is silently declared as a new local masking the global
Definition: design.txt:93
static getAllGroups()
Return the set of defined explicit groups.
Definition: User.php:4644
outputHeader($summaryMessageKey= '')
Outputs a summary message on top of special pages Per default the message key is the canonical name o...
static closeElement($element)
Shortcut to close an XML element.
Definition: Xml.php:118
Parent class for all special pages.
Definition: SpecialPage.php:36
const NS_PROJECT
Definition: Defines.php:73
static getCanonicalName($index)
Returns the canonical (English) name for a given index.
formatPermissions($permissions, $revoke, $add, $remove, $addSelf, $removeSelf)
Create a user-readable list of permissions from the given array.
static openElement($element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes! ...
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:12
This special page lists all defined user groups and the associated rights.
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
static link($target, $html=null, $customAttribs=[], $query=[], $options=[])
This function returns an HTML link to the given target.
Definition: Linker.php:195
static escapeId($id, $options=[])
Given a value, escape it so that it can be used in an id attribute and return it. ...
Definition: Sanitizer.php:1132
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
getConfig()
Shortcut to get main config object.
getLanguage()
Shortcut to get user's language.
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:56
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
static element($element, $attribs=[], $contents= '')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:230
static getRightDescription($right)
Get the description of a given right.
Definition: User.php:4941
execute($par)
Show the special page.