From 7ac7e24d8cc97cb3c0234b0058661770c0d0f44c Mon Sep 17 00:00:00 2001 From: Crack Date: Thu, 22 Jul 2010 01:29:36 +0200 Subject: [PATCH] more styling for disabled options new "Developer" tab (by default all options are disabled, users can't modify them) fixed UserprefsDisallow export in setup script --- libraries/config.default.php | 9 +++- libraries/config/ConfigFile.class.php | 11 ++-- libraries/config/FormDisplay.class.php | 54 ++++++++++--------- libraries/config/FormDisplay.tpl.php | 23 +++++--- libraries/config/messages.inc.php | 8 ++- libraries/config/setup.forms.php | 5 ++ libraries/config/user_preferences.forms.php | 23 ++++---- libraries/user_preferences.inc.php | 2 +- prefs_forms.php | 13 +++++ setup/scripts.js | 3 ++ .../darkblue_orange/css/theme_right.css.php | 7 +++ themes/original/css/theme_right.css.php | 7 +++ 12 files changed, 119 insertions(+), 46 deletions(-) diff --git a/libraries/config.default.php b/libraries/config.default.php index 4524cb268..df641a899 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -2310,11 +2310,16 @@ $cfg['InitialSlidersState'] = 'closed'; /** * User preferences: disallow these settings - * For possible setting names look in libraries/config/user_preferences.forms.php + * For possible setting names look in libraries/config/user_preferences.forms.php. Use + * + * $cfg['UserprefsDisallow'] = array_merge($this->settings['UserprefsDisallow'], array()); + * + * to append new keys. * * @global array $cfg['UserprefsDisallow'] */ -$cfg['UserprefsDisallow'] = array(); +$cfg['UserprefsDisallow'] = array( + 'Error_Handler/display', 'Error_Handler/gather', 'DBG/sql', 'DBG/php'); /** * User preferences: disabling options by users diff --git a/libraries/config/ConfigFile.class.php b/libraries/config/ConfigFile.class.php index 2d3ff28d5..869f9a72e 100644 --- a/libraries/config/ConfigFile.class.php +++ b/libraries/config/ConfigFile.class.php @@ -520,18 +520,23 @@ class ConfigFile foreach ($var_value as $v) { $retv[] = var_export($v, true); } + $ret = "\$cfg['$var_name'] = array("; + $ret_end = ');' . $crlf; + if ($var_name == 'UserprefsDisallow') { + $ret = "\$cfg['$var_name'] = array_merge(\$this->settings['UserprefsDisallow'],\n\tarray("; + $ret_end = ')' . $ret_end; + } if (count($retv) <= 4) { // up to 4 values - one line - $ret = "\$cfg['$var_name'] = array(" . implode(', ', $retv) . ');' . $crlf; + $ret .= implode(', ', $retv); } else { // more than 4 values - value per line - $ret = "\$cfg['$var_name'] = array("; $imax = count($retv)-1; for ($i = 0; $i <= $imax; $i++) { $ret .= ($i < $imax ? ($i > 0 ? ',' : '') : '') . $crlf . ' ' . $retv[$i]; } - $ret .= ');' . $crlf; } + $ret .= $ret_end; } else { // string keys: $cfg[key][subkey] = value foreach ($var_value as $k => $v) { diff --git a/libraries/config/FormDisplay.class.php b/libraries/config/FormDisplay.class.php index 7f9f56613..1fbd33998 100644 --- a/libraries/config/FormDisplay.class.php +++ b/libraries/config/FormDisplay.class.php @@ -175,7 +175,6 @@ class FormDisplay $this->is_validated = true; } - /** * Outputs HTML for forms * @@ -192,7 +191,6 @@ class FormDisplay * @uses PMA_config_get_validators() * @uses PMA_jsFormat() * @uses PMA_lang() - * @uses PMA_read_userprefs_fieldnames() * @param bool $tabbed_form * @param bool $show_restore_default whether show "restore default" button besides the input field */ @@ -229,14 +227,9 @@ class FormDisplay } // user preferences - if ($this->userprefs_keys === null) { - $this->userprefs_keys = array_flip(PMA_read_userprefs_fieldnames()); - // read real config for user preferences display - $userprefs_disallow = defined('PMA_SETUP') && PMA_SETUP - ? ConfigFile::getInstance()->get('UserprefsDisallow', array()) - : $GLOBALS['cfg']['UserprefsDisallow']; - $this->userprefs_disallow = array_flip($userprefs_disallow); - } + $this->_loadUserprefsInfo(); + $default_disallow = array_flip( + ConfigFile::getInstance()->getDefault('UserprefsDisallow', array())); // display forms foreach ($this->forms as $form) { @@ -252,9 +245,10 @@ class FormDisplay foreach ($form->fields as $field => $path) { $work_path = array_search($path, $this->system_paths); $translated_path = $this->translated_paths[$work_path]; - // always true/false for user preferences display + // always true/false/'disable' for user preferences display + // otherwise null $userprefs_allow = isset($this->userprefs_keys[$path]) - ? !isset($this->userprefs_disallow[$path]) + ? (isset($default_disallow[$path]) ? 'disable' : !isset($this->userprefs_disallow[$path])) : null; // display input $this->_displayFieldInput($form, $field, $path, $work_path, @@ -306,7 +300,8 @@ class FormDisplay * @param string $work_path work path, eg. Servers/4/verbose * @param string $translated_path work path changed so that it can be used as XHTML id * @param bool $show_restore_default whether show "restore default" button besides the input field - * @param mixed $userprefs_allow whether user preferences are enabled for this field (null - no support, true/false - enabled/disabled) + * @param mixed $userprefs_allow whether user preferences are enabled for this field + * (null - no support, true/false - enabled/disabled) * @param array &$js_default array which stores JavaScript code to be displayed */ private function _displayFieldInput(Form $form, $field, $system_path, $work_path, @@ -490,7 +485,6 @@ class FormDisplay * @uses Form::getOptionType() * @uses Form::getOptionValueList() * @uses PMA_lang_name() - * @uses PMA_read_userprefs_fieldnames() * @param array|string $forms array of form names * @param bool $allow_partial_save allows for partial form saving on failed validation * @return boolean true on success (no errors and all saved) @@ -504,13 +498,8 @@ class FormDisplay $values = array(); $to_save = array(); $is_setup_script = defined('PMA_SETUP') && PMA_SETUP; - if ($is_setup_script && $this->userprefs_keys === null) { - $this->userprefs_keys = array_flip(PMA_read_userprefs_fieldnames()); - // read real config for user preferences display - $userprefs_disallow = $is_setup_script - ? ConfigFile::getInstance()->get('UserprefsDisallow', array()) - : $GLOBALS['cfg']['UserprefsDisallow']; - $this->userprefs_disallow = array_flip($userprefs_disallow); + if ($is_setup_script) { + $this->_loadUserprefsInfo(); } $this->errors = array(); @@ -664,7 +653,7 @@ class FormDisplay if ($test == 'Import' || $test == 'Export') { return ''; } - return 'Documentation.html#cfg_' . self::_getOptName($path); + return 'Documentation.html#cfg_' . $this->_getOptName($path); } /** @@ -675,7 +664,7 @@ class FormDisplay */ public function getWikiLink($path) { - $opt_name = self::_getOptName($path); + $opt_name = $this->_getOptName($path); if (substr($opt_name, 0, 7) == 'Servers') { $opt_name = substr($opt_name, 8); if (strpos($opt_name, 'AllowDeny') === 0) { @@ -701,11 +690,28 @@ class FormDisplay * @param string $path * @return string */ - private static function _getOptName($path) + private function _getOptName($path) { return str_replace( array('Servers/1/', 'disable/', '/'), array('Servers/', '', '_'), $path); } + + /** + * Fills out {@link userprefs_keys} and {@link userprefs_disallow} + * + * @uses PMA_read_userprefs_fieldnames() + */ + private function _loadUserprefsInfo() + { + if ($this->userprefs_keys === null) { + $this->userprefs_keys = array_flip(PMA_read_userprefs_fieldnames()); + // read real config for user preferences display + $userprefs_disallow = defined('PMA_SETUP') && PMA_SETUP + ? ConfigFile::getInstance()->get('UserprefsDisallow', array()) + : $GLOBALS['cfg']['UserprefsDisallow']; + $this->userprefs_disallow = array_flip($userprefs_disallow); + } + } } ?> \ No newline at end of file diff --git a/libraries/config/FormDisplay.tpl.php b/libraries/config/FormDisplay.tpl.php index db20bbb95..5e443bdfa 100644 --- a/libraries/config/FormDisplay.tpl.php +++ b/libraries/config/FormDisplay.tpl.php @@ -104,7 +104,8 @@ function display_fieldset_top($title = '', $description = '', $errors = null, $a * o errors - error array * o setvalue - (string) shows button allowing to set poredefined value * o show_restore_default - (boolean) whether show "restore default" button - * o userprefs_allow - whether user preferences are enabled for this field (null - no support, true/false - enabled/disabled) + * o userprefs_allow - whether user preferences are enabled for this field (null - no support, + * true/false - enabled/disabled, 'disable' - false and field is disabled) * o userprefs_comment - (string) field comment * o values - key - value paris for /> + name="-userprefs-allow" /> 'prefs_manage.php', 'text' => __('Manage your settings'))) . "\n"; echo '
  •    
  • ' . "\n"; -$script_name = basename(basename($GLOBALS['PMA_PHP_SELF'])); +$script_name = basename($GLOBALS['PMA_PHP_SELF']); foreach (array_keys($forms) as $formset) { $tab = array( 'link' => 'prefs_forms.php', diff --git a/prefs_forms.php b/prefs_forms.php index a73e529d3..06cad1c7c 100644 --- a/prefs_forms.php +++ b/prefs_forms.php @@ -26,6 +26,19 @@ require_once './libraries/user_preferences.inc.php'; $form_display = new FormDisplay(); foreach ($forms[$form_param] as $form_name => $form) { + // skip Developer form if no setting is available + if ($form_name == 'Developer') { + $show = false; + foreach ($form as $field_name) { + if (array_search($field_name, $GLOBALS['cfg']['UserprefsDisallow']) === false) { + $show = true; + break; + } + } + if (!$show) { + continue; + } + } $form_display->registerForm($form_name, $form); } diff --git a/setup/scripts.js b/setup/scripts.js index 8a853c08a..f223e0436 100644 --- a/setup/scripts.js +++ b/setup/scripts.js @@ -183,6 +183,9 @@ $(function() { return; } var el = $(this).find('input'); + if (el.attr('disabled')) { + return; + } el.attr('checked', !el.attr('checked')); }); }); diff --git a/themes/darkblue_orange/css/theme_right.css.php b/themes/darkblue_orange/css/theme_right.css.php index 446f3c0a1..11f78653c 100644 --- a/themes/darkblue_orange/css/theme_right.css.php +++ b/themes/darkblue_orange/css/theme_right.css.php @@ -1445,6 +1445,13 @@ fieldset .group-field th { padding-left: 1.5em; } +fieldset .disabled-field th, +fieldset .disabled-field th small, +fieldset .disabled-field td { + color: #777; + background-color: #eee; +} + .config-form .lastrow { border-top: 1px #000 solid; } diff --git a/themes/original/css/theme_right.css.php b/themes/original/css/theme_right.css.php index 028dd57dc..33bdfb7a3 100644 --- a/themes/original/css/theme_right.css.php +++ b/themes/original/css/theme_right.css.php @@ -1377,6 +1377,13 @@ fieldset .group-field th { padding-left: 1.5em; } +fieldset .disabled-field th, +fieldset .disabled-field th small, +fieldset .disabled-field td { + color: #666; + background-color: #ddd; +} + .config-form .lastrow { border-top: 1px #000 solid; }