From 2c451b8deb28b5ee2b166ee1c0e2e9d9c87c855c Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Mon, 27 May 2024 17:52:08 +0200 Subject: [PATCH] Locales/Search * do not apply minimum string length limiter to logographic languages --- includes/defines.php | 3 +++ includes/utilities.php | 6 ++++++ pages/search.php | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/includes/defines.php b/includes/defines.php index d5e907bd..8377b1b2 100644 --- a/includes/defines.php +++ b/includes/defines.php @@ -157,10 +157,13 @@ define('U_GROUP_PREMIUM_PERMISSIONS', (U_GROUP_PREMIUM|U_GROUP_STAFF|U_GRO // Locales define('LOCALE_EN', 0); +define('LOCALE_KR', 1); // unused define('LOCALE_FR', 2); define('LOCALE_DE', 3); define('LOCALE_CN', 4); +define('LOCALE_TW', 5); // unused define('LOCALE_ES', 6); +define('LOCALE_MX', 7); // unused define('LOCALE_RU', 8); // red buttons on the top of the page diff --git a/includes/utilities.php b/includes/utilities.php index 4a39645a..6b29d2fe 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -853,6 +853,12 @@ abstract class Util )); } + // todo: create Locale object and integrate + public static function isLogographic(int $localeId) : bool + { + return $localeId == LOCALE_CN || $localeId == LOCALE_TW || $localeId == LOCALE_KR; + } + // default back to enUS if localization unavailable public static function localizedString(array $data, string $field, bool $silent = false) : string { diff --git a/pages/search.php b/pages/search.php index 15cca1f1..24ba6e85 100644 --- a/pages/search.php +++ b/pages/search.php @@ -135,14 +135,14 @@ class SearchPage extends GenericPage continue; else if ($clean[0] == '-') { - if (mb_strlen($clean) < 4) + if (mb_strlen($clean) < 4 && !Util::isLogographic(User::$localeId)) $this->invalid[] = mb_substr($raw, 1); else $this->excluded[] = mb_substr(str_replace('_', '\\_', $clean), 1); } else if ($clean !== '') { - if (mb_strlen($clean) < 3) + if (mb_strlen($clean) < 3 && !Util::isLogographic(User::$localeId)) $this->invalid[] = $raw; else $this->included[] = str_replace('_', '\\_', $clean);