From d01b01c6cc73dd8e58808af7a4dd08a4c75f2cc2 Mon Sep 17 00:00:00 2001 From: Jackmcbarn Date: Sun, 14 Sep 2014 21:52:21 -0400 Subject: [PATCH] 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 --- includes/api/ApiQuerySiteinfo.php | 8 ++- includes/specials/SpecialListgrouprights.php | 57 +++++++++++--------- 2 files changed, 39 insertions(+), 26 deletions(-) diff --git a/includes/api/ApiQuerySiteinfo.php b/includes/api/ApiQuerySiteinfo.php index 522c7c0805..719a69bbb2 100644 --- a/includes/api/ApiQuerySiteinfo.php +++ b/includes/api/ApiQuerySiteinfo.php @@ -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' ); + } } } diff --git a/includes/specials/SpecialListgrouprights.php b/includes/specials/SpecialListgrouprights.php index b5818eab45..88ddb401e3 100644 --- a/includes/specials/SpecialListgrouprights.php +++ b/includes/specials/SpecialListgrouprights.php @@ -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 ) ) { -- 2.20.1