From 8671c058d57b57614730d78df069693e917e0182 Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Tue, 30 Sep 2025 22:45:28 +0900 Subject: [PATCH] Fix incorrect page range when there are not enough pages #2602 --- classes/page/PageHandler.class.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/classes/page/PageHandler.class.php b/classes/page/PageHandler.class.php index 82d45e97f..0a74fcd0f 100644 --- a/classes/page/PageHandler.class.php +++ b/classes/page/PageHandler.class.php @@ -44,24 +44,23 @@ class PageHandler extends Handler implements Iterator $this->page_count = $page_count; $this->point = 0; - $first_page = $cur_page - (int) ($page_count / 2); - if($first_page < 1) + if ($this->cur_page > $total_page) { - $first_page = 1; + $this->cur_page = $total_page; + } + if ($this->page_count > $total_page) + { + $this->page_count = $total_page; } - if($total_page > $page_count && $first_page + $page_count - 1 > $total_page) + $first_page = max(1, $this->cur_page - floor($this->page_count / 2)); + if (($first_page + $this->page_count - 1) > $total_page) { - $first_page -= $first_page + $page_count - 1 - $total_page; + $first_page = max(1, $total_page - $this->page_count + 1); } $this->first_page = $first_page; $this->last_page = $total_page; - - if($total_page < $this->page_count) - { - $this->page_count = $total_page; - } } /**