diff --git a/libraries/classes/Controllers/Preferences/ExportController.php b/libraries/classes/Controllers/Preferences/ExportController.php index 621665045f53..46a19d7ee987 100644 --- a/libraries/classes/Controllers/Preferences/ExportController.php +++ b/libraries/classes/Controllers/Preferences/ExportController.php @@ -47,7 +47,7 @@ public function __construct( public function index(): void { global $cfg, $cf, $error, $tabHash, $hash; - global $server, $PMA_Config; + global $server, $PMA_Config, $route; $cf = new ConfigFile($PMA_Config->base_settings); $this->userPreferences->pageInit($cf); @@ -90,7 +90,13 @@ public function index(): void $scripts = $header->getScripts(); $scripts->addFile('config.js'); - $this->response->addHTML(UserPreferencesHeader::getContent($this->template, $this->relation)); + $cfgRelation = $this->relation->getRelationsParam(); + + $this->response->addHTML($this->template->render('preferences/header', [ + 'route' => $route, + 'is_saved' => ! empty($_GET['saved']), + 'has_config_storage' => $cfgRelation['userconfigwork'], + ])); if ($formDisplay->hasErrors()) { $formErrors = $formDisplay->displayErrors(); diff --git a/libraries/classes/Controllers/Preferences/FeaturesController.php b/libraries/classes/Controllers/Preferences/FeaturesController.php index ee1e8f04f377..8a0c0a7d41d2 100644 --- a/libraries/classes/Controllers/Preferences/FeaturesController.php +++ b/libraries/classes/Controllers/Preferences/FeaturesController.php @@ -47,7 +47,7 @@ public function __construct( public function index(): void { global $cfg, $cf, $error, $tabHash, $hash; - global $server, $PMA_Config; + global $server, $PMA_Config, $route; $cf = new ConfigFile($PMA_Config->base_settings); $this->userPreferences->pageInit($cf); @@ -90,7 +90,13 @@ public function index(): void $scripts = $header->getScripts(); $scripts->addFile('config.js'); - $this->response->addHTML(UserPreferencesHeader::getContent($this->template, $this->relation)); + $cfgRelation = $this->relation->getRelationsParam(); + + $this->response->addHTML($this->template->render('preferences/header', [ + 'route' => $route, + 'is_saved' => ! empty($_GET['saved']), + 'has_config_storage' => $cfgRelation['userconfigwork'], + ])); if ($formDisplay->hasErrors()) { $formErrors = $formDisplay->displayErrors(); diff --git a/libraries/classes/Controllers/Preferences/ImportController.php b/libraries/classes/Controllers/Preferences/ImportController.php index b3f7017f0237..78af26afe576 100644 --- a/libraries/classes/Controllers/Preferences/ImportController.php +++ b/libraries/classes/Controllers/Preferences/ImportController.php @@ -47,7 +47,7 @@ public function __construct( public function index(): void { global $cfg, $cf, $error, $tabHash, $hash; - global $server, $PMA_Config; + global $server, $PMA_Config, $route; $cf = new ConfigFile($PMA_Config->base_settings); $this->userPreferences->pageInit($cf); @@ -90,7 +90,13 @@ public function index(): void $scripts = $header->getScripts(); $scripts->addFile('config.js'); - $this->response->addHTML(UserPreferencesHeader::getContent($this->template, $this->relation)); + $cfgRelation = $this->relation->getRelationsParam(); + + $this->response->addHTML($this->template->render('preferences/header', [ + 'route' => $route, + 'is_saved' => ! empty($_GET['saved']), + 'has_config_storage' => $cfgRelation['userconfigwork'], + ])); if ($formDisplay->hasErrors()) { $formErrors = $formDisplay->displayErrors(); diff --git a/libraries/classes/Controllers/Preferences/MainPanelController.php b/libraries/classes/Controllers/Preferences/MainPanelController.php index 1b36a180a469..cabd999843c6 100644 --- a/libraries/classes/Controllers/Preferences/MainPanelController.php +++ b/libraries/classes/Controllers/Preferences/MainPanelController.php @@ -47,7 +47,7 @@ public function __construct( public function index(): void { global $cfg, $cf, $error, $tabHash, $hash; - global $server, $PMA_Config; + global $server, $PMA_Config, $route; $cf = new ConfigFile($PMA_Config->base_settings); $this->userPreferences->pageInit($cf); @@ -90,7 +90,13 @@ public function index(): void $scripts = $header->getScripts(); $scripts->addFile('config.js'); - $this->response->addHTML(UserPreferencesHeader::getContent($this->template, $this->relation)); + $cfgRelation = $this->relation->getRelationsParam(); + + $this->response->addHTML($this->template->render('preferences/header', [ + 'route' => $route, + 'is_saved' => ! empty($_GET['saved']), + 'has_config_storage' => $cfgRelation['userconfigwork'], + ])); if ($formDisplay->hasErrors()) { $formErrors = $formDisplay->displayErrors(); diff --git a/libraries/classes/Controllers/Preferences/ManageController.php b/libraries/classes/Controllers/Preferences/ManageController.php index 9a7ab42f29bf..b872aa7a0e19 100644 --- a/libraries/classes/Controllers/Preferences/ManageController.php +++ b/libraries/classes/Controllers/Preferences/ManageController.php @@ -67,7 +67,7 @@ public function __construct( public function index(): void { global $cf, $error, $filename, $import_handle, $json, $PMA_Config, $lang, $max_upload_size; - global $new_config, $config, $return_url, $form_display, $all_ok, $params, $query; + global $new_config, $config, $return_url, $form_display, $all_ok, $params, $query, $route; $cf = new ConfigFile($PMA_Config->base_settings); $this->userPreferences->pageInit($cf); @@ -153,7 +153,13 @@ public function index(): void } if (! $all_ok) { // mimic original form and post json in a hidden field - echo UserPreferencesHeader::getContent($this->template, $this->relation); + $cfgRelation = $this->relation->getRelationsParam(); + + echo $this->template->render('preferences/header', [ + 'route' => $route, + 'is_saved' => ! empty($_GET['saved']), + 'has_config_storage' => $cfgRelation['userconfigwork'], + ]); echo $this->template->render('preferences/manage/error', [ 'form_errors' => $form_display->displayErrors(), @@ -224,7 +230,14 @@ public function index(): void $scripts = $header->getScripts(); $scripts->addFile('config.js'); - echo UserPreferencesHeader::getContent($this->template, $this->relation); + $cfgRelation = $this->relation->getRelationsParam(); + + echo $this->template->render('preferences/header', [ + 'route' => $route, + 'is_saved' => ! empty($_GET['saved']), + 'has_config_storage' => $cfgRelation['userconfigwork'], + ]); + if ($error) { if (! $error instanceof Message) { $error = Message::error($error); diff --git a/libraries/classes/Controllers/Preferences/NavigationController.php b/libraries/classes/Controllers/Preferences/NavigationController.php index 829b05980f25..de662daec3b6 100644 --- a/libraries/classes/Controllers/Preferences/NavigationController.php +++ b/libraries/classes/Controllers/Preferences/NavigationController.php @@ -47,7 +47,7 @@ public function __construct( public function index(): void { global $cfg, $cf, $error, $tabHash, $hash; - global $server, $PMA_Config; + global $server, $PMA_Config, $route; $cf = new ConfigFile($PMA_Config->base_settings); $this->userPreferences->pageInit($cf); @@ -90,7 +90,13 @@ public function index(): void $scripts = $header->getScripts(); $scripts->addFile('config.js'); - $this->response->addHTML(UserPreferencesHeader::getContent($this->template, $this->relation)); + $cfgRelation = $this->relation->getRelationsParam(); + + $this->response->addHTML($this->template->render('preferences/header', [ + 'route' => $route, + 'is_saved' => ! empty($_GET['saved']), + 'has_config_storage' => $cfgRelation['userconfigwork'], + ])); if ($formDisplay->hasErrors()) { $formErrors = $formDisplay->displayErrors(); diff --git a/libraries/classes/Controllers/Preferences/SqlController.php b/libraries/classes/Controllers/Preferences/SqlController.php index 03e330602e40..feda63f9aef0 100644 --- a/libraries/classes/Controllers/Preferences/SqlController.php +++ b/libraries/classes/Controllers/Preferences/SqlController.php @@ -47,7 +47,7 @@ public function __construct( public function index(): void { global $cfg, $cf, $error, $tabHash, $hash; - global $server, $PMA_Config; + global $server, $PMA_Config, $route; $cf = new ConfigFile($PMA_Config->base_settings); $this->userPreferences->pageInit($cf); @@ -90,7 +90,13 @@ public function index(): void $scripts = $header->getScripts(); $scripts->addFile('config.js'); - $this->response->addHTML(UserPreferencesHeader::getContent($this->template, $this->relation)); + $cfgRelation = $this->relation->getRelationsParam(); + + $this->response->addHTML($this->template->render('preferences/header', [ + 'route' => $route, + 'is_saved' => ! empty($_GET['saved']), + 'has_config_storage' => $cfgRelation['userconfigwork'], + ])); if ($formDisplay->hasErrors()) { $formErrors = $formDisplay->displayErrors(); diff --git a/libraries/classes/Controllers/Preferences/TwoFactorController.php b/libraries/classes/Controllers/Preferences/TwoFactorController.php index ee47eea8efeb..5db69bffae84 100644 --- a/libraries/classes/Controllers/Preferences/TwoFactorController.php +++ b/libraries/classes/Controllers/Preferences/TwoFactorController.php @@ -32,9 +32,15 @@ public function __construct($response, $dbi, Template $template, Relation $relat public function index(): void { - global $cfg; + global $cfg, $route; - echo UserPreferencesHeader::getContent($this->template, $this->relation); + $cfgRelation = $this->relation->getRelationsParam(); + + echo $this->template->render('preferences/header', [ + 'route' => $route, + 'is_saved' => ! empty($_GET['saved']), + 'has_config_storage' => $cfgRelation['userconfigwork'], + ]); $twoFactor = new TwoFactor($cfg['Server']['user']); diff --git a/libraries/classes/UserPreferencesHeader.php b/libraries/classes/UserPreferencesHeader.php deleted file mode 100644 index d4595339b48d..000000000000 --- a/libraries/classes/UserPreferencesHeader.php +++ /dev/null @@ -1,165 +0,0 @@ - 'index.php?route=/preferences/manage', - 'text' => __('Manage your settings'), - 'active' => $route === '/preferences/manage', - ] - ) . "\n"; - /* Second authentication factor */ - $content .= Generator::getHtmlTab( - [ - 'link' => 'index.php?route=/preferences/two-factor', - 'text' => __('Two-factor authentication'), - 'active' => $route === '/preferences/two-factor', - ] - ) . "\n"; - - $content .= Generator::getHtmlTab( - [ - 'link' => 'index.php?route=/preferences/features', - 'text' => __('Features'), - 'icon' => 'b_tblops', - 'active' => $route === '/preferences/features', - ] - ) . "\n"; - - $content .= Generator::getHtmlTab( - [ - 'link' => 'index.php?route=/preferences/sql', - 'text' => __('SQL queries'), - 'icon' => 'b_sql', - 'active' => $route === '/preferences/sql', - ] - ) . "\n"; - - $content .= Generator::getHtmlTab( - [ - 'link' => 'index.php?route=/preferences/navigation', - 'text' => __('Navigation panel'), - 'icon' => 'b_select', - 'active' => $route === '/preferences/navigation', - ] - ) . "\n"; - - $content .= Generator::getHtmlTab( - [ - 'link' => 'index.php?route=/preferences/main-panel', - 'text' => __('Main panel'), - 'icon' => 'b_props', - 'active' => $route === '/preferences/main-panel', - ] - ) . "\n"; - - $content .= Generator::getHtmlTab( - [ - 'link' => 'index.php?route=/preferences/export', - 'text' => __('Export'), - 'icon' => 'b_export', - 'active' => $route === '/preferences/export', - ] - ) . "\n"; - - $content .= Generator::getHtmlTab( - [ - 'link' => 'index.php?route=/preferences/import', - 'text' => __('Import'), - 'icon' => 'b_import', - 'active' => $route === '/preferences/import', - ] - ) . "\n"; - - return '
' . - $template->render( - 'list/unordered', - [ - 'id' => 'topmenu2', - 'class' => 'user_prefs_tabs', - 'content' => $content, - ] - ) . '
'; - } - - protected static function displayConfigurationSavedMessage(): ?string - { - // show "configuration saved" message and reload navigation panel if needed - if (! empty($_GET['saved'])) { - return Message::rawSuccess(__('Configuration has been saved.')) - ->getDisplay(); - } - - return null; - } - - /** - * @param Relation $relation Relation instance - */ - protected static function sessionStorageWarning(Relation $relation): ?string - { - // warn about using session storage for settings - $cfgRelation = $relation->getRelationsParam(); - if (! $cfgRelation['userconfigwork']) { - $msg = __( - 'Your preferences will be saved for current session only. Storing them ' - . 'permanently requires %sphpMyAdmin configuration storage%s.' - ); - $msg = Sanitize::sanitizeMessage( - sprintf($msg, '[doc@linked-tables]', '[/doc]') - ); - return Message::notice($msg) - ->getDisplay(); - } - - return null; - } -} diff --git a/templates/preferences/header.twig b/templates/preferences/header.twig new file mode 100644 index 000000000000..1505b4e7c18e --- /dev/null +++ b/templates/preferences/header.twig @@ -0,0 +1,63 @@ +
+ + + {% if is_saved %} + {{ 'Configuration has been saved.'|trans|raw_success }} + {% endif %} + + {% if not has_config_storage %} + {% apply format('', '')|notice %} + {% trans 'Your preferences will be saved for current session only. Storing them permanently requires %sphpMyAdmin configuration storage%s.' %} + {% endapply %} + {% endif %} diff --git a/test/classes/UserPreferencesHeaderTest.php b/test/classes/UserPreferencesHeaderTest.php deleted file mode 100644 index 659bc180784f..000000000000 --- a/test/classes/UserPreferencesHeaderTest.php +++ /dev/null @@ -1,114 +0,0 @@ -getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $GLOBALS['dbi'] = $dbi; - $GLOBALS['route'] = '/preferences/features'; - $_GET['route'] = '/preferences/features'; - $_GET['form'] = 'Features'; - - $template = new Template(); - $content = UserPreferencesHeader::getContent($template, new Relation($dbi, $template)); - - $this->assertStringContainsString( - '
  • ', - $content - ); - $this->assertStringContainsString( - '', - $content - ); - $this->assertStringContainsString( - 'Features Features', - $content - ); - } - - /** - * Test for getContent with "saved" get parameter - * - * @throws Throwable - * @throws Twig_Error_Loader - * @throws Twig_Error_Runtime - * @throws Twig_Error_Syntax - */ - public function testGetContentAfterSave(): void - { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $GLOBALS['dbi'] = $dbi; - $_GET['saved'] = true; - - $template = new Template(); - $this->assertStringContainsString( - 'Configuration has been saved.', - UserPreferencesHeader::getContent($template, new Relation($dbi, $template)) - ); - } - - /** - * Test for getContent with session storage - * - * @throws Throwable - * @throws Twig_Error_Loader - * @throws Twig_Error_Runtime - * @throws Twig_Error_Syntax - */ - public function testGetContentWithSessionStorage(): void - { - $dbi = $this->getMockBuilder(DatabaseInterface::class) - ->disableOriginalConstructor() - ->getMock(); - - $GLOBALS['dbi'] = $dbi; - - $template = new Template(); - $this->assertStringContainsString( - 'Your preferences will be saved for current session only. Storing them permanently requires', - UserPreferencesHeader::getContent($template, new Relation($dbi, $template)) - ); - } -}