MediaWiki  1.23.8
SpecialListgrouprights.php
Go to the documentation of this file.
1 <?php
35  function __construct() {
36  parent::__construct( 'Listgrouprights' );
37  }
38 
42  public function execute( $par ) {
43  global $wgImplicitGroups;
44  global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
45  global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
46 
47  $this->setHeaders();
48  $this->outputHeader();
49 
50  $out = $this->getOutput();
51  $out->addModuleStyles( 'mediawiki.special' );
52 
53  $out->wrapWikiMsg( "<div class=\"mw-listgrouprights-key\">\n$1\n</div>", 'listgrouprights-key' );
54 
55  $out->addHTML(
56  Xml::openElement( 'table', array( 'class' => 'wikitable mw-listgrouprights-table' ) ) .
57  '<tr>' .
58  Xml::element( 'th', null, $this->msg( 'listgrouprights-group' )->text() ) .
59  Xml::element( 'th', null, $this->msg( 'listgrouprights-rights' )->text() ) .
60  '</tr>'
61  );
62 
63  $allGroups = array_unique( array_merge(
64  array_keys( $wgGroupPermissions ),
65  array_keys( $wgRevokePermissions ),
66  array_keys( $wgAddGroups ),
67  array_keys( $wgRemoveGroups ),
68  array_keys( $wgGroupsAddToSelf ),
69  array_keys( $wgGroupsRemoveFromSelf )
70  ) );
71  asort( $allGroups );
72 
73  foreach ( $allGroups as $group ) {
74  $permissions = isset( $wgGroupPermissions[$group] )
75  ? $wgGroupPermissions[$group]
76  : array();
77  $groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
78  ? 'all'
79  : $group;
80 
81  $msg = $this->msg( 'group-' . $groupname );
82  $groupnameLocalized = !$msg->isBlank() ? $msg->text() : $groupname;
83 
84  $msg = $this->msg( 'grouppage-' . $groupname )->inContentLanguage();
85  $grouppageLocalized = !$msg->isBlank() ?
86  $msg->text() :
87  MWNamespace::getCanonicalName( NS_PROJECT ) . ':' . $groupname;
88 
89  if ( $group == '*' ) {
90  // Do not make a link for the generic * group
91  $grouppage = htmlspecialchars( $groupnameLocalized );
92  } else {
93  $grouppage = Linker::link(
94  Title::newFromText( $grouppageLocalized ),
95  htmlspecialchars( $groupnameLocalized )
96  );
97  }
98 
99  if ( $group === 'user' ) {
100  // Link to Special:listusers for implicit group 'user'
101  $grouplink = '<br />' . Linker::linkKnown(
102  SpecialPage::getTitleFor( 'Listusers' ),
103  $this->msg( 'listgrouprights-members' )->escaped()
104  );
105  } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
106  $grouplink = '<br />' . Linker::linkKnown(
107  SpecialPage::getTitleFor( 'Listusers' ),
108  $this->msg( 'listgrouprights-members' )->escaped(),
109  array(),
110  array( '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( $wgRevokePermissions[$group] ) ? $wgRevokePermissions[$group] : array();
118  $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
119  $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
120  $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
121  $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
122 
123  $id = $group == '*' ? false : Sanitizer::escapeId( $group );
124  $out->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
125  "
126  <td>$grouppage$grouplink</td>
127  <td>" .
128  $this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
129  $addgroupsSelf, $removegroupsSelf ) .
130  '</td>
131  '
132  ) );
133  }
134  $out->addHTML( Xml::closeElement( 'table' ) );
136  }
137 
138  private function outputNamespaceProtectionInfo() {
140  $out = $this->getOutput();
141 
142  if ( count( $wgNamespaceProtection ) == 0 ) {
143  return;
144  }
145 
146  $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse();
147  $out->addHTML(
148  Html::rawElement( 'h2', array(), Html::element( 'span', array(
149  'class' => 'mw-headline',
150  'id' => $wgParser->guessSectionNameFromWikiText( $header )
151  ), $header ) ) .
152  Xml::openElement( 'table', array( 'class' => 'wikitable' ) ) .
154  'th',
155  array(),
156  $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text()
157  ) .
159  'th',
160  array(),
161  $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text()
162  )
163  );
164 
165  ksort( $wgNamespaceProtection );
166  foreach ( $wgNamespaceProtection as $namespace => $rights ) {
167  if ( !in_array( $namespace, MWNamespace::getValidNamespaces() ) ) {
168  continue;
169  }
170 
171  if ( $namespace == NS_MAIN ) {
172  $namespaceText = $this->msg( 'blanknamespace' )->text();
173  } else {
174  $namespaceText = $wgContLang->convertNamespace( $namespace );
175  }
176 
177  $out->addHTML(
178  Xml::openElement( 'tr' ) .
180  'td',
181  array(),
182  Linker::link(
183  SpecialPage::getTitleFor( 'Allpages' ),
184  $namespaceText,
185  array(),
186  array( 'namespace' => $namespace )
187  )
188  ) .
189  Xml::openElement( 'td' ) . Xml::openElement( 'ul' )
190  );
191 
192  if ( !is_array( $rights ) ) {
193  $rights = array( $rights );
194  }
195 
196  foreach ( $rights as $right ) {
197  $out->addHTML(
198  Html::rawElement( 'li', array(), $this->msg(
199  'listgrouprights-right-display',
200  User::getRightDescription( $right ),
202  'span',
203  array( 'class' => 'mw-listgrouprights-right-name' ),
204  $right
205  )
206  )->parse() )
207  );
208  }
209 
210  $out->addHTML(
211  Xml::closeElement( 'ul' ) .
212  Xml::closeElement( 'td' ) .
213  Xml::closeElement( 'tr' )
214  );
215  }
216  $out->addHTML( Xml::closeElement( 'table' ) );
217  }
218 
230  private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
231  $r = array();
232  foreach ( $permissions as $permission => $granted ) {
233  //show as granted only if it isn't revoked to prevent duplicate display of permissions
234  if ( $granted && ( !isset( $revoke[$permission] ) || !$revoke[$permission] ) ) {
235  $description = $this->msg( 'listgrouprights-right-display',
236  User::getRightDescription( $permission ),
237  '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
238  )->parse();
239  $r[] = $description;
240  }
241  }
242  foreach ( $revoke as $permission => $revoked ) {
243  if ( $revoked ) {
244  $description = $this->msg( 'listgrouprights-right-revoked',
245  User::getRightDescription( $permission ),
246  '<span class="mw-listgrouprights-right-name">' . $permission . '</span>'
247  )->parse();
248  $r[] = $description;
249  }
250  }
251 
252  sort( $r );
253 
254  $lang = $this->getLanguage();
255 
256  if ( $add === true ) {
257  $r[] = $this->msg( 'listgrouprights-addgroup-all' )->escaped();
258  } elseif ( is_array( $add ) && count( $add ) ) {
259  $add = array_values( array_unique( $add ) );
260  $r[] = $this->msg( 'listgrouprights-addgroup',
261  $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ),
262  count( $add )
263  )->parse();
264  }
265 
266  if ( $remove === true ) {
267  $r[] = $this->msg( 'listgrouprights-removegroup-all' )->escaped();
268  } elseif ( is_array( $remove ) && count( $remove ) ) {
269  $remove = array_values( array_unique( $remove ) );
270  $r[] = $this->msg( 'listgrouprights-removegroup',
271  $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
272  count( $remove )
273  )->parse();
274  }
275 
276  if ( $addSelf === true ) {
277  $r[] = $this->msg( 'listgrouprights-addgroup-self-all' )->escaped();
278  } elseif ( is_array( $addSelf ) && count( $addSelf ) ) {
279  $addSelf = array_values( array_unique( $addSelf ) );
280  $r[] = $this->msg( 'listgrouprights-addgroup-self',
281  $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
282  count( $addSelf )
283  )->parse();
284  }
285 
286  if ( $removeSelf === true ) {
287  $r[] = $this->msg( 'listgrouprights-removegroup-self-all' )->parse();
288  } elseif ( is_array( $removeSelf ) && count( $removeSelf ) ) {
289  $removeSelf = array_values( array_unique( $removeSelf ) );
290  $r[] = $this->msg( 'listgrouprights-removegroup-self',
291  $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
292  count( $removeSelf )
293  )->parse();
294  }
295 
296  if ( empty( $r ) ) {
297  return '';
298  } else {
299  return '<ul><li>' . implode( "</li>\n<li>", $r ) . '</li></ul>';
300  }
301  }
302 
303  protected function getGroupName() {
304  return 'users';
305  }
306 }
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:189
php
skin txt MediaWiki includes four core it has been set as the default in MediaWiki since the replacing Monobook it had been been the default skin since before being replaced by Vector largely rewritten in while keeping its appearance Several legacy skins were removed in the as the burden of supporting them became too heavy to bear Those in etc for skin dependent CSS etc for skin dependent JavaScript These can also be customised on a per user by etc This feature has led to a wide variety of user styles becoming that gallery is a good place to ending in php
Definition: skin.txt:62
MWNamespace\getValidNamespaces
static getValidNamespaces()
Returns an array of the namespaces (by integer id) that exist on the wiki.
Definition: Namespace.php:273
SpecialPage\getOutput
getOutput()
Get the OutputPage being used for this instance.
Definition: SpecialPage.php:535
text
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
$right
return false if a UserGetRights hook might remove the named right $right
Definition: hooks.txt:2798
SpecialPage\getTitleFor
static getTitleFor( $name, $subpage=false, $fragment='')
Get a localised Title object for a specified special page name.
Definition: SpecialPage.php:74
SpecialListGroupRights\outputNamespaceProtectionInfo
outputNamespaceProtectionInfo()
Definition: SpecialListgrouprights.php:138
$wgContLang
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 content language as $wgContLang
Definition: design.txt:56
SpecialPage\getLanguage
getLanguage()
Shortcut to get user's language.
Definition: SpecialPage.php:578
SpecialListGroupRights\__construct
__construct()
Constructor.
Definition: SpecialListgrouprights.php:35
Xml\openElement
static openElement( $element, $attribs=null)
This opens an XML element.
Definition: Xml.php:109
Linker\linkKnown
static linkKnown( $target, $html=null, $customAttribs=array(), $query=array(), $options=array( 'known', 'noclasses'))
Identical to link(), except $options defaults to 'known'.
Definition: Linker.php:264
Linker\link
static link( $target, $html=null, $customAttribs=array(), $query=array(), $options=array())
This function returns an HTML link to the given target.
Definition: Linker.php:192
NS_MAIN
const NS_MAIN
Definition: Defines.php:79
$out
$out
Definition: UtfNormalGenerate.php:167
NS_PROJECT
const NS_PROJECT
Definition: Defines.php:83
SpecialListGroupRights\formatPermissions
formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf)
Create a user-readable list of permissions from the given array.
Definition: SpecialListgrouprights.php:230
Html\element
static element( $element, $attribs=array(), $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition: Html.php:148
Xml\element
static element( $element, $attribs=null, $contents='', $allowShortTag=true)
Format an XML element with given attributes and, optionally, text content.
Definition: Xml.php:39
array
the array() calling protocol came about after MediaWiki 1.4rc1.
List of Api Query prop modules.
SpecialPage\setHeaders
setHeaders()
Sets headers - this should be called from the execute() method of all derived classes!
Definition: SpecialPage.php:352
global
when a variable name is used in a it is silently declared as a new masking the global
Definition: design.txt:93
false
processing should stop and the error should be shown to the user * false
Definition: hooks.txt:188
Sanitizer\escapeId
static escapeId( $id, $options=array())
Given a value, escape it so that it can be used in an id attribute and return it.
Definition: Sanitizer.php:1099
SpecialPage\msg
msg()
Wrapper around wfMessage that sets the current context.
Definition: SpecialPage.php:609
SpecialPage
Parent class for all special pages.
Definition: SpecialPage.php:33
Xml\closeElement
static closeElement( $element)
Shortcut to close an XML element.
Definition: Xml.php:118
User\getRightDescription
static getRightDescription( $right)
Get the description of a given right.
Definition: User.php:4495
$wgParser
$wgParser
Definition: Setup.php:567
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:303
SpecialListGroupRights
This special page lists all defined user groups and the associated rights.
Definition: SpecialListgrouprights.php:31
$wgNamespaceProtection
if(!isset( $wgVersion)) if( $wgScript===false) if( $wgLoadScript===false) if( $wgArticlePath===false) if(!empty( $wgActionPaths) &&!isset( $wgActionPaths['view'])) if( $wgStylePath===false) if( $wgLocalStylePath===false) if( $wgStyleDirectory===false) if( $wgExtensionAssetsPath===false) if( $wgLogo===false) if( $wgUploadPath===false) if( $wgUploadDirectory===false) if( $wgReadOnlyFile===false) if( $wgFileCacheDirectory===false) if( $wgDeletedDirectory===false) if(isset( $wgFileStore['deleted']['directory'])) if(isset( $wgFooterIcons['copyright']) &&isset( $wgFooterIcons['copyright']['copyright']) && $wgFooterIcons['copyright']['copyright']===array()) if(isset( $wgFooterIcons['poweredby']) &&isset( $wgFooterIcons['poweredby']['mediawiki']) && $wgFooterIcons['poweredby']['mediawiki']['src']===null) $wgNamespaceProtection[NS_MEDIAWIKI]
Unconditional protection for NS_MEDIAWIKI since otherwise it's too easy for a sysadmin to set $wgName...
Definition: Setup.php:135
Html\rawElement
static rawElement( $element, $attribs=array(), $contents='')
Returns an HTML element in a string.
Definition: Html.php:124
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:443
MWNamespace\getCanonicalName
static getCanonicalName( $index)
Returns the canonical (English) name for a given index.
Definition: Namespace.php:237