From 6b2f774ba83a856eb39040059a1d2ed78645aa4b Mon Sep 17 00:00:00 2001 From: Crack Date: Sat, 5 Jun 2010 15:42:55 +0200 Subject: [PATCH] Add category tabs to preferences page Setup script refactoring --- .gitignore | 1 + .gsoc/options.txt | 12 +- libraries/common.lib.php | 4 +- libraries/config.values.php | 85 ++++++++ .../lib => libraries/config}/Form.class.php | 3 +- .../lib => libraries/config}/messages.inc.php | 0 libraries/user_preferences.lib.php | 105 ++++++++++ setup/config.php | 2 +- setup/frames/form.inc.php | 2 +- setup/frames/servers.inc.php | 2 +- setup/lib/ConfigFile.class.php | 23 +- setup/lib/common.inc.php | 196 +----------------- setup/lib/config_info.inc.php | 82 +------- user_preferences.php | 45 ++++ 14 files changed, 266 insertions(+), 296 deletions(-) create mode 100644 libraries/config.values.php rename {setup/lib => libraries/config}/Form.class.php (98%) rename {setup/lib => libraries/config}/messages.inc.php (100%) create mode 100644 libraries/user_preferences.lib.php create mode 100644 user_preferences.php diff --git a/.gitignore b/.gitignore index 3e12f7d6f..a773f8e3e 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ phpmyadmin.wpj .settings .buildpath .cache +.idea *.sw[op] # Locales locale diff --git a/.gsoc/options.txt b/.gsoc/options.txt index 60701209e..e4bb56b94 100644 --- a/.gsoc/options.txt +++ b/.gsoc/options.txt @@ -3,10 +3,10 @@ General DefaultLang (just persist main page settings?) DefaultConnectionCollation (just persist main page settings?) ThemeDefault (if ThemeManager == true) - NaturalOrder - InitialSlidersState - ErrorIconic - ReplaceHelpImg + NaturalOrder [s-] + InitialSlidersState [s-] + ErrorIconic [s-] + ReplaceHelpImg [s-] Text fields CharEditing [s] CharTextareaCols [s] @@ -14,7 +14,6 @@ Text fields TextareaCols [s-] TextareaRows [s-] LongtextDoubleTextarea [s-] - SQL Queries ShowSQL [s] Confirm [s] @@ -90,14 +89,13 @@ In edit mode... ForeignKeyMaxLimit [s] CtrlArrowsMoving [s] DefaultPropDisplay [s-] - - Tabs display settings LightTabs [s] PropertiesIconic [s] DefaultTabServer [s] DefaultTabDatabase [s] DefaultTabTable [s] + SQL Query Box Edit [s] Explain [s] diff --git a/libraries/common.lib.php b/libraries/common.lib.php index ec2f8eb67..8a7e9e541 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -1637,7 +1637,7 @@ function PMA_generate_html_tab($tab, $url_params = array()) $defaults = array( 'text' => '', 'class' => '', - 'active' => false, + 'active' => null, 'link' => '', 'sep' => '?', 'attr' => '', @@ -1656,7 +1656,7 @@ function PMA_generate_html_tab($tab, $url_params = array()) } elseif (! empty($tab['active']) || PMA_isValid($GLOBALS['active_page'], 'identical', $tab['link'])) { $tab['class'] = 'active'; - } elseif (empty($GLOBALS['active_page']) + } elseif (is_null($tab['active']) && empty($GLOBALS['active_page']) && basename($GLOBALS['PMA_PHP_SELF']) == $tab['link'] && empty($tab['warning'])) { $tab['class'] = 'active'; diff --git a/libraries/config.values.php b/libraries/config.values.php new file mode 100644 index 000000000..4d645cb64 --- /dev/null +++ b/libraries/config.values.php @@ -0,0 +1,85 @@ + array( + 'port' => 'integer', + 'connect_type' => array('tcp', 'socket'), + 'extension' => array('mysql', 'mysqli'), + 'auth_type' => array('config', 'http', 'signon', 'cookie'), + 'AllowDeny' => array( + 'order' => array('', 'deny,allow', 'allow,deny', 'explicit')), + 'only_db' => 'array')); +$cfg_db['RecodingEngine'] = array('auto', 'iconv', 'recode'); +$cfg_db['DefaultCharset'] = $GLOBALS['cfg']['AvailableCharsets']; +$cfg_db['OBGzip'] = array('auto', true, false); +$cfg_db['ShowTooltipAliasTB'] = array('nested', true, false); +$cfg_db['DisplayDatabasesList'] = array('auto', true, false); +$cfg_db['LeftLogoLinkWindow'] = array('main', 'new'); +$cfg_db['LeftDefaultTabTable'] = array( + 'tbl_structure.php', // fields list + 'tbl_sql.php', // SQL form + 'tbl_select.php', // search page + 'tbl_change.php', // insert row page + 'sql.php'); // browse page +$cfg_db['NavigationBarIconic'] = array(true, false, 'both'); +$cfg_db['Order'] = array('ASC', 'DESC', 'SMART'); +$cfg_db['ProtectBinary'] = array(false, 'blob', 'all'); +$cfg_db['CharEditing'] = array('input', 'textarea'); +$cfg_db['PropertiesIconic'] = array(true, false, 'both'); +$cfg_db['DefaultTabServer'] = array( + 'main.php', // the welcome page (recommended for multiuser setups) + 'server_databases.php', // list of databases + 'server_status.php', // runtime information + 'server_variables.php', // MySQL server variables + 'server_privileges.php', // user management + 'server_processlist.php'); // process list +$cfg_db['DefaultTabDatabase'] = array( + 'db_structure.php', // tables list + 'db_sql.php', // SQL form + 'db_search.php', // search query + 'db_operations.php'); // operations on database +$cfg_db['DefaultTabTable'] = array( + 'tbl_structure.php', // fields list + 'tbl_sql.php', // SQL form + 'tbl_select.php', // search page + 'tbl_change.php', // insert row page + 'sql.php'); // browse page +$cfg_db['QueryWindowDefTab'] = array( + 'sql', // SQL + 'files', // Import files + 'history', // SQL history + 'full'); // All (SQL and SQL history) +$cfg_db['Import']['format'] = array( + 'csv', // CSV + 'docsql', // DocSQL + 'ldi', // CSV using LOAD DATA + 'sql'); // SQL +$cfg_db['Import']['sql_compatibility'] = array( + 'NONE', 'ANSI', 'DB2', 'MAXDB', 'MYSQL323', 'MYSQL40', 'MSSQL', 'ORACLE', + // removed; in MySQL 5.0.33, this produces exports that + // can't be read by POSTGRESQL (see our bug #1596328) + //'POSTGRESQL', + 'TRADITIONAL'); +$cfg_db['Import']['ldi_local_option'] = array('auto', true, false); +$cfg_db['Export']['format'] = array('codegen', 'csv', 'excel', 'htmlexcel', + 'htmlword', 'latex', 'ods', 'odt', 'pdf', 'sql', 'texytext', 'xls', 'xml', + 'yaml'); +$cfg_db['Export']['compression'] = array('none', 'zip', 'gzip', 'bzip2'); +$cfg_db['Export']['charset'] = array_merge(array(''), $GLOBALS['cfg']['AvailableCharsets']); + +?> \ No newline at end of file diff --git a/setup/lib/Form.class.php b/libraries/config/Form.class.php similarity index 98% rename from setup/lib/Form.class.php rename to libraries/config/Form.class.php index 1e1fad4a4..f543e1fa6 100644 --- a/setup/lib/Form.class.php +++ b/libraries/config/Form.class.php @@ -2,9 +2,8 @@ /** * Form handling code. * - * @package phpMyAdmin-setup + * @package phpMyAdmin * @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0 - * @version $Id$ */ /** diff --git a/setup/lib/messages.inc.php b/libraries/config/messages.inc.php similarity index 100% rename from setup/lib/messages.inc.php rename to libraries/config/messages.inc.php diff --git a/libraries/user_preferences.lib.php b/libraries/user_preferences.lib.php new file mode 100644 index 000000000..c53c3dd75 --- /dev/null +++ b/libraries/user_preferences.lib.php @@ -0,0 +1,105 @@ + \ No newline at end of file diff --git a/setup/config.php b/setup/config.php index e2bd13214..0aec5cc24 100644 --- a/setup/config.php +++ b/setup/config.php @@ -11,7 +11,7 @@ * Core libraries. */ require './lib/common.inc.php'; -require_once './setup/lib/Form.class.php'; +require_once './libraries/config/Form.class.php'; require_once './setup/lib/FormDisplay.class.php'; $form_display = new FormDisplay(); diff --git a/setup/frames/form.inc.php b/setup/frames/form.inc.php index 019b110be..03e3970d9 100644 --- a/setup/frames/form.inc.php +++ b/setup/frames/form.inc.php @@ -14,7 +14,7 @@ if (!defined('PHPMYADMIN')) { /** * Core libraries. */ -require_once './setup/lib/Form.class.php'; +require_once './libraries/config/Form.class.php'; require_once './setup/lib/FormDisplay.class.php'; require_once './setup/lib/form_processing.lib.php'; diff --git a/setup/frames/servers.inc.php b/setup/frames/servers.inc.php index 17ff2f9e4..b5fa11b36 100644 --- a/setup/frames/servers.inc.php +++ b/setup/frames/servers.inc.php @@ -14,7 +14,7 @@ if (!defined('PHPMYADMIN')) { /** * Core libraries. */ -require_once './setup/lib/Form.class.php'; +require_once './libraries/config/Form.class.php'; require_once './setup/lib/FormDisplay.class.php'; require_once './setup/lib/form_processing.lib.php'; diff --git a/setup/lib/ConfigFile.class.php b/setup/lib/ConfigFile.class.php index e7e7b288f..9ba3ef524 100644 --- a/setup/lib/ConfigFile.class.php +++ b/setup/lib/ConfigFile.class.php @@ -55,7 +55,7 @@ class ConfigFile // apply default values overrides if (count($cfg_db['_overrides'])) { foreach ($cfg_db['_overrides'] as $path => $value) { - array_write($path, $cfg, $value); + PMA_array_write($path, $cfg, $value); } } @@ -92,9 +92,9 @@ class ConfigFile $default_value = $this->getDefault($canonical_path); if (!isset($this->persistKeys[$canonical_path]) && (($value == $default_value) || (empty($value) && empty($default_value)))) { - array_remove($path, $_SESSION['ConfigFile']); + PMA_array_remove($path, $_SESSION['ConfigFile']); } else { - array_write($path, $_SESSION['ConfigFile'], $value); + PMA_array_write($path, $_SESSION['ConfigFile'], $value); } } @@ -107,7 +107,7 @@ class ConfigFile */ public function get($path, $default = null) { - return array_read($path, $_SESSION['ConfigFile'], $default); + return PMA_array_read($path, $_SESSION['ConfigFile'], $default); } /** @@ -121,7 +121,7 @@ class ConfigFile */ public function getDefault($canonical_path, $default = null) { - return array_read($canonical_path, $this->cfg, $default); + return PMA_array_read($canonical_path, $this->cfg, $default); } /** @@ -134,7 +134,7 @@ class ConfigFile */ public function getValue($path, $default = null) { - $v = array_read($path, $_SESSION['ConfigFile'], null); + $v = PMA_array_read($path, $_SESSION['ConfigFile'], null); if ($v !== null) { return $v; } @@ -161,7 +161,7 @@ class ConfigFile */ public function getDbEntry($path, $default = null) { - return array_read($path, $this->cfgDb, $default); + return PMA_array_read($path, $this->cfgDb, $default); } /** @@ -252,13 +252,18 @@ class ConfigFile } /** - * Returns config file path + * Returns config file path, relative to phpMyAdmin's root path * * @return unknown */ public function getFilePath() { - return $this->getDbEntry('_config_file_path'); + // Load paths + if (!defined('SETUP_CONFIG_FILE')) { + require_once './libraries/vendor_config.php'; + } + + return SETUP_CONFIG_FILE; } /** diff --git a/setup/lib/common.inc.php b/setup/lib/common.inc.php index 2d1f1f691..4e15aac96 100644 --- a/setup/lib/common.inc.php +++ b/setup/lib/common.inc.php @@ -4,7 +4,6 @@ * * @package phpMyAdmin-setup * @license http://www.gnu.org/licenses/gpl.html GNU GPL 2.0 - * @version $Id$ */ /** @@ -20,8 +19,9 @@ 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/url_generating.lib.php'; -require_once './setup/lib/messages.inc.php'; require_once './setup/lib/ConfigFile.class.php'; // use default error handler @@ -37,194 +37,4 @@ if (!isset($_SESSION['ConfigFile'])) { // allows for redirection even after sending some data ob_start(); -/** - * Returns value of an element in $array given by $path. - * $path is a string describing position of an element in an associative array, - * eg. Servers/1/host refers to $array[Servers][1][host] - * - * @param string $path - * @param array $array - * @param mixed $default - * @return mixed array element or $default - */ -function array_read($path, $array, $default = null) -{ - $keys = explode('/', $path); - $value =& $array; - foreach ($keys as $key) { - if (!isset($value[$key])) { - return $default; - } - $value =& $value[$key]; - } - return $value; -} - -/** - * Stores value in an array - * - * @param string $path - * @param array &$array - * @param mixed $value - */ -function array_write($path, &$array, $value) -{ - $keys = explode('/', $path); - $last_key = array_pop($keys); - $a =& $array; - foreach ($keys as $key) { - if (!isset($a[$key])) { - $a[$key] = array(); - } - $a =& $a[$key]; - } - $a[$last_key] = $value; -} - -/** - * Removes value from an array - * - * @param string $path - * @param array &$array - * @param mixed $value - */ -function array_remove($path, &$array) -{ - $keys = explode('/', $path); - $keys_last = array_pop($keys); - $path = array(); - $depth = 0; - - $path[0] =& $array; - $found = true; - // go as deep as required or possible - foreach ($keys as $key) { - if (!isset($path[$depth][$key])) { - $found = false; - break; - } - $depth++; - $path[$depth] =& $path[$depth-1][$key]; - } - // if element found, remove it - if ($found) { - unset($path[$depth][$keys_last]); - $depth--; - } - - // remove empty nested arrays - for (; $depth >= 0; $depth--) { - if (!isset($path[$depth+1]) || count($path[$depth+1]) == 0) { - unset($path[$depth][$keys[$depth]]); - } else { - break; - } - } -} - -/** - * Returns sanitized language string, taking into account our special codes - * for formatting. Takes variable number of arguments. - * Based on PMA_sanitize from sanitize.lib.php. - * - * @param string $lang_key key in $GLOBALS WITHOUT 'strSetup' prefix - * @param mixed $args arguments for sprintf - * @return string - */ -function PMA_lang($lang_key) -{ - static $search, $replace; - - // some quick cache'ing - if ($search === null) { - $replace_pairs = array( - '<' => '<', - '>' => '>', - '[em]' => '', - '[/em]' => '', - '[strong]' => '', - '[/strong]' => '', - '[code]' => '', - '[/code]' => '', - '[kbd]' => '', - '[/kbd]' => '', - '[br]' => '
', - '[sup]' => '', - '[/sup]' => ''); - $search = array_keys($replace_pairs); - $replace = array_values($replace_pairs); - } - if (!isset($GLOBALS["strSetup$lang_key"])) { - return $lang_key; - } - $message = str_replace($search, $replace, $GLOBALS["strSetup$lang_key"]); - // replace [a@"$1"]$2[/a] with $2 - $message = preg_replace('#\[a@("?)([^\]]+)\1\]([^\[]+)\[/a\]#e', - "PMA_lang_link_replace('$2', '$3')", $message); - - if (func_num_args() == 1) { - return $message; - } else { - $args = func_get_args(); - array_shift($args); - return vsprintf($message, $args); - } -} - -/** - * Returns translated field name - * - * @param string $canonical_path - * @return string - */ -function PMA_lang_name($canonical_path) -{ - $lang_key = str_replace( - array('Servers/1/', '/'), - array('Servers/', '_'), - $canonical_path) . '_name'; - return isset($GLOBALS["strSetup$lang_key"]) - ? $GLOBALS["strSetup$lang_key"] - : $lang_key; -} - -/** - * Returns translated field description - * - * @param string $canonical_path - * @return string - */ -function PMA_lang_desc($canonical_path) -{ - $lang_key = str_replace( - array('Servers/1/', '/'), - array('Servers/', '_'), - $canonical_path) . '_desc'; - return isset($GLOBALS["strSetup$lang_key"]) - ? PMA_lang($lang_key) - : ''; -} - -/** - * Wraps link in <a> tags and replaces argument separator in internal links - * to the one returned by PMA_get_arg_separator() - * - * @param string $link - * @param string $text - * @return string - */ -function PMA_lang_link_replace($link, $text) -{ - static $separator; - - if (!isset($separator)) { - $separator = PMA_get_arg_separator('html'); - } - - if (!preg_match('#^http://#', $link)) { - $link = str_replace('&', $separator, $link); - } - - return '' . $text . ''; -} -?> +?> \ No newline at end of file diff --git a/setup/lib/config_info.inc.php b/setup/lib/config_info.inc.php index 71a6bc503..3b9f25e7b 100644 --- a/setup/lib/config_info.inc.php +++ b/setup/lib/config_info.inc.php @@ -16,87 +16,9 @@ if (!defined('PHPMYADMIN')) { } /** - * Load paths. + * Load config value database ($cfg_db) */ -require_once('./libraries/vendor_config.php'); - -$cfg_db = array(); - -// path to config file, relative to phpMyAdmin's root path -$cfg_db['_config_file_path'] = SETUP_CONFIG_FILE; - -/** - * Value meaning: - * o array - select field, array contains allowed values - * o string - type override - * - * Use normal array, paths won't be expanded - */ -$cfg_db['Servers'] = array(1 => array( - 'port' => 'integer', - 'connect_type' => array('tcp', 'socket'), - 'extension' => array('mysql', 'mysqli'), - 'auth_type' => array('config', 'http', 'signon', 'cookie'), - 'AllowDeny' => array( - 'order' => array('', 'deny,allow', 'allow,deny', 'explicit')), - 'only_db' => 'array')); -$cfg_db['RecodingEngine'] = array('auto', 'iconv', 'recode'); -$cfg_db['DefaultCharset'] = $GLOBALS['cfg']['AvailableCharsets']; -$cfg_db['OBGzip'] = array('auto', true, false); -$cfg_db['ShowTooltipAliasTB'] = array('nested', true, false); -$cfg_db['DisplayDatabasesList'] = array('auto', true, false); -$cfg_db['LeftLogoLinkWindow'] = array('main', 'new'); -$cfg_db['LeftDefaultTabTable'] = array( - 'tbl_structure.php', // fields list - 'tbl_sql.php', // SQL form - 'tbl_select.php', // search page - 'tbl_change.php', // insert row page - 'sql.php'); // browse page -$cfg_db['NavigationBarIconic'] = array(true, false, 'both'); -$cfg_db['Order'] = array('ASC', 'DESC', 'SMART'); -$cfg_db['ProtectBinary'] = array(false, 'blob', 'all'); -$cfg_db['CharEditing'] = array('input', 'textarea'); -$cfg_db['PropertiesIconic'] = array(true, false, 'both'); -$cfg_db['DefaultTabServer'] = array( - 'main.php', // the welcome page (recommended for multiuser setups) - 'server_databases.php', // list of databases - 'server_status.php', // runtime information - 'server_variables.php', // MySQL server variables - 'server_privileges.php', // user management - 'server_processlist.php'); // process list -$cfg_db['DefaultTabDatabase'] = array( - 'db_structure.php', // tables list - 'db_sql.php', // SQL form - 'db_search.php', // search query - 'db_operations.php'); // operations on database -$cfg_db['DefaultTabTable'] = array( - 'tbl_structure.php', // fields list - 'tbl_sql.php', // SQL form - 'tbl_select.php', // search page - 'tbl_change.php', // insert row page - 'sql.php'); // browse page -$cfg_db['QueryWindowDefTab'] = array( - 'sql', // SQL - 'files', // Import files - 'history', // SQL history - 'full'); // All (SQL and SQL history) -$cfg_db['Import']['format'] = array( - 'csv', // CSV - 'docsql', // DocSQL - 'ldi', // CSV using LOAD DATA - 'sql'); // SQL -$cfg_db['Import']['sql_compatibility'] = array( - 'NONE', 'ANSI', 'DB2', 'MAXDB', 'MYSQL323', 'MYSQL40', 'MSSQL', 'ORACLE', - // removed; in MySQL 5.0.33, this produces exports that - // can't be read by POSTGRESQL (see our bug #1596328) - //'POSTGRESQL', - 'TRADITIONAL'); -$cfg_db['Import']['ldi_local_option'] = array('auto', true, false); -$cfg_db['Export']['format'] = array('codegen', 'csv', 'excel', 'htmlexcel', - 'htmlword', 'latex', 'ods', 'odt', 'pdf', 'sql', 'texytext', 'xls', 'xml', - 'yaml'); -$cfg_db['Export']['compression'] = array('none', 'zip', 'gzip', 'bzip2'); -$cfg_db['Export']['charset'] = array_merge(array(''), $GLOBALS['cfg']['AvailableCharsets']); +require './libraries/config.values.php'; /** * Config options which will be placed in config file even if they are set diff --git a/user_preferences.php b/user_preferences.php new file mode 100644 index 000000000..e9ada9fc6 --- /dev/null +++ b/user_preferences.php @@ -0,0 +1,45 @@ + 'user_preferences.php', + 'text' => PMA_ifSetOr($GLOBALS['strSetupForm_' . $form], $form), // TODO: remove ifSetOr + 'active' => $form == PMA_ifSetOr($_GET['form'], ''), + 'url_params' => array('form' => $form) + ); +} + +echo PMA_generate_html_tabs($tabs, array()); + + +/** + * Displays the footer + */ +require_once './libraries/footer.inc.php'; +?> \ No newline at end of file