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
This commit is contained in:
Crack
2010-07-22 01:29:36 +02:00
parent 7b0135ed6a
commit 7ac7e24d8c
12 changed files with 119 additions and 46 deletions

View File

@@ -2310,11 +2310,16 @@ $cfg['InitialSlidersState'] = 'closed';
/** /**
* User preferences: disallow these settings * 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
* <code>
* $cfg['UserprefsDisallow'] = array_merge($this->settings['UserprefsDisallow'], array());
* </code>
* to append new keys.
* *
* @global array $cfg['UserprefsDisallow'] * @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 * User preferences: disabling options by users

View File

@@ -520,18 +520,23 @@ class ConfigFile
foreach ($var_value as $v) { foreach ($var_value as $v) {
$retv[] = var_export($v, true); $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) { if (count($retv) <= 4) {
// up to 4 values - one line // up to 4 values - one line
$ret = "\$cfg['$var_name'] = array(" . implode(', ', $retv) . ');' . $crlf; $ret .= implode(', ', $retv);
} else { } else {
// more than 4 values - value per line // more than 4 values - value per line
$ret = "\$cfg['$var_name'] = array(";
$imax = count($retv)-1; $imax = count($retv)-1;
for ($i = 0; $i <= $imax; $i++) { for ($i = 0; $i <= $imax; $i++) {
$ret .= ($i < $imax ? ($i > 0 ? ',' : '') : '') . $crlf . ' ' . $retv[$i]; $ret .= ($i < $imax ? ($i > 0 ? ',' : '') : '') . $crlf . ' ' . $retv[$i];
} }
$ret .= ');' . $crlf;
} }
$ret .= $ret_end;
} else { } else {
// string keys: $cfg[key][subkey] = value // string keys: $cfg[key][subkey] = value
foreach ($var_value as $k => $v) { foreach ($var_value as $k => $v) {

View File

@@ -175,7 +175,6 @@ class FormDisplay
$this->is_validated = true; $this->is_validated = true;
} }
/** /**
* Outputs HTML for forms * Outputs HTML for forms
* *
@@ -192,7 +191,6 @@ class FormDisplay
* @uses PMA_config_get_validators() * @uses PMA_config_get_validators()
* @uses PMA_jsFormat() * @uses PMA_jsFormat()
* @uses PMA_lang() * @uses PMA_lang()
* @uses PMA_read_userprefs_fieldnames()
* @param bool $tabbed_form * @param bool $tabbed_form
* @param bool $show_restore_default whether show "restore default" button besides the input field * @param bool $show_restore_default whether show "restore default" button besides the input field
*/ */
@@ -229,14 +227,9 @@ class FormDisplay
} }
// user preferences // user preferences
if ($this->userprefs_keys === null) { $this->_loadUserprefsInfo();
$this->userprefs_keys = array_flip(PMA_read_userprefs_fieldnames()); $default_disallow = array_flip(
// read real config for user preferences display ConfigFile::getInstance()->getDefault('UserprefsDisallow', array()));
$userprefs_disallow = defined('PMA_SETUP') && PMA_SETUP
? ConfigFile::getInstance()->get('UserprefsDisallow', array())
: $GLOBALS['cfg']['UserprefsDisallow'];
$this->userprefs_disallow = array_flip($userprefs_disallow);
}
// display forms // display forms
foreach ($this->forms as $form) { foreach ($this->forms as $form) {
@@ -252,9 +245,10 @@ class FormDisplay
foreach ($form->fields as $field => $path) { foreach ($form->fields as $field => $path) {
$work_path = array_search($path, $this->system_paths); $work_path = array_search($path, $this->system_paths);
$translated_path = $this->translated_paths[$work_path]; $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]) $userprefs_allow = isset($this->userprefs_keys[$path])
? !isset($this->userprefs_disallow[$path]) ? (isset($default_disallow[$path]) ? 'disable' : !isset($this->userprefs_disallow[$path]))
: null; : null;
// display input // display input
$this->_displayFieldInput($form, $field, $path, $work_path, $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 $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 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 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 * @param array &$js_default array which stores JavaScript code to be displayed
*/ */
private function _displayFieldInput(Form $form, $field, $system_path, $work_path, private function _displayFieldInput(Form $form, $field, $system_path, $work_path,
@@ -490,7 +485,6 @@ class FormDisplay
* @uses Form::getOptionType() * @uses Form::getOptionType()
* @uses Form::getOptionValueList() * @uses Form::getOptionValueList()
* @uses PMA_lang_name() * @uses PMA_lang_name()
* @uses PMA_read_userprefs_fieldnames()
* @param array|string $forms array of form names * @param array|string $forms array of form names
* @param bool $allow_partial_save allows for partial form saving on failed validation * @param bool $allow_partial_save allows for partial form saving on failed validation
* @return boolean true on success (no errors and all saved) * @return boolean true on success (no errors and all saved)
@@ -504,13 +498,8 @@ class FormDisplay
$values = array(); $values = array();
$to_save = array(); $to_save = array();
$is_setup_script = defined('PMA_SETUP') && PMA_SETUP; $is_setup_script = defined('PMA_SETUP') && PMA_SETUP;
if ($is_setup_script && $this->userprefs_keys === null) { if ($is_setup_script) {
$this->userprefs_keys = array_flip(PMA_read_userprefs_fieldnames()); $this->_loadUserprefsInfo();
// 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(); $this->errors = array();
@@ -664,7 +653,7 @@ class FormDisplay
if ($test == 'Import' || $test == 'Export') { if ($test == 'Import' || $test == 'Export') {
return ''; 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) public function getWikiLink($path)
{ {
$opt_name = self::_getOptName($path); $opt_name = $this->_getOptName($path);
if (substr($opt_name, 0, 7) == 'Servers') { if (substr($opt_name, 0, 7) == 'Servers') {
$opt_name = substr($opt_name, 8); $opt_name = substr($opt_name, 8);
if (strpos($opt_name, 'AllowDeny') === 0) { if (strpos($opt_name, 'AllowDeny') === 0) {
@@ -701,11 +690,28 @@ class FormDisplay
* @param string $path * @param string $path
* @return string * @return string
*/ */
private static function _getOptName($path) private function _getOptName($path)
{ {
return str_replace( return str_replace(
array('Servers/1/', 'disable/', '/'), array('Servers/1/', 'disable/', '/'),
array('Servers/', '', '_'), $path); 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);
}
}
} }
?> ?>

View File

@@ -104,7 +104,8 @@ function display_fieldset_top($title = '', $description = '', $errors = null, $a
* o errors - error array * o errors - error array
* o setvalue - (string) shows button allowing to set poredefined value * o setvalue - (string) shows button allowing to set poredefined value
* o show_restore_default - (boolean) whether show "restore default" button * 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 userprefs_comment - (string) field comment
* o values - key - value paris for <select> fields * o values - key - value paris for <select> fields
* o values_escaped - (boolean) tells whether values array is already escaped (defaults to false) * o values_escaped - (boolean) tells whether values array is already escaped (defaults to false)
@@ -136,21 +137,26 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
: $_SESSION['PMA_Theme']->img_path; : $_SESSION['PMA_Theme']->img_path;
} }
$has_errors = isset($opts['errors']) && !empty($opts['errors']); $has_errors = isset($opts['errors']) && !empty($opts['errors']);
$option_is_disabled = !$is_setup_script && isset($opts['userprefs_allow']) && !$opts['userprefs_allow'];
$name_id = 'name="' . htmlspecialchars($path) . '" id="' . htmlspecialchars($path) . '"';
$field_class = $type == 'checkbox' ? 'checkbox' : ''; $field_class = $type == 'checkbox' ? 'checkbox' : '';
if (!$value_is_default) { if (!$value_is_default) {
$field_class .= ($field_class == '' ? '' : ' ') . ($has_errors ? 'custom field-error' : 'custom'); $field_class .= ($field_class == '' ? '' : ' ') . ($has_errors ? 'custom field-error' : 'custom');
} }
$field_class = $field_class ? ' class="' . $field_class . '"' : ''; $field_class = $field_class ? ' class="' . $field_class . '"' : '';
$name_id = 'name="' . htmlspecialchars($path) . '" id="' . htmlspecialchars($path) . '"'; $tr_class = $_FormDisplayGroup ? 'group-field' : '';
$tr_class = $_FormDisplayGroup ? ' class="group-field"' : '';
if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') { if (isset($opts['setvalue']) && $opts['setvalue'] == ':group') {
unset($opts['setvalue']); unset($opts['setvalue']);
$tr_class = ' class="group-header-field"'; $tr_class = 'group-header-field';
if ($_FormDisplayGroup) { if ($_FormDisplayGroup) {
display_group_footer(); display_group_footer();
} }
$_FormDisplayGroup = true; $_FormDisplayGroup = true;
} }
if ($option_is_disabled) {
$tr_class .= ($tr_class ? ' ' : '') . 'disabled-field';
}
$tr_class = $tr_class ? ' class="' . $tr_class . '"' : '';
?> ?>
<tr<?php echo $tr_class ?>> <tr<?php echo $tr_class ?>>
<th> <th>
@@ -161,7 +167,7 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
<?php if (!empty($opts['wiki'])){ ?><a href="<?php echo $opts['wiki'] ?>" target="wiki"><img class="icon" src="<?php echo $img_path ?>b_info.png" width="11" height="11" alt="Wiki" title="Wiki" /></a><?php } ?> <?php if (!empty($opts['wiki'])){ ?><a href="<?php echo $opts['wiki'] ?>" target="wiki"><img class="icon" src="<?php echo $img_path ?>b_info.png" width="11" height="11" alt="Wiki" title="Wiki" /></a><?php } ?>
</span> </span>
<?php } ?> <?php } ?>
<?php if (!$is_setup_script && isset($opts['userprefs_allow']) && !$opts['userprefs_allow']) { ?> <?php if ($option_is_disabled) { ?>
<span class="disabled-notice" title="<?php echo __('This setting is disabled, it will not be applied to your configuration') ?>"><?php echo __('Disabled') ?></span> <span class="disabled-notice" title="<?php echo __('This setting is disabled, it will not be applied to your configuration') ?>"><?php echo __('Disabled') ?></span>
<?php } ?> <?php } ?>
<?php if (!empty($description)) { ?><small><?php echo $description ?></small><?php } ?> <?php if (!empty($description)) { ?><small><?php echo $description ?></small><?php } ?>
@@ -252,9 +258,14 @@ function display_input($path, $name, $description = '', $type, $value, $value_is
</td> </td>
<?php <?php
if ($is_setup_script && isset($opts['userprefs_allow'])) { if ($is_setup_script && isset($opts['userprefs_allow'])) {
$disabled = '';
if ($opts['userprefs_allow'] === 'disable') {
$opts['userprefs_allow'] = false;
$disabled = ' disabled="$disabled"';
}
?> ?>
<td class="userprefs-allow" title="<?php echo __('Allow users to customize this value') ?>"> <td class="userprefs-allow" title="<?php echo __('Allow users to customize this value') ?>">
<input type="checkbox" name="<?php echo $path ?>-userprefs-allow" <?php if ($opts['userprefs_allow']) echo 'checked="checked"' ?> /> <input type="checkbox"<?php echo $disabled ?> name="<?php echo $path ?>-userprefs-allow" <?php if ($opts['userprefs_allow']) echo 'checked="checked"' ?> />
</td> </td>
<?php <?php
} else if ($is_setup_script) { } else if ($is_setup_script) {

View File

@@ -39,6 +39,8 @@ $strConfigConfigurationFile = __('Configuration file');
$strConfigConfirm_desc = __('Whether a warning (&quot;Are your really sure...&quot;) should be displayed when you\'re about to lose data'); $strConfigConfirm_desc = __('Whether a warning (&quot;Are your really sure...&quot;) should be displayed when you\'re about to lose data');
$strConfigConfirm_name = __('Confirm DROP queries'); $strConfigConfirm_name = __('Confirm DROP queries');
$strConfigCtrlArrowsMoving_name = __('Field navigation using Ctrl+Arrows'); $strConfigCtrlArrowsMoving_name = __('Field navigation using Ctrl+Arrows');
$strConfigDBG_php_name = __('Debug PHP');
$strConfigDBG_sql_name = __('Debug SQL');
$strConfigDefaultDisplay_name = __('Default display direction'); $strConfigDefaultDisplay_name = __('Default display direction');
$strConfigDefaultPropDisplay_desc = __('[kbd]horizontal[/kbd], [kbd]vertical[/kbd] or a number that indicates maximum number for which vertical model is used'); $strConfigDefaultPropDisplay_desc = __('[kbd]horizontal[/kbd], [kbd]vertical[/kbd] or a number that indicates maximum number for which vertical model is used');
$strConfigDefaultPropDisplay_name = __('Display direction for altering/creating columns'); $strConfigDefaultPropDisplay_name = __('Display direction for altering/creating columns');
@@ -56,6 +58,8 @@ $strConfigDisplayServersList_desc = __('Show server listing as a list instead of
$strConfigDisplayServersList_name = __('Display servers as a list'); $strConfigDisplayServersList_name = __('Display servers as a list');
$strConfigEditInWindow_desc = __('Edit SQL queries in popup window'); $strConfigEditInWindow_desc = __('Edit SQL queries in popup window');
$strConfigEditInWindow_name = __('Edit in window'); $strConfigEditInWindow_name = __('Edit in window');
$strConfigError_Handler_display_name = __('Display errors');
$strConfigError_Handler_gather_name = __('Gather errors');
$strConfigErrorIconic_desc = __('Show icons for warning, error and information messages'); $strConfigErrorIconic_desc = __('Show icons for warning, error and information messages');
$strConfigErrorIconic_name = __('Iconic errors'); $strConfigErrorIconic_name = __('Iconic errors');
$strConfigExecTimeLimit_desc = __('Set the number of seconds a script is allowed to run ([kbd]0[/kbd] for no limit)'); $strConfigExecTimeLimit_desc = __('Set the number of seconds a script is allowed to run ([kbd]0[/kbd] for no limit)');
@@ -152,13 +156,15 @@ $strConfigForm_CodeGen = 'CodeGen';
$strConfigForm_CodeGen_desc = __('Customize default options'); $strConfigForm_CodeGen_desc = __('Customize default options');
$strConfigForm_Csv = __('CSV'); $strConfigForm_Csv = __('CSV');
$strConfigForm_Csv_desc = __('Customize default options'); $strConfigForm_Csv_desc = __('Customize default options');
$strConfigForm_Developer = __('Developer');
$strConfigForm_Developer_desc = __('Settings for phpMyAdmin developers');
$strConfigForm_Edit = __('Edit mode'); $strConfigForm_Edit = __('Edit mode');
$strConfigForm_Edit_desc = __('Customize edit mode'); $strConfigForm_Edit_desc = __('Customize edit mode');
$strConfigForm_Export = __('Export'); $strConfigForm_Export = __('Export');
$strConfigForm_Export_defaults = __('Export defaults'); $strConfigForm_Export_defaults = __('Export defaults');
$strConfigForm_Export_defaults_desc = __('Customize default export options'); $strConfigForm_Export_defaults_desc = __('Customize default export options');
$strConfigForm_Features = __('Features'); $strConfigForm_Features = __('Features');
$strConfigForm_General = __('General settings'); $strConfigForm_General = __('General');
$strConfigForm_General_desc = __('Set some commonly used options'); $strConfigForm_General_desc = __('Set some commonly used options');
$strConfigForm_Import = __('Import'); $strConfigForm_Import = __('Import');
$strConfigForm_Import_defaults = __('Import defaults'); $strConfigForm_Import_defaults = __('Import defaults');

View File

@@ -106,6 +106,11 @@ $forms['Features']['Warnings'] = array(
'PmaNoRelation_DisableWarning', 'PmaNoRelation_DisableWarning',
'SuhosinDisableWarning', 'SuhosinDisableWarning',
'McryptDisableWarning'); 'McryptDisableWarning');
$forms['Features']['Developer'] = array(
'Error_Handler/display',
'Error_Handler/gather',
'DBG/sql',
'DBG/php');
$forms['Features']['Other_core_settings'] = array( $forms['Features']['Other_core_settings'] = array(
'NaturalOrder', 'NaturalOrder',
'InitialSlidersState', 'InitialSlidersState',

View File

@@ -31,6 +31,20 @@ $forms['Features']['Text_fields'] = array(
'TextareaCols', 'TextareaCols',
'TextareaRows', 'TextareaRows',
'LongtextDoubleTextarea'); 'LongtextDoubleTextarea');
$forms['Features']['Page_titles'] = array(
'TitleDefault',
'TitleTable',
'TitleDatabase',
'TitleServer');
$forms['Features']['Warnings'] = array(
'PmaNoRelation_DisableWarning',
'SuhosinDisableWarning',
'McryptDisableWarning');
$forms['Features']['Developer'] = array(
'Error_Handler/display',
'Error_Handler/gather',
'DBG/sql',
'DBG/php');
$forms['Sql_queries']['Sql_queries'] = array( $forms['Sql_queries']['Sql_queries'] = array(
'ShowSQL', 'ShowSQL',
'Confirm', 'Confirm',
@@ -52,15 +66,6 @@ $forms['Sql_queries']['Sql_validator'] = array(
'SQLValidator/use', 'SQLValidator/use',
'SQLValidator/username', 'SQLValidator/username',
'SQLValidator/password'); 'SQLValidator/password');
$forms['Features']['Page_titles'] = array(
'TitleDefault',
'TitleTable',
'TitleDatabase',
'TitleServer');
$forms['Features']['Warnings'] = array(
'PmaNoRelation_DisableWarning',
'SuhosinDisableWarning',
'McryptDisableWarning');
$forms['Left_frame']['Left_frame'] = array( $forms['Left_frame']['Left_frame'] = array(
'LeftFrameLight', 'LeftFrameLight',
'LeftDisplayLogo', 'LeftDisplayLogo',

View File

@@ -30,7 +30,7 @@ echo PMA_generate_html_tab(array(
'link' => 'prefs_manage.php', 'link' => 'prefs_manage.php',
'text' => __('Manage your settings'))) . "\n"; 'text' => __('Manage your settings'))) . "\n";
echo '<li>&nbsp; &nbsp;</li>' . "\n"; echo '<li>&nbsp; &nbsp;</li>' . "\n";
$script_name = basename(basename($GLOBALS['PMA_PHP_SELF'])); $script_name = basename($GLOBALS['PMA_PHP_SELF']);
foreach (array_keys($forms) as $formset) { foreach (array_keys($forms) as $formset) {
$tab = array( $tab = array(
'link' => 'prefs_forms.php', 'link' => 'prefs_forms.php',

View File

@@ -26,6 +26,19 @@ require_once './libraries/user_preferences.inc.php';
$form_display = new FormDisplay(); $form_display = new FormDisplay();
foreach ($forms[$form_param] as $form_name => $form) { 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); $form_display->registerForm($form_name, $form);
} }

View File

@@ -183,6 +183,9 @@ $(function() {
return; return;
} }
var el = $(this).find('input'); var el = $(this).find('input');
if (el.attr('disabled')) {
return;
}
el.attr('checked', !el.attr('checked')); el.attr('checked', !el.attr('checked'));
}); });
}); });

View File

@@ -1445,6 +1445,13 @@ fieldset .group-field th {
padding-left: 1.5em; 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 { .config-form .lastrow {
border-top: 1px #000 solid; border-top: 1px #000 solid;
} }

View File

@@ -1377,6 +1377,13 @@ fieldset .group-field th {
padding-left: 1.5em; 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 { .config-form .lastrow {
border-top: 1px #000 solid; border-top: 1px #000 solid;
} }