Don't list nonexistent groups as addable or removable
authorJackmcbarn <jackmcbarn@gmail.com>
Mon, 15 Sep 2014 01:52:21 +0000 (21:52 -0400)
committerJackmcbarn <jackmcbarn@gmail.com>
Mon, 15 Sep 2014 02:48:01 +0000 (22:48 -0400)
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

includes/api/ApiQuerySiteinfo.php
includes/specials/SpecialListgrouprights.php

index 522c7c0..719a69b 100644 (file)
@@ -501,6 +501,7 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
                $data = array();
                $result = $this->getResult();
+               $allGroups = User::getAllGroups();
                foreach ( $config->get( 'GroupPermissions' ) as $group => $permissions ) {
                        $arr = array(
                                'name' => $group,
@@ -527,8 +528,11 @@ class ApiQuerySiteinfo extends ApiQueryBase {
 
                        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' );
+                                       }
                                }
                        }
 
index b5818ea..88ddb40 100644 (file)
@@ -251,45 +251,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 ) ) {