From 5f952b8992ec57099b246dfc34fd2adb4e559518 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Thu, 28 Sep 2023 17:30:35 +0200 Subject: [PATCH] Use intl Collator to sort strings See #4672 --- .../install/files/lib/acp/form/BoxAddForm.class.php | 11 ++++++----- .../files/lib/acp/form/DataImportForm.class.php | 10 ++++++---- .../files/lib/acp/form/LanguageExportForm.class.php | 8 +++++--- .../files/lib/acp/form/LanguageImportForm.class.php | 8 +++++--- .../files/lib/acp/page/TemplateListPage.class.php | 8 +++++--- .../EditorGetMentionSuggestionsAction.class.php | 9 ++++++--- .../install/files/lib/data/user/UserAction.class.php | 8 +++++--- .../files/lib/data/user/group/UserGroup.class.php | 8 +++++--- .../system/condition/UserTrophyCondition.class.php | 8 +++++--- .../system/search/acp/ACPSearchResultList.class.php | 8 +++++--- 10 files changed, 53 insertions(+), 33 deletions(-) diff --git a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php index 542cca4dda..81ee80abd3 100644 --- a/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/BoxAddForm.class.php @@ -260,13 +260,14 @@ class BoxAddForm extends AbstractForm } $this->availableBoxControllers = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.boxController'); - - \uasort($this->availableBoxControllers, static function (ObjectType $a, ObjectType $b) { - return \strcmp( + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \uasort( + $this->availableBoxControllers, + static fn (ObjectType $a, ObjectType $b) => $collator->compare( WCF::getLanguage()->get('wcf.acp.box.boxController.' . $a->objectType), WCF::getLanguage()->get('wcf.acp.box.boxController.' . $b->objectType) - ); - }); + ) + ); $this->readBoxPositions(); } diff --git a/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php b/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php index 1a1cd34c7b..052e8d5046 100644 --- a/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/DataImportForm.class.php @@ -133,12 +133,14 @@ class DataImportForm extends AbstractForm $this->exporters = ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.exporter'); // sort exporters by name - \uksort($this->exporters, static function ($a, $b) { - return \strcasecmp( + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \uksort( + $this->exporters, + static fn (string $a, string $b) => $collator->compare( WCF::getLanguage()->get('wcf.acp.dataImport.exporter.' . $a), WCF::getLanguage()->get('wcf.acp.dataImport.exporter.' . $b) - ); - }); + ) + ); $this->importers = \array_keys(ObjectTypeCache::getInstance()->getObjectTypes('com.woltlab.wcf.importer')); diff --git a/wcfsetup/install/files/lib/acp/form/LanguageExportForm.class.php b/wcfsetup/install/files/lib/acp/form/LanguageExportForm.class.php index 253b67ba15..aa5b9555de 100644 --- a/wcfsetup/install/files/lib/acp/form/LanguageExportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LanguageExportForm.class.php @@ -151,9 +151,11 @@ class LanguageExportForm extends AbstractForm parent::assignVariables(); $packages = PackageCache::getInstance()->getPackages(); - \usort($packages, static function (Package $a, Package $b) { - return $a->getName() <=> $b->getName(); - }); + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \usort( + $packages, + static fn (Package $a, Package $b) => $collator->compare($a->getName(), $b->getName()) + ); WCF::getTPL()->assign([ 'languageID' => $this->languageID, diff --git a/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php b/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php index d10466e016..6cfd2f7ef8 100644 --- a/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php +++ b/wcfsetup/install/files/lib/acp/form/LanguageImportForm.class.php @@ -174,9 +174,11 @@ class LanguageImportForm extends AbstractForm parent::assignVariables(); $packages = PackageCache::getInstance()->getPackages(); - \usort($packages, static function (Package $a, Package $b) { - return $a->getName() <=> $b->getName(); - }); + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \usort( + $packages, + static fn (Package $a, Package $b) => $collator->compare($a->getName(), $b->getName()) + ); WCF::getTPL()->assign([ 'languages' => $this->languages, diff --git a/wcfsetup/install/files/lib/acp/page/TemplateListPage.class.php b/wcfsetup/install/files/lib/acp/page/TemplateListPage.class.php index 8c22b66e2d..a7859d8ce3 100644 --- a/wcfsetup/install/files/lib/acp/page/TemplateListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/TemplateListPage.class.php @@ -148,9 +148,11 @@ class TemplateListPage extends SortablePage $package->getName(); } - \uasort($this->availableApplications, static function (Package $a, Package $b) { - return $a->getName() <=> $b->getName(); - }); + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \uasort( + $this->availableApplications, + static fn (Package $a, Package $b) => $collator->compare($a->getName(), $b->getName()) + ); } /** diff --git a/wcfsetup/install/files/lib/action/EditorGetMentionSuggestionsAction.class.php b/wcfsetup/install/files/lib/action/EditorGetMentionSuggestionsAction.class.php index ddf6513102..0e56965860 100644 --- a/wcfsetup/install/files/lib/action/EditorGetMentionSuggestionsAction.class.php +++ b/wcfsetup/install/files/lib/action/EditorGetMentionSuggestionsAction.class.php @@ -10,6 +10,7 @@ use wcf\data\user\group\UserGroup; use wcf\data\user\UserProfile; use wcf\data\user\UserProfileList; use wcf\http\Helper; +use wcf\system\WCF; /** * Suggests users that may be mentioned. @@ -91,9 +92,11 @@ final class EditorGetMentionSuggestionsAction implements RequestHandlerInterface return \str_starts_with(\mb_strtolower($userGroup->getName()), $query); }); - \usort($userGroups, static function (UserGroup $a, UserGroup $b) { - return \mb_strtolower($a->getName()) <=> \mb_strtolower($b->getName()); - }); + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \usort( + $userGroups, + static fn (UserGroup $a, UserGroup $b) => $collator->compare($a->getName(), $b->getName()) + ); return $userGroups; } diff --git a/wcfsetup/install/files/lib/data/user/UserAction.class.php b/wcfsetup/install/files/lib/data/user/UserAction.class.php index d964c3ca50..0b5e6ab1f4 100644 --- a/wcfsetup/install/files/lib/data/user/UserAction.class.php +++ b/wcfsetup/install/files/lib/data/user/UserAction.class.php @@ -584,9 +584,11 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio } } - \usort($list, static function (array $item1, array $item2) { - return \strcasecmp($item1['label'], $item2['label']); - }); + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \usort( + $list, + static fn (array $item1, array $item2) => $collator->compare($item1['label'], $item2['label']) + ); } // find users diff --git a/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php b/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php index 8e2cccd914..242e2b885e 100644 --- a/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php +++ b/wcfsetup/install/files/lib/data/user/group/UserGroup.class.php @@ -639,8 +639,10 @@ class UserGroup extends DatabaseObject implements ITitledObject */ public static function sortGroups(array &$userGroups) { - \uasort($userGroups, static function (self $groupA, self $groupB) { - return \strcasecmp($groupA->getName(), $groupB->getName()); - }); + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \uasort( + $userGroups, + static fn (self $groupA, self $groupB) => $collator->compare($groupA->getName(), $groupB->getName()) + ); } } diff --git a/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php b/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php index f244f59d6a..801ba0f125 100644 --- a/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php +++ b/wcfsetup/install/files/lib/system/condition/UserTrophyCondition.class.php @@ -207,9 +207,11 @@ HTML; $trophyList->readObjects(); $this->trophies = $trophyList->getObjects(); - \uasort($this->trophies, static function (Trophy $a, Trophy $b) { - return \strcmp($a->getTitle(), $b->getTitle()); - }); + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \uasort( + $this->trophies, + static fn (Trophy $a, Trophy $b) => $collator->compare($a->getTitle(), $b->getTitle()) + ); } return $this->trophies; diff --git a/wcfsetup/install/files/lib/system/search/acp/ACPSearchResultList.class.php b/wcfsetup/install/files/lib/system/search/acp/ACPSearchResultList.class.php index afb9c73cd0..cdfeb98f90 100644 --- a/wcfsetup/install/files/lib/system/search/acp/ACPSearchResultList.class.php +++ b/wcfsetup/install/files/lib/system/search/acp/ACPSearchResultList.class.php @@ -85,9 +85,11 @@ class ACPSearchResultList implements \Countable, \Iterator */ public function sort(): void { - \usort($this->results, static function (ACPSearchResult $a, ACPSearchResult $b) { - return \strcmp($a->getTitle(), $b->getTitle()); - }); + $collator = new \Collator(WCF::getLanguage()->getLocale()); + \usort( + $this->results, + static fn (ACPSearchResult $a, ACPSearchResult $b) => $collator->compare($a->getTitle(), $b->getTitle()) + ); } /** -- 2.20.1