Jackmcbarn has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/160377

Change subject: Don't list nonexistent groups as addable or removable
......................................................................

Don't list nonexistent groups as addable or removable

You can't add or remove a group that doesn't exist, so don't claim that
it's possible on Special:ListGroupRights or the API.

Change-Id: I02d3f00142ca1cb0cdcbf30e79fecb3c96e96405
---
M includes/api/ApiQuerySiteinfo.php
M includes/specials/SpecialListgrouprights.php
2 files changed, 39 insertions(+), 26 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/core 
refs/changes/77/160377/1

diff --git a/includes/api/ApiQuerySiteinfo.php 
b/includes/api/ApiQuerySiteinfo.php
index 522c7c0..153a497 100644
--- a/includes/api/ApiQuerySiteinfo.php
+++ b/includes/api/ApiQuerySiteinfo.php
@@ -525,10 +525,14 @@
                                'remove-self' => $config->get( 
'GroupsRemoveFromSelf' )
                        );
 
+                       $allGroups = User::getAllGroups();
                        foreach ( $groupArr as $type => $rights ) {
                                if ( isset( $rights[$group] ) ) {
-                                       $arr[$type] = $rights[$group];
-                                       $result->setIndexedTagName( 
$arr[$type], 'group' );
+                                       $groups = array_intersect( 
$rights[$group], $allGroups );
+                                       if ( $groups ) {
+                                               $arr[$type] = $groups;
+                                               $result->setIndexedTagName( 
$arr[$type], 'group' );
+                                       }
                                }
                        }
 
diff --git a/includes/specials/SpecialListgrouprights.php 
b/includes/specials/SpecialListgrouprights.php
index b5818ea..88ddb40 100644
--- a/includes/specials/SpecialListgrouprights.php
+++ b/includes/specials/SpecialListgrouprights.php
@@ -251,45 +251,54 @@
                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 ) ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/160377
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I02d3f00142ca1cb0cdcbf30e79fecb3c96e96405
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Jackmcbarn <jackmcb...@gmail.com>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to