From 59064c6e91cb8bfa4b0a8a32ec1851de66f38596 Mon Sep 17 00:00:00 2001 From: Kamil Tekiela Date: Wed, 15 Jan 2025 19:56:48 +0000 Subject: [PATCH] Fix approximate navigation Signed-off-by: Kamil Tekiela --- libraries/classes/Display/Results.php | 25 +++++++++++++++++++------ phpstan-baseline.neon | 8 ++++---- psalm-baseline.xml | 9 ++++++--- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index d6a82fc438..e80b0b3655 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -840,12 +840,16 @@ class Results // Move to the next page or to the last one $moveForwardButtons = ''; if ( + ! ( // view with unknown number of rows - ($this->properties['unlim_num_rows'] === -1 || $this->properties['unlim_num_rows'] === false) - || (! $isShowingAll - && intval($_SESSION['tmpval']['pos']) + intval($_SESSION['tmpval']['max_rows']) - < $this->properties['unlim_num_rows'] - && $this->properties['num_rows'] >= $_SESSION['tmpval']['max_rows']) + $this->properties['unlim_num_rows'] !== -1 + && $this->properties['unlim_num_rows'] !== false + && ($isShowingAll + || ( $this->isExactCount() + && (int) $_SESSION['tmpval']['pos'] + (int) $_SESSION['tmpval']['max_rows'] + >= $this->properties['unlim_num_rows']) + || $this->properties['num_rows'] < $_SESSION['tmpval']['max_rows']) + ) ) { $moveForwardButtons = $this->getMoveForwardButtonsForTableNavigation( htmlspecialchars($this->properties['sql_query']), @@ -878,6 +882,15 @@ class Results ]; } + private function isExactCount(): bool + { + // If we have the full page of rows, we don't know + // if there are more unless unlimNumRows is smaller than MaxExactCount + return $this->properties['unlim_num_rows'] < $GLOBALS['cfg']['MaxExactCount'] + || $_SESSION['tmpval']['max_rows'] === self::ALL_ROWS + || $this->properties['num_rows'] < $_SESSION['tmpval']['max_rows']; + } + /** * Prepare move backward buttons - previous and first * @@ -3962,7 +3975,7 @@ class Results } } elseif (($_SESSION['tmpval']['max_rows'] === self::ALL_ROWS) || ($posNext > $total)) { $firstShownRec = $_SESSION['tmpval']['pos']; - $lastShownRec = $total - 1; + $lastShownRec = $firstShownRec + $this->properties['num_rows'] - 1; } else { $firstShownRec = $_SESSION['tmpval']['pos']; $lastShownRec = $posNext - 1; diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 4f518eca59..5716ce506f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -15652,7 +15652,7 @@ parameters: - message: "#^Cannot access offset 'MaxExactCount' on mixed\\.$#" - count: 1 + count: 2 path: libraries/classes/Display/Results.php - @@ -15762,7 +15762,7 @@ parameters: - message: "#^Cannot access offset 'max_rows' on mixed\\.$#" - count: 19 + count: 20 path: libraries/classes/Display/Results.php - @@ -15927,7 +15927,7 @@ parameters: - message: "#^Cannot cast mixed to int\\.$#" - count: 4 + count: 6 path: libraries/classes/Display/Results.php - @@ -16532,7 +16532,7 @@ parameters: - message: "#^Parameter \\#1 \\$var of function intval expects array\\|bool\\|float\\|int\\|resource\\|string\\|null, mixed given\\.$#" - count: 4 + count: 2 path: libraries/classes/Display/Results.php - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 100c449229..de54a3db7a 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -6074,7 +6074,7 @@ $sortExpression $urlParams - + $_SESSION['tmpval']['display_binary'] $_SESSION['tmpval']['display_binary'] $_SESSION['tmpval']['display_binary'] @@ -6097,6 +6097,7 @@ $_SESSION['tmpval']['max_rows'] $_SESSION['tmpval']['max_rows'] $_SESSION['tmpval']['max_rows'] + $_SESSION['tmpval']['max_rows'] $_SESSION['tmpval']['pftext'] $_SESSION['tmpval']['pftext'] $_SESSION['tmpval']['pftext'] @@ -6220,7 +6221,7 @@ $row[$sortedColumnIndex] $row[$sortedColumnIndex] - + $_SESSION['tmpval']['geoOption'] $_SESSION['tmpval']['max_rows'] $_SESSION['tmpval']['pftext'] @@ -6247,6 +6248,7 @@ $index $lastShownRec $lastShownRec + $lastShownRec $linkingUrlParams[$new_param['param_info']] $m $meta->name @@ -6274,7 +6276,7 @@ new $className() new $this->transformationInfo[$dbLower][$tblLower][$nameLower][1]() - + $_SESSION['tmpval']['max_rows'] $_SESSION['tmpval']['max_rows'] $_SESSION['tmpval']['pos'] @@ -6287,6 +6289,7 @@ $file $firstShownRec $firstShownRec + $firstShownRec $sortExpressionNoDirection[$indexInExpression]