From 75ff49a1ffcef0fdd27e6bf8d6421210413cfed4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C4=9Bj=20Such=C3=A1nek?= Date: Tue, 24 Sep 2019 13:49:18 +0200 Subject: [PATCH] Sort user groups when shown in drop-downs This makes searching for them easier and makes their order less arbitrary, especially when they are localized. Replace one sort function wrongly chosen by me. Change-Id: I231f28656333c5bf846bedfedb6ba5040a09f74e --- includes/api/ApiQueryAllUsers.php | 6 +++++- includes/api/ApiQueryContributors.php | 6 +++++- includes/api/ApiUserrights.php | 12 +++++++++--- includes/specials/SpecialActiveUsers.php | 2 +- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/includes/api/ApiQueryAllUsers.php b/includes/api/ApiQueryAllUsers.php index 0ea6af3247d..cbe8368a5f1 100644 --- a/includes/api/ApiQueryAllUsers.php +++ b/includes/api/ApiQueryAllUsers.php @@ -325,9 +325,13 @@ class ApiQueryAllUsers extends ApiQueryBase { return 'anon-public-user-private'; } - public function getAllowedParams() { + public function getAllowedParams( $flags = 0 ) { $userGroups = User::getAllGroups(); + if ( $flags & ApiBase::GET_VALUES_FOR_HELP ) { + sort( $userGroups ); + } + return [ 'from' => null, 'to' => null, diff --git a/includes/api/ApiQueryContributors.php b/includes/api/ApiQueryContributors.php index f2e306fe835..ea5b7c313a2 100644 --- a/includes/api/ApiQueryContributors.php +++ b/includes/api/ApiQueryContributors.php @@ -223,10 +223,14 @@ class ApiQueryContributors extends ApiQueryBase { return 'public'; } - public function getAllowedParams() { + public function getAllowedParams( $flags = 0 ) { $userGroups = User::getAllGroups(); $userRights = $this->getPermissionManager()->getAllPermissions(); + if ( $flags & ApiBase::GET_VALUES_FOR_HELP ) { + sort( $userGroups ); + } + return [ 'group' => [ ApiBase::PARAM_TYPE => $userGroups, diff --git a/includes/api/ApiUserrights.php b/includes/api/ApiUserrights.php index 3aaae70483c..bfb2256b8c9 100644 --- a/includes/api/ApiUserrights.php +++ b/includes/api/ApiUserrights.php @@ -160,7 +160,13 @@ class ApiUserrights extends ApiBase { return true; } - public function getAllowedParams() { + public function getAllowedParams( $flags = 0 ) { + $allGroups = $this->getAllGroups(); + + if ( $flags & ApiBase::GET_VALUES_FOR_HELP ) { + sort( $allGroups ); + } + $a = [ 'user' => [ ApiBase::PARAM_TYPE => 'user', @@ -169,7 +175,7 @@ class ApiUserrights extends ApiBase { ApiBase::PARAM_TYPE => 'integer', ], 'add' => [ - ApiBase::PARAM_TYPE => $this->getAllGroups(), + ApiBase::PARAM_TYPE => $allGroups, ApiBase::PARAM_ISMULTI => true ], 'expiry' => [ @@ -178,7 +184,7 @@ class ApiUserrights extends ApiBase { ApiBase::PARAM_DFLT => 'infinite', ], 'remove' => [ - ApiBase::PARAM_TYPE => $this->getAllGroups(), + ApiBase::PARAM_TYPE => $allGroups, ApiBase::PARAM_ISMULTI => true ], 'reason' => [ diff --git a/includes/specials/SpecialActiveUsers.php b/includes/specials/SpecialActiveUsers.php index 7995e3ef92b..0f072248638 100644 --- a/includes/specials/SpecialActiveUsers.php +++ b/includes/specials/SpecialActiveUsers.php @@ -84,7 +84,7 @@ class SpecialActiveUsers extends SpecialPage { $msg = htmlspecialchars( UserGroupMembership::getGroupName( $group ) ); $options[$msg] = $group; } - asort( $options ); + ksort( $options ); // Backwards-compatibility with old URLs $req = $this->getRequest();