From bc3ba231628e4c26ffdb8d88c1e829ecd312fd49 Mon Sep 17 00:00:00 2001 From: Sarjuuk Date: Thu, 11 May 2023 14:37:34 +0200 Subject: [PATCH] Guides/Fixups * fix urls in user menu * strip anchors from tooltip title * prevent line breaks in description * make only in english info popup modular --- includes/user.class.php | 2 +- includes/utilities.php | 10 +++++++--- localization/lang.class.php | 1 + localization/locale_dede.php | 3 ++- localization/locale_enus.php | 3 ++- localization/locale_eses.php | 3 ++- localization/locale_frfr.php | 3 ++- localization/locale_ruru.php | 3 ++- localization/locale_zhcn.php | 3 ++- pages/genericPage.class.php | 2 +- pages/guide.php | 14 ++++++++++++-- static/js/global.js | 2 +- 12 files changed, 35 insertions(+), 14 deletions(-) diff --git a/includes/user.class.php b/includes/user.class.php index 185f5853..76eed4f1 100644 --- a/includes/user.class.php +++ b/includes/user.class.php @@ -677,7 +677,7 @@ class User if ($guides = DB::Aowow()->select('SELECT `id`, `title`, `url` FROM ?_guides WHERE `userId` = ?d AND `status` <> ?d', self::$id, GUIDE_STATUS_ARCHIVED)) { // fix url - array_walk($guides, fn(&$x) => $x['url'] = '/?guide='.($x['url'] ?? $x['id'])); + array_walk($guides, fn(&$x) => $x['url'] = '?guide='.($x['url'] ?? $x['id'])); $result = $guides; } diff --git a/includes/utilities.php b/includes/utilities.php index e3de4847..862e2b8d 100644 --- a/includes/utilities.php +++ b/includes/utilities.php @@ -18,6 +18,10 @@ class SimpleXML extends SimpleXMLElement trait TrRequestData { + // const in trait supported in php8.2+ + public static $PATTERN_TEXT_LINE = '/[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui'; + public static $PATTERN_TEXT_BLOB = '/[\x00-\x09\x0B-\x1F\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui'; + private $filtered = false; private function initRequestData() : void @@ -61,7 +65,7 @@ trait TrRequestData return $val === ''; // parameter is expected to be empty } - public static function checkInt(string $val) : int + private static function checkInt(string $val) : int { if (preg_match('/^-?\d+$/', $val)) return intVal($val); @@ -112,13 +116,13 @@ trait TrRequestData private static function checkTextLine(string $val) : string { // trim non-printable chars - return preg_replace('/[\p{Cc}\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui', '', $val); + return preg_replace(self::$PATTERN_TEXT_LINE, '', $val); } private static function checkTextBlob(string $val) : string { // trim non-printable chars - return preg_replace('/[\x00-\x09\x0B-\x1F\p{Cf}\p{Co}\p{Cs}\p{Cn}]/ui', '', $val); + return preg_replace(self::$PATTERN_TEXT_BLOB, '', $val); } } diff --git a/localization/lang.class.php b/localization/lang.class.php index c83b0ec1..1e45d676 100644 --- a/localization/lang.class.php +++ b/localization/lang.class.php @@ -3,6 +3,7 @@ class Lang { private static $timeUnits; + private static $lang; private static $main; private static $account; private static $user; diff --git a/localization/locale_dede.php b/localization/locale_dede.php index 7e258690..70b7bd8d 100644 --- a/localization/locale_dede.php +++ b/localization/locale_dede.php @@ -16,6 +16,7 @@ $lang = array( 'pl' => ["Jahre", "Monate", "Wochen", "Tage", "Stunden", "Minuten", "Sekunden", "Millisekunden"], 'ab' => ["J.", "M.", "W.", "Tag", "Std.", "Min.", "Sek.", "Ms."] ), + 'lang' => ['Englisch', null, 'Französisch', 'Deutsch', 'Chinesisch', null, 'Spanisch', null, 'Russisch'], 'main' => array( 'name' => "Name", 'link' => "Link", @@ -99,7 +100,7 @@ $lang = array( ), // article & infobox - 'englishOnly' => "Diese Seite ist nur in Englisch verfügbar.", + 'langOnly' => "Diese Seite ist nur in %s verfügbar.", // calculators 'preset' => "Vorlage", diff --git a/localization/locale_enus.php b/localization/locale_enus.php index b4657e1f..6f90be9f 100644 --- a/localization/locale_enus.php +++ b/localization/locale_enus.php @@ -16,6 +16,7 @@ $lang = array( 'pl' => ["years", "months", "weeks", "days", "hours", "minutes", "seconds", "milliseconds"], 'ab' => ["yr", "mo", "wk", "day", "hr", "min", "sec", "ms"] ), + 'lang' => ['English', null, 'French', 'German', 'Chinese', null, 'Spanish', null, 'Russian'], 'main' => array( 'name' => "name", 'link' => "Link", @@ -99,7 +100,7 @@ $lang = array( ), // article & infobox - 'englishOnly' => "This page is only available in English.", + 'langOnly' => "This page is only available in %s.", // calculators 'preset' => "Preset", diff --git a/localization/locale_eses.php b/localization/locale_eses.php index bd00077d..7000be32 100644 --- a/localization/locale_eses.php +++ b/localization/locale_eses.php @@ -16,6 +16,7 @@ $lang = array( 'pl' => ["años", "meses", "semanas", "dias", "horas", "minutos", "segundos", "milisegundos"], 'ab' => ["año", "mes", "sem", "", "h", "min", "seg", "ms"] ), + 'lang' => ['inglés', null, 'francés', 'alemán', 'chino', null, 'español', null, 'ruso'], 'main' => array( 'name' => "nombre", 'link' => "Enlace", @@ -99,7 +100,7 @@ $lang = array( ), // article & infobox - 'englishOnly' => "Esta página sólo está disponible en inglés.", + 'langOnly' => "Esta página sólo está disponible en %s.", // calculators 'preset' => "Predet.", diff --git a/localization/locale_frfr.php b/localization/locale_frfr.php index 4838abee..abbcb497 100644 --- a/localization/locale_frfr.php +++ b/localization/locale_frfr.php @@ -16,6 +16,7 @@ $lang = array( 'pl' => ["années", "mois", "semaines", "jours", "heures", "minutes", "secondes", "millisecondes"], 'ab' => ["an", "mo", "sem", "jour", "h", "min", "s", "ms"] ), + 'lang' => ['anglais', null, 'français', 'allemand', 'chinois', null, 'espagnol', null, 'russe'], 'main' => array( 'name' => "nom", 'link' => "Lien", @@ -99,7 +100,7 @@ $lang = array( ), // article & infobox - 'englishOnly' => "Cette page n'est disponible qu'en anglais pour le moment.", + 'langOnly' => "Cette page n'est disponible qu'en %s pour le moment.", // calculators 'preset' => "Prédéterminée", diff --git a/localization/locale_ruru.php b/localization/locale_ruru.php index 95c21af6..da012177 100644 --- a/localization/locale_ruru.php +++ b/localization/locale_ruru.php @@ -16,6 +16,7 @@ $lang = array( 'pl' => ["годы", "месяцы", "недели", "дн.", "часы", "мин", "секунды", "миллисекундах"], 'ab' => ["г.", "мес.", "нед.", "дн", "ч.", "мин", "сек.", "мс"] ), + 'lang' => ["английском", null, "французском", "немецком", "китайском", null, "испанском", null, "русском"], 'main' => array( 'name' => "название", 'link' => "Ссылка", @@ -99,7 +100,7 @@ $lang = array( ), // article & infobox - 'englishOnly' => "Эта страница доступна только на английском языке.", + 'langOnly' => "Эта страница доступна только на %s языке.", // calculators 'preset' => "Готовая таблица", diff --git a/localization/locale_zhcn.php b/localization/locale_zhcn.php index 0eb523ce..c3cd4ee9 100644 --- a/localization/locale_zhcn.php +++ b/localization/locale_zhcn.php @@ -16,6 +16,7 @@ $lang = array( 'pl' => ["年", "月", "周", "天", "小时", "分钟", "秒", "毫秒"], 'ab' => ["年", "月", "周", "天", "小时", "分钟", "秒", "毫秒"] ), + 'lang' => ['英语', null, '法语', '德语', '中文', null, '西班牙语', null, '俄语'], 'main' => array( 'name' => "名字", 'link' => "链接", @@ -99,7 +100,7 @@ $lang = array( ), // article & infobox - 'englishOnly' => "该页面仅以英语提供。", + 'langOnly' => "该页面仅以%s提供。", // calculators 'preset' => "预设", diff --git a/pages/genericPage.class.php b/pages/genericPage.class.php index 9c408c75..2ce1a666 100644 --- a/pages/genericPage.class.php +++ b/pages/genericPage.class.php @@ -567,7 +567,7 @@ class GenericPage $this->infobox = $article['quickInfo']; if ($article['locale'] != User::$localeId) - $this->article['params']['prepend'] = '
'.Lang::main('englishOnly').'
'; + $this->article['params']['prepend'] = '
'.Lang::main('langOnly', [Lang::lang($article['locale'])]).'
'; if (method_exists($this, 'postArticle')) // e.g. update variables in article $this->postArticle(); diff --git a/pages/guide.php b/pages/guide.php index 7a05486a..cec296fd 100644 --- a/pages/guide.php +++ b/pages/guide.php @@ -44,7 +44,7 @@ class GuidePage extends GenericPage 'submit' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkEmptySet'], 'title' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkTextLine'], 'name' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkTextLine'], - 'description' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkTextBlob'], + 'description' => ['filter' => FILTER_CALLBACK, 'options' => 'GuidePage::checkDescription'], 'changelog' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkTextBlob'], 'body' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkTextBlob'], 'locale' => ['filter' => FILTER_CALLBACK, 'options' => 'GenericPage::checkInt'], @@ -521,7 +521,7 @@ class GuidePage extends GenericPage $power = new StdClass(); if (!$this->subject->error) { - $power->{'name_'.User::$localeString} = $this->name; + $power->{'name_'.User::$localeString} = strip_tags($this->name); $power->{'tooltip_'.User::$localeString} = $this->subject->renderTooltip(); } @@ -550,6 +550,16 @@ class GuidePage extends GenericPage if ($this->subject?->getField('status') == GUIDE_STATUS_APPROVED) DB::Aowow()->query('UPDATE ?_guides SET `views` = `views` + 1 WHERE `id` = ?d', $this->typeId); } + + protected static function checkDescription(string $str) : string + { + // run checkTextBlob and also replace \n => \s and \s+ => \s + $str = preg_replace(parent::$PATTERN_TEXT_BLOB, '', $str); + + $str = strtr($str, ["\n" => ' ', "\r" => ' ']); + + return preg_replace('/\s+/', ' ', trim($str)); + } } ?> diff --git a/static/js/global.js b/static/js/global.js index 65645d09..84c9d469 100644 --- a/static/js/global.js +++ b/static/js/global.js @@ -652,7 +652,7 @@ var PageTemplate = new function() $.each(g_user.guides, function(idx, guide) { - var menuItem = [guide.id, guide.title, guide.url, [[guide.id, LANG.button_edit, '/?guide=edit&id=' + guide.id]]]; + var menuItem = [guide.id, guide.title, guide.url, [[guide.id, LANG.button_edit, '?guide=edit&id=' + guide.id]]]; submenu.push(menuItem); });