From 5931a4ca94b6efdb29fc878a8f7027e95df552a6 Mon Sep 17 00:00:00 2001 From: pupi1985 Date: Mon, 10 Jan 2022 13:28:22 -0300 Subject: [PATCH] Allow pagination of element lists that exceed QA_MAX_LIMIT_START --- qa-include/app/format.php | 18 +++++++++++++++--- qa-include/pages/search.php | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/qa-include/app/format.php b/qa-include/app/format.php index 50d5cf01a..fd60963e2 100644 --- a/qa-include/app/format.php +++ b/qa-include/app/format.php @@ -1220,16 +1220,28 @@ function qa_insert_login_links($htmlmessage, $topage = null, $params = null) * @param $count * @param $prevnext * @param array $params - * @param bool $hasmore + * @param bool|int|null $startLimit * @param null $anchor * @return array|null */ -function qa_html_page_links($request, $start, $pagesize, $count, $prevnext, $params = array(), $hasmore = false, $anchor = null) +function qa_html_page_links($request, $start, $pagesize, $count, $prevnext, $params = array(), $startLimit = QA_MAX_LIMIT_START, $anchor = null) { if (qa_to_override(__FUNCTION__)) { $args=func_get_args(); return qa_call_override(__FUNCTION__, $args); } + // Backwards compatibility. Changed from boolean to int in v1.8.7 + if (is_bool($startLimit)) { + $startLimit = QA_MAX_LIMIT_START; + } + + if (is_int($startLimit)) { + $hasmore = $count > $startLimit; + $count = min((int)$count, 1 + $startLimit); + } else { // if $startLimit is null + $hasmore = false; + } + $thispage = 1 + floor($start / $pagesize); - $lastpage = ceil(min((int)$count, 1 + QA_MAX_LIMIT_START) / $pagesize); + $lastpage = ceil((int)$count / $pagesize); if ($thispage > 1 || $lastpage > $thispage) { $links = array('label' => qa_lang_html('main/page_label'), 'items' => array()); diff --git a/qa-include/pages/search.php b/qa-include/pages/search.php index 267adf9be..5c9db6fc6 100644 --- a/qa-include/pages/search.php +++ b/qa-include/pages/search.php @@ -127,7 +127,7 @@ } $qa_content['page_links'] = qa_html_page_links(qa_request(), $start, $pagesize, $start + $gotcount, - qa_opt('pages_prev_next'), array('q' => $inquery), $gotcount >= $count); + qa_opt('pages_prev_next'), array('q' => $inquery), $start + $gotcount - ($gotcount < $count ? 0 : 1)); if (qa_opt('feed_for_search')) { $qa_content['feed'] = array(