allow users to set only_db and hide_db
This commit is contained in:
@@ -32,6 +32,13 @@ class ConfigFile
|
||||
*/
|
||||
private $persistKeys = array();
|
||||
|
||||
/**
|
||||
* Changes keys while updating config in {@link updateWithGlobalConfig()} or reading
|
||||
* by {@link getConfig()} or {@link getConfigArray()}
|
||||
* @var array
|
||||
*/
|
||||
private $cfgUpdateReadMapping = array();
|
||||
|
||||
/**
|
||||
* Key filter for {@link set()}
|
||||
* @var array|null
|
||||
@@ -136,6 +143,16 @@ class ConfigFile
|
||||
$this->setFilter = array_flip($keys);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets path mapping for updating config in {@link updateWithGlobalConfig()} or reading
|
||||
* by {@link getConfig()} or {@link getConfigArray()}
|
||||
* @var array
|
||||
*/
|
||||
public function setCfgUpdateReadMapping(array $mapping)
|
||||
{
|
||||
$this->cfgUpdateReadMapping = $mapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resets configuration data
|
||||
*/
|
||||
@@ -216,21 +233,26 @@ class ConfigFile
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates config with values read from PMA_Config class
|
||||
* Updates config with values read from given array
|
||||
* (config will contain differences to defaults from config.defaults.php).
|
||||
*
|
||||
* @param PMA_Config $PMA_Config
|
||||
* @param array $cfg
|
||||
*/
|
||||
public function updateWithGlobalConfig(PMA_Config $PMA_Config)
|
||||
public function updateWithGlobalConfig(array $cfg)
|
||||
{
|
||||
// load config array and flatten it
|
||||
$this->_flattenArrayResult = array();
|
||||
array_walk($PMA_Config->settings, array($this, '_flattenArray'), '');
|
||||
array_walk($cfg, array($this, '_flattenArray'), '');
|
||||
$flat_cfg = $this->_flattenArrayResult;
|
||||
$this->_flattenArrayResult = null;
|
||||
|
||||
// save values
|
||||
// map for translating a few user preferences paths, should be complemented
|
||||
// by code reading from generated config to perform inverse mapping
|
||||
foreach ($flat_cfg as $path => $value) {
|
||||
if (isset($this->cfgUpdateReadMapping[$path])) {
|
||||
$path = $this->cfgUpdateReadMapping[$path];
|
||||
}
|
||||
$this->set($path, $value, $path);
|
||||
}
|
||||
}
|
||||
@@ -426,7 +448,12 @@ class ConfigFile
|
||||
*/
|
||||
public function getConfig()
|
||||
{
|
||||
return $_SESSION[$this->id];
|
||||
$c = $_SESSION[$this->id];
|
||||
foreach ($this->cfgUpdateReadMapping as $map_to => $map_from) {
|
||||
PMA_array_write($map_to, $c, PMA_array_read($map_from, $c));
|
||||
PMA_array_remove($map_from, $c);
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -445,6 +472,14 @@ class ConfigFile
|
||||
foreach ($persistKeys as $k) {
|
||||
$c[$k] = $this->getDefault($k);
|
||||
}
|
||||
|
||||
foreach ($this->cfgUpdateReadMapping as $map_to => $map_from) {
|
||||
if (!isset($c[$map_from])) {
|
||||
continue;
|
||||
}
|
||||
$c[$map_to] = $c[$map_from];
|
||||
unset($c[$map_from]);
|
||||
}
|
||||
return $c;
|
||||
}
|
||||
}
|
||||
|
@@ -390,7 +390,7 @@ $strConfigServers_host_name = __('Server hostname');
|
||||
$strConfigServers_LogoutURL_name = __('Logout URL');
|
||||
$strConfigServers_nopassword_desc = __('Try to connect without password');
|
||||
$strConfigServers_nopassword_name = __('Connect without password');
|
||||
$strConfigServers_only_db_desc = __('You can use MySQL wildcard characters (% and _), escape them if you want to use their literal instances, i.e. use \'my\_db\' and not \'my_db\'');
|
||||
$strConfigServers_only_db_desc = __('You can use MySQL wildcard characters (% and _), escape them if you want to use their literal instances, i.e. use [kbd]\'my\_db\'[/kbd] and not [kbd]\'my_db\'[/kbd]. Using this option you can sort database list, just enter their names in order and use [kbd]*[/kbd] at the end to show the rest in alphabetical order.');
|
||||
$strConfigServers_only_db_name = __('Show only listed databases');
|
||||
$strConfigServers_password_desc = __('Leave empty if not using config auth');
|
||||
$strConfigServers_password_name = __('Password for config auth');
|
||||
|
@@ -18,6 +18,8 @@ $forms['Features']['General'] = array(
|
||||
'InitialSlidersState',
|
||||
'ErrorIconic',
|
||||
'ReplaceHelpImg',
|
||||
'Servers/1/only_db', // saves to Server/only_db
|
||||
'Servers/1/hide_db', // saves to Server/hide_db
|
||||
'SkipLockedTables',
|
||||
'MaxDbList',
|
||||
'MaxTableList');
|
||||
|
@@ -51,7 +51,10 @@ $forms_all_keys = PMA_read_userprefs_fieldnames($forms);
|
||||
$cf = ConfigFile::getInstance();
|
||||
$cf->resetConfigData(); // start with a clean instance
|
||||
$cf->setAllowedKeys($forms_all_keys);
|
||||
$cf->updateWithGlobalConfig($GLOBALS['PMA_Config']);
|
||||
$cf->setCfgUpdateReadMapping(array(
|
||||
'Server/hide_db' => 'Servers/1/hide_db',
|
||||
'Server/only_db' => 'Servers/1/only_db'));
|
||||
$cf->updateWithGlobalConfig($GLOBALS['cfg']);
|
||||
|
||||
// todo: debug - remove
|
||||
$arr = $cf->getConfigArray();
|
||||
|
@@ -147,6 +147,8 @@ function PMA_apply_userprefs(array $config_data)
|
||||
$whitelist['fontsize'] = true;
|
||||
$whitelist['lang'] = true;
|
||||
$whitelist['collation_connection'] = true;
|
||||
$whitelist['Server/hide_db'] = true;
|
||||
$whitelist['Server/only_db'] = true;
|
||||
foreach ($config_data as $path => $value) {
|
||||
if (!isset($whitelist[$path]) || isset($blacklist[$path])) {
|
||||
continue;
|
||||
@@ -230,7 +232,8 @@ function PMA_userprefs_redirect(array $forms, array $old_settings, $file_name, $
|
||||
$new_settings = ConfigFile::getInstance()->getConfigArray();
|
||||
$diff_keys = array_keys(array_diff_assoc($old_settings, $new_settings)
|
||||
+ array_diff_assoc($new_settings, $old_settings));
|
||||
$check_keys = array('NaturalOrder', 'MainPageIconic', 'DefaultTabDatabase');
|
||||
$check_keys = array('NaturalOrder', 'MainPageIconic', 'DefaultTabDatabase',
|
||||
'Server/hide_db', 'Server/only_db');
|
||||
$check_keys = array_merge($check_keys, $forms['Left_frame']['Left_frame'],
|
||||
$forms['Left_frame']['Left_databases']);
|
||||
$diff = array_intersect($check_keys, $diff_keys);
|
||||
|
@@ -30,7 +30,7 @@ foreach ($forms[$form_param] as $form_name => $form) {
|
||||
if ($form_name == 'Developer' && !$GLOBALS['cfg']['UserprefsDeveloperTab']) {
|
||||
continue;
|
||||
}
|
||||
$form_display->registerForm($form_name, $form);
|
||||
$form_display->registerForm($form_name, $form, 1);
|
||||
}
|
||||
|
||||
if (isset($_POST['revert'])) {
|
||||
|
Reference in New Issue
Block a user