From f9c73c7b10e5c57bfb8deb965491f84c9d6623c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Tue, 28 Nov 2017 15:15:34 +0100 Subject: [PATCH 1/4] Remove special casing for font size MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is now stored in configuration in same way as any other setting. Issue #13466 Issue #11688 Signed-off-by: Michal Čihař --- doc/config.rst | 7 ++ index.php | 11 ++++ libraries/classes/Config.php | 66 ++----------------- libraries/classes/Config/Descriptions.php | 2 + .../Config/Forms/User/FeaturesForm.php | 1 + libraries/classes/Theme.php | 2 +- libraries/classes/UserPreferences.php | 1 - libraries/config.default.php | 5 ++ libraries/config.values.php | 1 + prefs_manage.php | 10 +-- test/classes/ConfigTest.php | 22 +++---- test/classes/ThemeTest.php | 2 +- 12 files changed, 45 insertions(+), 85 deletions(-) diff --git a/doc/config.rst b/doc/config.rst index e62b52da4a..1c5780b1a9 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -3219,6 +3219,13 @@ Theme manager settings Whether to allow different theme for each server. +.. config:option:: $cfg['FontSize'] + + :type: string + :default: '82%' + + Font size to use, is applied in CSS. + Default queries --------------- diff --git a/index.php b/index.php index 98039f1b0f..66627f3e75 100644 --- a/index.php +++ b/index.php @@ -66,6 +66,17 @@ if (isset($_REQUEST['ajax_request']) && ! empty($_REQUEST['access_time'])) { exit; } +if (isset($_POST['set_fontsize']) && preg_match('/^[0-9.]+(px|em|pt|\%)$/', $_POST['set_fontsize'])) { + $GLOBALS['PMA_Config']->setUserValue( + null, + 'FontSize', + $_POST['set_fontsize'], + '82%' + ); + header('Location: index.php' . Url::getCommonRaw()); + exit(); +} + // See FAQ 1.34 if (! empty($_REQUEST['db'])) { $page = null; diff --git a/libraries/classes/Config.php b/libraries/classes/Config.php index 4053a4c2a5..9387b89454 100644 --- a/libraries/classes/Config.php +++ b/libraries/classes/Config.php @@ -756,12 +756,6 @@ class Config $this->setSource($source); } - /** - * We check and set the font size at this point, to make the font size - * selector work also for users without a config.inc.php - */ - $this->checkFontsize(); - if (! $this->checkConfigSource()) { // even if no config file, set collation_connection $this->checkCollationConnection(); @@ -934,11 +928,6 @@ class Config $_SESSION['cache'][$cache_key]['userprefs_mtime'] ); - // backup some settings - $org_fontsize = ''; - if (isset($this->settings['fontsize'])) { - $org_fontsize = $this->settings['fontsize']; - } // load config array $this->settings = array_replace_recursive($this->settings, $config_data); $GLOBALS['cfg'] = array_replace_recursive($GLOBALS['cfg'], $config_data); @@ -977,15 +966,6 @@ class Config } } - // save font size - if ((! isset($config_data['fontsize']) - && $org_fontsize != '82%') - || isset($config_data['fontsize']) - && $org_fontsize != $config_data['fontsize'] - ) { - $this->setUserValue(null, 'fontsize', $org_fontsize, '82%'); - } - // save language if (isset($_COOKIE['pma_lang']) || isset($_POST['lang'])) { if ((! isset($config_data['lang']) @@ -1234,18 +1214,14 @@ class Config /** * returns a unique value to force a CSS reload if either the config * or the theme changes - * must also check the pma_fontsize cookie in case there is no - * config file * * @return int Summary of unix timestamps and fontsize, * to be unique on theme parameters change */ public function getThemeUniqueValue() { - if (null !== $this->get('fontsize')) { - $fontsize = intval($this->get('fontsize')); - } elseif (isset($_COOKIE['pma_fontsize'])) { - $fontsize = intval($_COOKIE['pma_fontsize']); + if (null !== $this->get('FontSize')) { + $fontsize = intval($this->get('FontSize')); } else { $fontsize = 0; } @@ -1285,34 +1261,6 @@ class Config $this->set('collation_connection', $collation); } - /** - * checks for font size configuration, and sets font size as requested by user - * - * @return void - */ - public function checkFontsize() - { - $new_fontsize = ''; - - if (isset($_GET['set_fontsize'])) { - $new_fontsize = $_GET['set_fontsize']; - } elseif (isset($_POST['set_fontsize'])) { - $new_fontsize = $_POST['set_fontsize']; - } elseif (isset($_COOKIE['pma_fontsize'])) { - $new_fontsize = $_COOKIE['pma_fontsize']; - } - - if (preg_match('/^[0-9.]+(px|em|pt|\%)$/', $new_fontsize)) { - $this->set('fontsize', $new_fontsize); - } elseif (! $this->get('fontsize')) { - // 80% would correspond to the default browser font size - // of 16, but use 82% to help read the monoface font - $this->set('fontsize', '82%'); - } - - $this->setCookie('pma_fontsize', $this->get('fontsize'), '82%'); - } - /** * checks if upload is enabled * @@ -1548,14 +1496,10 @@ class Config */ protected static function getFontsizeSelection() { - $current_size = $GLOBALS['PMA_Config']->get('fontsize'); + $current_size = $GLOBALS['PMA_Config']->get('FontSize'); // for the case when there is no config file (this is supported) if (empty($current_size)) { - if (isset($_COOKIE['pma_fontsize'])) { - $current_size = htmlspecialchars($_COOKIE['pma_fontsize']); - } else { - $current_size = '82%'; - } + $current_size = '82%'; } $options = Config::getFontsizeOptions($current_size); @@ -1583,7 +1527,7 @@ class Config public static function getFontsizeForm() { return '
' . "\n" + . ' method="post" action="index.php" class="disableAjax">' . "\n" . Url::getHiddenInputs() . "\n" . Config::getFontsizeSelection() . "\n" . '
'; diff --git a/libraries/classes/Config/Descriptions.php b/libraries/classes/Config/Descriptions.php index b46b8c4b87..5173eab335 100644 --- a/libraries/classes/Config/Descriptions.php +++ b/libraries/classes/Config/Descriptions.php @@ -1478,6 +1478,8 @@ class Descriptions return __('Order'); case 'Console_OrderBy_name': return __('Order by'); + case 'FontSize_name': + return __('Font size'); } return null; } diff --git a/libraries/classes/Config/Forms/User/FeaturesForm.php b/libraries/classes/Config/Forms/User/FeaturesForm.php index b3e027e510..6e8e30d1d1 100644 --- a/libraries/classes/Config/Forms/User/FeaturesForm.php +++ b/libraries/classes/Config/Forms/User/FeaturesForm.php @@ -24,6 +24,7 @@ class FeaturesForm extends BaseForm 'SendErrorReports', 'ConsoleEnterExecutes', 'DisableShortcutKeys', + 'FontSize', ), 'Databases' => array( 'Servers/1/only_db', // saves to Server/only_db diff --git a/libraries/classes/Theme.php b/libraries/classes/Theme.php index acb1cd6d9a..52e1fe4667 100644 --- a/libraries/classes/Theme.php +++ b/libraries/classes/Theme.php @@ -433,7 +433,7 @@ class Theme */ function getFontSize() { - $fs = $GLOBALS['PMA_Config']->get('fontsize'); + $fs = $GLOBALS['PMA_Config']->get('FontSize'); if (!is_null($fs)) { return $fs; } diff --git a/libraries/classes/UserPreferences.php b/libraries/classes/UserPreferences.php index 05e90ab4a9..69fd8905dc 100644 --- a/libraries/classes/UserPreferences.php +++ b/libraries/classes/UserPreferences.php @@ -168,7 +168,6 @@ class UserPreferences $whitelist = array_flip(UserFormList::getFields()); // whitelist some additional fields which are custom handled $whitelist['ThemeDefault'] = true; - $whitelist['fontsize'] = true; $whitelist['lang'] = true; $whitelist['collation_connection'] = true; $whitelist['Server/hide_db'] = true; diff --git a/libraries/config.default.php b/libraries/config.default.php index fc42feba92..e74e8828e0 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -2860,6 +2860,11 @@ $cfg['ThemeDefault'] = 'pmahomme'; $cfg['ThemePerServer'] = false; +/** + * Font size to use by default + */ +$cfg['FontSize'] = '82%'; + /******************************************************************************* * */ diff --git a/libraries/config.values.php b/libraries/config.values.php index 1e7409e679..a32189e3b8 100644 --- a/libraries/config.values.php +++ b/libraries/config.values.php @@ -263,6 +263,7 @@ $cfg_db['_validators'] = array( 'Servers/1/hide_db' => 'validateRegex', 'TextareaCols' => 'validatePositiveNumber', 'TextareaRows' => 'validatePositiveNumber', + 'FontSize' => array(array('validateByRegex', '/^[0-9.]+(px|em|pt|\%)$/')), 'TrustedProxies' => 'validateTrustedProxies'); /** diff --git a/prefs_manage.php b/prefs_manage.php index 74a97fff96..a87ec2c63c 100644 --- a/prefs_manage.php +++ b/prefs_manage.php @@ -145,7 +145,7 @@ if (isset($_POST['submit_export']) exit; } - // check for ThemeDefault and fontsize + // check for ThemeDefault $params = array(); $tmanager = ThemeManager::getInstance(); if (isset($config['ThemeDefault']) @@ -155,11 +155,6 @@ if (isset($_POST['submit_export']) $tmanager->setActiveTheme($config['ThemeDefault']); $tmanager->setThemeCookie(); } - if (isset($config['fontsize']) - && $config['fontsize'] != $GLOBALS['PMA_Config']->get('fontsize') - ) { - $params['set_fontsize'] = $config['fontsize']; - } if (isset($config['lang']) && $config['lang'] != $GLOBALS['lang'] ) { @@ -201,9 +196,6 @@ if (isset($_POST['submit_export']) $result = UserPreferences::save(array()); if ($result === true) { $params = array(); - if ($GLOBALS['PMA_Config']->get('fontsize') != '82%') { - $GLOBALS['PMA_Config']->removeCookie('pma_fontsize'); - } $GLOBALS['PMA_Config']->removeCookie('pma_collaction_connection'); $GLOBALS['PMA_Config']->removeCookie('pma_lang'); UserPreferences::redirect('prefs_manage.php', $params); diff --git a/test/classes/ConfigTest.php b/test/classes/ConfigTest.php index 39cd267b7b..20e067ff58 100644 --- a/test/classes/ConfigTest.php +++ b/test/classes/ConfigTest.php @@ -98,9 +98,8 @@ class ConfigTest extends PmaTestCase ); //test getFontsizeOptions for "em" unit - $fontsize = $GLOBALS['PMA_Config']->get('fontsize'); - $GLOBALS['PMA_Config']->set('fontsize', ''); - $_COOKIE['pma_fontsize'] = "10em"; + $fontsize = $GLOBALS['PMA_Config']->get('FontSize'); + $GLOBALS['PMA_Config']->set('FontSize', '10em'); $this->assertContains( '