From 45b04ab15d4948a6798bb2c792238b8f01a34c6f Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Wed, 20 Sep 2006 11:15:56 +0000 Subject: [PATCH] replaced $dblist with new PMA_List_Database class --- ChangeLog | 14 +- export.php | 9 +- left.php | 26 +- libraries/Table.class.php | 28 +- libraries/common.lib.php | 375 ++++++--------------------- libraries/database_interface.lib.php | 77 ++---- libraries/dbi/mysql.dbi.lib.php | 6 +- libraries/dbi/mysqli.dbi.lib.php | 2 +- libraries/sql_query_form.lib.php | 2 - querywindow.php | 11 - server_databases.php | 2 +- server_export.php | 13 +- tbl_properties_operations.php | 32 +-- 13 files changed, 151 insertions(+), 446 deletions(-) diff --git a/ChangeLog b/ChangeLog index 313c6bd6d..2a5bb1e76 100755 --- a/ChangeLog +++ b/ChangeLog @@ -5,8 +5,16 @@ phpMyAdmin - ChangeLog $Id$ $Source$ +2006-08-11 Sebastian Mendel + * export.php, left.php, libraries\Table.class.php, libraries\common.lib.php, + libraries\database_interface.lib.php, libraries\dbi\mysql.dbi.lib.php, + libraries\dbi\mysqli.dbi.lib.php, libraries\sql_query_form.lib.php, + querywindow.php, server_databases.php, server_export.php, + tbl_properties_operations.php: + replaced $dblist with new PMA_List_Database class + 2006-09-19 Marc Delisle - * Documentation.html, libraries/footer.inc.php, + * Documentation.html, libraries/footer.inc.php, libraries/dbg/profiling.php: remove profiling feature due to licensing issues (non GPL code) @@ -16,7 +24,7 @@ $Source$ 2006-09-15 Marc Delisle * libraries/common.lib.php libraries/Config.class.php: - rename a function borrowed from Moodle to avoid double definition + rename a function borrowed from Moodle to avoid double definition when PMA is called by Moodle * lang/finnish: Update, thanks to Yoneh - yoneh. * lang/bulgarian: Update, thanks to Stanislav Yordanov - stanprog. @@ -85,7 +93,7 @@ $Source$ Add support for LogoutURL. 2006-08-22 Marc Delisle - * scripts/setup.php: bug #1536112, better fix (in case of + * scripts/setup.php: bug #1536112, better fix (in case of register_globals enabled), thanks to Michal ### 2.8.2.3 released from MAINT_2_8_2 * scripts/setup.php: bug #1544692, version 2.8.2.3 breaks setup.php diff --git a/export.php b/export.php index ad96b989b..91ff5753a 100644 --- a/export.php +++ b/export.php @@ -403,19 +403,12 @@ $do_dates = isset($GLOBALS[$what . '_dates']); */ // Gets the number of tables if a dump of a database has been required if ($export_type == 'server') { - /** - * Gets the databases list - if it has not been built yet - */ - if ($server > 0 && empty($dblist)) { - PMA_availableDatabases(); - } - if (isset($db_select)) { $tmp_select = implode($db_select, '|'); $tmp_select = '|' . $tmp_select . '|'; } // Walk over databases - foreach ($dblist AS $current_db) { + foreach ($GLOBALS['PMA_List_Database']->items as $current_db) { if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|')) || !isset($tmp_select)) { if (!PMA_exportDBHeader($current_db)) { diff --git a/left.php b/left.php index ef39a462e..31a847349 100644 --- a/left.php +++ b/left.php @@ -31,16 +31,9 @@ $cfgRelation = PMA_getRelationsParam(); * before the user choose among available ones at the welcome screen. */ if ($server > 0) { - // this function is defined in "common.lib.php" - // it defines $num_dbs and $dblist - PMA_availableDatabases(); - - if ((! isset($db) || ! strlen($db)) && count($dblist) === 1) { - reset($dblist); - $db = current($dblist); + if (! isset($db) || ! strlen($db)) { + $db = $GLOBALS['PMA_List_Database']->getSingleItem(); } -} else { - $num_dbs = 0; } $db = isset($db) ? $db : ''; @@ -123,7 +116,7 @@ require_once './libraries/header_http.inc.php'; count()) { // no database available, so we break here echo '

' . $strNoDatabases . '

'; @@ -144,7 +137,7 @@ if ($num_dbs === 0) { PMA_outBufferPost($ob_mode); } exit(); -} elseif ($GLOBALS['cfg']['LeftFrameLight'] && $num_dbs > 1) { +} elseif ($GLOBALS['cfg']['LeftFrameLight'] && $GLOBALS['PMA_List_Database']->count() > 1) { // more than one database available and LeftFrameLight is true // display db selectbox // @@ -255,24 +248,23 @@ if ($GLOBALS['cfg']['LeftFrameLight'] && isset($db) && strlen($db)) { * @global $img_minus * @global $img_plus * @global $href_left - * @global $num_dbs * @global $db_start * @global $common_url_query * @param array $ext_dblist extended db list */ function PMA_displayDbList($ext_dblist) { - global $element_counter, $img_minus, $img_plus, $href_left, $num_dbs, + global $element_counter, $img_minus, $img_plus, $href_left, $db_start, $common_url_query; // get table list, for all databases // doing this in one step takes advantage of a single query with information_schema! - $tables_full = PMA_DBI_get_tables_full($GLOBALS['dblist']); + $tables_full = PMA_DBI_get_tables_full($GLOBALS['PMA_List_Database']->items); $url_dbgroup = ''; echo '
    '; $close_db_group = false; foreach ($ext_dblist as $group => $db_group) { - if ($num_dbs > 1) { + if ($GLOBALS['PMA_List_Database']->count() > 1) { if ($close_db_group) { $url_dbgroup = ''; echo '
'; @@ -311,7 +303,7 @@ function PMA_displayDbList($ext_dblist) { // Displays the database name echo '
  • ' . "\n"; - if ($num_dbs > 1) { + if ($GLOBALS['PMA_List_Database']->count() > 1) { // only with more than one db we need collapse ... if ($db_start != $db['name'] || $db['num_tables'] < 1) { // display + only if this db is not preselected @@ -384,7 +376,7 @@ function PMA_displayDbList($ext_dblist) { $tables = PMA_getTableList($db['name']); } $child_visible = - (bool) ($num_dbs === 1 || $db_start == $db['name']); + (bool) ($GLOBALS['PMA_List_Database']->count() === 1 || $db_start == $db['name']); PMA_displayTableList($tables, $child_visible, '', $db['name']); } elseif ($GLOBALS['cfg']['LeftFrameLight']) { // no tables and LeftFrameLight: diff --git a/libraries/Table.class.php b/libraries/Table.class.php index 1a5af8a14..173c61700 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -504,7 +504,7 @@ class PMA_Table { * FIXME: use RENAME for move operations * - works only if the databases are on the same filesystem, * how can we check that? try the operation and - * catch an error? + * catch an error? * - for views, only if MYSQL > 50013 * - still have to handle pmadb synch. * @@ -512,7 +512,7 @@ class PMA_Table { */ function moveCopy($source_db, $source_table, $target_db, $target_table, $what, $move, $mode) { - global $dblist, $err_url; + global $err_url; if (! isset($GLOBALS['sql_query'])) { $GLOBALS['sql_query'] = ''; @@ -523,9 +523,8 @@ class PMA_Table { $GLOBALS['asfile'] = 1; // Ensure the target is valid - if (count($dblist) > 0 && - (! in_array($source_db, $dblist) || ! in_array($target_db, $dblist))) { - // TODO exit really needed here? or just a return? + if (! $GLOBALS['PMA_List_Database']->exists($source_db, $target_db)) { + // @TODO exit really needed here? or just a return? exit; } @@ -545,7 +544,7 @@ class PMA_Table { require_once './libraries/export/sql.php'; $no_constraints_comments = true; - $GLOBALS['sql_constraints_query'] = ''; + $GLOBALS['sql_constraints_query'] = ''; $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url); unset($no_constraints_comments); @@ -556,7 +555,7 @@ class PMA_Table { // this is not a CREATE TABLE, so find the first VIEW $target_for_view = PMA_backquote($target_db); while (true) { - if ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'VIEW') { + if ($parsed_sql[$i]['type'] == 'alpha_reservedWord' && $parsed_sql[$i]['data'] == 'VIEW') { break; } $i++; @@ -570,7 +569,7 @@ class PMA_Table { } /* no need to PMA_backquote() */ - if (isset($target_for_view)) { + if (isset($target_for_view)) { $parsed_sql[$i]['data'] = $target_for_view; } else { $parsed_sql[$i]['data'] = $target; @@ -610,7 +609,7 @@ class PMA_Table { // find the first quote_backtick, it must be the source table name while ($parsed_sql[$i]['type'] != 'quote_backtick') { $i++; - // maybe someday we should guard against going over limit + // maybe someday we should guard against going over limit //if ($i == $parsed_sql['len']) { // break; //} @@ -636,13 +635,13 @@ class PMA_Table { // Generate query back $GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql, 'query_only'); - if ($mode == 'one_table') { + if ($mode == 'one_table') { PMA_DBI_query($GLOBALS['sql_constraints_query']); - } + } $GLOBALS['sql_query'] .= "\n" . $GLOBALS['sql_constraints_query']; - if ($mode == 'one_table') { + if ($mode == 'one_table') { unset($GLOBALS['sql_constraints_query']); - } + } } } else { @@ -862,8 +861,7 @@ class PMA_Table { { if (null !== $new_db && $new_db !== $this->getDbName()) { // Ensure the target is valid - if (count($GLOBALS['dblist']) > 0 - && ! in_array($new_db, $GLOBALS['dblist'])) { + if (! $GLOBALS['PMA_List_Database']->exists($new_db)) { $this->errors[] = $GLOBALS['strInvalidDatabase'] . ': ' . $new_db; return false; } diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 6ce32d0d3..d5d3d9b6e 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -89,17 +89,15 @@ function PMA_securePath($path) /** * returns array with dbs grouped with extended infos * - * @uses $GLOBALS['dblist'] from PMA_availableDatabases() - * @uses $GLOBALS['num_dbs'] from PMA_availableDatabases() + * @todo move into PMA_List_Databases + * @uses $GLOBALS['PMA_List_Database'] * @uses $GLOBALS['cfgRelation']['commwork'] * @uses $GLOBALS['cfg']['ShowTooltip'] * @uses $GLOBALS['cfg']['LeftFrameDBTree'] * @uses $GLOBALS['cfg']['LeftFrameDBSeparator'] * @uses $GLOBALS['cfg']['ShowTooltipAliasDB'] - * @uses PMA_availableDatabases() * @uses PMA_getTableCount() * @uses PMA_getComments() - * @uses PMA_availableDatabases() * @uses is_array() * @uses implode() * @uses strstr() @@ -108,13 +106,9 @@ function PMA_securePath($path) */ function PMA_getDbList() { - if (empty($GLOBALS['dblist'])) { - PMA_availableDatabases(); - } - $dblist = $GLOBALS['dblist']; $dbgroups = array(); $parts = array(); - foreach ($dblist as $key => $db) { + foreach ($GLOBALS['PMA_List_Database']->items as $key => $db) { // garvin: Get comments from PMA comments table $db_tooltip = ''; if ($GLOBALS['cfg']['ShowTooltip'] @@ -155,18 +149,18 @@ function PMA_getDbList() 'comment' => $db_tooltip, 'num_tables' => PMA_getTableCount($db), ); - } // end foreach ($dblist as $db) + } // end foreach ($GLOBALS['PMA_List_Database']->items as $db) return $dbgroups; } /** * returns html code for select form element with dbs * + * @todo move into PMA_List_Databases * @return string html code select */ function PMA_getHtmlSelectDb($selected = '') { - $dblist = PMA_getDbList(); // TODO: IE can not handle different text directions in select boxes // so, as mostly names will be in english, we set the whole selectbox to LTR // and EN @@ -174,7 +168,7 @@ function PMA_getHtmlSelectDb($selected = '') .' onchange="if (this.value != \'\') window.parent.openDb(this.value);">' . "\n" .'' ."\n"; - foreach ($dblist as $group => $dbs) { + foreach (PMA_getDbList() as $group => $dbs) { if (count($dbs) > 1) { $return .= '' . "\n"; @@ -223,138 +217,6 @@ function PMA_getTableCount($db) return $num_tables; } - -/** - * Get the complete list of Databases a user can access - * - * @param boolean whether to include check on failed 'only_db' operations - * @param resource database handle (superuser) - * @param integer amount of databases inside the 'only_db' container - * @param resource possible resource from a failed previous query - * @param resource database handle (user) - * @param array configuration - * @param array previous list of databases - * - * @return array all databases a user has access to - * - * @access private - */ -function PMA_safe_db_list($only_db_check, $controllink, $dblist_cnt, $userlink, - $cfg, $dblist) -{ - if ($only_db_check == false) { - // try to get the available dbs list - // use userlink by default - $dblist = PMA_DBI_get_dblist(); - $dblist_cnt = count($dblist); - - // PMA_DBI_get_dblist() relies on the ability to run "SHOW DATABASES". - // On servers started with --skip-show-database, this is not possible - // so we have here a fallback method, which relies on the controluser - // being able to access the "mysql" db, as explained in the doc. - - if (!$dblist_cnt) { - $auth_query = 'SELECT User, Select_priv ' - . 'FROM mysql.user ' - . 'WHERE User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\''; - $rs = PMA_DBI_try_query($auth_query, $controllink); - } // end - } - - // Access to "mysql" db allowed and dblist still empty -> gets the - // usable db list - if (!$dblist_cnt && ($rs && @PMA_DBI_num_rows($rs))) { - $row = PMA_DBI_fetch_assoc($rs); - PMA_DBI_free_result($rs); - // Correction uva 19991215 - // Previous code assumed database "mysql" admin table "db" column - // "db" contains literal name of user database, and works if so. - // Mysql usage generally (and uva usage specifically) allows this - // column to contain regular expressions (we have all databases - // owned by a given student/faculty/staff beginning with user i.d. - // and governed by default by a single set of privileges with - // regular expression as key). This breaks previous code. - // This maintenance is to fix code to work correctly for regular - // expressions. - if ($row['Select_priv'] != 'Y') { - - // 1. get allowed dbs from the "mysql.db" table - // lem9: User can be blank (anonymous user) - $local_query = 'SELECT DISTINCT Db FROM mysql.db WHERE Select_priv = \'Y\' AND (User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\' OR User = \'\')'; - $rs = PMA_DBI_try_query($local_query, $controllink); - if ($rs && @PMA_DBI_num_rows($rs)) { - // Will use as associative array of the following 2 code - // lines: - // the 1st is the only line intact from before - // correction, - // the 2nd replaces $dblist[] = $row['Db']; - $uva_mydbs = array(); - // Code following those 2 lines in correction continues - // populating $dblist[], as previous code did. But it is - // now populated with actual database names instead of - // with regular expressions. - while ($row = PMA_DBI_fetch_assoc($rs)) { - // loic1: all databases cases - part 1 - if ( !isset($row['Db']) || ! strlen($row['Db']) || $row['Db'] == '%') { - $uva_mydbs['%'] = 1; - break; - } - // loic1: avoid multiple entries for dbs - if (!isset($uva_mydbs[$row['Db']])) { - $uva_mydbs[$row['Db']] = 1; - } - } // end while - PMA_DBI_free_result($rs); - $uva_alldbs = PMA_DBI_query('SHOW DATABASES;', $GLOBALS['controllink']); - // loic1: all databases cases - part 2 - if (isset($uva_mydbs['%'])) { - while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) { - $dblist[] = $uva_row[0]; - } // end while - } else { - while ($uva_row = PMA_DBI_fetch_row($uva_alldbs)) { - $uva_db = $uva_row[0]; - if (isset($uva_mydbs[$uva_db]) && $uva_mydbs[$uva_db] == 1) { - $dblist[] = $uva_db; - $uva_mydbs[$uva_db] = 0; - } elseif (!isset($dblist[$uva_db])) { - foreach ($uva_mydbs as $uva_matchpattern => $uva_value) { - // loic1: fixed bad regexp - // TODO: db names may contain characters - // that are regexp instructions - $re = '(^|(\\\\\\\\)+|[^\])'; - $uva_regex = ereg_replace($re . '%', '\\1.*', ereg_replace($re . '_', '\\1.{1}', $uva_matchpattern)); - // Fixed db name matching - // 2000-08-28 -- Benjamin Gandon - if (ereg('^' . $uva_regex . '$', $uva_db)) { - $dblist[] = $uva_db; - break; - } - } // end while - } // end if ... elseif ... - } // end while - } // end else - PMA_DBI_free_result($uva_alldbs); - unset($uva_mydbs); - } // end if - - // 2. get allowed dbs from the "mysql.tables_priv" table - $local_query = 'SELECT DISTINCT Db FROM mysql.tables_priv WHERE Table_priv LIKE \'%Select%\' AND User = \'' . PMA_sqlAddslashes($cfg['Server']['user']) . '\''; - $rs = PMA_DBI_try_query($local_query, $controllink); - if ($rs && @PMA_DBI_num_rows($rs)) { - while ($row = PMA_DBI_fetch_assoc($rs)) { - if (!in_array($row['Db'], $dblist)) { - $dblist[] = $row['Db']; - } - } // end while - PMA_DBI_free_result($rs); - } // end if - } // end if - } // end building available dbs from the "mysql" db - - return $dblist; -} - /** * Converts numbers like 10M into bytes * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas @@ -635,11 +497,11 @@ if (!defined('PMA_MINIMUM_COMMON')) { * * @access public */ - function PMA_displayMaximumUploadSize($max_upload_size) - { - list($max_size, $max_unit) = PMA_formatByteDown($max_upload_size); - return '(' . sprintf($GLOBALS['strMaximumSize'], $max_size, $max_unit) . ')'; - } + function PMA_displayMaximumUploadSize($max_upload_size) + { + list($max_size, $max_unit) = PMA_formatByteDown($max_upload_size); + return '(' . sprintf($GLOBALS['strMaximumSize'], $max_size, $max_unit) . ')'; + } /** * Generates a hidden field which should indicate to the browser @@ -1166,50 +1028,6 @@ if (!defined('PMA_MINIMUM_COMMON')) { } } - /** - * Get the list and number of available databases. - * - * @param string the url to go back to in case of error - * - * @return boolean always true - * - * @global array the list of available databases - * @global integer the number of available databases - * @global array current configuration - */ - function PMA_availableDatabases($error_url = '') - { - global $dblist; - global $num_dbs; - global $cfg; - - // 1. A list of allowed databases has already been defined by the - // authentication process -> gets the available databases list - if (count($dblist)) { - foreach ($dblist as $key => $db) { - if (!@PMA_DBI_select_db($db) || (!empty($GLOBALS['cfg']['Server']['hide_db']) && preg_match('/' . $GLOBALS['cfg']['Server']['hide_db'] . '/', $db))) { - unset($dblist[$key]); - } // end if - } // end for - } // end if - // 2. Allowed database list is empty -> gets the list of all databases - // on the server - elseif (empty($cfg['Server']['only_db'])) { - $dblist = PMA_DBI_get_dblist(); // needed? or PMA_mysqlDie('', 'SHOW DATABASES;', false, $error_url); - } // end else - - $num_dbs = count($dblist); - - // natural order for db list; but do not sort if user asked - // for a specific order with the 'only_db' mechanism - if (!is_array($GLOBALS['cfg']['Server']['only_db']) - && $GLOBALS['cfg']['NaturalOrder']) { - natsort($dblist); - } - - return true; - } // end of the 'PMA_availableDatabases()' function - /** * returns array with tables of given db with extended infomation and grouped * @@ -2715,15 +2533,34 @@ $variables_whitelist = array ( ); foreach (get_defined_vars() as $key => $value) { - if (!in_array($key, $variables_whitelist)) { + if (! in_array($key, $variables_whitelist)) { unset($$key); } } -unset($key, $value); +unset($key, $value, $variables_whitelist); /** - * check if a subform is submitted + * Subforms - some functions need to be called by form, cause of the limited url + * length, but if this functions inside another form you cannot just open a new + * form - so phpMyAdmin uses 'arrays' inside this form + * + * + *
    + * ... main form elments ... + * + * ... other subform data ... + * + * ... other subforms ... + * + * ... other subform data ... + * + * ... main form elments ... + * + * + *
    $dummy) { if (!in_array($key, $allow_list)) { - unset($_REQUEST[$key]); - unset($_GET[$key]); - unset($_POST[$key]); - unset($GLOBALS[$key]); + unset($_REQUEST[$key], $_GET[$key], $_POST[$key], $GLOBALS[$key]); } else { // allowed stuff could be compromised so escape it $_REQUEST[$key] = htmlspecialchars($_REQUEST[$key], ENT_QUOTES); } } + unset($key, $dummy); } @@ -2919,7 +2767,7 @@ if (isset($_REQUEST['db'])) { } /** - * @var string $db current selected database + * @var string $table current selected table */ if (isset($_REQUEST['table'])) { // can we strip tags from this? @@ -2967,6 +2815,9 @@ if (empty($_SESSION['PMA_Config'])) { $_SESSION['PMA_Config'] = new PMA_Config('./config.inc.php'); } elseif (version_compare(phpversion(), '5', 'lt')) { + /** + * @todo: move all __wakeup() functionality into session.inc.php + */ $_SESSION['PMA_Config']->__wakeup(); } @@ -2974,7 +2825,10 @@ if (!defined('PMA_MINIMUM_COMMON')) { $_SESSION['PMA_Config']->checkPmaAbsoluteUri(); } -// BC +/** + * BC - enable backward compatibility + * exports all config settings into $GLOBALS ($GLOBALS['cfg']) + */ $_SESSION['PMA_Config']->enableBc(); @@ -3009,6 +2863,7 @@ require './libraries/language.lib.php'; /** * check for errors occured while loading config + * this check is done here after loading lang files to present errors in locale */ if ($_SESSION['PMA_Config']->error_config_file) { $GLOBALS['PMA_errors'][] = $strConfigFileError @@ -3080,6 +2935,9 @@ unset($default_server); if (! isset($_SESSION['PMA_Theme_Manager'])) { $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager; } else { + /** + * @todo: move all __wakeup() functionality into session.inc.php + */ $_SESSION['PMA_Theme_Manager']->checkConfig(); } @@ -3093,6 +2951,9 @@ if (isset($_REQUEST['server']) && !isset($_REQUEST['set_theme'])) { $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp); unset($tmp); } +/** + * @todo: move into PMA_Theme_Manager::__wakeup() + */ if (isset($_REQUEST['set_theme'])) { // if user selected a theme $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']); @@ -3128,11 +2989,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { */ require_once './libraries/string.lib.php'; - /** - * @var array database list - */ - $dblist = array(); - /** * If no server is selected, make sure that $cfg['Server'] is empty (so * that nothing will work), and skip server authentication. @@ -3141,7 +2997,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { * present a choice of servers in the case that there are multiple servers * and '$cfg['ServerDefault'] = 0' is set. */ - if (!empty($_REQUEST['server']) && !empty($cfg['Servers'][$_REQUEST['server']])) { + if (! empty($_REQUEST['server']) && ! empty($cfg['Servers'][$_REQUEST['server']])) { $GLOBALS['server'] = $_REQUEST['server']; $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']]; } else { @@ -3156,7 +3012,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { $GLOBALS['url_params']['server'] = $GLOBALS['server']; - if (!empty($cfg['Server'])) { + if (! empty($cfg['Server'])) { /** * Loads the proper database interface for this server @@ -3239,15 +3095,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { unset($allowDeny_forbidden); //Clean up after you! } - // The user can work with only some databases - if (isset($cfg['Server']['only_db']) && $cfg['Server']['only_db'] != '') { - if (is_array($cfg['Server']['only_db'])) { - $dblist = $cfg['Server']['only_db']; - } else { - $dblist[] = $cfg['Server']['only_db']; - } - } // end if - $bkp_track_err = @ini_set('track_errors', 1); // Try to connect MySQL with the control user profile (will be used to @@ -3290,81 +3137,14 @@ if (! defined('PMA_MINIMUM_COMMON')) { */ require_once './libraries/sqlvalidator.lib.php'; - // if 'only_db' is set for the current user, there is no need to check for - // available databases in the "mysql" db - $dblist_cnt = count($dblist); - if ($dblist_cnt) { - $true_dblist = array(); - $is_show_dbs = true; - - $dblist_asterisk_bool = false; - for ($i = 0; $i < $dblist_cnt; $i++) { - - // The current position - if ($dblist[$i] == '*' && $dblist_asterisk_bool == false) { - $dblist_asterisk_bool = true; - $dblist_full = PMA_safe_db_list(false, $controllink, false, - $userlink, $cfg, $dblist); - foreach ($dblist_full as $dbl_val) { - if (!in_array($dbl_val, $dblist)) { - $true_dblist[] = $dbl_val; - } - } - - continue; - } elseif ($dblist[$i] == '*') { - // We don't want more than one asterisk inside our 'only_db'. - continue; - } - if ($is_show_dbs && preg_match('/(^|[^\\\\])(_|%)/', $dblist[$i])) { - $local_query = 'SHOW DATABASES LIKE \'' . $dblist[$i] . '\''; - // here, a PMA_DBI_query() could fail silently - // if SHOW DATABASES is disabled - $rs = PMA_DBI_try_query($local_query, $userlink); - - if ($i == 0 && ! $rs) { - $error_code = substr(PMA_DBI_getError($userlink), 1, 4); - if ($error_code == 1227 || $error_code == 1045) { - // "SHOW DATABASES" statement is disabled or not allowed to user - $true_dblist[] = str_replace('\\_', '_', str_replace('\\%', '%', $dblist[$i])); - $is_show_dbs = false; - } - unset($error_code); - } - // Debug - // elseif (PMA_DBI_getError($controllink)) { - // PMA_mysqlDie(PMA_DBI_getError($controllink), $local_query, false); - // } - while ($row = @PMA_DBI_fetch_row($rs)) { - $true_dblist[] = $row[0]; - } // end while - if ($rs) { - PMA_DBI_free_result($rs); - } - } else { - $true_dblist[] = str_replace('\\_', '_', - str_replace('\\%', '%', $dblist[$i])); - } // end if... else... - } // end for - $dblist = $true_dblist; - unset($true_dblist, $i, $dbl_val); - $only_db_check = true; - } // end if - - // 'only_db' is empty for the current user... - else { - $only_db_check = false; - } // end if (!$dblist_cnt) - - if (isset($dblist_full) && !count($dblist_full)) { - $dblist = PMA_safe_db_list($only_db_check, $controllink, - $dblist_cnt, $userlink, $cfg, $dblist); - } - unset($only_db_check, $dblist_full); + /** + * database list + */ + require_once './libraries/PMA_List_Database.class.php'; + $PMA_List_Database = new PMA_List_Database($userlink, $controllink); } // end server connecting - // Kanji encoding convert feature appended by Y.Kawada (2002/2/20) if (@function_exists('mb_convert_encoding') && strpos(' ' . $lang, 'ja-') @@ -3375,6 +3155,7 @@ if (! defined('PMA_MINIMUM_COMMON')) { /** * save some settings in cookies + * @todo: should be done in PMA_Config */ PMA_setCookie('pma_lang', $GLOBALS['lang']); PMA_setCookie('pma_charset', $GLOBALS['convcharset']); diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index 2f42880eb..d5e57dc64 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -172,30 +172,6 @@ function PMA_DBI_convert_message( $message ) { return $message; } -/** - * returns array with database names - * - * @return array $databases - */ -function PMA_DBI_get_dblist($link = null) -{ - $dbs_array = PMA_DBI_fetch_result('SHOW DATABASES;', $link); - - // Before MySQL 4.0.2, SHOW DATABASES could send the - // whole list, so check if we really have access: - if (PMA_MYSQL_INT_VERSION < 40002 || !empty($GLOBALS['cfg']['Server']['hide_db'])) { - foreach ($dbs_array as $key => $db) { - if (!@PMA_DBI_select_db($db, $link) || (!empty($GLOBALS['cfg']['Server']['hide_db']) && preg_match('/' . $GLOBALS['cfg']['Server']['hide_db'] . '/', $db))) { - unset( $dbs_array[$key] ); - } - } - // re-index values - $dbs_array = array_values( $dbs_array ); - } - - return $dbs_array; -} - /** * returns array with table names for given db * @@ -393,27 +369,17 @@ function PMA_DBI_get_tables_full($database, $table = false, } } -/** - * returns count of databases for current server - * - * @param string $database databases to count - * @param resource $link mysql db link - */ -function PMA_DBI_get_databases_count($database = null, $link = null) -{ - return count(PMA_DBI_get_dblist($link)); -} - /** * returns array with databases containing extended infos about them * - * @param string $databases database - * @param boolean $force_stats retrieve stats also for MySQL < 5 - * @param resource $link mysql link - * @param string $sort_by collumn to order by - * @param string $sort_order ASC or DESC - * @param integer $limit_offset starting offset for LIMIT - * @param bool|int $limit_count row count for LIMIT or true for $GLOBALS['cfg']['MaxDbList'] + * @todo move into PMA_List_Database? + * @param string $databases database + * @param boolean $force_stats retrieve stats also for MySQL < 5 + * @param resource $link mysql link + * @param string $sort_by collumn to order by + * @param string $sort_order ASC or DESC + * @param integer $limit_offset starting offset for LIMIT + * @param bool|int $limit_count row count for LIMIT or true for $GLOBALS['cfg']['MaxDbList'] * @return array $databases */ function PMA_DBI_get_databases_full($database = null, $force_stats = false, @@ -490,9 +456,19 @@ function PMA_DBI_get_databases_full($database = null, $force_stats = false, ORDER BY ' . PMA_backquote($sort_by) . ' ' . $sort_order . $limit; $databases = PMA_DBI_fetch_result( $sql, 'SCHEMA_NAME', null, $link ); + + // display only databases also in official database list + // f.e. to apply hide_db and only_db + $drops = array_diff(array_keys($databases), $GLOBALS['PMA_List_Database']->items); + if (count($drops)) { + foreach ($drops as $drop) { + unset($databases[$drop]); + } + } + unset($sql_where_schema, $sql); } else { - foreach ( PMA_DBI_get_dblist( $link ) as $database_name ) { + foreach ($GLOBALS['PMA_List_Database']->items as $database_name) { // MySQL forward compatibility // so pma could use this array as if every server is of version >5.0 $databases[$database_name]['SCHEMA_NAME'] = $database_name; @@ -625,8 +601,7 @@ function PMA_DBI_get_columns_full($database = null, $table = null, unset( $sql_wheres, $sql ); } else { if ( null === $database ) { - $databases = PMA_DBI_get_dblist(); - foreach ( $databases as $database ) { + foreach ($GLOBALS['PMA_List_Database']->items as $database) { $columns[$database] = PMA_DBI_get_columns_full($database, null, null, $link); } @@ -1185,14 +1160,14 @@ function PMA_isSuperuser() { /** - * returns an array of PROCEDURE or FUNCTION names for a db + * returns an array of PROCEDURE or FUNCTION names for a db * * @uses PMA_DBI_free_result() * @param string $db db name - * @param string $which PROCEDURE | FUNCTION + * @param string $which PROCEDURE | FUNCTION * @param resource $link mysql link * - * @return array the procedure names or function names + * @return array the procedure names or function names */ function PMA_DBI_get_procedures_or_functions($db, $which, $link = null) { @@ -1207,15 +1182,15 @@ function PMA_DBI_get_procedures_or_functions($db, $which, $link = null) { } /** - * returns the definition of a specific PROCEDURE or FUNCTION + * returns the definition of a specific PROCEDURE or FUNCTION * * @uses PMA_DBI_fetch_value() * @param string $db db name - * @param string $which PROCEDURE | FUNCTION + * @param string $which PROCEDURE | FUNCTION * @param string $proc_or_function_name the procedure name or function name * @param resource $link mysql link * - * @return string the procedure's or function's definition + * @return string the procedure's or function's definition */ function PMA_DBI_get_procedure_or_function_def($db, $which, $proc_or_function_name, $link = null) { diff --git a/libraries/dbi/mysql.dbi.lib.php b/libraries/dbi/mysql.dbi.lib.php index d3fb35775..79e427fc3 100644 --- a/libraries/dbi/mysql.dbi.lib.php +++ b/libraries/dbi/mysql.dbi.lib.php @@ -61,12 +61,12 @@ function PMA_DBI_connect($user, $password, $is_controluser = FALSE) { } $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, $password, empty($client_flags) ? NULL : $client_flags); - + // Retry with empty password if we're allowed to if (empty($link) && $cfg['Server']['nopassword'] && !$is_controluser) { $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, '', empty($client_flags) ? NULL : $client_flags); } - + if (empty($link)) { PMA_auth_fails(); } // end if @@ -249,7 +249,7 @@ function PMA_DBI_get_client_info() { */ function PMA_DBI_getError($link = null) { - unset($GLOBALS['errno']); + $GLOBALS['errno'] = 0; if (null === $link && isset($GLOBALS['userlink'])) { $link =& $GLOBALS['userlink']; diff --git a/libraries/dbi/mysqli.dbi.lib.php b/libraries/dbi/mysqli.dbi.lib.php index 436e17d02..5f17bcae0 100644 --- a/libraries/dbi/mysqli.dbi.lib.php +++ b/libraries/dbi/mysqli.dbi.lib.php @@ -405,7 +405,7 @@ function PMA_DBI_get_client_info() */ function PMA_DBI_getError($link = null) { - unset($GLOBALS['errno']); + $GLOBALS['errno'] = 0; if (null === $link && isset($GLOBALS['userlink'])) { $link =& $GLOBALS['userlink']; diff --git a/libraries/sql_query_form.lib.php b/libraries/sql_query_form.lib.php index daf181339..092e7c548 100644 --- a/libraries/sql_query_form.lib.php +++ b/libraries/sql_query_form.lib.php @@ -180,11 +180,9 @@ function PMA_sqlQueryForm($query = true, $display_tab = false) * @uses $GLOBALS['cfg']['TextareaRows'] * @uses $GLOBALS['strShowThisQuery'] * @uses $GLOBALS['strGo'] - * @uses PMA_availableDatabases() * @uses PMA_USR_OS * @uses PMA_USR_BROWSER_AGENT * @uses PMA_USR_BROWSER_VER - * @uses PMA_availableDatabases() * @uses htmlspecialchars() * @param string $query query to display in the textarea * @param boolean $is_querywindow if inside querywindow or not diff --git a/querywindow.php b/querywindow.php index 5140ab1c4..25b2ccb94 100644 --- a/querywindow.php +++ b/querywindow.php @@ -35,17 +35,6 @@ $cfgRelation = PMA_getRelationsParam(); $_sql_history = array(); $_input_query_history = array(); -/** - * Get the list and number of available databases. - * Skipped if no server selected: in this case no database should be displayed - * before the user choose among available ones at the welcome screen. - */ -if ($server > 0) { - PMA_availableDatabases(); // this function is defined in "common.lib.php" -} else { - $num_dbs = 0; -} - // garvin: For re-usability, moved http-headers and stylesheets // to a seperate file. It can now be included by libraries/header.inc.php, // querywindow.php. diff --git a/server_databases.php b/server_databases.php index 6a6e69b0c..964de8762 100644 --- a/server_databases.php +++ b/server_databases.php @@ -85,7 +85,7 @@ echo '

    ' . "\n" if ($server > 0) { $databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by, $sort_order, $pos, true); - $databases_count = PMA_DBI_get_databases_count(); + $databases_count = $PMA_List_Database->count(); } else { $databases_count = 0; } diff --git a/server_export.php b/server_export.php index c4b47979d..9e3cdf884 100644 --- a/server_export.php +++ b/server_export.php @@ -14,22 +14,11 @@ $js_to_run = 'functions.js'; */ require('./libraries/server_links.inc.php'); -/** - * Gets the databases list - if it has not been built yet - */ -if ($server > 0 && empty($dblist)) { - PMA_availableDatabases(); -} -?> - - - - -' - . htmlspecialchars($each_db) . ''; - echo "\n"; -} // end foreach $dblist -?> + getHtmlOptions(); ?>  . 
    + // next value but users can decide if they want it or not for the operation + ?>
    @@ -346,17 +337,7 @@ if (isset($auto_increment) && strlen($auto_increment) > 0
     . 
    @@ -480,7 +461,8 @@ $this_url_params = array_merge($url_params, if ($cfgRelation['relwork'] && $tbl_type != "INNODB") { // we need this PMA_DBI_select_db if the user has access to more than one db - // and $GLOBALS['db'] is not the last of the list, because PMA_availableDatabases() + // and $GLOBALS['db'] is not the last of the list, because + // PMA_List_Database::_checkAccess() // has made a PMA_DBI_select_db() on the last one PMA_DBI_select_db($GLOBALS['db']); $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);