moved some more code into class, some documentation improvements

This commit is contained in:
Sebastian Mendel
2006-09-21 12:59:57 +00:00
parent 34a7e9d555
commit ca44c117a2
4 changed files with 202 additions and 261 deletions

View File

@@ -7,6 +7,8 @@ $Source$
2006-09-21 Sebastian Mendel <cybot_tm@users.sourceforge.net>
* libraries/PMA_List.class.php: new PMA_List class
* libraries/PMA_List_Database.class.php, left.php, libraries\common.lib.php:
moved some more code into class, some documentation improvements
2006-09-20 Marc Delisle <lem9@users.sourceforge.net>
### 2.9.0 released from QA_2_9

View File

@@ -230,7 +230,7 @@ if (! $GLOBALS['PMA_List_Database']->count()) {
<label for="lightm_db"><?php echo $strDatabase; ?></label>
<?php
echo PMA_generate_common_hidden_inputs() . "\n";
echo PMA_getHtmlSelectDb($db) . "\n";
echo $GLOBALS['PMA_List_Database']->getHtmlSelectGrouped(true) . "\n";
echo '<noscript>' . "\n"
.'<input type="submit" name="Go" value="' . $strGo . '" />' . "\n"
.'</noscript>' . "\n"
@@ -306,7 +306,7 @@ if ($GLOBALS['cfg']['LeftFrameLight'] && isset($db) && strlen($db)) {
echo '<p>' . $GLOBALS['strSelectADb'] . '</p>' . "\n";
} else {
$common_url_query = PMA_generate_common_url();
PMA_displayDbList(PMA_getDbList());
PMA_displayDbList($GLOBALS['PMA_List_Database']->getGroupedDetails());
}
/**

View File

@@ -2,44 +2,27 @@
/**
* holds the PMA_List_Database class
*
* possible at a later stage we could abstratc this a little bit more:
*
* PMA
* -> PMA_Config
* -> PMA_Theme
* -> ...
* -> PMA_List
* -> PMA_List_Table
* -> PMA_List_Server
* -> PMA_List_Database
* -> PMA_List_Database_Mysql
* -> PMA_List_Database_Mysql_3
* -> PMA_List_Database_Mysql_4
* -> PMA_List_Database_Mysql_5
* -> PMA_List_Database_OtherDbms
* -> ...
*
*/
//require_once 'PMA_List.class.php';
/**
* the list base class
*/
require_once './libraries/PMA_List.class.php';
/**
* handles database lists
*
* @todo this object should be attached to the server object
* @todo make use of INFORMATION_SCHEMA !?
* @todo support --skip-showdatabases and user has only global rights?
* @todo add caching
* @todo this object should be attached to the PMA_Server object
* @todo ? make use of INFORMATION_SCHEMA
* @todo ? support --skip-showdatabases and user has only global rights
* <code>
* $PMA_List_Database = new PMA_List_Database($userlink, $controllink);
* </code>
* @access public
* @since phpMyAdmin 2.9.10
*/
/*public*/ class PMA_List_Database /* extends PMA_List */ {
/**
* @var array the list items
* @access public
* @todo move into PMA_List
*/
var $items = array();
/*public*/ class PMA_List_Database extends PMA_List
{
/**
* @var mixed database link resource|object to be used
* @access protected
@@ -58,12 +41,6 @@
*/
var $_db_link_control = null;
/**
* @var bool whether we need to re-index the database list for consistency keys
* @access protected
*/
var $_need_to_reindex = false;
/**
* @var boolean whether SHOW DATABASES is disabled or not
* @access protected
@@ -121,11 +98,16 @@
/**
* checks if the configuration wants to hide some databases
*
* @todo temporaly use this docblock to test how to doc $GLOBALS
* @access protected
* @uses PMA_List_Database::$items
* @uses PMA_List_Database::$_need_to_reindex to set it if reuqired
* @uses preg_match()
* @global $cfg
* @uses $GLOBALS['cfg']
* @uses $GLOBALS['cfg']['Server']
* @uses $GLOBALS['cfg']['Server']['hide_db']
* @global array $GLOBALS['cfg']
* @global array $cfg
*/
function _checkHideDatabase()
{
@@ -152,8 +134,8 @@
* @uses PMA_List_Database::$_db_link_control in case of SHOW DATABASES is disabled for userlink
* @uses PMA_DBI_fetch_result()
* @uses PMA_DBI_getError()
* @global $error_showdatabases to alert not allowed SHOW DATABASE
* @global $errno from PMA_DBI_getError()
* @global boolean $error_showdatabases to alert not allowed SHOW DATABASE
* @global integer $errno from PMA_DBI_getError()
* @param string $like_db_name usally a db_name containing wildcards
*/
function _retrieve($like_db_name = '')
@@ -203,7 +185,7 @@
* @uses PMA_MYSQL_INT_VERSION
* @uses array_values()
* @uses natsort()
* @global $cfg
* @global array $cfg
*/
function build()
{
@@ -244,7 +226,7 @@
* @uses is_array()
* @uses strlen()
* @uses is_string()
* @global $cfg
* @global array $cfg
* @return boolean false if there is no only_db, otherwise true
*/
function _checkOnlyDatabase()
@@ -289,104 +271,133 @@
}
/**
* returns first item from list
* returns default item
*
* @todo move into PMA_List
* @uses PMA_List_Database::$items
* @uses reset()
* @return string value of first item
*/
function getFirst()
{
return reset($this->items);
}
/**
* returns item only if there is only one in the list
*
* @todo move into PMA_List
* @uses PMA_List_Database::count()
* @uses PMA_List_Database::getFirst()
* @uses PMA_List_Database::emptyItem()
* @return single item
*/
function getSingleItem()
{
if ($this->count() === 1) {
return $this->getFirst();
}
return $this->emptyItem();
}
/**
* returns list item count
*
* @todo move into PMA_List
* @uses PMA_List_Database::$items
* @uses count()
*/
function count()
{
return count($this->items);
}
/**
* defines what is an empty item (0, '', false or null)
*
* @todo add as abstract into PMA_List
*/
function emptyItem()
{
return '';
}
/**
* checks if the given db names exists in the current list, if there is
* missing at least one item it reutrns false other wise true
*
* @uses PMA_List_Database::$items
* @uses func_get_args()
* @uses in_array()
* @param string $db_name,.. one or more mysql result resources
* @return boolean true if all items exists, otheriwse false
*/
function exists()
{
foreach (func_get_args() as $result) {
if (! in_array($result, $this->items)) {
return false;
}
}
return true;
}
/**
* returns HTML <option>-tags to be used inside <select></select>
*
* @uses PMA_List_Database::$items
* @uses htmlspecialchars()
* @uses PMA_List::getEmpty()
* @uses strlen()
* @global $db
* @param mixed $selected the selected db or true for selecting current db
* @return string HTML option tags
* @global string $db
* @return string default item
*/
function getHtmlOptions($selected = '')
function getDefault()
{
if (true === $selected && strlen($GLOBALS['db'])) {
$selected = $GLOBALS['db'];
}
$options = '';
foreach ($this->items as $each_db) {
$options .= '<option value="' . htmlspecialchars($each_db) . '"';
if ($selected === $each_db) {
$options .= ' selected="selected"';
}
$options .= '>' . htmlspecialchars($each_db) . '</option>' . "\n";
if (strlen($GLOBALS['db'])) {
return $GLOBALS['db'];
}
return $options;
return $this->getEmpty();
}
/**
* returns array with dbs grouped with extended infos
*
* @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_getTableCount()
* @uses PMA_getComments()
* @uses is_array()
* @uses implode()
* @uses strstr()
* @uses explode()
* @return array db list
*/
function getGroupedDetails()
{
$dbgroups = array();
$parts = array();
foreach ($this->items as $key => $db) {
// garvin: Get comments from PMA comments table
$db_tooltip = '';
if ($GLOBALS['cfg']['ShowTooltip']
&& $GLOBALS['cfgRelation']['commwork']) {
$_db_tooltip = PMA_getComments($db);
if (is_array($_db_tooltip)) {
$db_tooltip = implode(' ', $_db_tooltip);
}
}
if ($GLOBALS['cfg']['LeftFrameDBTree']
&& $GLOBALS['cfg']['LeftFrameDBSeparator']
&& strstr($db, $GLOBALS['cfg']['LeftFrameDBSeparator']))
{
// use strpos instead of strrpos; it seems more common to
// have the db name, the separator, then the rest which
// might contain a separator
// like dbname_the_rest
$pos = strpos($db, $GLOBALS['cfg']['LeftFrameDBSeparator']);
$group = substr($db, 0, $pos);
$disp_name_cut = substr($db, $pos);
} else {
$group = $db;
$disp_name_cut = $db;
}
$disp_name = $db;
if ($db_tooltip && $GLOBALS['cfg']['ShowTooltipAliasDB']) {
$disp_name = $db_tooltip;
$disp_name_cut = $db_tooltip;
$db_tooltip = $db;
}
$dbgroups[$group][$db] = array(
'name' => $db,
'disp_name_cut' => $disp_name_cut,
'disp_name' => $disp_name,
'comment' => $db_tooltip,
'num_tables' => PMA_getTableCount($db),
);
} // end foreach ($GLOBALS['PMA_List_Database']->items as $db)
return $dbgroups;
}
/**
* returns html code for select form element with dbs
*
* @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
*
* @return string html code select
*/
function getHtmlSelectGrouped($selected = '')
{
if (true === $selected) {
$selected = $this->getDefault();
}
$return = '<select name="db" id="lightm_db" xml:lang="en" dir="ltr"'
. ' onchange="if (this.value != \'\') window.parent.openDb(this.value);">' . "\n"
. '<option value="" dir="' . $GLOBALS['text_dir'] . '">'
. '(' . $GLOBALS['strDatabases'] . ') ...</option>' . "\n";
foreach ($this->getGroupedDetails() as $group => $dbs) {
if (count($dbs) > 1) {
$return .= '<optgroup label="' . htmlspecialchars($group)
. '">' . "\n";
// wether display db_name cuted by the group part
$cut = true;
} else {
// .. or full
$cut = false;
}
foreach ($dbs as $db) {
$return .= '<option value="' . $db['name'] . '"'
.' title="' . $db['comment'] . '"';
if ($db['name'] == $selected) {
$return .= ' selected="selected"';
}
$return .= '>' . ($cut ? $db['disp_name_cut'] : $db['disp_name'])
.' (' . $db['num_tables'] . ')</option>' . "\n";
}
if (count($dbs) > 1) {
$return .= '</optgroup>' . "\n";
}
}
$return .= '</select>';
return $return;
}
/**

View File

@@ -86,116 +86,6 @@ function PMA_securePath($path)
return $path;
} // end function
/**
* returns array with dbs grouped with extended infos
*
* @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_getTableCount()
* @uses PMA_getComments()
* @uses is_array()
* @uses implode()
* @uses strstr()
* @uses explode()
* @return array db list
*/
function PMA_getDbList()
{
$dbgroups = array();
$parts = array();
foreach ($GLOBALS['PMA_List_Database']->items as $key => $db) {
// garvin: Get comments from PMA comments table
$db_tooltip = '';
if ($GLOBALS['cfg']['ShowTooltip']
&& $GLOBALS['cfgRelation']['commwork']) {
$_db_tooltip = PMA_getComments($db);
if (is_array($_db_tooltip)) {
$db_tooltip = implode(' ', $_db_tooltip);
}
}
if ($GLOBALS['cfg']['LeftFrameDBTree']
&& $GLOBALS['cfg']['LeftFrameDBSeparator']
&& strstr($db, $GLOBALS['cfg']['LeftFrameDBSeparator']))
{
// use strpos instead of strrpos; it seems more common to
// have the db name, the separator, then the rest which
// might contain a separator
// like dbname_the_rest
$pos = strpos($db, $GLOBALS['cfg']['LeftFrameDBSeparator']);
$group = substr($db, 0, $pos);
$disp_name_cut = substr($db, $pos);
} else {
$group = $db;
$disp_name_cut = $db;
}
$disp_name = $db;
if ($db_tooltip && $GLOBALS['cfg']['ShowTooltipAliasDB']) {
$disp_name = $db_tooltip;
$disp_name_cut = $db_tooltip;
$db_tooltip = $db;
}
$dbgroups[$group][$db] = array(
'name' => $db,
'disp_name_cut' => $disp_name_cut,
'disp_name' => $disp_name,
'comment' => $db_tooltip,
'num_tables' => PMA_getTableCount($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 = '')
{
// 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
$return = '<select name="db" id="lightm_db" xml:lang="en" dir="ltr"'
.' onchange="if (this.value != \'\') window.parent.openDb(this.value);">' . "\n"
.'<option value="" dir="' . $GLOBALS['text_dir'] . '">(' . $GLOBALS['strDatabases'] . ') ...</option>'
."\n";
foreach (PMA_getDbList() as $group => $dbs) {
if (count($dbs) > 1) {
$return .= '<optgroup label="' . htmlspecialchars($group)
. '">' . "\n";
// wether display db_name cuted by the group part
$cut = true;
} else {
// .. or full
$cut = false;
}
foreach ($dbs as $db) {
$return .= '<option value="' . $db['name'] . '"'
.' title="' . $db['comment'] . '"';
if ($db['name'] == $selected) {
$return .= ' selected="selected"';
}
$return .= '>' . ($cut ? $db['disp_name_cut'] : $db['disp_name'])
.' (' . $db['num_tables'] . ')</option>' . "\n";
}
if (count($dbs) > 1) {
$return .= '</optgroup>' . "\n";
}
}
$return .= '</select>';
return $return;
}
/**
* returns count of tables in given db
*
@@ -459,11 +349,25 @@ function PMA_getenv($var_name) {
* include here only libraries which contain only function definitions
* no code im main()!
*/
/* Input sanitizing */
/**
* Input sanitizing
*/
require_once './libraries/sanitizing.lib.php';
/**
* the PMA_Theme class
*/
require_once './libraries/Theme.class.php';
/**
* the PMA_Theme_Manager class
*/
require_once './libraries/Theme_Manager.class.php';
/**
* the PMA_Config class
*/
require_once './libraries/Config.class.php';
/**
* the PMA_Table class
*/
require_once './libraries/Table.class.php';
@@ -796,6 +700,9 @@ if (!defined('PMA_MINIMUM_COMMON')) {
{
global $cfg, $table, $db, $sql_query;
/**
* start http output, display html headers
*/
require_once './libraries/header.inc.php';
if (!$error_message) {
@@ -947,6 +854,9 @@ if (!defined('PMA_MINIMUM_COMMON')) {
}
echo ' </fieldset>' . "\n\n";
if ($exit) {
/**
* display footer and exit
*/
require_once './libraries/footer.inc.php';
}
} // end of the 'PMA_mysqlDie()' function
@@ -1035,7 +945,6 @@ if (!defined('PMA_MINIMUM_COMMON')) {
* @uses $GLOBALS['cfg']['LeftFrameTableLevel']
* @uses $GLOBALS['cfg']['ShowTooltipAliasTB']
* @uses $GLOBALS['cfg']['NaturalOrder']
* @uses PMA_DBI_fetch_result()
* @uses PMA_backquote()
* @uses count()
* @uses array_merge
@@ -2138,6 +2047,9 @@ window.parent.updateTableTitle('<?php echo $uni_tbl; ?>', '<?php echo PMA_jsForm
}
}
if ($found_error) {
/**
* display html meta tags
*/
require_once './libraries/header_meta_style.inc.php';
echo '</head><body><p>' . $error_message . '</p></body></html>';
if ($die) {
@@ -2592,7 +2504,9 @@ if (get_magic_quotes_gpc()) {
PMA_arrayWalkRecursive($_REQUEST, 'stripslashes', true);
}
// start session
/**
* start session
*/
require_once './libraries/session.inc.php';
/**
@@ -2607,17 +2521,17 @@ if (empty($__redirect) && !defined('PMA_NO_VARIABLES_IMPORT')) {
*/
/**
* @var array $GLOBALS['PMA_errors'] holds errors
* @global array $GLOBALS['PMA_errors'] holds errors
*/
$GLOBALS['PMA_errors'] = array();
/**
* @var array $GLOBALS['url_params'] holds params to be passed to next page
* @global array $GLOBALS['url_params'] holds params to be passed to next page
*/
$GLOBALS['url_params'] = array();
/**
* @var array whitelist for $goto
* @global array $goto_whitelist the whitelist for $GLOBALS['goto']
*/
$goto_whitelist = array(
//'browse_foreigners.php',
@@ -2691,7 +2605,7 @@ if (! PMA_checkPageValidity($__redirect, $goto_whitelist)) {
}
/**
* @var string $goto holds page that should be displayed
* @global string $GLOBALS['goto'] holds page that should be displayed
*/
// Security fix: disallow accessing serious server files via "?goto="
if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
@@ -2703,7 +2617,7 @@ if (PMA_checkPageValidity($_REQUEST['goto'], $goto_whitelist)) {
}
/**
* @var string $back returning page
* @global string $GLOBALS['back'] returning page
*/
if (PMA_checkPageValidity($_REQUEST['back'], $goto_whitelist)) {
$GLOBALS['back'] = $_REQUEST['back'];
@@ -2747,7 +2661,7 @@ if (! isset($_REQUEST['token']) || $_SESSION['PMA_token'] != $_REQUEST['token'])
/**
* @var string $convcharset
* @global string $convcharset
* @see also select_lang.lib.php
*/
if (isset($_REQUEST['convcharset'])) {
@@ -2755,7 +2669,7 @@ if (isset($_REQUEST['convcharset'])) {
}
/**
* @var string $db current selected database
* @global string $GLOBALS['db'] current selected database
*/
if (isset($_REQUEST['db'])) {
// can we strip tags from this?
@@ -2767,7 +2681,7 @@ if (isset($_REQUEST['db'])) {
}
/**
* @var string $table current selected table
* @global string $GLOBALS['table'] current selected table
*/
if (isset($_REQUEST['table'])) {
// can we strip tags from this?
@@ -2779,7 +2693,7 @@ if (isset($_REQUEST['table'])) {
}
/**
* @var string $sql_query sql query to be executed
* @global string $GLOBALS['sql_query'] sql query to be executed
*/
if (isset($_REQUEST['sql_query'])) {
$GLOBALS['sql_query'] = $_REQUEST['sql_query'];
@@ -3038,7 +2952,11 @@ if (! defined('PMA_MINIMUM_COMMON')) {
);
exit();
}
/**
* the required auth type plugin
*/
require_once './libraries/auth/' . $cfg['Server']['auth_type'] . '.auth.lib.php';
if (!PMA_auth_check()) {
PMA_auth();
} else {
@@ -3054,6 +2972,9 @@ if (! defined('PMA_MINIMUM_COMMON')) {
if (isset($cfg['Server']['AllowDeny'])
&& isset($cfg['Server']['AllowDeny']['order'])) {
/**
* ip based access library
*/
require_once './libraries/ip_allow_deny.lib.php';
$allowDeny_forbidden = false; // default
@@ -3122,7 +3043,9 @@ if (! defined('PMA_MINIMUM_COMMON')) {
@ini_set('track_errors', $bkp_track_err);
unset($bkp_track_err);
/* If we auto switched to utf-8 we need to reread messages here */
/**
* If we auto switched to utf-8 we need to reread messages here
*/
if (defined('PMA_LANG_RELOAD')) {
require './libraries/language.lib.php';
}
@@ -3138,14 +3061,16 @@ if (! defined('PMA_MINIMUM_COMMON')) {
require_once './libraries/sqlvalidator.lib.php';
/**
* database list
* the PMA_List_Database class
*/
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)
/**
* Kanji encoding convert feature appended by Y.Kawada (2002/2/20)
*/
if (@function_exists('mb_convert_encoding')
&& strpos(' ' . $lang, 'ja-')
&& file_exists('./libraries/kanji-encoding.lib.php')) {
@@ -3169,6 +3094,9 @@ if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) {
if (isset($_GET['is_js_confirmed'])) {
$is_js_confirmed = 1;
}
/**
* include subform target page
*/
require $__redirect;
exit();
}