From e8c51f936d738b47c6489bfd8ea3bee7c479b371 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Fri, 12 Jul 2019 21:10:24 -0300 Subject: [PATCH] Use the router for the server_variables.php page MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: MaurĂ­cio Meneghini Fauth --- index.php | 3 +++ libraries/classes/Advisor.php | 4 ++-- libraries/classes/Core.php | 1 - libraries/classes/Menu.php | 2 +- libraries/classes/Plugins/Auth/AuthenticationConfig.php | 2 +- libraries/classes/Sanitize.php | 1 - libraries/classes/Util.php | 4 ++-- .../entry_points/server/variables.php | 6 +++--- templates/server/variables/index.twig | 4 ++-- test/classes/AdvisorTest.php | 4 ++-- test/classes/Controllers/Server/VariablesControllerTest.php | 2 +- test/classes/CoreTest.php | 1 - test/classes/Plugins/Auth/AuthenticationConfigTest.php | 2 +- 13 files changed, 18 insertions(+), 18 deletions(-) rename server_variables.php => libraries/entry_points/server/variables.php (87%) diff --git a/index.php b/index.php index cf0e844231..b0b86b7ac0 100644 --- a/index.php +++ b/index.php @@ -42,6 +42,9 @@ if (isset($_GET['route']) || isset($_POST['route'])) { require_once ROOT_PATH . 'libraries/entry_points/server/status/queries.php'; }); }); + $routes->addRoute(['GET', 'POST'], '/variables', function () { + require_once ROOT_PATH . 'libraries/entry_points/server/variables.php'; + }); }); }); $routeInfo = $dispatcher->dispatch( diff --git a/libraries/classes/Advisor.php b/libraries/classes/Advisor.php index 9ec85fd9db..b135da1ecf 100644 --- a/libraries/classes/Advisor.php +++ b/libraries/classes/Advisor.php @@ -424,7 +424,7 @@ class Advisor $rule['issue'] = $this->translate($rule['issue']); // Replaces {server_variable} with 'server_variable' - // linking to server_variables.php + // linking to /server/variables $rule['recommendation'] = preg_replace_callback( '/\{([a-z_0-9]+)\}/Ui', [ @@ -470,7 +470,7 @@ class Advisor */ private function replaceVariable(array $matches): string { - return ' $matches[1]]) . '">' . htmlspecialchars($matches[1]) . ''; } diff --git a/libraries/classes/Core.php b/libraries/classes/Core.php index 0e8f2404df..dda04ce6fc 100644 --- a/libraries/classes/Core.php +++ b/libraries/classes/Core.php @@ -52,7 +52,6 @@ class Core 'server_status_advisor.php', 'server_status_monitor.php', 'server_status_variables.php', - 'server_variables.php', 'sql.php', 'tbl_addfield.php', 'tbl_change.php', diff --git a/libraries/classes/Menu.php b/libraries/classes/Menu.php index d3ccc362be..dd86394c2e 100644 --- a/libraries/classes/Menu.php +++ b/libraries/classes/Menu.php @@ -645,7 +645,7 @@ class Menu } $tabs['vars']['icon'] = 's_vars'; - $tabs['vars']['link'] = 'server_variables.php'; + $tabs['vars']['link'] = Url::getFromRoute('/server/variables'); $tabs['vars']['text'] = __('Variables'); $tabs['charset']['icon'] = 's_asci'; diff --git a/libraries/classes/Plugins/Auth/AuthenticationConfig.php b/libraries/classes/Plugins/Auth/AuthenticationConfig.php index 7ebd1ae225..0a5216e6c5 100644 --- a/libraries/classes/Plugins/Auth/AuthenticationConfig.php +++ b/libraries/classes/Plugins/Auth/AuthenticationConfig.php @@ -151,7 +151,7 @@ class AuthenticationConfig extends AuthenticationPlugin $GLOBALS['cfg']['DefaultTabServer'], 'server' ) - , Url::getCommon() , '" class="button disableAjax">' + , '" class="button disableAjax">' , __('Retry to connect') , '' , "\n"; echo ' diff --git a/libraries/classes/Sanitize.php b/libraries/classes/Sanitize.php index edce612799..be220a050f 100644 --- a/libraries/classes/Sanitize.php +++ b/libraries/classes/Sanitize.php @@ -38,7 +38,6 @@ class Sanitize // possible return values from Util::getScriptNameForOption './index.php?', './server_status.php?', - './server_variables.php?', './server_privileges.php?', './db_structure.php?', './db_sql.php?', diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 2ba8069972..4790dd1a69 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -3183,13 +3183,13 @@ class Util // Values for $cfg['DefaultTabServer'] switch ($target) { case 'welcome': - return 'index.php'; + return Url::getFromRoute('/'); case 'databases': return Url::getFromRoute('/server/databases'); case 'status': return 'server_status.php'; case 'variables': - return 'server_variables.php'; + return Url::getFromRoute('/server/variables'); case 'privileges': return 'server_privileges.php'; } diff --git a/server_variables.php b/libraries/entry_points/server/variables.php similarity index 87% rename from server_variables.php rename to libraries/entry_points/server/variables.php index c842484e38..9e61f1417b 100644 --- a/server_variables.php +++ b/libraries/entry_points/server/variables.php @@ -10,11 +10,11 @@ declare(strict_types=1); use PhpMyAdmin\Controllers\Server\VariablesController; use PhpMyAdmin\Response; -if (! defined('ROOT_PATH')) { - define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR); +if (! defined('PHPMYADMIN')) { + exit; } -require_once ROOT_PATH . 'libraries/common.inc.php'; +global $containerBuilder; /** @var VariablesController $controller */ $controller = $containerBuilder->get(VariablesController::class); diff --git a/templates/server/variables/index.twig b/templates/server/variables/index.twig index 3465e7f010..9dc019ec7d 100644 --- a/templates/server/variables/index.twig +++ b/templates/server/variables/index.twig @@ -6,7 +6,7 @@ {% if variables is not empty %} - + {{ get_icon('b_save', 'Save'|trans) }} @@ -80,4 +80,4 @@ {{ 'Not enough privilege to view server variables and settings. %s'|trans|format( link_to_var_documentation('show_compatibility_56', is_mariadb) )|error }} -{% endif %} \ No newline at end of file +{% endif %} diff --git a/test/classes/AdvisorTest.php b/test/classes/AdvisorTest.php index d06bfbcadd..20a8a285e4 100644 --- a/test/classes/AdvisorTest.php +++ b/test/classes/AdvisorTest.php @@ -211,8 +211,8 @@ class AdvisorTest extends PmaTestCase 'id' => 'Variable', 'name' => 'Variable', 'issue' => 'issue', - 'recommendation' => 'Recommend status_var', + 'recommendation' => 'Recommend status_var', ], null, ], diff --git a/test/classes/Controllers/Server/VariablesControllerTest.php b/test/classes/Controllers/Server/VariablesControllerTest.php index 7afaa2fe5b..72ab033dcf 100644 --- a/test/classes/Controllers/Server/VariablesControllerTest.php +++ b/test/classes/Controllers/Server/VariablesControllerTest.php @@ -99,7 +99,7 @@ class VariablesControllerTest extends TestCase $html = $controller->index([]); $this->assertStringContainsString( - 'server_variables.php' . Url::getCommon(), + 'index.php?route=/server/variables', $html ); $this->assertStringContainsString( diff --git a/test/classes/CoreTest.php b/test/classes/CoreTest.php index 0b09848b82..ccd9a70c33 100644 --- a/test/classes/CoreTest.php +++ b/test/classes/CoreTest.php @@ -33,7 +33,6 @@ class CoreTest extends PmaTestCase 'pdf_pages.php', 'pdf_schema.php', 'server_binlog.php', - 'server_variables.php', 'sql.php', 'tbl_select.php', 'transformation_overview.php', diff --git a/test/classes/Plugins/Auth/AuthenticationConfigTest.php b/test/classes/Plugins/Auth/AuthenticationConfigTest.php index 2699f5687c..2096d9037c 100644 --- a/test/classes/Plugins/Auth/AuthenticationConfigTest.php +++ b/test/classes/Plugins/Auth/AuthenticationConfigTest.php @@ -132,7 +132,7 @@ class AuthenticationConfigTest extends PmaTestCase ); $this->assertStringContainsString( - 'Retry to connect', $html );