From b26895ed59c9a4b1742cf76e1e49d83e4db80d5f Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Sun, 3 Mar 2013 08:14:29 -0500 Subject: [PATCH 1/4] bug #3840 When exporting to gzip format, the data is compressed 2 times --- ChangeLog | 1 + export.php | 39 +++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index e0d14daa58..13c74a8ca2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -95,6 +95,7 @@ underscore - No longer package .travis.yml configuration file when creating a release. - bug #3830 Can't export custom query because it lowercases table names - bug #3829 Enabling query profiling crashes javascript based navigation +- bug #3840 When exporting to gzip format, the data is compressed 2 times 3.5.8.0 (not yet released) - bug #3828 MariaDB reported as MySQL diff --git a/export.php b/export.php index 429bc1db32..88fab5f7ad 100644 --- a/export.php +++ b/export.php @@ -137,7 +137,27 @@ $dump_buffer_len = 0; // We send fake headers to avoid browser timeout when buffering $time_start = time(); - +/** + * Detect whether gzencode is needed; it might not be needed if + * the server is already compressing by itself + * + * @return bool Whether gzencode is needed + */ +function PMA_gzencodeNeeded() +{ + if (@function_exists('gzencode') + && ! @ini_get('zlib.output_compression') + // Here, we detect Apache's mod_deflate so we bet that + // this module is active for this instance of phpMyAdmin + // and therefore, will gzip encode the content + && ! (function_exists('apache_get_modules') + && in_array('mod_deflate', apache_get_modules())) + ) { + return true; + } else { + return false; + } +} /** * Output handler for all exports, if needed buffering, it stores data into * $dump_buffer, otherwise it prints thems out. @@ -180,10 +200,10 @@ function PMA_exportOutputHandler($line) ) { $dump_buffer = bzcompress($dump_buffer); } elseif ($GLOBALS['compression'] == 'gzip' - && @function_exists('gzencode') + && PMA_gzencodeNeeded() ) { // as a gzipped file - // without the optional parameter level because it bug + // without the optional parameter level because it bugs $dump_buffer = gzencode($dump_buffer); } if ($GLOBALS['save_on_server']) { @@ -765,19 +785,10 @@ if (! empty($asfile)) { if (@function_exists('bzcompress')) { $dump_buffer = bzcompress($dump_buffer); } - } elseif ($compression == 'gzip') { + } elseif ($compression == 'gzip' && PMA_gzencodeNeeded()) { // 3. as a gzipped file - if (@function_exists('gzencode') - && ! @ini_get('zlib.output_compression') - // Here, we detect Apache's mod_deflate so we bet that - // this module is active for this instance of phpMyAdmin - // and therefore, will gzip encode the content - && ! (function_exists('apache_get_modules') - && in_array('mod_deflate', apache_get_modules())) - ) { - // without the optional parameter level because it bug + // without the optional parameter level because it bugs $dump_buffer = gzencode($dump_buffer); - } } /* If we saved on server, we have to close file now */ From 9e69186e58a93390a98f463d67325e7ca0852b02 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Thu, 7 Mar 2013 08:00:39 -0500 Subject: [PATCH 2/4] Remove incorrect ChangeLog entry --- ChangeLog | 1 - 1 file changed, 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 13c74a8ca2..e0d14daa58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -95,7 +95,6 @@ underscore - No longer package .travis.yml configuration file when creating a release. - bug #3830 Can't export custom query because it lowercases table names - bug #3829 Enabling query profiling crashes javascript based navigation -- bug #3840 When exporting to gzip format, the data is compressed 2 times 3.5.8.0 (not yet released) - bug #3828 MariaDB reported as MySQL From ad2f0309cdff2f998bbfe288d67abdede7092dd2 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Thu, 7 Mar 2013 13:00:44 -0500 Subject: [PATCH 3/4] Partial fix for bug #3820 (hide_db) --- libraries/navigation/Nodes/Node.class.php | 44 +++++++++++++++-------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index df45a0b9ed..486ecc82bf 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -359,15 +359,10 @@ class Node */ public function getData($type, $pos, $searchClause = '') { + // @todo obey the DisableIS directive $query = "SELECT `SCHEMA_NAME` "; $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; - if (! empty($searchClause)) { - $query .= "WHERE `SCHEMA_NAME` LIKE '%"; - $query .= PMA_Util::sqlAddSlashes( - $searchClause, true - ); - $query .= "%' "; - } + $query .= $this->getWhereClause($searchClause); $query .= "ORDER BY `SCHEMA_NAME` ASC "; $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}"; return PMA_DBI_fetch_result($query); @@ -399,13 +394,7 @@ class Node if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $query = "SELECT COUNT(*) "; $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; - if (! empty($searchClause)) { - $query .= "WHERE `SCHEMA_NAME` LIKE '%"; - $query .= PMA_Util::sqlAddSlashes( - $searchClause, true - ); - $query .= "%' "; - } + $query .= $this->getWhereClause($searchClause); $retval = (int)PMA_DBI_fetch_value($query); } else { $query = "SHOW DATABASES "; @@ -420,5 +409,32 @@ class Node } return $retval; } + + /** + * Returns the WHERE clause depending on the $searchClause parameter + * and the hide_db directive + * + * @param string $searchClause A string used to filter the results of the query + * + * @return string + */ + private function getWhereClause($searchClause = '') + { + $whereClause = "WHERE TRUE "; + if (! empty($searchClause)) { + $whereClause .= "AND `SCHEMA_NAME` LIKE '%"; + $whereClause .= PMA_Util::sqlAddSlashes( + $searchClause, true + ); + $whereClause .= "%' "; + } + + if (! empty($GLOBALS['cfg']['Server']['hide_db'])) { + $whereClause .= "AND `SCHEMA_NAME` NOT REGEXP '" + . $GLOBALS['cfg']['Server']['hide_db'] . "' "; + } + return $whereClause; + } + } ?> From 299107387ee2fbe0bfe8662211e496ecc1d75342 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Fri, 8 Mar 2013 06:15:46 -0500 Subject: [PATCH 4/4] Coding style fix --- libraries/navigation/Nodes/Node.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/navigation/Nodes/Node.class.php b/libraries/navigation/Nodes/Node.class.php index 486ecc82bf..a0ecbd8b68 100644 --- a/libraries/navigation/Nodes/Node.class.php +++ b/libraries/navigation/Nodes/Node.class.php @@ -362,7 +362,7 @@ class Node // @todo obey the DisableIS directive $query = "SELECT `SCHEMA_NAME` "; $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; - $query .= $this->getWhereClause($searchClause); + $query .= $this->_getWhereClause($searchClause); $query .= "ORDER BY `SCHEMA_NAME` ASC "; $query .= "LIMIT $pos, {$GLOBALS['cfg']['MaxNavigationItems']}"; return PMA_DBI_fetch_result($query); @@ -394,7 +394,7 @@ class Node if (! $GLOBALS['cfg']['Servers'][$GLOBALS['server']]['DisableIS']) { $query = "SELECT COUNT(*) "; $query .= "FROM `INFORMATION_SCHEMA`.`SCHEMATA` "; - $query .= $this->getWhereClause($searchClause); + $query .= $this->_getWhereClause($searchClause); $retval = (int)PMA_DBI_fetch_value($query); } else { $query = "SHOW DATABASES "; @@ -418,7 +418,7 @@ class Node * * @return string */ - private function getWhereClause($searchClause = '') + private function _getWhereClause($searchClause = '') { $whereClause = "WHERE TRUE "; if (! empty($searchClause)) {