From ca44c117a29e60bbe7c33220e2f9a7b484b8d62a Mon Sep 17 00:00:00 2001 From: Sebastian Mendel Date: Thu, 21 Sep 2006 12:59:57 +0000 Subject: [PATCH] moved some more code into class, some documentation improvements --- ChangeLog | 2 + left.php | 4 +- libraries/PMA_List_Database.class.php | 279 +++++++++++++------------- libraries/common.lib.php | 178 +++++----------- 4 files changed, 202 insertions(+), 261 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3f33ea5cd..f85caa145 100755 --- a/ChangeLog +++ b/ChangeLog @@ -7,6 +7,8 @@ $Source$ 2006-09-21 Sebastian Mendel * 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 ### 2.9.0 released from QA_2_9 diff --git a/left.php b/left.php index 5ded8648c..7be533cfc 100644 --- a/left.php +++ b/left.php @@ -230,7 +230,7 @@ if (! $GLOBALS['PMA_List_Database']->count()) { getHtmlSelectGrouped(true) . "\n"; echo '' . "\n" @@ -306,7 +306,7 @@ if ($GLOBALS['cfg']['LeftFrameLight'] && isset($db) && strlen($db)) { echo '

' . $GLOBALS['strSelectADb'] . '

' . "\n"; } else { $common_url_query = PMA_generate_common_url(); - PMA_displayDbList(PMA_getDbList()); + PMA_displayDbList($GLOBALS['PMA_List_Database']->getGroupedDetails()); } /** diff --git a/libraries/PMA_List_Database.class.php b/libraries/PMA_List_Database.class.php index e244f68ee..b4cdef282 100644 --- a/libraries/PMA_List_Database.class.php +++ b/libraries/PMA_List_Database.class.php @@ -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 + * + * $PMA_List_Database = new PMA_List_Database($userlink, $controllink); + * * @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