Skip to content

Commit

Permalink
Remove special casing for font size
Browse files Browse the repository at this point in the history
It is now stored in configuration in same way as any other setting.

Issue #13466
Issue #11688

Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Nov 28, 2017
1 parent cbbf0d5 commit f9c73c7
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 85 deletions.
7 changes: 7 additions & 0 deletions doc/config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------

Expand Down
11 changes: 11 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@
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;
Expand Down
66 changes: 5 additions & 61 deletions libraries/classes/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -756,12 +756,6 @@ public function load($source = null)
$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();
Expand Down Expand Up @@ -934,11 +928,6 @@ public function loadUserPreferences()
$_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);
Expand Down Expand Up @@ -977,15 +966,6 @@ public function loadUserPreferences()
}
}

// 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'])
Expand Down Expand Up @@ -1234,18 +1214,14 @@ public function getSource()
/**
* 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;
}
Expand Down Expand Up @@ -1285,34 +1261,6 @@ public function checkCollationConnection()
$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
*
Expand Down Expand Up @@ -1548,14 +1496,10 @@ protected static function getFontsizeOptions($current_size = '82%')
*/
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);

Expand Down Expand Up @@ -1583,7 +1527,7 @@ protected static function getFontsizeSelection()
public static function getFontsizeForm()
{
return '<form name="form_fontsize_selection" id="form_fontsize_selection"'
. ' method="get" action="index.php" class="disableAjax">' . "\n"
. ' method="post" action="index.php" class="disableAjax">' . "\n"
. Url::getHiddenInputs() . "\n"
. Config::getFontsizeSelection() . "\n"
. '</form>';
Expand Down
2 changes: 2 additions & 0 deletions libraries/classes/Config/Descriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,8 @@ public static function getString($path, $type = 'name')
return __('Order');
case 'Console_OrderBy_name':
return __('Order by');
case 'FontSize_name':
return __('Font size');
}
return null;
}
Expand Down
1 change: 1 addition & 0 deletions libraries/classes/Config/Forms/User/FeaturesForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static function getForms()
'SendErrorReports',
'ConsoleEnterExecutes',
'DisableShortcutKeys',
'FontSize',
),
'Databases' => array(
'Servers/1/only_db', // saves to Server/only_db
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public function getPrintPreview()
*/
function getFontSize()
{
$fs = $GLOBALS['PMA_Config']->get('fontsize');
$fs = $GLOBALS['PMA_Config']->get('FontSize');
if (!is_null($fs)) {
return $fs;
}
Expand Down
1 change: 0 additions & 1 deletion libraries/classes/UserPreferences.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ public static function apply(array $config_data)
$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;
Expand Down
5 changes: 5 additions & 0 deletions libraries/config.default.php
Original file line number Diff line number Diff line change
Expand Up @@ -2860,6 +2860,11 @@
$cfg['ThemePerServer'] = false;


/**
* Font size to use by default
*/
$cfg['FontSize'] = '82%';

/*******************************************************************************
*
*/
Expand Down
1 change: 1 addition & 0 deletions libraries/config.values.php
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
'Servers/1/hide_db' => 'validateRegex',
'TextareaCols' => 'validatePositiveNumber',
'TextareaRows' => 'validatePositiveNumber',
'FontSize' => array(array('validateByRegex', '/^[0-9.]+(px|em|pt|\%)$/')),
'TrustedProxies' => 'validateTrustedProxies');

/**
Expand Down
10 changes: 1 addition & 9 deletions prefs_manage.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
exit;
}

// check for ThemeDefault and fontsize
// check for ThemeDefault
$params = array();
$tmanager = ThemeManager::getInstance();
if (isset($config['ThemeDefault'])
Expand All @@ -155,11 +155,6 @@
$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']
) {
Expand Down Expand Up @@ -201,9 +196,6 @@
$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);
Expand Down
22 changes: 10 additions & 12 deletions test/classes/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,8 @@ public function testGetFontsizeForm()
);

//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(
'<option value="7em"',
Config::getFontsizeForm()
Expand All @@ -111,7 +110,7 @@ public function testGetFontsizeForm()
);

//test getFontsizeOptions for "pt" unit
$_COOKIE['pma_fontsize'] = "10pt";
$GLOBALS['PMA_Config']->set('FontSize', '10pt');
$this->assertContains(
'<option value="2pt"',
Config::getFontsizeForm()
Expand All @@ -122,7 +121,7 @@ public function testGetFontsizeForm()
);

//test getFontsizeOptions for "px" unit
$_COOKIE['pma_fontsize'] = "10px";
$GLOBALS['PMA_Config']->set('FontSize', '10px');
$this->assertContains(
'<option value="5px"',
Config::getFontsizeForm()
Expand All @@ -133,7 +132,7 @@ public function testGetFontsizeForm()
);

//test getFontsizeOptions for unknown unit
$_COOKIE['pma_fontsize'] = "10abc";
$GLOBALS['PMA_Config']->set('FontSize', '10abc');
$this->assertContains(
'<option value="7abc"',
Config::getFontsizeForm()
Expand All @@ -142,9 +141,8 @@ public function testGetFontsizeForm()
'<option value="8abc"',
Config::getFontsizeForm()
);
unset($_COOKIE['pma_fontsize']);
//rollback the fontsize setting
$GLOBALS['PMA_Config']->set('fontsize', $fontsize);
$GLOBALS['PMA_Config']->set('FontSize', $fontsize);
}

/**
Expand Down Expand Up @@ -840,15 +838,15 @@ public function testGetThemeUniqueValue()
$GLOBALS['PMA_Theme']->filesize_info
);

$this->object->set('fontsize', 10);
$this->object->set('FontSize', 10);
$this->assertEquals(10 + $partial_sum, $this->object->getThemeUniqueValue());
$this->object->set('fontsize', null);

$_COOKIE['pma_fontsize'] = 20;
$this->object->set('FontSize', 20);
$this->assertEquals(20 + $partial_sum, $this->object->getThemeUniqueValue());
unset($_COOKIE['pma_fontsize']);
$this->object->set('FontSize', null);

$this->assertEquals($partial_sum, $this->object->getThemeUniqueValue());
$this->object->set('FontSize', '82%');

}

Expand Down
2 changes: 1 addition & 1 deletion test/classes/ThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public function testGetFontSize()
'82%'
);

$GLOBALS['PMA_Config']->set('fontsize', '12px');
$GLOBALS['PMA_Config']->set('FontSize', '12px');
$this->assertEquals(
$this->object->getFontSize(),
'12px'
Expand Down

0 comments on commit f9c73c7

Please sign in to comment.