Use the router for prefs_forms.php

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2019-08-20 00:01:26 -03:00
parent e7c6eaf667
commit 5a83fd36b9
7 changed files with 31 additions and 32 deletions

View File

@ -122,6 +122,11 @@ if (isset($_GET['route']) || isset($_POST['route'])) {
$routes->addRoute('GET', '/phpinfo', function () {
require_once ROOT_PATH . 'libraries/entry_points/phpinfo.php';
});
$routes->addGroup('/preferences', function (RouteCollector $routes) {
$routes->addRoute(['GET', 'POST'], '/forms', function () {
require_once ROOT_PATH . 'libraries/entry_points/preferences/forms.php';
});
});
$routes->addGroup('/server', function (RouteCollector $routes) {
$routes->addRoute(['GET', 'POST'], '/binlog', function () {
require_once ROOT_PATH . 'libraries/entry_points/server/binlog.php';

View File

@ -200,7 +200,7 @@ var ErrorReport = {
* @return void
*/
redirectToSettings: function () {
window.location.href = 'prefs_forms.php';
window.location.href = 'index.php?route=/preferences/forms';
},
/**
* Returns the report data to send to the server

View File

@ -631,14 +631,12 @@ class Menu
$tabs['settings']['icon'] = 'b_tblops';
$tabs['settings']['link'] = 'prefs_manage.php';
$tabs['settings']['text'] = __('Settings');
$tabs['settings']['active'] = in_array(
basename($GLOBALS['PMA_PHP_SELF']),
[
'prefs_forms.php',
'prefs_manage.php',
'prefs_twofactor.php',
]
);
$tabs['settings']['active'] = in_array(basename($GLOBALS['PMA_PHP_SELF']), [
'prefs_manage.php',
'prefs_twofactor.php',
]) || (isset($_REQUEST['route']) && in_array($_REQUEST['route'], [
'/preferences/forms',
]));
if (! empty($binary_logs)) {
$tabs['binlog']['icon'] = 's_tbl';

View File

@ -258,7 +258,7 @@ class UserPreferences
$hash = '#' . urlencode($hash);
}
Core::sendHeaderLocation('./' . $file_name
. Url::getCommonRaw($url_params) . $hash);
. Url::getCommonRaw($url_params, strpos($file_name, '?') === false ? '?' : '&') . $hash);
}
/**

View File

@ -94,15 +94,15 @@ class UserPreferencesHeader
'Import' => 'b_import',
'Export' => 'b_export',
];
$script_name = basename($GLOBALS['PMA_PHP_SELF']);
$route = $_GET['route'] ?? $_POST['route'] ?? '';
$content = null;
foreach (UserFormList::getAll() as $formset) {
$formset_class = UserFormList::get($formset);
$tab = [
'link' => 'prefs_forms.php',
'link' => 'index.php?route=/preferences/forms',
'text' => $formset_class::getName(),
'icon' => $tabs_icons[$formset],
'active' => 'prefs_forms.php' === $script_name && $formset === $form_param,
'active' => $route === '/preferences/forms' && $formset === $form_param,
];
$content .= Util::getHtmlTab($tab, ['form' => $formset]) . "\n";
}

View File

@ -18,17 +18,12 @@ use PhpMyAdmin\Url;
use PhpMyAdmin\UserPreferences;
use PhpMyAdmin\UserPreferencesHeader;
if (! defined('ROOT_PATH')) {
define('ROOT_PATH', __DIR__ . DIRECTORY_SEPARATOR);
if (! defined('PHPMYADMIN')) {
exit;
}
global $containerBuilder;
/**
* Gets some core libraries and displays a top message if required
*/
require_once ROOT_PATH . 'libraries/common.inc.php';
/** @var Template $template */
$template = $containerBuilder->get('template');
$userPreferences = new UserPreferences();
@ -53,8 +48,8 @@ if (isset($_POST['revert'])) {
// redirect
$url_params = ['form' => $form_param];
Core::sendHeaderLocation(
'./prefs_forms.php'
. Url::getCommonRaw($url_params)
'./index.php?route=/preferences/forms'
. Url::getCommonRaw($url_params, '&')
);
exit;
}
@ -69,7 +64,7 @@ if ($form_display->process(false) && ! $form_display->hasErrors()) {
$tabHash = isset($_POST['tab_hash']) ? $_POST['tab_hash'] : null;
$hash = ltrim($tabHash, '#');
$userPreferences->redirect(
'prefs_forms.php',
'index.php?route=/preferences/forms',
['form' => $form_param],
$hash
);
@ -97,9 +92,13 @@ echo $template->render('preferences/forms/main', [
'error' => $error ? $error->getDisplay() : '',
'has_errors' => $form_display->hasErrors(),
'errors' => $formErrors ?? null,
'form' => $form_display->getDisplay(true, true, true, 'prefs_forms.php?form=' . $form_param, [
'server' => $GLOBALS['server'],
]),
'form' => $form_display->getDisplay(
true,
true,
true,
Url::getFromRoute('/preferences/forms', ['form' => $form_param]),
['server' => $GLOBALS['server']]
),
]);
if ($response->isAjax()) {

View File

@ -35,12 +35,8 @@ class UserPreferencesHeaderTest extends PmaTestCase
*/
protected function setUp(): void
{
/*
global $cfg;
include ROOT_PATH . 'libraries/config.default.php';
*/
$GLOBALS['server'] = 0;
$GLOBALS['PMA_PHP_SELF'] = '/prefs_forms.php';
$GLOBALS['PMA_PHP_SELF'] = 'index.php';
}
/**
@ -59,6 +55,7 @@ class UserPreferencesHeaderTest extends PmaTestCase
->getMock();
$GLOBALS['dbi'] = $dbi;
$_GET['route'] = '/preferences/forms';
$_GET['form'] = 'Features';
$template = new Template();
@ -69,7 +66,7 @@ class UserPreferencesHeaderTest extends PmaTestCase
$content
);
$this->assertStringContainsString(
'<a href="prefs_forms.php?form=Features&amp;server=0&amp;lang=en" class="tabactive">',
'<a href="index.php?route=/preferences/forms&amp;form=Features&amp;server=0&amp;lang=en" class="tabactive">',
$content
);
$this->assertStringContainsString(