Setup script refactoring: moved ConfigFile, Form, FormDisplay
Config db overrides and validation info stored in config.values.php
This commit is contained in:
@@ -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');
|
||||
?>
|
@@ -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);
|
@@ -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,11 +158,12 @@ 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();
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
?>
|
||||
|
@@ -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
|
||||
|
@@ -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 '<h2>' . $page_title . '</h2>';
|
||||
}
|
||||
$form_display = new FormDisplay();
|
||||
$form_display->registerForm('Server', $id);
|
||||
$form_display->registerForm('Server_login_options', $id);
|
||||
$form_display->registerForm('Server_config', $id);
|
||||
$form_display->registerForm('Server_pmadb', $id);
|
||||
$form_display->registerForm('Server_tracking', $id);
|
||||
$form_display->registerForm('Server', $forms['Server'], $id);
|
||||
$form_display->registerForm('Server_login_options', $forms['Server_login_options'], $id);
|
||||
$form_display->registerForm('Server_config', $forms['Server_config'], $id);
|
||||
$form_display->registerForm('Server_pmadb', $forms['Server_pmadb'], $id);
|
||||
$form_display->registerForm('Server_tracking', $forms['Server_tracking'], $id);
|
||||
process_formset($form_display);
|
||||
?>
|
||||
|
@@ -21,8 +21,8 @@ if (!file_exists('./libraries/common.inc.php')) {
|
||||
require_once './libraries/common.inc.php';
|
||||
require_once './libraries/config/config_functions.lib.php';
|
||||
require_once './libraries/config/messages.inc.php';
|
||||
require_once './libraries/config/ConfigFile.class.php';
|
||||
require_once './libraries/url_generating.lib.php';
|
||||
require_once './setup/lib/ConfigFile.class.php';
|
||||
|
||||
// use default error handler
|
||||
restore_error_handler();
|
||||
@@ -33,6 +33,20 @@ $GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
|
||||
if (!isset($_SESSION['ConfigFile'])) {
|
||||
$_SESSION['ConfigFile'] = array();
|
||||
}
|
||||
ConfigFile::getInstance()->setPersistKeys(array(
|
||||
'DefaultLang',
|
||||
'ServerDefault',
|
||||
'UploadDir',
|
||||
'SaveDir',
|
||||
'Servers/1/verbose',
|
||||
'Servers/1/host',
|
||||
'Servers/1/port',
|
||||
'Servers/1/socket',
|
||||
'Servers/1/extension',
|
||||
'Servers/1/connect_type',
|
||||
'Servers/1/auth_type',
|
||||
'Servers/1/user',
|
||||
'Servers/1/password'));
|
||||
|
||||
// allows for redirection even after sending some data
|
||||
ob_start();
|
||||
|
@@ -1,71 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* Description of options with non-standard values, list of persistent options
|
||||
* and validator assignments.
|
||||
*
|
||||
* By default data types are taken from config.default.php, here we define
|
||||
* only allowed values for select fields and type overrides.
|
||||
*
|
||||
* @package phpMyAdmin-setup
|
||||
* @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
if (!defined('PHPMYADMIN')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load config value database ($cfg_db)
|
||||
*/
|
||||
require './libraries/config.values.php';
|
||||
|
||||
/**
|
||||
* Config options which will be placed in config file even if they are set
|
||||
* to their default values (use only full paths)
|
||||
*/
|
||||
$persist_keys = array(
|
||||
'DefaultLang',
|
||||
'ServerDefault',
|
||||
'UploadDir',
|
||||
'SaveDir',
|
||||
'Servers/1/verbose',
|
||||
'Servers/1/host',
|
||||
'Servers/1/port',
|
||||
'Servers/1/socket',
|
||||
'Servers/1/extension',
|
||||
'Servers/1/connect_type',
|
||||
'Servers/1/auth_type',
|
||||
'Servers/1/user',
|
||||
'Servers/1/password');
|
||||
|
||||
/**
|
||||
* 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 validate.lib.php and 'validators'
|
||||
* object in 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');
|
||||
?>
|
@@ -9,7 +9,7 @@
|
||||
* assigned to a form element (formset name or field path). Even if there are
|
||||
* no errors, key must be set with an empty value.
|
||||
*
|
||||
* Valdiation functions are assigned in $cfg_db['_validators'] (config_info.inc.php).
|
||||
* Valdiation functions are assigned in $cfg_db['_validators'] (config.values.php).
|
||||
*
|
||||
* @package phpMyAdmin-setup
|
||||
* @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0
|
||||
@@ -193,7 +193,7 @@ function validate_server($path, $values)
|
||||
*/
|
||||
function validate_pmadb($path, $values)
|
||||
{
|
||||
$tables = array('Servers/1/bookmarktable', 'Servers/1/relation', 'Servers/1/table_info', 'Servers/1/table_coords', 'Servers/1/pdf_pages', 'Servers/1/column_info', 'Servers/1/history', 'Servers/1/designer_coords');
|
||||
//$tables = array('Servers/1/bookmarktable', 'Servers/1/relation', 'Servers/1/table_info', 'Servers/1/table_coords', 'Servers/1/pdf_pages', 'Servers/1/column_info', 'Servers/1/history', 'Servers/1/designer_coords');
|
||||
$result = array('Server_pmadb' => '', 'Servers/1/controluser' => '', 'Servers/1/controlpass' => '');
|
||||
$error = false;
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
require_once './libraries/common.inc.php';
|
||||
require_once './libraries/user_preferences.lib.php';
|
||||
require_once './libraries/config/messages.inc.php';
|
||||
require_once './libraries/config/FormDisplay.class.php';
|
||||
|
||||
$GLOBALS['js_include'][] = 'js/settings_forms.js';
|
||||
|
||||
@@ -26,17 +27,25 @@ if (! empty($message)) {
|
||||
$common_url_query = PMA_generate_common_url('', '');
|
||||
|
||||
$tabs = array();
|
||||
$active_formset = filter_input(INPUT_GET, 'form');
|
||||
if (!isset($forms[$active_formset])) {
|
||||
$active_formset = array_shift(array_keys($forms));
|
||||
}
|
||||
foreach (array_keys($forms) as $form) {
|
||||
$tabs[] = array(
|
||||
'link' => 'user_preferences.php',
|
||||
'text' => PMA_ifSetOr($GLOBALS['strSetupForm_' . $form], $form), // TODO: remove ifSetOr
|
||||
'active' => $form == PMA_ifSetOr($_GET['form'], ''),
|
||||
'active' => $form == $active_formset,
|
||||
'url_params' => array('form' => $form)
|
||||
);
|
||||
}
|
||||
|
||||
echo PMA_generate_html_tabs($tabs, array());
|
||||
|
||||
$form_display = new FormDisplay();
|
||||
foreach ($forms[$active_formset] as $form_name => $form) {
|
||||
$form_display->registerForm($form_name, $form);
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the footer
|
||||
|
Reference in New Issue
Block a user