diff --git a/export.php b/export.php index 7b6cb7a389..ed232c5cb4 100644 --- a/export.php +++ b/export.php @@ -295,62 +295,13 @@ if (!defined('TESTSUITE')) { // Generate filename and mime type if needed if ($asfile) { - $pma_uri_parts = parse_url($cfg['PmaAbsoluteUri']); - if ($export_type == 'server') { - if (isset($remember_template)) { - $GLOBALS['PMA_Config']->setUserValue( - 'pma_server_filename_template', - 'Export/file_template_server', - $filename_template - ); - } - } elseif ($export_type == 'database') { - if (isset($remember_template)) { - $GLOBALS['PMA_Config']->setUserValue( - 'pma_db_filename_template', - 'Export/file_template_database', - $filename_template - ); - } - } else { - if (isset($remember_template)) { - $GLOBALS['PMA_Config']->setUserValue( - 'pma_table_filename_template', - 'Export/file_template_table', - $filename_template - ); - } - } - $filename = PMA_Util::expandUserString($filename_template); - // remove dots in filename (coming from either the template or already - // part of the filename) to avoid a remote code execution vulnerability - $filename = PMA_sanitizeFilename($filename, $replaceDots = true); - - // Grab basic dump extension and mime type - // Check if the user already added extension; - // get the substring where the extension would be if it was included - $extension_start_pos = strlen($filename) - strlen( - $export_plugin->getProperties()->getExtension() - ) - 1; - $user_extension = substr($filename, $extension_start_pos, strlen($filename)); - $required_extension = "." . $export_plugin->getProperties()->getExtension(); - if (strtolower($user_extension) != $required_extension) { - $filename .= $required_extension; - } - $mime_type = $export_plugin->getProperties()->getMimeType(); - - // If dump is going to be compressed, set correct mime_type and add - // compression to extension - if ($compression == 'bzip2') { - $filename .= '.bz2'; - $mime_type = 'application/x-bzip2'; - } elseif ($compression == 'gzip') { - $filename .= '.gz'; - $mime_type = 'application/x-gzip'; - } elseif ($compression == 'zip') { - $filename .= '.zip'; - $mime_type = 'application/zip'; + if (empty($remember_template)) { + $remember_template = ''; } + list($filename, $mime_type) = PMA_getExportFilenameAndMimetype( + $export_type, $remember_template, $export_plugin, $compression, + $filename_template + ); } // Open file on server if needed diff --git a/libraries/export.lib.php b/libraries/export.lib.php index aa047d6d34..a29f907cac 100644 --- a/libraries/export.lib.php +++ b/libraries/export.lib.php @@ -221,4 +221,77 @@ function PMA_getMemoryLimitForExport() $memory_limit /= 8; return $memory_limit; } + +/** + * Return the filename and MIME type for export file + * + * @param string $export_type type of export + * @param string $remember_template whether to remember template + * @param object $export_plugin the export plugin + * @param string $compression compression asked + * @param string $filename_template the filename template + * + * @return array the filename template and mime type + */ +function PMA_getExportFilenameAndMimetype( + $export_type, $remember_template, $export_plugin, $compression, + $filename_template +) { + if ($export_type == 'server') { + if (! empty($remember_template)) { + $GLOBALS['PMA_Config']->setUserValue( + 'pma_server_filename_template', + 'Export/file_template_server', + $filename_template + ); + } + } elseif ($export_type == 'database') { + if (! empty($remember_template)) { + $GLOBALS['PMA_Config']->setUserValue( + 'pma_db_filename_template', + 'Export/file_template_database', + $filename_template + ); + } + } else { + if (! empty($remember_template)) { + $GLOBALS['PMA_Config']->setUserValue( + 'pma_table_filename_template', + 'Export/file_template_table', + $filename_template + ); + } + } + $filename = PMA_Util::expandUserString($filename_template); + // remove dots in filename (coming from either the template or already + // part of the filename) to avoid a remote code execution vulnerability + $filename = PMA_sanitizeFilename($filename, $replaceDots = true); + + // Grab basic dump extension and mime type + // Check if the user already added extension; + // get the substring where the extension would be if it was included + $extension_start_pos = strlen($filename) - strlen( + $export_plugin->getProperties()->getExtension() + ) - 1; + $user_extension = substr($filename, $extension_start_pos, strlen($filename)); + $required_extension = "." . $export_plugin->getProperties()->getExtension(); + if (strtolower($user_extension) != $required_extension) { + $filename .= $required_extension; + } + $mime_type = $export_plugin->getProperties()->getMimeType(); + + // If dump is going to be compressed, set correct mime_type and add + // compression to extension + if ($compression == 'bzip2') { + $filename .= '.bz2'; + $mime_type = 'application/x-bzip2'; + } elseif ($compression == 'gzip') { + $filename .= '.gz'; + $mime_type = 'application/x-gzip'; + } elseif ($compression == 'zip') { + $filename .= '.zip'; + $mime_type = 'application/zip'; + } + return array($filename, $mime_type); +} ?> diff --git a/libraries/server_collations.lib.php b/libraries/server_collations.lib.php index 3c34d4ce5d..39855c8205 100644 --- a/libraries/server_collations.lib.php +++ b/libraries/server_collations.lib.php @@ -32,23 +32,14 @@ function PMA_getHtmlForCharsets($mysql_charsets, $mysql_collations, */ $html = '
' . "\n" . '' . "\n" - . '' . "\n" + . '' . "\n" . ' ' . "\n" . '' . "\n"; - $i = 0; $table_row_count = count($mysql_charsets) + count($mysql_collations); foreach ($mysql_charsets as $current_charset) { - if ($i >= $table_row_count / 2) { - $i = 0; - $html .= '
' . __('Collation') . '
' . __('Collation') . '' . __('Description') . '
' . "\n" - . '' . "\n" - . '' . "\n" - . ' ' . "\n" - . '' . "\n"; - } - $i++; + $html .= '
' . __('Collation') . '' . __('Description') . '
' . "\n" . ' ' . htmlspecialchars($current_charset) . "\n" . (empty($mysql_charsets_descriptions[$current_charset]) @@ -62,10 +53,10 @@ function PMA_getHtmlForCharsets($mysql_charsets, $mysql_collations, $html .= PMA_getHtmlForCollationCurrentCharset( $current_charset, $mysql_collations, - $i, $mysql_default_collations, $mysql_collations_available ); + } unset($table_row_count); $html .= '
' . "\n" @@ -79,20 +70,19 @@ function PMA_getHtmlForCharsets($mysql_charsets, $mysql_collations, * * @param String $current_charset Current Charset * @param Array $mysql_collations Collations list - * @param int &$i Display Index * @param Array $mysql_default_collations Default Collations list * @param Array $mysql_collations_available Available Collations list * * @return string */ function PMA_getHtmlForCollationCurrentCharset( - $current_charset, $mysql_collations, &$i, + $current_charset, $mysql_collations, $mysql_default_collations, $mysql_collations_available ) { $odd_row = true; $html = ''; foreach ($mysql_collations[$current_charset] as $current_collation) { - $i++; + $html .= '