summaryrefslogtreecommitdiff
path: root/includes/specials/SpecialListgrouprights.php
diff options
context:
space:
mode:
Diffstat (limited to 'includes/specials/SpecialListgrouprights.php')
-rw-r--r--includes/specials/SpecialListgrouprights.php200
1 files changed, 147 insertions, 53 deletions
diff --git a/includes/specials/SpecialListgrouprights.php b/includes/specials/SpecialListgrouprights.php
index 82a4f70f..5bae28f0 100644
--- a/includes/specials/SpecialListgrouprights.php
+++ b/includes/specials/SpecialListgrouprights.php
@@ -29,21 +29,15 @@
* @author Petr Kadlec <mormegil@centrum.cz>
*/
class SpecialListGroupRights extends SpecialPage {
- /**
- * Constructor
- */
function __construct() {
parent::__construct( 'Listgrouprights' );
}
/**
* Show the special page
+ * @param string|null $par
*/
public function execute( $par ) {
- global $wgImplicitGroups;
- global $wgGroupPermissions, $wgRevokePermissions, $wgAddGroups, $wgRemoveGroups;
- global $wgGroupsAddToSelf, $wgGroupsRemoveFromSelf;
-
$this->setHeaders();
$this->outputHeader();
@@ -60,19 +54,26 @@ class SpecialListGroupRights extends SpecialPage {
'</tr>'
);
+ $config = $this->getConfig();
+ $groupPermissions = $config->get( 'GroupPermissions' );
+ $revokePermissions = $config->get( 'RevokePermissions' );
+ $addGroups = $config->get( 'AddGroups' );
+ $removeGroups = $config->get( 'RemoveGroups' );
+ $groupsAddToSelf = $config->get( 'GroupsAddToSelf' );
+ $groupsRemoveFromSelf = $config->get( 'GroupsRemoveFromSelf' );
$allGroups = array_unique( array_merge(
- array_keys( $wgGroupPermissions ),
- array_keys( $wgRevokePermissions ),
- array_keys( $wgAddGroups ),
- array_keys( $wgRemoveGroups ),
- array_keys( $wgGroupsAddToSelf ),
- array_keys( $wgGroupsRemoveFromSelf )
+ array_keys( $groupPermissions ),
+ array_keys( $revokePermissions ),
+ array_keys( $addGroups ),
+ array_keys( $removeGroups ),
+ array_keys( $groupsAddToSelf ),
+ array_keys( $groupsRemoveFromSelf )
) );
asort( $allGroups );
foreach ( $allGroups as $group ) {
- $permissions = isset( $wgGroupPermissions[$group] )
- ? $wgGroupPermissions[$group]
+ $permissions = isset( $groupPermissions[$group] )
+ ? $groupPermissions[$group]
: array();
$groupname = ( $group == '*' ) // Replace * with a more descriptive groupname
? 'all'
@@ -102,7 +103,7 @@ class SpecialListGroupRights extends SpecialPage {
SpecialPage::getTitleFor( 'Listusers' ),
$this->msg( 'listgrouprights-members' )->escaped()
);
- } elseif ( !in_array( $group, $wgImplicitGroups ) ) {
+ } elseif ( !in_array( $group, $config->get( 'ImplicitGroups' ) ) ) {
$grouplink = '<br />' . Linker::linkKnown(
SpecialPage::getTitleFor( 'Listusers' ),
$this->msg( 'listgrouprights-members' )->escaped(),
@@ -114,15 +115,16 @@ class SpecialListGroupRights extends SpecialPage {
$grouplink = '';
}
- $revoke = isset( $wgRevokePermissions[$group] ) ? $wgRevokePermissions[$group] : array();
- $addgroups = isset( $wgAddGroups[$group] ) ? $wgAddGroups[$group] : array();
- $removegroups = isset( $wgRemoveGroups[$group] ) ? $wgRemoveGroups[$group] : array();
- $addgroupsSelf = isset( $wgGroupsAddToSelf[$group] ) ? $wgGroupsAddToSelf[$group] : array();
- $removegroupsSelf = isset( $wgGroupsRemoveFromSelf[$group] ) ? $wgGroupsRemoveFromSelf[$group] : array();
+ $revoke = isset( $revokePermissions[$group] ) ? $revokePermissions[$group] : array();
+ $addgroups = isset( $addGroups[$group] ) ? $addGroups[$group] : array();
+ $removegroups = isset( $removeGroups[$group] ) ? $removeGroups[$group] : array();
+ $addgroupsSelf = isset( $groupsAddToSelf[$group] ) ? $groupsAddToSelf[$group] : array();
+ $removegroupsSelf = isset( $groupsRemoveFromSelf[$group] )
+ ? $groupsRemoveFromSelf[$group]
+ : array();
$id = $group == '*' ? false : Sanitizer::escapeId( $group );
- $out->addHTML( Html::rawElement( 'tr', array( 'id' => $id ),
- "
+ $out->addHTML( Html::rawElement( 'tr', array( 'id' => $id ), "
<td>$grouppage$grouplink</td>
<td>" .
$this->formatPermissions( $permissions, $revoke, $addgroups, $removegroups,
@@ -132,17 +134,100 @@ class SpecialListGroupRights extends SpecialPage {
) );
}
$out->addHTML( Xml::closeElement( 'table' ) );
+ $this->outputNamespaceProtectionInfo();
+ }
+
+ private function outputNamespaceProtectionInfo() {
+ global $wgParser, $wgContLang;
+ $out = $this->getOutput();
+ $namespaceProtection = $this->getConfig()->get( 'NamespaceProtection' );
+
+ if ( count( $namespaceProtection ) == 0 ) {
+ return;
+ }
+
+ $header = $this->msg( 'listgrouprights-namespaceprotection-header' )->parse();
+ $out->addHTML(
+ Html::rawElement( 'h2', array(), Html::element( 'span', array(
+ 'class' => 'mw-headline',
+ 'id' => $wgParser->guessSectionNameFromWikiText( $header )
+ ), $header ) ) .
+ Xml::openElement( 'table', array( 'class' => 'wikitable' ) ) .
+ Html::element(
+ 'th',
+ array(),
+ $this->msg( 'listgrouprights-namespaceprotection-namespace' )->text()
+ ) .
+ Html::element(
+ 'th',
+ array(),
+ $this->msg( 'listgrouprights-namespaceprotection-restrictedto' )->text()
+ )
+ );
+
+ ksort( $namespaceProtection );
+ foreach ( $namespaceProtection as $namespace => $rights ) {
+ if ( !in_array( $namespace, MWNamespace::getValidNamespaces() ) ) {
+ continue;
+ }
+
+ if ( $namespace == NS_MAIN ) {
+ $namespaceText = $this->msg( 'blanknamespace' )->text();
+ } else {
+ $namespaceText = $wgContLang->convertNamespace( $namespace );
+ }
+
+ $out->addHTML(
+ Xml::openElement( 'tr' ) .
+ Html::rawElement(
+ 'td',
+ array(),
+ Linker::link(
+ SpecialPage::getTitleFor( 'Allpages' ),
+ $namespaceText,
+ array(),
+ array( 'namespace' => $namespace )
+ )
+ ) .
+ Xml::openElement( 'td' ) . Xml::openElement( 'ul' )
+ );
+
+ if ( !is_array( $rights ) ) {
+ $rights = array( $rights );
+ }
+
+ foreach ( $rights as $right ) {
+ $out->addHTML(
+ Html::rawElement( 'li', array(), $this->msg(
+ 'listgrouprights-right-display',
+ User::getRightDescription( $right ),
+ Html::element(
+ 'span',
+ array( 'class' => 'mw-listgrouprights-right-name' ),
+ $right
+ )
+ )->parse() )
+ );
+ }
+
+ $out->addHTML(
+ Xml::closeElement( 'ul' ) .
+ Xml::closeElement( 'td' ) .
+ Xml::closeElement( 'tr' )
+ );
+ }
+ $out->addHTML( Xml::closeElement( 'table' ) );
}
/**
* Create a user-readable list of permissions from the given array.
*
- * @param array $permissions of permission => bool (from $wgGroupPermissions items)
- * @param array $revoke of permission => bool (from $wgRevokePermissions items)
- * @param array $add of groups this group is allowed to add or true
- * @param array $remove of groups this group is allowed to remove or true
- * @param array $addSelf of groups this group is allowed to add to self or true
- * @param array $removeSelf of group this group is allowed to remove from self or true
+ * @param array $permissions Array of permission => bool (from $wgGroupPermissions items)
+ * @param array $revoke Array of permission => bool (from $wgRevokePermissions items)
+ * @param array $add Array of groups this group is allowed to add or true
+ * @param array $remove Array of groups this group is allowed to remove or true
+ * @param array $addSelf Array of groups this group is allowed to add to self or true
+ * @param array $removeSelf Array of group this group is allowed to remove from self or true
* @return string List of all granted permissions, separated by comma separator
*/
private function formatPermissions( $permissions, $revoke, $add, $remove, $addSelf, $removeSelf ) {
@@ -170,45 +255,54 @@ class SpecialListGroupRights extends SpecialPage {
sort( $r );
$lang = $this->getLanguage();
+ $allGroups = User::getAllGroups();
if ( $add === true ) {
$r[] = $this->msg( 'listgrouprights-addgroup-all' )->escaped();
- } elseif ( is_array( $add ) && count( $add ) ) {
- $add = array_values( array_unique( $add ) );
- $r[] = $this->msg( 'listgrouprights-addgroup',
- $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ),
- count( $add )
- )->parse();
+ } elseif ( is_array( $add ) ) {
+ $add = array_intersect( array_values( array_unique( $add ) ), $allGroups );
+ if ( count( $add ) ) {
+ $r[] = $this->msg( 'listgrouprights-addgroup',
+ $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $add ) ),
+ count( $add )
+ )->parse();
+ }
}
if ( $remove === true ) {
$r[] = $this->msg( 'listgrouprights-removegroup-all' )->escaped();
- } elseif ( is_array( $remove ) && count( $remove ) ) {
- $remove = array_values( array_unique( $remove ) );
- $r[] = $this->msg( 'listgrouprights-removegroup',
- $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
- count( $remove )
- )->parse();
+ } elseif ( is_array( $remove ) ) {
+ $remove = array_intersect( array_values( array_unique( $remove ) ), $allGroups );
+ if ( count( $remove ) ) {
+ $r[] = $this->msg( 'listgrouprights-removegroup',
+ $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $remove ) ),
+ count( $remove )
+ )->parse();
+ }
}
if ( $addSelf === true ) {
$r[] = $this->msg( 'listgrouprights-addgroup-self-all' )->escaped();
- } elseif ( is_array( $addSelf ) && count( $addSelf ) ) {
- $addSelf = array_values( array_unique( $addSelf ) );
- $r[] = $this->msg( 'listgrouprights-addgroup-self',
- $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
- count( $addSelf )
- )->parse();
+ } elseif ( is_array( $addSelf ) ) {
+ $addSelf = array_intersect( array_values( array_unique( $addSelf ) ), $allGroups );
+ if ( count( $addSelf ) ) {
+ $r[] = $this->msg( 'listgrouprights-addgroup-self',
+ $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $addSelf ) ),
+ count( $addSelf )
+ )->parse();
+ }
}
if ( $removeSelf === true ) {
$r[] = $this->msg( 'listgrouprights-removegroup-self-all' )->parse();
- } elseif ( is_array( $removeSelf ) && count( $removeSelf ) ) {
- $removeSelf = array_values( array_unique( $removeSelf ) );
- $r[] = $this->msg( 'listgrouprights-removegroup-self',
- $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
- count( $removeSelf )
- )->parse();
+ } elseif ( is_array( $removeSelf ) ) {
+ $removeSelf = array_intersect( array_values( array_unique( $removeSelf ) ), $allGroups );
+ if ( count( $removeSelf ) ) {
+ $r[] = $this->msg( 'listgrouprights-removegroup-self',
+ $lang->listToText( array_map( array( 'User', 'makeGroupLinkWiki' ), $removeSelf ) ),
+ count( $removeSelf )
+ )->parse();
+ }
}
if ( empty( $r ) ) {