diff --git a/db_operations.php b/db_operations.php index d3a1f0a2b076..517db1098592 100644 --- a/db_operations.php +++ b/db_operations.php @@ -53,7 +53,7 @@ // rebuild the database list because PMA_Table::moveCopy // checks in this list if the target db exists - $GLOBALS['PMA_List_Database']->build(); + $GLOBALS['pma']->databases->build(); } if (isset($GLOBALS['add_constraints'])) { diff --git a/export.php b/export.php index bb1f479986ad..0ce9e6e71b02 100644 --- a/export.php +++ b/export.php @@ -417,7 +417,7 @@ function PMA_exportOutputHandler($line) $tmp_select = '|' . $tmp_select . '|'; } // Walk over databases - foreach ($GLOBALS['PMA_List_Database']->items as $current_db) { + foreach ($GLOBALS['pma']->databases as $current_db) { if ((isset($tmp_select) && strpos(' ' . $tmp_select, '|' . $current_db . '|')) || !isset($tmp_select)) { if (!PMA_exportDBHeader($current_db)) { diff --git a/libraries/List.class.php b/libraries/List.class.php index b531059c8d5d..4758a453c186 100644 --- a/libraries/List.class.php +++ b/libraries/List.class.php @@ -11,86 +11,49 @@ * @since phpMyAdmin 2.9.10 * @abstract */ -/* abstract public */ class PMA_List +abstract class PMA_List extends ArrayObject { - /** - * @var array the list items - * @access public - */ - var $items = array(); - - /** - * @var array details for list items - * @access public - */ - var $details = array(); - - /** - * @var bool whether we need to re-index the database list for consistency keys - * @access protected - */ - var $_need_to_reindex = false; - /** * @var mixed empty item */ - var $item_empty = ''; + protected $item_empty = ''; - /** - * returns first item from list - * - * @uses PMA_List::$items to get first item - * @uses reset() to retrive first item from PMA_List::$items array - * @return string value of first item - */ - function getFirst() + public function __construct($array = array(), $flags = 0, $iterator_class = "ArrayIterator") { - return reset($this->items); + parent::__construct($array, $flags, $iterator_class); } - + /** * returns item only if there is only one in the list * - * @uses PMA_List::count() to decide what to return - * @uses PMA_List::getFirst() to return it + * @uses count() + * @uses reset() * @uses PMA_List::getEmpty() to return it * @return single item */ - function getSingleItem() + public function getSingleItem() { - if ($this->count() === 1) { - return $this->getFirst(); + if (count($this) === 1) { + return reset($this); } return $this->getEmpty(); } - /** - * returns list item count - * - * @uses PMA_List::$items to count it items - * @uses count() to count items in PMA_List::$items - * @return integer PMA_List::$items count - */ - function count() - { - return count($this->items); - } - /** * defines what is an empty item (0, '', false or null) * * @uses PMA_List::$item_empty as return value * @return mixed an empty item */ - function getEmpty() + public function getEmpty() { return $this->item_empty; } /** * 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 + * missing at least one item it returns false other wise true * * @uses PMA_List::$items to check for existence of specific item * @uses func_get_args() @@ -98,10 +61,10 @@ function getEmpty() * @param string $db_name,.. one or more mysql result resources * @return boolean true if all items exists, otheriwse false */ - function exists() + public function exists() { foreach (func_get_args() as $result) { - if (! in_array($result, $this->items)) { + if (! in_array($result, $this)) { return false; } } @@ -119,22 +82,22 @@ function exists() * @param boolean $include_information_schema * @return string HTML option tags */ - function getHtmlOptions($selected = '', $include_information_schema = true) + public function getHtmlOptions($selected = '', $include_information_schema = true) { if (true === $selected) { $selected = $this->getDefault(); } $options = ''; - foreach ($this->items as $each_db) { - if (false === $include_information_schema && 'information_schema' === $each_db) { + foreach ($this as $each_item) { + if (false === $include_information_schema && 'information_schema' === $each_item) { continue; } - $options .= '' . "\n"; } return $options; @@ -146,7 +109,7 @@ function getHtmlOptions($selected = '', $include_information_schema = true) * @uses PMA_List::getEmpty() as fallback * @return string default item */ - function getDefault() + public function getDefault() { return $this->getEmpty(); } @@ -154,8 +117,7 @@ function getDefault() /** * builds up the list * - * @abstract */ - /* abstract public */ function build() {} + abstract public function build(); } ?> diff --git a/libraries/List_Database.class.php b/libraries/List_Database.class.php index a553641b5d82..0cf60574d2ff 100644 --- a/libraries/List_Database.class.php +++ b/libraries/List_Database.class.php @@ -28,33 +28,29 @@ { /** * @var mixed database link resource|object to be used - * @access protected */ - var $_db_link = null; + protected $_db_link = null; /** * @var mixed user database link resource|object - * @access protected */ - var $_db_link_user = null; + protected $_db_link_user = null; /** * @var mixed controluser database link resource|object - * @access protected */ - var $_db_link_control = null; + protected $_db_link_control = null; /** * @var boolean whether SHOW DATABASES is disabled or not * @access protected */ - var $_show_databases_disabled = false; + protected $_show_databases_disabled = false; /** * @var string command to retrieve databases from server - * @access protected */ - var $_command = null; + protected $_command = null; /** * Constructor @@ -66,11 +62,13 @@ * @param mixed $db_link_user user database link resource|object * @param mixed $db_link_control control database link resource|object */ - function __construct($db_link_user = null, $db_link_control = null) { + public function __construct($db_link_user = null, $db_link_control = null) + { $this->_db_link = $db_link_user; $this->_db_link_user = $db_link_user; $this->_db_link_control = $db_link_control; + parent::__construct(); $this->build(); } @@ -78,32 +76,27 @@ function __construct($db_link_user = null, $db_link_control = null) { * 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() * @uses $cfg['Server']['hide_db'] */ - function _checkHideDatabase() + protected function _checkHideDatabase() { if (empty($GLOBALS['cfg']['Server']['hide_db'])) { return; } - foreach ($this->items as $key => $db) { + foreach ($this as $key => $db) { if (preg_match('/' . $GLOBALS['cfg']['Server']['hide_db'] . '/', $db)) { - unset($this->items[$key]); + $this->offsetUnset($key); } } - // re-index values - $this->_need_to_reindex = true; } /** * retrieves database list from server * * @todo we could also search mysql tables if all fail? - * @access protected * @uses PMA_List_Database::$_show_databases_disabled for not retrying if SHOW DATABASES is disabled * @uses PMA_List_Database::$_db_link * @uses PMA_List_Database::$_db_link_control in case of SHOW DATABASES is disabled for userlink @@ -113,7 +106,7 @@ function _checkHideDatabase() * @uses $GLOBALS['errno'] * @param string $like_db_name usally a db_name containing wildcards */ - function _retrieve($like_db_name = null) + protected function _retrieve($like_db_name = null) { if ($this->_show_databases_disabled) { return array(); @@ -156,7 +149,6 @@ function _retrieve($like_db_name = null) * builds up the list * * @uses PMA_List_Database::$items to initialize it - * @uses PMA_List_Database::$_need_to_reindex * @uses PMA_List_Database::_checkOnlyDatabase() * @uses PMA_List_Database::_retrieve() * @uses PMA_List_Database::_checkHideDatabase() @@ -164,23 +156,17 @@ function _retrieve($like_db_name = null) * @uses natsort() * @uses $cfg['NaturalOrder'] */ - function build() + public function build() { - $this->items = array(); - if (! $this->_checkOnlyDatabase()) { - $this->items = $this->_retrieve(); + $items = $this->_retrieve(); if ($GLOBALS['cfg']['NaturalOrder']) { - natsort($this->items); - $this->_need_to_reindex = true; + natsort($items); } + $this->exchangeArray($items); } - + $this->_checkHideDatabase(); - - if ($this->_need_to_reindex) { - $this->items = array_values($this->items); - } } /** @@ -199,7 +185,7 @@ function build() * @uses $cfg['Server']['only_db'] * @return boolean false if there is no only_db, otherwise true */ - function _checkOnlyDatabase() + protected function _checkOnlyDatabase() { if (is_string($GLOBALS['cfg']['Server']['only_db']) && strlen($GLOBALS['cfg']['Server']['only_db'])) { @@ -211,12 +197,14 @@ function _checkOnlyDatabase() if (! is_array($GLOBALS['cfg']['Server']['only_db'])) { return false; } + + $items = array(); foreach ($GLOBALS['cfg']['Server']['only_db'] as $each_only_db) { if ($each_only_db === '*' && ! $this->_show_databases_disabled) { // append all not already listed dbs to the list - $this->items = array_merge($this->items, - array_diff($this->_retrieve(), $this->items)); + $items = array_merge($items, + array_diff($this->_retrieve(), $items)); // there can only be one '*', and this can only be last break; } @@ -225,17 +213,19 @@ function _checkOnlyDatabase() // thus containing not escaped _ or % if (! preg_match('/(^|[^\\\\])(_|%)/', $each_only_db)) { // ... not contains wildcard - $this->items[] = PMA_unescape_mysql_wildcards($each_only_db); + $items[] = PMA_unescape_mysql_wildcards($each_only_db); continue; } if (! $this->_show_databases_disabled) { - $this->items = array_merge($this->items, $this->_retrieve($each_only_db)); + $items = array_merge($items, $this->_retrieve($each_only_db)); continue; } // @todo induce error, about not using wildcards with SHOW DATABASE disabled? } + + $this->exchangeArray($items); return true; } @@ -248,7 +238,7 @@ function _checkOnlyDatabase() * @uses strlen() * @return string default item */ - function getDefault() + public function getDefault() { if (strlen($GLOBALS['db'])) { return $GLOBALS['db']; @@ -276,7 +266,7 @@ function getDefault() * @param integer $count * @return array db list */ - function getGroupedDetails($offset, $count) + public function getGroupedDetails($offset, $count) { $dbgroups = array(); $parts = array(); @@ -334,15 +324,14 @@ function getGroupedDetails($offset, $count) /** * returns a part of the items * - * @uses PMA_List_Database::$items * @uses array_slice() * @param integer $offset * @param integer $count * @return array some items */ - function getLimitedItems($offset, $count) + public function getLimitedItems($offset, $count) { - return(array_slice($this->items, $offset, $count)); + return array_slice($this->getArrayCopy(), $offset, $count); } /** @@ -350,7 +339,7 @@ function getLimitedItems($offset, $count) * * @return string html code list */ - function getHtmlListGrouped($selected = '', $offset, $count) + public function getHtmlListGrouped($selected = '', $offset, $count) { if (true === $selected) { $selected = $this->getDefault(); @@ -406,7 +395,7 @@ function getHtmlListGrouped($selected = '', $offset, $count) * * @return string html code select */ - function getHtmlSelectGrouped($selected = '', $offset, $count) + public function getHtmlSelectGrouped($selected = '', $offset, $count) { if (true === $selected) { $selected = $this->getDefault(); @@ -451,9 +440,8 @@ function getHtmlSelectGrouped($selected = '', $offset, $count) * this is just a backup, if all is fine this can be deleted later * * @deprecated - * @access protected */ - function _checkAgainstPrivTables() + protected function _checkAgainstPrivTables() { // 1. get allowed dbs from the "mysql.db" table // lem9: User can be blank (anonymous user) diff --git a/libraries/PMA.php b/libraries/PMA.php new file mode 100644 index 000000000000..25c69f61997a --- /dev/null +++ b/libraries/PMA.php @@ -0,0 +1,94 @@ +getDatabaseList(); + break; + case 'userlink' : + return $this->userlink; + break; + case 'controllink' : + return $this->controllink; + break; + } + + return null; + } + + /** + * magic access to protected/inaccessible members/properties + * + * @see http://php.net/language.oop5.overloading + */ + public function __set($param, $value) + { + switch ($param) { + case 'userlink' : + $this->userlink = $value; + break; + case 'controllink' : + $this->controllink = $value; + break; + } + } + + /** + * Accessor to PMA::$databases + * + * @uses PMA::$databases + * @uses PMA::$userlink + * @uses PMA::$controllink + * @uses PMA_List_Database + * @return PMA_List_Databases + */ + public function getDatabaseList() + { + if (null === $this->databases) { + $this->databases = new PMA_List_Database($this->userlink, $this->controllink); + } + + return $this->databases; + } +} +?> \ No newline at end of file diff --git a/libraries/Table.class.php b/libraries/Table.class.php index 94fe7d99c24f..9ef9ba8afc6c 100644 --- a/libraries/Table.class.php +++ b/libraries/Table.class.php @@ -559,12 +559,12 @@ static public function moveCopy($source_db, $source_table, $target_db, $target_t $GLOBALS['asfile'] = 1; // Ensure the target is valid - if (! $GLOBALS['PMA_List_Database']->exists($source_db, $target_db)) { - if (! $GLOBALS['PMA_List_Database']->exists($source_db)) { + if (! $GLOBALS['pma']->databases->exists($source_db, $target_db)) { + if (! $GLOBALS['pma']->databases->exists($source_db)) { $GLOBALS['message'] = PMA_Message::rawError('source database `' . htmlspecialchars($source_db) . '` not found'); } - if (! $GLOBALS['PMA_List_Database']->exists($target_db)) { + if (! $GLOBALS['pma']->databases->exists($target_db)) { $GLOBALS['message'] = PMA_Message::rawError('target database `' . htmlspecialchars($target_db) . '` not found'); } @@ -951,7 +951,7 @@ function rename($new_name, $new_db = null) { if (null !== $new_db && $new_db !== $this->getDbName()) { // Ensure the target is valid - if (! $GLOBALS['PMA_List_Database']->exists($new_db)) { + if (! $GLOBALS['pma']->databases->exists($new_db)) { $this->errors[] = $GLOBALS['strInvalidDatabase'] . ': ' . $new_db; return false; } diff --git a/libraries/common.inc.php b/libraries/common.inc.php index faafa4df64ee..fde9f71e089c 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -907,9 +907,11 @@ /** * the PMA_List_Database class */ - require_once './libraries/List_Database.class.php'; - $PMA_List_Database = new PMA_List_Database($userlink, $controllink); - + require_once './libraries/PMA.php'; + $pma = new PMA; + $pma->userlink = $userlink; + $pma->controllink = $controllink; + /** * some resetting has to be done when switching servers */ diff --git a/libraries/database_interface.lib.php b/libraries/database_interface.lib.php index b33ff8f1a75d..29a27db8cd9c 100644 --- a/libraries/database_interface.lib.php +++ b/libraries/database_interface.lib.php @@ -487,7 +487,7 @@ function PMA_DBI_get_databases_full($database = null, $force_stats = false, // 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); + $drops = array_diff(array_keys($databases), $GLOBALS['pma']->databases); if (count($drops)) { foreach ($drops as $drop) { unset($databases[$drop]); @@ -496,7 +496,7 @@ function PMA_DBI_get_databases_full($database = null, $force_stats = false, } unset($sql_where_schema, $sql, $drops); } else { - foreach ($GLOBALS['PMA_List_Database']->items as $database_name) { + foreach ($GLOBALS['pma']->databases 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; @@ -630,7 +630,7 @@ function PMA_DBI_get_columns_full($database = null, $table = null, unset($sql_wheres, $sql); } else { if (null === $database) { - foreach ($GLOBALS['PMA_List_Database']->items as $database) { + foreach ($GLOBALS['pma']->databases as $database) { $columns[$database] = PMA_DBI_get_columns_full($database, null, null, $link); } diff --git a/libraries/mult_submits.inc.php b/libraries/mult_submits.inc.php index 5180fda05279..2e9b8274d896 100644 --- a/libraries/mult_submits.inc.php +++ b/libraries/mult_submits.inc.php @@ -420,7 +420,7 @@ if ($rebuild_database_list) { // avoid a problem with the database list navigator // when dropping a db from server_databases - $GLOBALS['PMA_List_Database']->build(); + $GLOBALS['pma']->databases->build(); } } ?> diff --git a/navigation.php b/navigation.php index c2053bebc038..b814b385196f 100644 --- a/navigation.php +++ b/navigation.php @@ -4,7 +4,7 @@ * the navigation frame - displays server, db and table selection tree * * @version $Id$ - * @uses $GLOBALS['PMA_List_Database'] + * @uses $GLOBALS['pma']->databases * @uses $GLOBALS['server'] * @uses $GLOBALS['db'] * @uses $GLOBALS['table'] @@ -24,7 +24,6 @@ * @uses $GLOBALS['cfg']['DefaultTabDatabase'] * @uses $GLOBALS['cfgRelation']['commwork']) { * @uses PMA_List_Database::getSingleItem() - * @uses PMA_List_Database::count() * @uses PMA_List_Database::getHtmlSelectGrouped() * @uses PMA_List_Database::getGroupedDetails() * @uses PMA_generate_common_url() @@ -86,7 +85,7 @@ function PMA_exitNavigationFrame() * selects the database if there is only one on current server */ if ($GLOBALS['server'] && ! strlen($GLOBALS['db'])) { - $GLOBALS['db'] = $GLOBALS['PMA_List_Database']->getSingleItem(); + $GLOBALS['db'] = $GLOBALS['pma']->databases->getSingleItem(); } $db_start = $GLOBALS['db']; @@ -188,11 +187,11 @@ function PMA_exitNavigationFrame() if (! $GLOBALS['server']) { // no server selected PMA_exitNavigationFrame(); -} elseif (! $GLOBALS['PMA_List_Database']->count()) { +} elseif (! count($GLOBALS['pma']->databases)) { // no database available, so we break here echo '

' . $GLOBALS['strNoDatabases'] . '

'; PMA_exitNavigationFrame(); -} elseif ($GLOBALS['cfg']['LeftFrameLight'] && $GLOBALS['PMA_List_Database']->count() > 1) { +} elseif ($GLOBALS['cfg']['LeftFrameLight'] && count($GLOBALS['pma']->databases) > 1) { $list = $cfg['DisplayDatabasesList']; if ($list === 'auto') { if (empty($GLOBALS['db'])) { @@ -216,7 +215,7 @@ function PMA_exitNavigationFrame() getHtmlSelectGrouped(true, $_SESSION['userconf']['navi_limit_offset'], $GLOBALS['cfg']['MaxDbList']) . "\n"; + echo $GLOBALS['pma']->databases->getHtmlSelectGrouped(true, $_SESSION['userconf']['navi_limit_offset'], $GLOBALS['cfg']['MaxDbList']) . "\n"; echo '' . "\n" @@ -225,10 +224,10 @@ function PMA_exitNavigationFrame() if (! empty($db)) { echo '
' . "\n"; } - echo $GLOBALS['PMA_List_Database']->getHtmlListGrouped(true, $_SESSION['userconf']['navi_limit_offset'], $GLOBALS['cfg']['MaxDbList']) . "\n"; + echo $GLOBALS['pma']->databases->getHtmlListGrouped(true, $_SESSION['userconf']['navi_limit_offset'], $GLOBALS['cfg']['MaxDbList']) . "\n"; } $_url_params = array('pos' => $pos); - PMA_listNavigator($GLOBALS['PMA_List_Database']->count(), $pos, $_url_params, 'navigation.php', 'frame_navigation', $GLOBALS['cfg']['MaxDbList']); + PMA_listNavigator(count($GLOBALS['pma']->databases), $pos, $_url_params, 'navigation.php', 'frame_navigation', $GLOBALS['cfg']['MaxDbList']); if (! empty($db)) { echo '
' . "\n"; } @@ -321,11 +320,11 @@ function PMA_exitNavigationFrame() } else { echo '
' . "\n"; $_url_params = array('pos' => $pos); - PMA_listNavigator($GLOBALS['PMA_List_Database']->count(), $pos, $_url_params, 'navigation.php', 'frame_navigation', $GLOBALS['cfg']['MaxDbList']); + PMA_listNavigator(count($GLOBALS['pma']->databases), $pos, $_url_params, 'navigation.php', 'frame_navigation', $GLOBALS['cfg']['MaxDbList']); echo '
' . "\n"; $common_url_query = PMA_generate_common_url(); - PMA_displayDbList($GLOBALS['PMA_List_Database']->getGroupedDetails($_SESSION['userconf']['navi_limit_offset'],$GLOBALS['cfg']['MaxDbList']), $_SESSION['userconf']['navi_limit_offset'],$GLOBALS['cfg']['MaxDbList']); + PMA_displayDbList($GLOBALS['pma']->databases->getGroupedDetails($_SESSION['userconf']['navi_limit_offset'],$GLOBALS['cfg']['MaxDbList']), $_SESSION['userconf']['navi_limit_offset'],$GLOBALS['cfg']['MaxDbList']); } /** @@ -357,13 +356,13 @@ function PMA_displayDbList($ext_dblist, $offset, $count) { // 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['PMA_List_Database']->getLimitedItems($offset, $count)); + $tables_full = PMA_DBI_get_tables_full($GLOBALS['pma']->databases->getLimitedItems($offset, $count)); $url_dbgroup = ''; echo ''; @@ -402,7 +401,7 @@ function PMA_displayDbList($ext_dblist, $offset, $count) { // Displays the database name echo '
  • ' . "\n"; - if ($GLOBALS['PMA_List_Database']->count() > 1) { + if (count($GLOBALS['pma']->databases) > 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 @@ -475,7 +474,7 @@ function PMA_displayDbList($ext_dblist, $offset, $count) { $tables = PMA_getTableList($db['name']); } $child_visible = - (bool) ($GLOBALS['PMA_List_Database']->count() === 1 || $db_start == $db['name']); + (bool) (count($GLOBALS['pma']->databases) === 1 || $db_start == $db['name']); PMA_displayTableList($tables, $child_visible, '', $db['name']); } elseif ($GLOBALS['cfg']['LeftFrameLight']) { // no tables and LeftFrameLight: diff --git a/server_databases.php b/server_databases.php index 11c5d604d40d..520f86fb34ee 100644 --- a/server_databases.php +++ b/server_databases.php @@ -92,7 +92,7 @@ if ($server > 0) { $databases = PMA_DBI_get_databases_full(null, $dbstats, null, $sort_by, $sort_order, $pos, true); - $databases_count = $PMA_List_Database->count(); + $databases_count = count($GLOBALS['pma']->databases); } else { $databases_count = 0; } diff --git a/server_export.php b/server_export.php index ea79c169a5a5..bc39f43c8d3a 100644 --- a/server_export.php +++ b/server_export.php @@ -30,7 +30,7 @@ $multi_values .= '
    -count() > $GLOBALS['cfg']['MaxDbList']) { +databases) > $GLOBALS['cfg']['MaxDbList']) { ?>
    -count() > $GLOBALS['cfg']['MaxDbList']) { +databases) > $GLOBALS['cfg']['MaxDbList']) { ?>