From 77f9ebb61a9a7f03ddb184d6b5d3b51cc152c001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Wed, 9 Nov 2022 14:55:14 -0300 Subject: Improve error message when UseDbSearch config is disabled MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces Html\Generator::mysqlDie() to avoid calling the exit construct. Signed-off-by: MaurĂ­cio Meneghini Fauth --- .../Controllers/Database/SearchController.php | 22 +++++++++++++++------- psalm-baseline.xml | 5 +---- templates/error/simple.twig | 11 +++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 templates/error/simple.twig diff --git a/libraries/classes/Controllers/Database/SearchController.php b/libraries/classes/Controllers/Database/SearchController.php index 07ab737a03..0fb26dab85 100644 --- a/libraries/classes/Controllers/Database/SearchController.php +++ b/libraries/classes/Controllers/Database/SearchController.php @@ -7,8 +7,9 @@ namespace PhpMyAdmin\Controllers\Database; use PhpMyAdmin\Controllers\AbstractController; use PhpMyAdmin\Database\Search; use PhpMyAdmin\DatabaseInterface; -use PhpMyAdmin\Html\Generator; +use PhpMyAdmin\Html\MySQLDocumentation; use PhpMyAdmin\Http\ServerRequest; +use PhpMyAdmin\Message; use PhpMyAdmin\ResponseRenderer; use PhpMyAdmin\Template; use PhpMyAdmin\Url; @@ -49,14 +50,21 @@ class SearchController extends AbstractController return; } - // If config variable $cfg['UseDbSearch'] is on false : exit. if (! $GLOBALS['cfg']['UseDbSearch']) { - Generator::mysqlDie( - __('Access denied!'), - '', - false, - $GLOBALS['errorUrl'] + $errorMessage = __( + 'Searching inside the database is disabled by the [code]$cfg[\'UseDbSearch\'][/code] configuration.' ); + $errorMessage .= MySQLDocumentation::showDocumentation('config', 'cfg_UseDbSearch'); + $this->response->setRequestStatus(false); + if ($this->response->isAjax()) { + $this->response->addJSON('message', Message::error($errorMessage)->getDisplay()); + + return; + } + + $this->render('error/simple', ['error_message' => $errorMessage, 'back_url' => $GLOBALS['errorUrl']]); + + return; } $GLOBALS['urlParams']['goto'] = Url::getFromRoute('/database/search'); diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 832def3006..6a888b10e0 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -13388,10 +13388,7 @@ - - escapeString - escapeString - escapeString + escapeString escapeString escapeString diff --git a/templates/error/simple.twig b/templates/error/simple.twig new file mode 100644 index 0000000000..8655f7f76b --- /dev/null +++ b/templates/error/simple.twig @@ -0,0 +1,11 @@ +
+

{{ 'Something went wrong'|trans }}

+
+
+ {{ error_message|error }} + {% if back_url != '' %} + {{ 'Go back'|trans }} + {% endif %} +
+
+
-- cgit v1.2.3