replaced $dblist with new PMA_List_Database class

This commit is contained in:
Sebastian Mendel
2006-09-20 11:15:56 +00:00
parent 9ec978a4a9
commit 45b04ab15d
13 changed files with 151 additions and 446 deletions

View File

@@ -5,8 +5,16 @@ phpMyAdmin - ChangeLog
$Id$ $Id$
$Source$ $Source$
2006-08-11 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* 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 <lem9@users.sourceforge.net> 2006-09-19 Marc Delisle <lem9@users.sourceforge.net>
* Documentation.html, libraries/footer.inc.php, * Documentation.html, libraries/footer.inc.php,
libraries/dbg/profiling.php: remove profiling feature libraries/dbg/profiling.php: remove profiling feature
due to licensing issues (non GPL code) due to licensing issues (non GPL code)
@@ -16,7 +24,7 @@ $Source$
2006-09-15 Marc Delisle <lem9@users.sourceforge.net> 2006-09-15 Marc Delisle <lem9@users.sourceforge.net>
* libraries/common.lib.php libraries/Config.class.php: * 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 when PMA is called by Moodle
* lang/finnish: Update, thanks to Yoneh - yoneh. * lang/finnish: Update, thanks to Yoneh - yoneh.
* lang/bulgarian: Update, thanks to Stanislav Yordanov - stanprog. * lang/bulgarian: Update, thanks to Stanislav Yordanov - stanprog.
@@ -85,7 +93,7 @@ $Source$
Add support for LogoutURL. Add support for LogoutURL.
2006-08-22 Marc Delisle <lem9@users.sourceforge.net> 2006-08-22 Marc Delisle <lem9@users.sourceforge.net>
* 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 register_globals enabled), thanks to Michal
### 2.8.2.3 released from MAINT_2_8_2 ### 2.8.2.3 released from MAINT_2_8_2
* scripts/setup.php: bug #1544692, version 2.8.2.3 breaks setup.php * scripts/setup.php: bug #1544692, version 2.8.2.3 breaks setup.php

View File

@@ -403,19 +403,12 @@ $do_dates = isset($GLOBALS[$what . '_dates']);
*/ */
// Gets the number of tables if a dump of a database has been required // Gets the number of tables if a dump of a database has been required
if ($export_type == 'server') { 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)) { if (isset($db_select)) {
$tmp_select = implode($db_select, '|'); $tmp_select = implode($db_select, '|');
$tmp_select = '|' . $tmp_select . '|'; $tmp_select = '|' . $tmp_select . '|';
} }
// Walk over databases // 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 . '|')) if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))
|| !isset($tmp_select)) { || !isset($tmp_select)) {
if (!PMA_exportDBHeader($current_db)) { if (!PMA_exportDBHeader($current_db)) {

View File

@@ -31,16 +31,9 @@ $cfgRelation = PMA_getRelationsParam();
* before the user choose among available ones at the welcome screen. * before the user choose among available ones at the welcome screen.
*/ */
if ($server > 0) { if ($server > 0) {
// this function is defined in "common.lib.php" if (! isset($db) || ! strlen($db)) {
// it defines $num_dbs and $dblist $db = $GLOBALS['PMA_List_Database']->getSingleItem();
PMA_availableDatabases();
if ((! isset($db) || ! strlen($db)) && count($dblist) === 1) {
reset($dblist);
$db = current($dblist);
} }
} else {
$num_dbs = 0;
} }
$db = isset($db) ? $db : ''; $db = isset($db) ? $db : '';
@@ -123,7 +116,7 @@ require_once './libraries/header_http.inc.php';
<?php <?php
require './libraries/left_header.inc.php'; require './libraries/left_header.inc.php';
if ($num_dbs === 0) { if (! $GLOBALS['PMA_List_Database']->count()) {
// no database available, so we break here // no database available, so we break here
echo '<p>' . $strNoDatabases . '</p></body></html>'; echo '<p>' . $strNoDatabases . '</p></body></html>';
@@ -144,7 +137,7 @@ if ($num_dbs === 0) {
PMA_outBufferPost($ob_mode); PMA_outBufferPost($ob_mode);
} }
exit(); 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 // more than one database available and LeftFrameLight is true
// display db selectbox // display db selectbox
// //
@@ -255,24 +248,23 @@ if ($GLOBALS['cfg']['LeftFrameLight'] && isset($db) && strlen($db)) {
* @global $img_minus * @global $img_minus
* @global $img_plus * @global $img_plus
* @global $href_left * @global $href_left
* @global $num_dbs
* @global $db_start * @global $db_start
* @global $common_url_query * @global $common_url_query
* @param array $ext_dblist extended db list * @param array $ext_dblist extended db list
*/ */
function PMA_displayDbList($ext_dblist) { 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; $db_start, $common_url_query;
// get table list, for all databases // get table list, for all databases
// doing this in one step takes advantage of a single query with information_schema! // 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 = ''; $url_dbgroup = '';
echo '<ul id="leftdatabaselist">'; echo '<ul id="leftdatabaselist">';
$close_db_group = false; $close_db_group = false;
foreach ($ext_dblist as $group => $db_group) { foreach ($ext_dblist as $group => $db_group) {
if ($num_dbs > 1) { if ($GLOBALS['PMA_List_Database']->count() > 1) {
if ($close_db_group) { if ($close_db_group) {
$url_dbgroup = ''; $url_dbgroup = '';
echo '</ul>'; echo '</ul>';
@@ -311,7 +303,7 @@ function PMA_displayDbList($ext_dblist) {
// Displays the database name // Displays the database name
echo '<li>' . "\n"; echo '<li>' . "\n";
if ($num_dbs > 1) { if ($GLOBALS['PMA_List_Database']->count() > 1) {
// only with more than one db we need collapse ... // only with more than one db we need collapse ...
if ($db_start != $db['name'] || $db['num_tables'] < 1) { if ($db_start != $db['name'] || $db['num_tables'] < 1) {
// display + only if this db is not preselected // display + only if this db is not preselected
@@ -384,7 +376,7 @@ function PMA_displayDbList($ext_dblist) {
$tables = PMA_getTableList($db['name']); $tables = PMA_getTableList($db['name']);
} }
$child_visible = $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']); PMA_displayTableList($tables, $child_visible, '', $db['name']);
} elseif ($GLOBALS['cfg']['LeftFrameLight']) { } elseif ($GLOBALS['cfg']['LeftFrameLight']) {
// no tables and LeftFrameLight: // no tables and LeftFrameLight:

View File

@@ -504,7 +504,7 @@ class PMA_Table {
* FIXME: use RENAME for move operations * FIXME: use RENAME for move operations
* - works only if the databases are on the same filesystem, * - works only if the databases are on the same filesystem,
* how can we check that? try the operation and * how can we check that? try the operation and
* catch an error? * catch an error?
* - for views, only if MYSQL > 50013 * - for views, only if MYSQL > 50013
* - still have to handle pmadb synch. * - 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) 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'])) { if (! isset($GLOBALS['sql_query'])) {
$GLOBALS['sql_query'] = ''; $GLOBALS['sql_query'] = '';
@@ -523,9 +523,8 @@ class PMA_Table {
$GLOBALS['asfile'] = 1; $GLOBALS['asfile'] = 1;
// Ensure the target is valid // Ensure the target is valid
if (count($dblist) > 0 && if (! $GLOBALS['PMA_List_Database']->exists($source_db, $target_db)) {
(! in_array($source_db, $dblist) || ! in_array($target_db, $dblist))) { // @TODO exit really needed here? or just a return?
// TODO exit really needed here? or just a return?
exit; exit;
} }
@@ -545,7 +544,7 @@ class PMA_Table {
require_once './libraries/export/sql.php'; require_once './libraries/export/sql.php';
$no_constraints_comments = true; $no_constraints_comments = true;
$GLOBALS['sql_constraints_query'] = ''; $GLOBALS['sql_constraints_query'] = '';
$sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url); $sql_structure = PMA_getTableDef($source_db, $source_table, "\n", $err_url);
unset($no_constraints_comments); unset($no_constraints_comments);
@@ -556,7 +555,7 @@ class PMA_Table {
// this is not a CREATE TABLE, so find the first VIEW // this is not a CREATE TABLE, so find the first VIEW
$target_for_view = PMA_backquote($target_db); $target_for_view = PMA_backquote($target_db);
while (true) { 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; break;
} }
$i++; $i++;
@@ -570,7 +569,7 @@ class PMA_Table {
} }
/* no need to PMA_backquote() */ /* no need to PMA_backquote() */
if (isset($target_for_view)) { if (isset($target_for_view)) {
$parsed_sql[$i]['data'] = $target_for_view; $parsed_sql[$i]['data'] = $target_for_view;
} else { } else {
$parsed_sql[$i]['data'] = $target; $parsed_sql[$i]['data'] = $target;
@@ -610,7 +609,7 @@ class PMA_Table {
// find the first quote_backtick, it must be the source table name // find the first quote_backtick, it must be the source table name
while ($parsed_sql[$i]['type'] != 'quote_backtick') { while ($parsed_sql[$i]['type'] != 'quote_backtick') {
$i++; $i++;
// maybe someday we should guard against going over limit // maybe someday we should guard against going over limit
//if ($i == $parsed_sql['len']) { //if ($i == $parsed_sql['len']) {
// break; // break;
//} //}
@@ -636,13 +635,13 @@ class PMA_Table {
// Generate query back // Generate query back
$GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql, $GLOBALS['sql_constraints_query'] = PMA_SQP_formatHtml($parsed_sql,
'query_only'); 'query_only');
if ($mode == 'one_table') { if ($mode == 'one_table') {
PMA_DBI_query($GLOBALS['sql_constraints_query']); PMA_DBI_query($GLOBALS['sql_constraints_query']);
} }
$GLOBALS['sql_query'] .= "\n" . $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']); unset($GLOBALS['sql_constraints_query']);
} }
} }
} else { } else {
@@ -862,8 +861,7 @@ class PMA_Table {
{ {
if (null !== $new_db && $new_db !== $this->getDbName()) { if (null !== $new_db && $new_db !== $this->getDbName()) {
// Ensure the target is valid // Ensure the target is valid
if (count($GLOBALS['dblist']) > 0 if (! $GLOBALS['PMA_List_Database']->exists($new_db)) {
&& ! in_array($new_db, $GLOBALS['dblist'])) {
$this->errors[] = $GLOBALS['strInvalidDatabase'] . ': ' . $new_db; $this->errors[] = $GLOBALS['strInvalidDatabase'] . ': ' . $new_db;
return false; return false;
} }

View File

@@ -89,17 +89,15 @@ function PMA_securePath($path)
/** /**
* returns array with dbs grouped with extended infos * returns array with dbs grouped with extended infos
* *
* @uses $GLOBALS['dblist'] from PMA_availableDatabases() * @todo move into PMA_List_Databases
* @uses $GLOBALS['num_dbs'] from PMA_availableDatabases() * @uses $GLOBALS['PMA_List_Database']
* @uses $GLOBALS['cfgRelation']['commwork'] * @uses $GLOBALS['cfgRelation']['commwork']
* @uses $GLOBALS['cfg']['ShowTooltip'] * @uses $GLOBALS['cfg']['ShowTooltip']
* @uses $GLOBALS['cfg']['LeftFrameDBTree'] * @uses $GLOBALS['cfg']['LeftFrameDBTree']
* @uses $GLOBALS['cfg']['LeftFrameDBSeparator'] * @uses $GLOBALS['cfg']['LeftFrameDBSeparator']
* @uses $GLOBALS['cfg']['ShowTooltipAliasDB'] * @uses $GLOBALS['cfg']['ShowTooltipAliasDB']
* @uses PMA_availableDatabases()
* @uses PMA_getTableCount() * @uses PMA_getTableCount()
* @uses PMA_getComments() * @uses PMA_getComments()
* @uses PMA_availableDatabases()
* @uses is_array() * @uses is_array()
* @uses implode() * @uses implode()
* @uses strstr() * @uses strstr()
@@ -108,13 +106,9 @@ function PMA_securePath($path)
*/ */
function PMA_getDbList() function PMA_getDbList()
{ {
if (empty($GLOBALS['dblist'])) {
PMA_availableDatabases();
}
$dblist = $GLOBALS['dblist'];
$dbgroups = array(); $dbgroups = array();
$parts = array(); $parts = array();
foreach ($dblist as $key => $db) { foreach ($GLOBALS['PMA_List_Database']->items as $key => $db) {
// garvin: Get comments from PMA comments table // garvin: Get comments from PMA comments table
$db_tooltip = ''; $db_tooltip = '';
if ($GLOBALS['cfg']['ShowTooltip'] if ($GLOBALS['cfg']['ShowTooltip']
@@ -155,18 +149,18 @@ function PMA_getDbList()
'comment' => $db_tooltip, 'comment' => $db_tooltip,
'num_tables' => PMA_getTableCount($db), 'num_tables' => PMA_getTableCount($db),
); );
} // end foreach ($dblist as $db) } // end foreach ($GLOBALS['PMA_List_Database']->items as $db)
return $dbgroups; return $dbgroups;
} }
/** /**
* returns html code for select form element with dbs * returns html code for select form element with dbs
* *
* @todo move into PMA_List_Databases
* @return string html code select * @return string html code select
*/ */
function PMA_getHtmlSelectDb($selected = '') function PMA_getHtmlSelectDb($selected = '')
{ {
$dblist = PMA_getDbList();
// TODO: IE can not handle different text directions in select boxes // 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 // so, as mostly names will be in english, we set the whole selectbox to LTR
// and EN // and EN
@@ -174,7 +168,7 @@ function PMA_getHtmlSelectDb($selected = '')
.' onchange="if (this.value != \'\') window.parent.openDb(this.value);">' . "\n" .' onchange="if (this.value != \'\') window.parent.openDb(this.value);">' . "\n"
.'<option value="" dir="' . $GLOBALS['text_dir'] . '">(' . $GLOBALS['strDatabases'] . ') ...</option>' .'<option value="" dir="' . $GLOBALS['text_dir'] . '">(' . $GLOBALS['strDatabases'] . ') ...</option>'
."\n"; ."\n";
foreach ($dblist as $group => $dbs) { foreach (PMA_getDbList() as $group => $dbs) {
if (count($dbs) > 1) { if (count($dbs) > 1) {
$return .= '<optgroup label="' . htmlspecialchars($group) $return .= '<optgroup label="' . htmlspecialchars($group)
. '">' . "\n"; . '">' . "\n";
@@ -223,138 +217,6 @@ function PMA_getTableCount($db)
return $num_tables; 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 * Converts numbers like 10M into bytes
* Used with permission from Moodle (http://moodle.org) by Martin Dougiamas * Used with permission from Moodle (http://moodle.org) by Martin Dougiamas
@@ -635,11 +497,11 @@ if (!defined('PMA_MINIMUM_COMMON')) {
* *
* @access public * @access public
*/ */
function PMA_displayMaximumUploadSize($max_upload_size) function PMA_displayMaximumUploadSize($max_upload_size)
{ {
list($max_size, $max_unit) = PMA_formatByteDown($max_upload_size); list($max_size, $max_unit) = PMA_formatByteDown($max_upload_size);
return '(' . sprintf($GLOBALS['strMaximumSize'], $max_size, $max_unit) . ')'; return '(' . sprintf($GLOBALS['strMaximumSize'], $max_size, $max_unit) . ')';
} }
/** /**
* Generates a hidden field which should indicate to the browser * 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 * 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) { foreach (get_defined_vars() as $key => $value) {
if (!in_array($key, $variables_whitelist)) { if (! in_array($key, $variables_whitelist)) {
unset($$key); 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
*
* <code>
* <form ...>
* ... main form elments ...
* <intput type="hidden" name="subform[action1][id]" value="1" />
* ... other subform data ...
* <intput type="submit" name="usesubform[action1]" value="do action1" />
* ... other subforms ...
* <intput type="hidden" name="subform[actionX][id]" value="X" />
* ... other subform data ...
* <intput type="submit" name="usesubform[actionX]" value="do actionX" />
* ... main form elments ...
* <intput type="submit" name="main_action" value="submit form" />
* </form>
* </code
*
* so we now check if a subform is submitted
*/ */
$__redirect = null; $__redirect = null;
if (isset($_POST['usesubform'])) { if (isset($_POST['usesubform'])) {
@@ -2733,15 +2570,21 @@ if (isset($_POST['usesubform'])) {
$subform = $_POST['subform'][$subform_id]; $subform = $_POST['subform'][$subform_id];
$_POST = $subform; $_POST = $subform;
$_REQUEST = $subform; $_REQUEST = $subform;
/**
* some subforms need another page than the main form, so we will just
* include this page at the end of this script - we use $__redirect to
* track this
*/
if (isset($_POST['redirect']) if (isset($_POST['redirect'])
&& $_POST['redirect'] != basename(PMA_getenv('PHP_SELF'))) { && $_POST['redirect'] != basename(PMA_getenv('PHP_SELF'))) {
$__redirect = $_POST['redirect']; $__redirect = $_POST['redirect'];
unset($_POST['redirect']); unset($_POST['redirect']);
} // end if (isset($_POST['redirect'])) }
unset($subform_id, $subform); unset($subform_id, $subform);
} // end if (isset($_POST['usesubform'])) }
// end check if a subform is submitted // end check if a subform is submitted
// remove quotes added by php
if (get_magic_quotes_gpc()) { if (get_magic_quotes_gpc()) {
PMA_arrayWalkRecursive($_GET, 'stripslashes', true); PMA_arrayWalkRecursive($_GET, 'stripslashes', true);
PMA_arrayWalkRecursive($_POST, 'stripslashes', true); PMA_arrayWalkRecursive($_POST, 'stripslashes', true);
@@ -2749,6 +2592,7 @@ if (get_magic_quotes_gpc()) {
PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true); PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
} }
// start session
require_once './libraries/session.inc.php'; require_once './libraries/session.inc.php';
/** /**
@@ -2868,10 +2712,17 @@ if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
} }
/** /**
* Check whether user supplied token is valid, if not remove any * Check whether user supplied token is valid, if not remove any possibly
* possibly dangerous stuff from request. * dangerous stuff from request.
*
* remember that some objects in the session with session_start and __wakeup()
* could acces this variables before we reach this point
* f.e. PMA_Config: fontsize
*
* @todo: variables should be handled by their respective owners (objects)
* f.e. lang, server, convcharset, collation_connection in PMA_Config
*/ */
if (!isset($_REQUEST['token']) || $_SESSION['PMA_token'] != $_REQUEST['token']) { if (! isset($_REQUEST['token']) || $_SESSION['PMA_token'] != $_REQUEST['token']) {
/* List of parameters which are allowed from unsafe source */ /* List of parameters which are allowed from unsafe source */
$allow_list = array( $allow_list = array(
'db', 'table', 'lang', 'server', 'convcharset', 'collation_connection', 'target', 'db', 'table', 'lang', 'server', 'convcharset', 'collation_connection', 'target',
@@ -2882,19 +2733,16 @@ if (!isset($_REQUEST['token']) || $_SESSION['PMA_token'] != $_REQUEST['token'])
/* Possible login form */ /* Possible login form */
'pma_servername', 'pma_username', 'pma_password', 'pma_servername', 'pma_username', 'pma_password',
); );
$keys = array_keys($_REQUEST);
/* Remove any non allowed stuff from requests */ /* Remove any non allowed stuff from requests */
foreach($keys as $key) { foreach($_REQUEST as $key => $dummy) {
if (!in_array($key, $allow_list)) { if (!in_array($key, $allow_list)) {
unset($_REQUEST[$key]); unset($_REQUEST[$key], $_GET[$key], $_POST[$key], $GLOBALS[$key]);
unset($_GET[$key]);
unset($_POST[$key]);
unset($GLOBALS[$key]);
} else { } else {
// allowed stuff could be compromised so escape it // allowed stuff could be compromised so escape it
$_REQUEST[$key] = htmlspecialchars($_REQUEST[$key], ENT_QUOTES); $_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'])) { if (isset($_REQUEST['table'])) {
// can we strip tags from this? // can we strip tags from this?
@@ -2967,6 +2815,9 @@ if (empty($_SESSION['PMA_Config'])) {
$_SESSION['PMA_Config'] = new PMA_Config('./config.inc.php'); $_SESSION['PMA_Config'] = new PMA_Config('./config.inc.php');
} elseif (version_compare(phpversion(), '5', 'lt')) { } elseif (version_compare(phpversion(), '5', 'lt')) {
/**
* @todo: move all __wakeup() functionality into session.inc.php
*/
$_SESSION['PMA_Config']->__wakeup(); $_SESSION['PMA_Config']->__wakeup();
} }
@@ -2974,7 +2825,10 @@ if (!defined('PMA_MINIMUM_COMMON')) {
$_SESSION['PMA_Config']->checkPmaAbsoluteUri(); $_SESSION['PMA_Config']->checkPmaAbsoluteUri();
} }
// BC /**
* BC - enable backward compatibility
* exports all config settings into $GLOBALS ($GLOBALS['cfg'])
*/
$_SESSION['PMA_Config']->enableBc(); $_SESSION['PMA_Config']->enableBc();
@@ -3009,6 +2863,7 @@ require './libraries/language.lib.php';
/** /**
* check for errors occured while loading config * 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) { if ($_SESSION['PMA_Config']->error_config_file) {
$GLOBALS['PMA_errors'][] = $strConfigFileError $GLOBALS['PMA_errors'][] = $strConfigFileError
@@ -3080,6 +2935,9 @@ unset($default_server);
if (! isset($_SESSION['PMA_Theme_Manager'])) { if (! isset($_SESSION['PMA_Theme_Manager'])) {
$_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager; $_SESSION['PMA_Theme_Manager'] = new PMA_Theme_Manager;
} else { } else {
/**
* @todo: move all __wakeup() functionality into session.inc.php
*/
$_SESSION['PMA_Theme_Manager']->checkConfig(); $_SESSION['PMA_Theme_Manager']->checkConfig();
} }
@@ -3093,6 +2951,9 @@ if (isset($_REQUEST['server']) && !isset($_REQUEST['set_theme'])) {
$_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp); $_SESSION['PMA_Theme_Manager']->setActiveTheme($tmp);
unset($tmp); unset($tmp);
} }
/**
* @todo: move into PMA_Theme_Manager::__wakeup()
*/
if (isset($_REQUEST['set_theme'])) { if (isset($_REQUEST['set_theme'])) {
// if user selected a theme // if user selected a theme
$_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']); $_SESSION['PMA_Theme_Manager']->setActiveTheme($_REQUEST['set_theme']);
@@ -3128,11 +2989,6 @@ if (! defined('PMA_MINIMUM_COMMON')) {
*/ */
require_once './libraries/string.lib.php'; 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 * If no server is selected, make sure that $cfg['Server'] is empty (so
* that nothing will work), and skip server authentication. * 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 * present a choice of servers in the case that there are multiple servers
* and '$cfg['ServerDefault'] = 0' is set. * 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']; $GLOBALS['server'] = $_REQUEST['server'];
$cfg['Server'] = $cfg['Servers'][$GLOBALS['server']]; $cfg['Server'] = $cfg['Servers'][$GLOBALS['server']];
} else { } else {
@@ -3156,7 +3012,7 @@ if (! defined('PMA_MINIMUM_COMMON')) {
$GLOBALS['url_params']['server'] = $GLOBALS['server']; $GLOBALS['url_params']['server'] = $GLOBALS['server'];
if (!empty($cfg['Server'])) { if (! empty($cfg['Server'])) {
/** /**
* Loads the proper database interface for this 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! 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); $bkp_track_err = @ini_set('track_errors', 1);
// Try to connect MySQL with the control user profile (will be used to // 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'; 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 * database list
$dblist_cnt = count($dblist); */
if ($dblist_cnt) { require_once './libraries/PMA_List_Database.class.php';
$true_dblist = array(); $PMA_List_Database = new PMA_List_Database($userlink, $controllink);
$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);
} // end server connecting } // end server connecting
// Kanji encoding convert feature appended by Y.Kawada (2002/2/20) // Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
if (@function_exists('mb_convert_encoding') if (@function_exists('mb_convert_encoding')
&& strpos(' ' . $lang, 'ja-') && strpos(' ' . $lang, 'ja-')
@@ -3375,6 +3155,7 @@ if (! defined('PMA_MINIMUM_COMMON')) {
/** /**
* save some settings in cookies * save some settings in cookies
* @todo: should be done in PMA_Config
*/ */
PMA_setCookie('pma_lang', $GLOBALS['lang']); PMA_setCookie('pma_lang', $GLOBALS['lang']);
PMA_setCookie('pma_charset', $GLOBALS['convcharset']); PMA_setCookie('pma_charset', $GLOBALS['convcharset']);

View File

@@ -172,30 +172,6 @@ function PMA_DBI_convert_message( $message ) {
return $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 * 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 * returns array with databases containing extended infos about them
* *
* @param string $databases database * @todo move into PMA_List_Database?
* @param boolean $force_stats retrieve stats also for MySQL < 5 * @param string $databases database
* @param resource $link mysql link * @param boolean $force_stats retrieve stats also for MySQL < 5
* @param string $sort_by collumn to order by * @param resource $link mysql link
* @param string $sort_order ASC or DESC * @param string $sort_by collumn to order by
* @param integer $limit_offset starting offset for LIMIT * @param string $sort_order ASC or DESC
* @param bool|int $limit_count row count for LIMIT or true for $GLOBALS['cfg']['MaxDbList'] * @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 * @return array $databases
*/ */
function PMA_DBI_get_databases_full($database = null, $force_stats = false, 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 ORDER BY ' . PMA_backquote($sort_by) . ' ' . $sort_order
. $limit; . $limit;
$databases = PMA_DBI_fetch_result( $sql, 'SCHEMA_NAME', null, $link ); $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); unset($sql_where_schema, $sql);
} else { } else {
foreach ( PMA_DBI_get_dblist( $link ) as $database_name ) { foreach ($GLOBALS['PMA_List_Database']->items as $database_name) {
// MySQL forward compatibility // MySQL forward compatibility
// so pma could use this array as if every server is of version >5.0 // so pma could use this array as if every server is of version >5.0
$databases[$database_name]['SCHEMA_NAME'] = $database_name; $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 ); unset( $sql_wheres, $sql );
} else { } else {
if ( null === $database ) { if ( null === $database ) {
$databases = PMA_DBI_get_dblist(); foreach ($GLOBALS['PMA_List_Database']->items as $database) {
foreach ( $databases as $database ) {
$columns[$database] = PMA_DBI_get_columns_full($database, null, $columns[$database] = PMA_DBI_get_columns_full($database, null,
null, $link); 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() * @uses PMA_DBI_free_result()
* @param string $db db name * @param string $db db name
* @param string $which PROCEDURE | FUNCTION * @param string $which PROCEDURE | FUNCTION
* @param resource $link mysql link * @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) { 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() * @uses PMA_DBI_fetch_value()
* @param string $db db name * @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 string $proc_or_function_name the procedure name or function name
* @param resource $link mysql link * @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) { function PMA_DBI_get_procedure_or_function_def($db, $which, $proc_or_function_name, $link = null) {

View File

@@ -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); $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 // Retry with empty password if we're allowed to
if (empty($link) && $cfg['Server']['nopassword'] && !$is_controluser) { 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); $link = PMA_DBI_real_connect($cfg['Server']['host'] . $server_port . $server_socket, $user, '', empty($client_flags) ? NULL : $client_flags);
} }
if (empty($link)) { if (empty($link)) {
PMA_auth_fails(); PMA_auth_fails();
} // end if } // end if
@@ -249,7 +249,7 @@ function PMA_DBI_get_client_info() {
*/ */
function PMA_DBI_getError($link = null) function PMA_DBI_getError($link = null)
{ {
unset($GLOBALS['errno']); $GLOBALS['errno'] = 0;
if (null === $link && isset($GLOBALS['userlink'])) { if (null === $link && isset($GLOBALS['userlink'])) {
$link =& $GLOBALS['userlink']; $link =& $GLOBALS['userlink'];

View File

@@ -405,7 +405,7 @@ function PMA_DBI_get_client_info()
*/ */
function PMA_DBI_getError($link = null) function PMA_DBI_getError($link = null)
{ {
unset($GLOBALS['errno']); $GLOBALS['errno'] = 0;
if (null === $link && isset($GLOBALS['userlink'])) { if (null === $link && isset($GLOBALS['userlink'])) {
$link =& $GLOBALS['userlink']; $link =& $GLOBALS['userlink'];

View File

@@ -180,11 +180,9 @@ function PMA_sqlQueryForm($query = true, $display_tab = false)
* @uses $GLOBALS['cfg']['TextareaRows'] * @uses $GLOBALS['cfg']['TextareaRows']
* @uses $GLOBALS['strShowThisQuery'] * @uses $GLOBALS['strShowThisQuery']
* @uses $GLOBALS['strGo'] * @uses $GLOBALS['strGo']
* @uses PMA_availableDatabases()
* @uses PMA_USR_OS * @uses PMA_USR_OS
* @uses PMA_USR_BROWSER_AGENT * @uses PMA_USR_BROWSER_AGENT
* @uses PMA_USR_BROWSER_VER * @uses PMA_USR_BROWSER_VER
* @uses PMA_availableDatabases()
* @uses htmlspecialchars() * @uses htmlspecialchars()
* @param string $query query to display in the textarea * @param string $query query to display in the textarea
* @param boolean $is_querywindow if inside querywindow or not * @param boolean $is_querywindow if inside querywindow or not

View File

@@ -35,17 +35,6 @@ $cfgRelation = PMA_getRelationsParam();
$_sql_history = array(); $_sql_history = array();
$_input_query_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 // garvin: For re-usability, moved http-headers and stylesheets
// to a seperate file. It can now be included by libraries/header.inc.php, // to a seperate file. It can now be included by libraries/header.inc.php,
// querywindow.php. // querywindow.php.

View File

@@ -85,7 +85,7 @@ echo '<h2>' . "\n"
if ($server > 0) { if ($server > 0) {
$databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by, $databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by,
$sort_order, $pos, true); $sort_order, $pos, true);
$databases_count = PMA_DBI_get_databases_count(); $databases_count = $PMA_List_Database->count();
} else { } else {
$databases_count = 0; $databases_count = 0;
} }

View File

@@ -14,22 +14,11 @@ $js_to_run = 'functions.js';
*/ */
require('./libraries/server_links.inc.php'); require('./libraries/server_links.inc.php');
/**
* Gets the databases list - if it has not been built yet
*/
if ($server > 0 && empty($dblist)) {
PMA_availableDatabases();
}
?>
<!-- Dump of a server -->
<?php
$export_page_title = $strViewDumpDatabases . "\n"; $export_page_title = $strViewDumpDatabases . "\n";
$multi_values = '<div align="center"><select name="db_select[]" size="6" multiple="multiple">'; $multi_values = '<div align="center"><select name="db_select[]" size="6" multiple="multiple">';
$multi_values .= "\n"; $multi_values .= "\n";
foreach ($dblist AS $current_db) { foreach ($GLOBALS['PMA_List_Database']->items as $current_db) {
if (!empty($selectall) || (isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) { if (!empty($selectall) || (isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|'))) {
$is_selected = ' selected="selected"'; $is_selected = ' selected="selected"';
} else { } else {

View File

@@ -74,7 +74,7 @@ if (isset($_REQUEST['submitoptions'])) {
$l_tbl_type = strtolower($tbl_type); $l_tbl_type = strtolower($tbl_type);
if (($l_tbl_type === 'myisam' || $l_tbl_type === 'isam') if (($l_tbl_type === 'myisam' || $l_tbl_type === 'isam')
&& isset($_REQUEST['new_pack_keys']) && isset($_REQUEST['new_pack_keys'])
&& $_REQUEST['new_pack_keys'] != (string)$pack_keys) { && $_REQUEST['new_pack_keys'] != (string)$pack_keys) {
$table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys']; $table_alters[] = 'pack_keys = ' . $_REQUEST['new_pack_keys'];
} }
@@ -183,24 +183,15 @@ unset($columns);
<fieldset id="fieldset_table_rename"> <fieldset id="fieldset_table_rename">
<legend><?php echo $strMoveTable; ?></legend> <legend><?php echo $strMoveTable; ?></legend>
<select name="target_db"> <select name="target_db">
<?php <?php echo $GLOBALS['PMA_List_Database']->getHtmlOptions(); ?>
// The function used below is defined in "common.lib.php"
PMA_availableDatabases('main.php?' . PMA_generate_common_url());
foreach ($dblist as $each_db) {
echo ' ';
echo '<option value="' . htmlspecialchars($each_db) . '">'
. htmlspecialchars($each_db) . '</option>';
echo "\n";
} // end foreach $dblist
?>
</select> </select>
&nbsp;<b>.</b>&nbsp; &nbsp;<b>.</b>&nbsp;
<input type="text" size="20" name="new_name" onfocus="this.select()" <input type="text" size="20" name="new_name" onfocus="this.select()"
value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br /> value="<?php echo htmlspecialchars($GLOBALS['table']); ?>" /><br />
<?php <?php
// starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT // starting with MySQL 5.0.24, SHOW CREATE TABLE includes the AUTO_INCREMENT
// next value but users can decide if they want it or not for the operation // next value but users can decide if they want it or not for the operation
?> ?>
<input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment" checked="checked" /> <input type="checkbox" name="sql_auto_increment" value="1" id="checkbox_auto_increment" checked="checked" />
<label for="checkbox_auto_increment"><?php echo $strAddAutoIncrement; ?></label><br /> <label for="checkbox_auto_increment"><?php echo $strAddAutoIncrement; ?></label><br />
</fieldset> </fieldset>
@@ -346,17 +337,7 @@ if (isset($auto_increment) && strlen($auto_increment) > 0
<fieldset> <fieldset>
<legend><?php echo $strCopyTable; ?></legend> <legend><?php echo $strCopyTable; ?></legend>
<select name="target_db"> <select name="target_db">
<?php <?php echo $GLOBALS['PMA_List_Database']->getHtmlOptions(true); ?>
foreach ($dblist as $each_db) {
echo ' ';
echo '<option value="' . htmlspecialchars($each_db) . '"';
if ($each_db === $GLOBALS['db']) {
echo ' selected="selected"';
}
echo '>' . htmlspecialchars($each_db) . '</option>';
echo "\n";
} // end foreach $dblist
?>
</select> </select>
&nbsp;<b>.</b>&nbsp; &nbsp;<b>.</b>&nbsp;
<input type="text" size="20" name="new_name" onfocus="this.select()" /><br /> <input type="text" size="20" name="new_name" onfocus="this.select()" /><br />
@@ -480,7 +461,8 @@ $this_url_params = array_merge($url_params,
if ($cfgRelation['relwork'] && $tbl_type != "INNODB") { if ($cfgRelation['relwork'] && $tbl_type != "INNODB") {
// we need this PMA_DBI_select_db if the user has access to more than one db // 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 // has made a PMA_DBI_select_db() on the last one
PMA_DBI_select_db($GLOBALS['db']); PMA_DBI_select_db($GLOBALS['db']);
$foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']); $foreign = PMA_getForeigners($GLOBALS['db'], $GLOBALS['table']);