diff --git a/Documentation.html b/Documentation.html index e471ce9e2..bdba1779e 100644 --- a/Documentation.html +++ b/Documentation.html @@ -2176,6 +2176,11 @@ setfacl -d -m "g:www-data:rwx" tmp closed state. A value of 'open' does the reverse. To completely disable all visual sliders, use 'disabled'. +
$cfg['UserprefsDisallow'] array
+
Contains names of configuration options (keys in $cfg array) + that users can't set through user preferences. For possible values, refer + to libraries/config/user_preferences.forms.php.
+
$cfg['TitleTable'] string
$cfg['TitleDatabase'] string
$cfg['TitleServer'] string
diff --git a/js/config.js b/js/config.js index 5a6a98cf9..85dc4c51f 100644 --- a/js/config.js +++ b/js/config.js @@ -571,7 +571,8 @@ function restoreField(field_id) { $(function() { $('.restore-default, .set-value').each(function() { var link = $(this); - link.css('opacity', 0.25); + // inline-block for IE so opacity inheritance works + link.css('display', 'inline-block').css('opacity', 0.25); if (!link.hasClass('restore-default')) { // restore-default is handled by markField link.css('display', ''); diff --git a/libraries/config.default.php b/libraries/config.default.php index 08b4e56d2..8db79c39b 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -2282,7 +2282,13 @@ $cfg['NaturalOrder'] = true; */ $cfg['InitialSlidersState'] = 'closed'; - +/** + * User preferences: disallow these settings + * For possible setting names look in libraries/config/user_preferences.forms.php + * + * @global array $cfg['UserprefsDisallow'] + */ +$cfg['UserprefsDisallow'] = array(); //----------------------------------------------------------------------------- // custom-setup by mkkeck: 2004-05-04 diff --git a/libraries/config/ConfigFile.class.php b/libraries/config/ConfigFile.class.php index f270561c7..acbb260f8 100644 --- a/libraries/config/ConfigFile.class.php +++ b/libraries/config/ConfigFile.class.php @@ -499,8 +499,9 @@ class ConfigFile } else { // more than 4 values - value per line $ret = "\$cfg['$var_name'] = array("; - for ($i = 0, $imax = count($ret)-1; $i <= $imax; $i++) { - $ret .= ($i < $imax ? $crlf : '') . ' ' . $v; + $imax = count($retv)-1; + for ($i = 0; $i <= $imax; $i++) { + $ret .= ($i < $imax ? ($i > 0 ? ',' : '') : '') . $crlf . ' ' . $retv[$i]; } $ret .= ');' . $crlf; } diff --git a/libraries/config/FormDisplay.class.php b/libraries/config/FormDisplay.class.php index 55a02952d..be643ac48 100644 --- a/libraries/config/FormDisplay.class.php +++ b/libraries/config/FormDisplay.class.php @@ -8,9 +8,8 @@ * o translated_path - work_path modified for HTML field name, a path with * slashes changed to hyphens, eg. Servers-4-verbose * - * @package phpMyAdmin-setup + * @package phpMyAdmin * @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0 - * @version $Id$ */ /** @@ -64,7 +63,19 @@ class FormDisplay * Tells whether forms have been validated * @var bool */ - private $is_valdiated = true; + private $is_validated = true; + + /** + * Dictionary with user preferences keys + * @var array + */ + private $userprefs_keys; + + /** + * Dictionary with disallowed user preferences keys + * @var array + */ + private $userprefs_disallow; public function __construct() { @@ -86,7 +97,7 @@ class FormDisplay public function registerForm($form_name, array $form, $server_id = null) { $this->forms[$form_name] = new Form($form_name, $form, $server_id); - $this->is_valdiated = false; + $this->is_validated = false; foreach ($this->forms[$form_name]->fields as $path) { $work_path = $server_id === null ? $path @@ -121,7 +132,7 @@ class FormDisplay */ private function _validate() { - if ($this->is_valdiated) { + if ($this->is_validated) { return; } @@ -155,7 +166,7 @@ class FormDisplay $this->errors[$work_path] = $error_list; } } - $this->is_valdiated = true; + $this->is_validated = true; } @@ -197,6 +208,16 @@ class FormDisplay $this->_validate(); } + // 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); + } + // display forms foreach ($this->forms as $form) { /* @var $form Form */ @@ -211,9 +232,13 @@ 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 + $userprefs_allow = isset($this->userprefs_keys[$path]) + ? !isset($this->userprefs_disallow[$path]) + : null; // display input $this->_displayFieldInput($form, $field, $path, $work_path, - $translated_path, $show_restore_default, $js_default); + $translated_path, $show_restore_default, $userprefs_allow, $js_default); // register JS validators for this field if (isset($validators[$path])) { js_validate($translated_path, $validators[$path], $js); @@ -250,10 +275,11 @@ 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 array &$js_default array which stores JavaScript code to be displayed */ private function _displayFieldInput(Form $form, $field, $system_path, $work_path, - $translated_path, $show_restore_default, array &$js_default) + $translated_path, $show_restore_default, $userprefs_allow, array &$js_default) { $name = PMA_lang_name($system_path); $description = PMA_lang_desc($system_path); @@ -270,7 +296,8 @@ class FormDisplay $opts = array( 'doc' => $this->getDocLink($system_path), 'wiki' => $this->getWikiLink($system_path), - 'show_restore_default' => $show_restore_default); + 'show_restore_default' => $show_restore_default, + 'userprefs_allow' => $userprefs_allow); if (isset($form->default[$system_path])) { $opts['setvalue'] = $form->default[$system_path]; } @@ -417,6 +444,16 @@ 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); + } + $this->errors = array(); foreach ($forms as $form) { /* @var $form Form */ @@ -448,6 +485,16 @@ class FormDisplay } } + // user preferences allow/disallow + if ($is_setup_script && isset($this->userprefs_keys[$system_path])) { + if (isset($this->userprefs_disallow[$system_path]) + && isset($_POST[$key . '-userprefs-allow'])) { + unset($this->userprefs_disallow[$system_path]); + } else if (!isset($_POST[$key . '-userprefs-allow'])) { + $this->userprefs_disallow[$system_path] = true; + } + } + // cast variables to correct type $type = $form->getOptionType($field); switch ($type) { @@ -516,6 +563,9 @@ class FormDisplay } $cf->set($work_path, $values[$path], $path); } + if ($is_setup_script) { + $cf->set('UserprefsDisallow', array_keys($this->userprefs_disallow)); + } } // don't look for non-critical errors diff --git a/libraries/config/FormDisplay.tpl.php b/libraries/config/FormDisplay.tpl.php index 68fe9f58c..6345c2651 100644 --- a/libraries/config/FormDisplay.tpl.php +++ b/libraries/config/FormDisplay.tpl.php @@ -2,9 +2,8 @@ /** * Form templates * - * @package phpMyAdmin-setup + * @package phpMyAdmin * @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0 - * @version $Id$ */ /** @@ -98,7 +97,7 @@ 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 show user preferences allow/deny checkbox (null - no, true/false - yes) + * o userprefs_allow - whether user preferences are enabled for this field (null - no support, true/false - enabled/disabled) * o values - key - value paris for '; break; case 'select': @@ -212,8 +209,18 @@ function display_input($path, $name, $description = '', $type, $value, $value_is echo ''; } ?> - + + + /> + +  '; + } + ?> - + diff --git a/setup/scripts.js b/setup/scripts.js index 4763ff081..8a853c08a 100644 --- a/setup/scripts.js +++ b/setup/scripts.js @@ -168,3 +168,25 @@ function ajaxValidate(parent, id, values) { return true; } + +// +// END: Form validation and field operations +// ------------------------------------------------------------------ + +// ------------------------------------------------------------------ +// User preferences allow/disallow UI +// + +$(function() { + $('.userprefs-allow').click(function(e) { + if (this != e.target) { + return; + } + var el = $(this).find('input'); + el.attr('checked', !el.attr('checked')); + }); +}); + +// +// END: User preferences allow/disallow UI +// ------------------------------------------------------------------ \ No newline at end of file diff --git a/setup/styles.css b/setup/styles.css index 23364177b..fc14a3235 100644 --- a/setup/styles.css +++ b/setup/styles.css @@ -262,6 +262,18 @@ fieldset td { vertical-align: top; } +fieldset td.userprefs-allow { + padding: 0; + vertical-align: middle; + text-align: center; + width: 3em; +} + +fieldset td.userprefs-allow:hover { + cursor: pointer; + background-color: #EEE; +} + fieldset th small { display: block; font-weight: normal; @@ -307,7 +319,7 @@ fieldset.simple .lastrow { span.checkbox { padding: 2px; - display: inline-block; + display: inline-block; } .custom { /* customized field */