diff --git a/libraries/config.values.php b/libraries/config.values.php index 4d645cb64..188335477 100644 --- a/libraries/config.values.php +++ b/libraries/config.values.php @@ -82,4 +82,33 @@ $cfg_db['Export']['format'] = array('codegen', 'csv', 'excel', 'htmlexcel', $cfg_db['Export']['compression'] = array('none', 'zip', 'gzip', 'bzip2'); $cfg_db['Export']['charset'] = array_merge(array(''), $GLOBALS['cfg']['AvailableCharsets']); +/** + * Default values overrides + * Use only full paths + */ +$cfg_db['_overrides'] = array(); +$cfg_db['_overrides']['Servers/1/extension'] = extension_loaded('mysqli') + ? 'mysqli' : 'mysql'; + +/** + * Validator assignments (functions from setup/validate.lib.php and 'validators' + * object in setup/scripts.js) + * Use only full paths and form ids + */ +$cfg_db['_validators'] = array( + 'Server' => 'validate_server', + 'Server_pmadb' => 'validate_pmadb', + 'Servers/1/port' => 'validate_port_number', + 'Servers/1/hide_db' => 'validate_regex', + 'TrustedProxies' => 'validate_trusted_proxies', + 'LoginCookieValidity' => 'validate_positive_number', + 'LoginCookieStore' => 'validate_non_negative_number', + 'QueryHistoryMax' => 'validate_positive_number', + 'LeftFrameTableLevel' => 'validate_positive_number', + 'MaxRows' => 'validate_positive_number', + 'CharTextareaCols' => 'validate_positive_number', + 'CharTextareaRows' => 'validate_positive_number', + 'InsertRows' => 'validate_positive_number', + 'ForeignKeyMaxLimit' => 'validate_positive_number', + 'Import/skip_queries' => 'validate_non_negative_number'); ?> \ No newline at end of file diff --git a/setup/lib/ConfigFile.class.php b/libraries/config/ConfigFile.class.php similarity index 94% rename from setup/lib/ConfigFile.class.php rename to libraries/config/ConfigFile.class.php index 9ba3ef524..bcb1e8ac2 100644 --- a/setup/lib/ConfigFile.class.php +++ b/libraries/config/ConfigFile.class.php @@ -3,14 +3,13 @@ * Config file management and generation * * @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0 - * @version $Id$ - * @package phpMyAdmin-setup + * @package phpMyAdmin */ /** * Config file management and generation class * - * @package phpMyAdmin-setup + * @package phpMyAdmin */ class ConfigFile { @@ -49,8 +48,7 @@ class ConfigFile // load additionsl config information $cfg_db = &$this->cfgDb; - $persist_keys = array(); - require './setup/lib/config_info.inc.php'; + require './libraries/config.values.php'; // apply default values overrides if (count($cfg_db['_overrides'])) { @@ -58,9 +56,6 @@ class ConfigFile PMA_array_write($path, $cfg, $value); } } - - // checking key presence is much faster than searching so move values to keys - $this->persistKeys = array_flip($persist_keys); } /** @@ -76,6 +71,18 @@ class ConfigFile return self::$_instance; } + /** + * Sets names of config options which will be placed in config file even if they are set + * to their default values (use only full paths) + * + * @param array $keys + */ + public function setPersistKeys($keys) + { + // checking key presence is much faster than searching so move values to keys + $this->persistKeys = array_flip($keys); + } + /** * Sets config value * @@ -112,7 +119,7 @@ class ConfigFile /** * Returns default config value or $default it it's not set ie. it doesn't - * exist in config.default.php ($cfg) and config_info.inc.php + * exist in config.default.php ($cfg) and config.values.php * ($_cfg_db['_overrides']) * * @param string $canonical_path @@ -312,7 +319,7 @@ class ConfigFile unset($persistKeys[$k]); } } - // keep 1d array keys which are present in $persist_keys (config_info.inc.php) + // keep 1d array keys which are present in $persist_keys (config.values.php) foreach (array_keys($persistKeys) as $k) { if (strpos($k, '/') === false) { $k = preg_replace('/[^A-Za-z0-9_]/', '_', $k); @@ -324,4 +331,4 @@ class ConfigFile return $ret; } } -?> +?> \ No newline at end of file diff --git a/libraries/config/Form.class.php b/libraries/config/Form.class.php index f543e1fa6..13ceee8b7 100644 --- a/libraries/config/Form.class.php +++ b/libraries/config/Form.class.php @@ -44,22 +44,17 @@ class Form */ private $fieldsTypes; - /** - * Cached forms - * @var array - */ - private static $_forms; - /** * Constructor, reads default config values * * @param string $form_name + * @param array $form * @param int $index arbitrary index, stored in Form::$index */ - public function __construct($form_name, $index = null) + public function __construct($form_name, array $form, $index = null) { $this->index = $index; - $this->loadForm($form_name); + $this->loadForm($form_name, $form); } /** @@ -120,21 +115,14 @@ class Form /** * Reads form paths to {@link $fields} + * + * @param array $form */ - protected function readFormPaths() + protected function readFormPaths($form) { - if (is_null(self::$_forms)) { - $forms =& self::$_forms; - require './setup/lib/forms.inc.php'; - } - - if (!isset(self::$_forms[$this->name])) { - return; - } - // flatten form fields' paths and save them to $fields $this->fields = array(); - array_walk(self::$_forms[$this->name], array($this, '_readFormPathsCallback'), ''); + array_walk($form, array($this, '_readFormPathsCallback'), ''); // $this->fields is an array of the form: [0..n] => 'field path' // change numeric indexes to contain field names (last part of the path) @@ -170,12 +158,13 @@ class Form * config file * * @param string $form_name + * @param array $form */ - public function loadForm($form_name) + public function loadForm($form_name, $form) { $this->name = $form_name; - $this->readFormPaths(); + $this->readFormPaths($form); $this->readTypes(); } } -?> +?> \ No newline at end of file diff --git a/setup/lib/FormDisplay.class.php b/libraries/config/FormDisplay.class.php similarity index 98% rename from setup/lib/FormDisplay.class.php rename to libraries/config/FormDisplay.class.php index 7b6bfebb4..62d21a1fd 100644 --- a/setup/lib/FormDisplay.class.php +++ b/libraries/config/FormDisplay.class.php @@ -71,11 +71,12 @@ class FormDisplay * Registers form in form manager * * @param string $form_name + * @param array $form * @param int $server_id 0 if new server, validation; >= 1 if editing a server */ - public function registerForm($form_name, $server_id = null) + public function registerForm($form_name, array $form, $server_id = null) { - $this->forms[$form_name] = new Form($form_name, $server_id); + $this->forms[$form_name] = new Form($form_name, $form, $server_id); $this->is_valdiated = false; foreach ($this->forms[$form_name]->fields as $path) { $work_path = $server_id === null @@ -162,7 +163,7 @@ class FormDisplay $js = array(); $js_default = array(); $tabbed_form = $tabbed_form && (count($this->forms) > 1); - $validators = ConfigFile::getInstance()->getDbEntry('_validators'); + $validators = ConfigFile::getInstance()->getDbEntry('_validators', array()); display_form_top(); diff --git a/setup/config.php b/setup/config.php index 0aec5cc24..8b514d27c 100644 --- a/setup/config.php +++ b/setup/config.php @@ -12,10 +12,12 @@ */ require './lib/common.inc.php'; require_once './libraries/config/Form.class.php'; -require_once './setup/lib/FormDisplay.class.php'; +require_once './libraries/config/FormDisplay.class.php'; + +require './setup/lib/forms.inc.php'; $form_display = new FormDisplay(); -$form_display->registerForm('_config.php'); +$form_display->registerForm('_config.php', $forms['_config.php']); $form_display->save('_config.php'); $config_file_path = ConfigFile::getInstance()->getFilePath(); diff --git a/setup/frames/config.inc.php b/setup/frames/config.inc.php index 4e925d912..5bb5785da 100644 --- a/setup/frames/config.inc.php +++ b/setup/frames/config.inc.php @@ -14,7 +14,7 @@ if (!defined('PHPMYADMIN')) { /** * Core libraries. */ -require_once './setup/lib/FormDisplay.class.php'; +require_once './libraries/config/FormDisplay.class.php'; require_once './setup/lib/index.lib.php'; $config_readable = false; diff --git a/setup/frames/form.inc.php b/setup/frames/form.inc.php index 03e3970d9..cc36aa6b7 100644 --- a/setup/frames/form.inc.php +++ b/setup/frames/form.inc.php @@ -15,9 +15,11 @@ if (!defined('PHPMYADMIN')) { * Core libraries. */ require_once './libraries/config/Form.class.php'; -require_once './setup/lib/FormDisplay.class.php'; +require_once './libraries/config/FormDisplay.class.php'; require_once './setup/lib/form_processing.lib.php'; +require './setup/lib/forms.inc.php'; + $formsets = array( 'features' => array( 'forms' => array('Import_export', 'Security', 'Sql_queries', 'Other_core_settings')), @@ -43,7 +45,7 @@ if (isset($GLOBALS['strSetupFormset_' . $formset_id])) { } $form_display = new FormDisplay(); foreach ($formset['forms'] as $form_name) { - $form_display->registerForm($form_name); + $form_display->registerForm($form_name, $forms[$form_name]); } process_formset($form_display); ?> diff --git a/setup/frames/index.inc.php b/setup/frames/index.inc.php index 43b657466..0bab3d632 100644 --- a/setup/frames/index.inc.php +++ b/setup/frames/index.inc.php @@ -15,7 +15,7 @@ if (!defined('PHPMYADMIN')) { * Core libraries. */ require_once './libraries/display_select_lang.lib.php'; -require_once './setup/lib/FormDisplay.class.php'; +require_once './libraries/config/FormDisplay.class.php'; require_once './setup/lib/index.lib.php'; // prepare unfiltered language list diff --git a/setup/frames/servers.inc.php b/setup/frames/servers.inc.php index b5fa11b36..12d0a4656 100644 --- a/setup/frames/servers.inc.php +++ b/setup/frames/servers.inc.php @@ -15,9 +15,11 @@ if (!defined('PHPMYADMIN')) { * Core libraries. */ require_once './libraries/config/Form.class.php'; -require_once './setup/lib/FormDisplay.class.php'; +require_once './libraries/config/FormDisplay.class.php'; require_once './setup/lib/form_processing.lib.php'; +require './setup/lib/forms.inc.php'; + $mode = filter_input(INPUT_GET, 'mode'); $id = filter_input(INPUT_GET, 'id', FILTER_VALIDATE_INT); @@ -41,10 +43,10 @@ if (isset($page_title)) { echo '