From 0f68dee15cd9a11715312ceaa0ebd8f2f702872d Mon Sep 17 00:00:00 2001 From: Kent Riboe Date: Sun, 5 Jul 2026 22:21:19 +0300 Subject: [PATCH] viewlog: per-page selector + Bootstrap 5 pager, fix footer layout (#1062) (#1063) Improve pagination on viewlog page (make page size configurable, use bootstrap 5 pager) Closes #1062. Thanks @knofte --- functions.inc.php | 48 +++++++++++++ languages/bg.lang | 1 + languages/ca.lang | 1 + languages/cn.lang | 1 + languages/cs.lang | 1 + languages/da.lang | 1 + languages/de.lang | 1 + languages/en.lang | 1 + languages/es.lang | 1 + languages/et.lang | 1 + languages/eu.lang | 1 + languages/fi.lang | 1 + languages/fo.lang | 1 + languages/fr.lang | 1 + languages/gl.lang | 1 + languages/hr.lang | 1 + languages/hu.lang | 1 + languages/is.lang | 1 + languages/it.lang | 1 + languages/ja.lang | 1 + languages/lt.lang | 1 + languages/mk.lang | 1 + languages/nb.lang | 1 + languages/nl.lang | 1 + languages/nn.lang | 1 + languages/pl.lang | 1 + languages/pt-br.lang | 1 + languages/pt-pt.lang | 1 + languages/ro.lang | 1 + languages/ru.lang | 1 + languages/sk.lang | 1 + languages/sl.lang | 1 + languages/sv.lang | 1 + languages/tr.lang | 1 + languages/tw.lang | 1 + languages/ua.lang | 1 + public/viewlog.php | 34 +++++++-- templates/viewlog.tpl | 128 +++++++++++++-------------------- tests/PaginationWindowTest.php | 58 +++++++++++++++ 39 files changed, 219 insertions(+), 84 deletions(-) create mode 100644 tests/PaginationWindowTest.php diff --git a/functions.inc.php b/functions.inc.php index 2deecc73..1e6ff4bb 100644 --- a/functions.inc.php +++ b/functions.inc.php @@ -1983,6 +1983,54 @@ function viewlog_domain_condition(bool $show_all, bool $is_global_admin, string return ''; } +/** + * Compute the page numbers to display in a windowed pager. + * + * Always includes page 1 and the last page, plus a window of $radius pages on + * either side of the current page. Gaps between those ranges are represented by + * a null entry (rendered as an ellipsis). For example current=20, total=50, + * radius=5 yields: [1, null, 15..25, null, 50]. + * + * @param int $current - the current page number (1-based) + * @param int $total_pages - total number of pages + * @param int $radius - how many pages to show either side of $current + * @return array - ordered page numbers, null marks an ellipsis gap + */ +function pagination_window(int $current, int $total_pages, int $radius = 5): array +{ + if ($total_pages <= 1) { + return $total_pages == 1 ? [1] : []; + } + + $current = max(1, min($current, $total_pages)); + $start = max(1, $current - $radius); + $end = min($total_pages, $current + $radius); + + # Only the window itself is built (O(radius)), with page 1 / the last page + # and ellipsis markers (null) prepended/appended as needed. + $result = []; + + if ($start > 1) { + $result[] = 1; + if ($start > 2) { + $result[] = null; # gap between page 1 and the window + } + } + + for ($i = $start; $i <= $end; $i++) { + $result[] = $i; + } + + if ($end < $total_pages) { + if ($end < $total_pages - 1) { + $result[] = null; # gap between the window and the last page + } + $result[] = $total_pages; + } + + return $result; +} + /** * db_where_clause * Action: builds and returns a WHERE clause for database queries. All given conditions will be AND'ed. diff --git a/languages/bg.lang b/languages/bg.lang index e35f5471..dc1bb5f2 100644 --- a/languages/bg.lang +++ b/languages/bg.lang @@ -217,6 +217,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Разглеждане на последните %s действия за '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Дата'; $PALANG['pViewlog_action'] = 'Действие'; $PALANG['pViewlog_data'] = 'Данни'; diff --git a/languages/ca.lang b/languages/ca.lang index 56896150..c3606107 100644 --- a/languages/ca.lang +++ b/languages/ca.lang @@ -215,6 +215,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Veure les últimes %s accions per '; $PALANG['pViewlog_welcome_all'] = 'Veure les últimes %s accions '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Data/Hora'; $PALANG['pViewlog_action'] = 'Acció'; $PALANG['pViewlog_data'] = 'Dades'; diff --git a/languages/cn.lang b/languages/cn.lang index c8212d38..4cc91805 100644 --- a/languages/cn.lang +++ b/languages/cn.lang @@ -216,6 +216,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = '查看最新的%s项操作日志 域名: '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = '时间'; $PALANG['pViewlog_action'] = '操作'; $PALANG['pViewlog_data'] = '内容'; diff --git a/languages/cs.lang b/languages/cs.lang index 52682530..ee4b60d6 100644 --- a/languages/cs.lang +++ b/languages/cs.lang @@ -226,6 +226,7 @@ $PALANG['reply_once_per_week'] = 'Odpovědět jednou za týden'; $PALANG['pViewlog_welcome'] = 'Prohlížet %s posledních akcí pro '; $PALANG['pViewlog_welcome_all'] = 'Prohlížet %s posledních akcí '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Časová značka'; $PALANG['pViewlog_action'] = 'Akce'; $PALANG['pViewlog_data'] = 'Poznámka'; diff --git a/languages/da.lang b/languages/da.lang index 9e5ed2f9..562864b2 100644 --- a/languages/da.lang +++ b/languages/da.lang @@ -223,6 +223,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Vis de sidste %s poster for '; $PALANG['pViewlog_welcome_all'] = 'Vis de sidste %s poster '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Tidsstempel'; $PALANG['pViewlog_action'] = 'Handling'; $PALANG['pViewlog_data'] = 'Data'; diff --git a/languages/de.lang b/languages/de.lang index 495f40aa..d451f8cd 100644 --- a/languages/de.lang +++ b/languages/de.lang @@ -220,6 +220,7 @@ $PALANG['reply_once_per_week'] = 'Einmal pro Woche antworten'; $PALANG['pViewlog_welcome'] = 'Zeigt die letzten %s Aktionen für '; $PALANG['pViewlog_welcome_all'] = 'Zeigt die letzten %s Aktionen '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Zeitpunkt'; $PALANG['pViewlog_action'] = 'Aktion'; $PALANG['pViewlog_data'] = 'Daten'; diff --git a/languages/en.lang b/languages/en.lang index 35aff8bf..35d1bc04 100644 --- a/languages/en.lang +++ b/languages/en.lang @@ -276,6 +276,7 @@ $PALANG['reply_once_per_week'] = 'Reply once a week'; $PALANG['pViewlog_welcome'] = 'View the last %s actions for '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Timestamp'; $PALANG['pViewlog_action'] = 'Action'; $PALANG['pViewlog_data'] = 'Data'; diff --git a/languages/es.lang b/languages/es.lang index a2bae21e..543d9f67 100644 --- a/languages/es.lang +++ b/languages/es.lang @@ -218,6 +218,7 @@ $PALANG['reply_once_per_week'] = 'Responder una vez por semana'; $PALANG['pViewlog_welcome'] = 'Ver las últimas %s acciones para '; $PALANG['pViewlog_welcome_all'] = 'Ver las últimas %s acciones '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Fecha/Hora'; $PALANG['pViewlog_action'] = 'Acción'; $PALANG['pViewlog_data'] = 'Datos'; diff --git a/languages/et.lang b/languages/et.lang index 57b95272..6a999cf9 100644 --- a/languages/et.lang +++ b/languages/et.lang @@ -216,6 +216,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Vaata %s viimast muudatust domeeniga '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Ajatempel'; $PALANG['pViewlog_action'] = 'Toiming'; $PALANG['pViewlog_data'] = 'Andmed'; diff --git a/languages/eu.lang b/languages/eu.lang index 83dd8965..54261dba 100644 --- a/languages/eu.lang +++ b/languages/eu.lang @@ -214,6 +214,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Honen azken %s ekintzak ikusi '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Data/ordua'; $PALANG['pViewlog_action'] = 'Ekintza'; $PALANG['pViewlog_data'] = 'Datuak'; diff --git a/languages/fi.lang b/languages/fi.lang index 55e7fc1b..29181c79 100644 --- a/languages/fi.lang +++ b/languages/fi.lang @@ -216,6 +216,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Näytä viimeiset kymmenen tapahtumaa domainille '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Aikaleima'; $PALANG['pViewlog_action'] = 'Tapahtuma'; $PALANG['pViewlog_data'] = 'Tiedot'; diff --git a/languages/fo.lang b/languages/fo.lang index d1986772..5f61197c 100644 --- a/languages/fo.lang +++ b/languages/fo.lang @@ -216,6 +216,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Vís seinastu %s hendingarnar fyri '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Tíðarstempul'; $PALANG['pViewlog_action'] = 'Hending'; $PALANG['pViewlog_data'] = 'Dáta'; diff --git a/languages/fr.lang b/languages/fr.lang index f74b9901..733dd81b 100644 --- a/languages/fr.lang +++ b/languages/fr.lang @@ -220,6 +220,7 @@ $PALANG['reply_once_per_week'] = 'Répondre une fois par semaine'; $PALANG['pViewlog_welcome'] = 'Visualiser les %s dernières actions pour '; $PALANG['pViewlog_welcome_all'] = 'Visualiser les %s dernières actions '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Date/Heure'; $PALANG['pViewlog_action'] = 'Action'; $PALANG['pViewlog_data'] = 'Information'; diff --git a/languages/gl.lang b/languages/gl.lang index 74df993a..40d24e7d 100644 --- a/languages/gl.lang +++ b/languages/gl.lang @@ -215,6 +215,7 @@ $PALANG['reply_once_per_week'] = 'Respostar unha vez á semana'; # XXX $PALANG['pViewlog_welcome'] = 'Ver as últimas %s accións para '; $PALANG['pViewlog_welcome_all'] = 'Ver as últimas %s accións '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Data/Hora'; $PALANG['pViewlog_action'] = 'Acción'; $PALANG['pViewlog_data'] = 'Datos'; diff --git a/languages/hr.lang b/languages/hr.lang index c13bcac9..a6bcbe68 100644 --- a/languages/hr.lang +++ b/languages/hr.lang @@ -215,6 +215,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Pogledaj zadnjih %s akcija za '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Vrijeme'; $PALANG['pViewlog_action'] = 'Akcija'; $PALANG['pViewlog_data'] = 'Podaci'; diff --git a/languages/hu.lang b/languages/hu.lang index e54b319f..b32705a3 100644 --- a/languages/hu.lang +++ b/languages/hu.lang @@ -220,6 +220,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Az utolsó %s esemény megtekintése: '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Idõbélyeg'; $PALANG['pViewlog_action'] = 'Akció'; $PALANG['pViewlog_data'] = 'Adat'; diff --git a/languages/is.lang b/languages/is.lang index 64c2fbc2..b37ee119 100644 --- a/languages/is.lang +++ b/languages/is.lang @@ -216,6 +216,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Skoða síðustu %s aðgerðir fyrir '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Tími'; $PALANG['pViewlog_action'] = 'aðgerð'; $PALANG['pViewlog_data'] = 'gögn'; diff --git a/languages/it.lang b/languages/it.lang index 9fab90e6..93e9c343 100644 --- a/languages/it.lang +++ b/languages/it.lang @@ -217,6 +217,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Elenca gli ultimi %s eventi per '; $PALANG['pViewlog_welcome_all'] = 'Elenca gli ultimi %s eventi '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Orario'; $PALANG['pViewlog_action'] = 'Azione'; $PALANG['pViewlog_data'] = 'Dati'; diff --git a/languages/ja.lang b/languages/ja.lang index 3076349f..d0cbb3a9 100644 --- a/languages/ja.lang +++ b/languages/ja.lang @@ -220,6 +220,7 @@ $PALANG['reply_once_per_week'] = '週に一度返信'; $PALANG['pViewlog_welcome'] = '過去 %s 個のアクション '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'タイムスタンプ'; $PALANG['pViewlog_action'] = 'アクション'; $PALANG['pViewlog_data'] = 'データ'; diff --git a/languages/lt.lang b/languages/lt.lang index 1af64086..c1d61664 100644 --- a/languages/lt.lang +++ b/languages/lt.lang @@ -217,6 +217,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Peržiūrėti paskutinius %s vartotojo veiksmų '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Laikas'; $PALANG['pViewlog_action'] = 'Veiksmas'; $PALANG['pViewlog_data'] = 'Duomenys'; diff --git a/languages/mk.lang b/languages/mk.lang index 7a1a8ce3..61555285 100644 --- a/languages/mk.lang +++ b/languages/mk.lang @@ -216,6 +216,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Преглед на последните %s операции за: '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Маркер (Timestamp)'; $PALANG['pViewlog_action'] = 'Операција'; $PALANG['pViewlog_data'] = 'Датум'; diff --git a/languages/nb.lang b/languages/nb.lang index 8f4a72f6..a579fe41 100644 --- a/languages/nb.lang +++ b/languages/nb.lang @@ -217,6 +217,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Vis de %s siste handlingene for '; $PALANG['pViewlog_welcome_all'] = 'Vis de %s siste handlingene '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Klokkeslett'; $PALANG['pViewlog_action'] = 'Handling'; $PALANG['pViewlog_data'] = 'Data'; diff --git a/languages/nl.lang b/languages/nl.lang index d0bd16e0..7601c7c8 100644 --- a/languages/nl.lang +++ b/languages/nl.lang @@ -219,6 +219,7 @@ $PALANG['reply_once_per_week'] = 'Beantwoord een keer per week'; $PALANG['pViewlog_welcome'] = 'Laat de laatste %s actie\'s zien van '; $PALANG['pViewlog_welcome_all'] = 'Laat de laatste %s actie\'s zien '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Tijd'; $PALANG['pViewlog_action'] = 'Actie'; $PALANG['pViewlog_data'] = 'Aanpassing'; diff --git a/languages/nn.lang b/languages/nn.lang index 099dfefb..a156f887 100644 --- a/languages/nn.lang +++ b/languages/nn.lang @@ -215,6 +215,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Vis de %s siste handlingene '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Klokkeslett'; $PALANG['pViewlog_action'] = 'Handling'; $PALANG['pViewlog_data'] = 'Data'; diff --git a/languages/pl.lang b/languages/pl.lang index 542eb39d..5dd5b2a2 100644 --- a/languages/pl.lang +++ b/languages/pl.lang @@ -219,6 +219,7 @@ $PALANG['reply_once_per_week'] = 'Odpowiedz raz na tydzień'; $PALANG['pViewlog_welcome'] = 'Pokaż %s ostatnich działań dla '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Data'; $PALANG['pViewlog_action'] = 'Działanie'; $PALANG['pViewlog_data'] = 'Dane'; diff --git a/languages/pt-br.lang b/languages/pt-br.lang index 584d0a98..f815f023 100644 --- a/languages/pt-br.lang +++ b/languages/pt-br.lang @@ -222,6 +222,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Últimas %s ações para '; $PALANG['pViewlog_welcome_all'] = 'Últimas %s ações '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Data/Hora'; $PALANG['pViewlog_action'] = 'Ação'; $PALANG['pViewlog_data'] = 'Descrição'; diff --git a/languages/pt-pt.lang b/languages/pt-pt.lang index 01e7ae88..128e7bea 100644 --- a/languages/pt-pt.lang +++ b/languages/pt-pt.lang @@ -222,6 +222,7 @@ $PALANG['reply_once_per_week'] = 'Responder uma vez por semana'; # XXX $PALANG['pViewlog_welcome'] = 'Últimas %s acções para '; $PALANG['pViewlog_welcome_all'] = 'Últimas %s acções '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Data/Hora'; $PALANG['pViewlog_action'] = 'Acção'; $PALANG['pViewlog_data'] = 'Descrição'; diff --git a/languages/ro.lang b/languages/ro.lang index 27ff7cb0..13eb278d 100644 --- a/languages/ro.lang +++ b/languages/ro.lang @@ -220,6 +220,7 @@ $PALANG['reply_once_per_week'] = 'Raspunde odata pe saptamana'; $PALANG['pViewlog_welcome'] = 'Vizualizati ultimele %s operatii pentru '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Data si ora'; $PALANG['pViewlog_action'] = 'Operatie'; $PALANG['pViewlog_data'] = 'Detalii'; diff --git a/languages/ru.lang b/languages/ru.lang index 88220355..7a742675 100644 --- a/languages/ru.lang +++ b/languages/ru.lang @@ -223,6 +223,7 @@ $PALANG['reply_once_per_week'] = 'Отвечать один раз в недел $PALANG['pViewlog_welcome'] = 'Просмотр %s последних действий для '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Время создания/модификации'; $PALANG['pViewlog_action'] = 'Действие'; $PALANG['pViewlog_data'] = 'Данные'; diff --git a/languages/sk.lang b/languages/sk.lang index 6db28678..adb8c7e6 100644 --- a/languages/sk.lang +++ b/languages/sk.lang @@ -217,6 +217,7 @@ $PALANG['reply_once_per_week'] = 'Odpovedať raz za týždeň'; $PALANG['pViewlog_welcome'] = 'Prehľad %s posledných akcií pre '; $PALANG['pViewlog_welcome_all'] = 'Prehľad %s posledných akcií '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Časová značka'; $PALANG['pViewlog_action'] = 'Akcia'; $PALANG['pViewlog_data'] = 'Podrobnosti'; diff --git a/languages/sl.lang b/languages/sl.lang index 9b22c14e..c905ad13 100644 --- a/languages/sl.lang +++ b/languages/sl.lang @@ -216,6 +216,7 @@ $PALANG['reply_once_per_week'] = 'Reply once per week'; # XXX $PALANG['pViewlog_welcome'] = 'Seznam zadnjih %s operacij za '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Čas'; $PALANG['pViewlog_action'] = 'Operacija'; $PALANG['pViewlog_data'] = 'Podatki'; diff --git a/languages/sv.lang b/languages/sv.lang index 0ef389f6..beccbf45 100644 --- a/languages/sv.lang +++ b/languages/sv.lang @@ -221,6 +221,7 @@ $PALANG['reply_once_per_week'] = 'Svara en gång i veckan'; $PALANG['pViewlog_welcome'] = 'Visa de senaste %s åtgärderna för '; $PALANG['pViewlog_welcome_all'] = 'Visa de senaste %s åtgärderna '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Tidpunkt'; $PALANG['pViewlog_action'] = 'Åtgärd'; $PALANG['pViewlog_data'] = 'Data'; diff --git a/languages/tr.lang b/languages/tr.lang index 07fb7cba..9bac571a 100644 --- a/languages/tr.lang +++ b/languages/tr.lang @@ -216,6 +216,7 @@ $PALANG['reply_once_per_week'] = 'Haftada bir kez yanıtla'; $PALANG['pViewlog_welcome'] = 'Son %s hareketi:'; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Timestamp'; # XXX $PALANG['pViewlog_action'] = 'Hareket'; $PALANG['pViewlog_data'] = 'Veri'; diff --git a/languages/tw.lang b/languages/tw.lang index 2cb91086..5fd13d89 100644 --- a/languages/tw.lang +++ b/languages/tw.lang @@ -218,6 +218,7 @@ $PALANG['reply_once_per_week'] = '每星期回覆一次'; $PALANG['pViewlog_welcome'] = '查看最新的%s項操作日誌 網域: '; $PALANG['pViewlog_welcome_all'] = 'View the last %s actions '; # XXX $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = '時間'; $PALANG['pViewlog_action'] = '操作'; $PALANG['pViewlog_data'] = '內容'; diff --git a/languages/ua.lang b/languages/ua.lang index d1cf1203..a80fa234 100644 --- a/languages/ua.lang +++ b/languages/ua.lang @@ -222,6 +222,7 @@ $PALANG['reply_once_per_week'] = 'Відповідати один раз на т $PALANG['pViewlog_welcome'] = 'Перегляд %s останніх дій для '; $PALANG['pViewlog_welcome_all'] = 'Перегляд останніх %s дій '; $PALANG['pViewlog_all_domains'] = 'All domains'; +$PALANG['pViewlog_per_page'] = 'Per page:'; $PALANG['pViewlog_timestamp'] = 'Час створення/модифікації'; $PALANG['pViewlog_action'] = 'Дія'; $PALANG['pViewlog_data'] = 'Данні'; diff --git a/public/viewlog.php b/public/viewlog.php index cb2f2b2f..dfbcbd20 100644 --- a/public/viewlog.php +++ b/public/viewlog.php @@ -49,7 +49,7 @@ $all_domains_value = '*'; # dropdown sentinel for the "All domains" option if ($_SERVER['REQUEST_METHOD'] == "GET") { - if (isset($_GET['page']) && $_GET['fDomain']) { + if (isset($_GET['page']) && isset($_GET['fDomain']) && $_GET['fDomain']) { $fDomain_aux = $_GET['fDomain']; if ($fDomain_aux === $all_domains_value) { $show_all = true; @@ -98,12 +98,32 @@ if (!$show_all && !(check_owner($username, $fDomain) || authentication_has_role( flash_error($PALANG['pViewlog_result_error']); } +# Number of log entries per page - user-selectable but whitelisted so a crafted +# value can't request an unbounded LIMIT. The configured $CONF['page_size'] is +# always offered so existing setups keep their default. +$page_size_options = array(10, 25, 50, 100, 1000); +$default_page_size = (int)($CONF['page_size'] ?? 10); +if (!in_array($default_page_size, $page_size_options, true)) { + $page_size_options[] = $default_page_size; +} +sort($page_size_options); + +if (isset($_POST['page_size'])) { + $requested_page_size = (int)$_POST['page_size']; +} elseif (isset($_GET['page_size'])) { + $requested_page_size = (int)$_GET['page_size']; +} else { + $requested_page_size = (int)($_SESSION['viewlog:page_size'] ?? $default_page_size); +} +$page_size = in_array($requested_page_size, $page_size_options, true) ? $requested_page_size : $default_page_size; +$_SESSION['viewlog:page_size'] = $page_size; + $tLog = array(); +$number_of_pages = 0; +$page_window = array(); if ($error != 1) { $table_log = table_by_key('log'); - $page_size = isset($CONF['page_size']) ? intval($CONF['page_size']) : 35; - $params = []; $condition = viewlog_domain_condition($show_all, authentication_has_role('global-admin'), $fDomain, $list_domains, $params); @@ -111,7 +131,6 @@ if ($error != 1) { $number_of_logs = 0; - $number_of_pages = 0; //get number of total logs $query = "SELECT count(*) as number_of_logs FROM $table_log $where_sql"; @@ -123,11 +142,13 @@ if ($error != 1) { $number_of_pages = ceil($number_of_logs / $page_size); # An empty result set (no matching log entries) has 0 pages; page 1 should - # then render an empty table rather than throwing. + # then be accepted (the template simply shows no log rows) rather than throwing. if ($number_of_pages > 0 && $page_number > $number_of_pages) { throw new InvalidArgumentException('Unknown page number'); } + $page_window = pagination_window($page_number, (int)$number_of_pages, 5); + if ($page_number == 1) { $offset = 0; } else { @@ -166,6 +187,9 @@ $smarty->assign('fDomain', $fDomain); $smarty->assign('show_all', $show_all); $smarty->assign('all_domains_value', $all_domains_value); $smarty->assign('domain_param', $show_all ? $all_domains_value : $fDomain); +$smarty->assign('page_size', $page_size); +$smarty->assign('page_size_options', $page_size_options); +$smarty->assign('page_window', $page_window); $smarty->assign('number_of_pages', $number_of_pages); $smarty->assign('page_number', $page_number); diff --git a/templates/viewlog.tpl b/templates/viewlog.tpl index a5517d92..ed6c3478 100644 --- a/templates/viewlog.tpl +++ b/templates/viewlog.tpl @@ -1,21 +1,27 @@
-
- + + + +
{if $tLog}
- {if $domain_selected} -

{$PALANG.pViewlog_welcome|replace:"%s":$CONF.page_size} {$fDomain}

+ {if $domain_selected} +

{$PALANG.pViewlog_welcome|replace:"%s":$page_size} {$fDomain}

{else} -

{$PALANG.pViewlog_welcome_all|replace:"%s":$CONF.page_size}

+

{$PALANG.pViewlog_welcome_all|replace:"%s":$page_size}

{/if}
@@ -40,80 +46,44 @@ {/foreach}
- -
-
- -
-
-
-
- - {if $number_of_pages < 6} -
- {for $i=1 to $number_of_pages} - - {/for} -
- {elseif $page_number > 3 && $page_number < ($number_of_pages -2 )} -
- -
-
- - - -
-
- -
- - - {else} - {if $page_number < 4} -
- - - - -
-
- -
- - {else} -
- -
-
- - - - -
- {/if} - {/if} - -
- -
-
-
-
- + {if $number_of_pages > 1} + + {/if} {/if}
diff --git a/tests/PaginationWindowTest.php b/tests/PaginationWindowTest.php new file mode 100644 index 00000000..bc967f51 --- /dev/null +++ b/tests/PaginationWindowTest.php @@ -0,0 +1,58 @@ +assertSame([], pagination_window(1, 0, 5)); + $this->assertSame([1], pagination_window(1, 1, 5)); + } + + public function testAllPagesShownWhenWithinWindow() + { + // radius 5 around page 3 covers everything up to page 7 - no ellipsis. + $this->assertSame([1, 2, 3, 4, 5, 6, 7], pagination_window(3, 7, 5)); + } + + public function testEllipsisOnBothSides() + { + $expected = [1, null, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, null, 50]; + $this->assertSame($expected, pagination_window(20, 50, 5)); + } + + public function testTrailingEllipsisOnly() + { + // Near the start: window reaches page 8, then a gap to the last page. + $this->assertSame([1, 2, 3, 4, 5, 6, 7, 8, null, 50], pagination_window(3, 50, 5)); + } + + public function testLeadingEllipsisOnly() + { + // Near the end: page 1, a gap, then the window through the last page. + $this->assertSame([1, null, 43, 44, 45, 46, 47, 48, 49, 50], pagination_window(48, 50, 5)); + } + + public function testCurrentPageClampedIntoRange() + { + // An out-of-range current page is clamped to the last page. + $this->assertSame([1, null, 8, 9, 10], pagination_window(999, 10, 2)); + } + + public function testNeverTwoAdjacentEllipses() + { + $window = pagination_window(25, 100, 5); + $previous = 1; + foreach ($window as $entry) { + $this->assertFalse($entry === null && $previous === null, 'two ellipses in a row'); + $previous = $entry; + } + // First and last real entries are always page 1 and the last page. + $this->assertSame(1, $window[0]); + $this->assertSame(100, $window[count($window) - 1]); + } +}