diff --git a/libraries/classes/Display/Export.php b/libraries/classes/Display/Export.php
index ab53769201..ecd6420e5c 100644
--- a/libraries/classes/Display/Export.php
+++ b/libraries/classes/Display/Export.php
@@ -32,15 +32,12 @@ class Export
*
* @param string $str option name
*
- * @return string
+ * @return boolean
*/
- public static function exportCheckboxCheck($str)
+ private static function checkboxCheck($str)
{
- if (isset($GLOBALS['cfg']['Export'][$str]) && $GLOBALS['cfg']['Export'][$str]) {
- return ' checked="checked"';
- }
-
- return null;
+ return isset($GLOBALS['cfg']['Export'][$str])
+ && $GLOBALS['cfg']['Export'][$str];
}
/**
@@ -165,16 +162,14 @@ class Export
}
/**
- * Returns HTML for the options in teplate dropdown
+ * Returns HTML for the options in template dropdown
*
- * @param string $export_type export type - server, database, or table
+ * @param string $exportType export type - server, database, or table
*
* @return string HTML for the options in teplate dropdown
*/
- public static function getOptionsForExportTemplates($export_type)
+ private static function getOptionsForExportTemplates($exportType)
{
- $ret = '-- ' . __('Select a template') . ' -- ';
-
// Get the relation settings
$cfgRelation = Relation::getRelationsParam();
@@ -183,24 +178,25 @@ class Export
. Util::backquote($cfgRelation['export_templates'])
. " WHERE `username` = "
. "'" . $GLOBALS['dbi']->escapeString($GLOBALS['cfg']['Server']['user'])
- . "' AND `export_type` = '" . $GLOBALS['dbi']->escapeString($export_type) . "'"
+ . "' AND `export_type` = '" . $GLOBALS['dbi']->escapeString($exportType) . "'"
. " ORDER BY `template_name`;";
$result = Relation::queryAsControlUser($query);
- if (!$result) {
- return $ret;
- }
- while ($row = $GLOBALS['dbi']->fetchAssoc($result, DatabaseInterface::CONNECT_CONTROL)) {
- $ret .= 'fetchAssoc($result, DatabaseInterface::CONNECT_CONTROL)) {
+ $templates[] = [
+ 'name' => $row['template_name'],
+ 'id' => $row['id'],
+ ];
}
- $ret .= '>';
- $ret .= htmlspecialchars($row['template_name']) . ' ';
}
- return $ret;
+ return Template::get('display/export/template_options')->render([
+ 'templates' => $templates,
+ 'selected_template' => !empty($_GET['template_id']) ? $_GET['template_id'] : null,
+ ]);
}
/**
@@ -212,194 +208,87 @@ class Export
{
global $cfg;
if (isset($_GET['quick_or_custom'])) {
- $export_method = $_GET['quick_or_custom'];
+ $exportMethod = $_GET['quick_or_custom'];
} else {
- $export_method = $cfg['Export']['method'];
+ $exportMethod = $cfg['Export']['method'];
}
- if ($export_method == 'custom-no-form') {
- return '';
- }
-
- $html = '
';
- $html .= '
' . __('Export method:') . ' ';
- $html .= '
';
- $html .= '';
- $html .= ' render([
+ 'export_method' => $exportMethod,
+ ]);
}
/**
* Prints Html For Export Options Selection
*
- * @param String $export_type Selected Export Type
- * @param String $multi_values Export Options
+ * @param string $exportType Selected Export Type
+ * @param string $multiValues Export Options
*
* @return string
*/
- public static function getHtmlForExportOptionsSelection($export_type, $multi_values)
+ public static function getHtmlForExportOptionsSelection($exportType, $multiValues)
{
- $html = '';
- if ($export_type == 'server') {
- $html .= '
' . __('Databases:') . ' ';
- } elseif ($export_type == 'database') {
- $html .= '' . __('Tables:') . ' ';
- }
- if (! empty($multi_values)) {
- $html .= $multi_values;
- }
- $html .= '';
-
- return $html;
+ return Template::get('display/export/selection')->render([
+ 'export_type' => $exportType,
+ 'multi_values' => $multiValues,
+ ]);
}
/**
* Prints Html For Export Options Format dropdown
*
- * @param ExportPlugin[] $export_list Export List
+ * @param ExportPlugin[] $exportList Export List
*
* @return string
*/
- public static function getHtmlForExportOptionsFormatDropdown($export_list)
+ public static function getHtmlForExportOptionsFormatDropdown($exportList)
{
- $html = '';
- $html .= '
' . __('Format:') . ' ';
- $html .= Plugins::getChoice('Export', 'what', $export_list, 'format');
- $html .= '';
- return $html;
+ $dropdown = Plugins::getChoice('Export', 'what', $exportList, 'format');
+ return Template::get('display/export/format_dropdown')->render([
+ 'dropdown' => $dropdown,
+ ]);
}
/**
* Prints Html For Export Options Format-specific options
*
- * @param ExportPlugin[] $export_list Export List
+ * @param ExportPlugin[] $exportList Export List
*
* @return string
*/
- public static function getHtmlForExportOptionsFormat($export_list)
+ public static function getHtmlForExportOptionsFormat($exportList)
{
- $html = '';
-
- if (Encoding::canConvertKanji()) {
- // Japanese encoding setting
- $html .= '';
- $html .= '
' . __('Encoding Conversion:') . ' ';
- $html .= Encoding::kanjiEncodingForm();
- $html .= '';
- }
-
- $html .= '';
-
- $html .= Util::getExternalBug(
- __('SQL compatibility mode'), 'mysql', '50027', '14515'
- );
global $cfg;
- if ($cfg['ExecTimeLimit'] > 0) {
- $html .= ' ';
- } else {
- // if the time limit set is zero, then time out won't occur
- // So no need to check for time out.
- $html .= ' ';
- }
- $html .= '
';
+ $options = Plugins::getOptions('Export', $exportList);
- return $html;
+ return Template::get('display/export/options_format')->render([
+ 'options' => $options,
+ 'can_convert_kanji' => Encoding::canConvertKanji(),
+ 'exec_time_limit' => $cfg['ExecTimeLimit'],
+ ]);
}
/**
* Prints Html For Export Options Rows
*
- * @param String $db Selected DB
- * @param String $table Selected Table
- * @param String $unlim_num_rows Num of Rows
+ * @param string $db Selected DB
+ * @param string $table Selected Table
+ * @param string $unlimNumRows Num of Rows
*
* @return string
*/
- public static function getHtmlForExportOptionsRows($db, $table, $unlim_num_rows)
+ public static function getHtmlForExportOptionsRows($db, $table, $unlimNumRows)
{
- $html = '';
- $html .= '
' . __('Rows:') . ' ';
- $html .= '
';
- $html .= '
';
- return $html;
+ $tableObject = new Table($table, $db);
+ $numberOfRows = $tableObject->countRecords();
+
+ return Template::get('display/export/options_rows')->render([
+ 'allrows' => isset($_GET['allrows']) ? $_GET['allrows'] : null,
+ 'limit_to' => isset($_GET['limit_to']) ? $_GET['limit_to'] : null,
+ 'limit_from' => isset($_GET['limit_from']) ? $_GET['limit_from'] : null,
+ 'unlim_num_rows' => $unlimNumRows,
+ 'number_of_rows' => $numberOfRows,
+ ]);
}
/**
@@ -410,34 +299,19 @@ class Export
public static function getHtmlForExportOptionsQuickExport()
{
global $cfg;
- $html = '';
- $html .= '
' . __('Output:') . ' ';
- $html .= '
';
- $html .= '';
- $html .= ' %s'),
- htmlspecialchars(Util::userDir($cfg['SaveDir']))
+ $saveDir = Util::userDir($cfg['SaveDir']);
+ $exportIsChecked = self::checkboxCheck(
+ 'quick_export_onserver'
+ );
+ $exportOverwriteIsChecked = self::checkboxCheck(
+ 'quick_export_onserver_overwrite'
);
- $html .= '';
- $html .= ' ';
- $html .= '';
- $html .= ' render([
+ 'save_dir' => $saveDir,
+ 'export_is_checked' => $exportIsChecked,
+ 'export_overwrite_is_checked' => $exportOverwriteIsChecked,
+ ]);
}
/**
@@ -448,49 +322,36 @@ class Export
public static function getHtmlForExportOptionsOutputSaveDir()
{
global $cfg;
- $html = ' ';
- $html .= ' %s'),
- htmlspecialchars(Util::userDir($cfg['SaveDir']))
+ $saveDir = Util::userDir($cfg['SaveDir']);
+ $exportIsChecked = self::checkboxCheck(
+ 'onserver'
+ );
+ $exportOverwriteIsChecked = self::checkboxCheck(
+ 'onserver_overwrite'
);
- $html .= '';
- $html .= ' ';
- $html .= '';
- $html .= ' render([
+ 'save_dir' => $saveDir,
+ 'export_is_checked' => $exportIsChecked,
+ 'export_overwrite_is_checked' => $exportOverwriteIsChecked,
+ ]);
}
/**
* Prints Html For Export Options
*
- * @param String $export_type Selected Export Type
+ * @param string $exportType Selected Export Type
*
* @return string
*/
- public static function getHtmlForExportOptionsOutputFormat($export_type)
+ public static function getHtmlForExportOptionsOutputFormat($exportType)
{
- $html = ' ';
- $html .= '';
- $html .= __('File name template:');
$trans = new Message;
$trans->addText(__('@SERVER@ will become the server name'));
- if ($export_type == 'database' || $export_type == 'table') {
+ if ($exportType == 'database' || $exportType == 'table') {
$trans->addText(__(', @DATABASE@ will become the database name'));
- if ($export_type == 'table') {
+ if ($exportType == 'table') {
$trans->addText(__(', @TABLE@ will become the table name'));
}
}
@@ -509,53 +370,38 @@ class Export
);
$msg->addParamHtml('');
$msg->addParam($trans);
- $doc_url = Util::getDocuLink('faq', 'faq6-27');
+ $docUrl = Util::getDocuLink('faq', 'faq6-27');
$msg->addParamHtml(
- ''
+ ' '
);
$msg->addParamHtml(' ');
- $html .= Util::showHint($msg);
- $html .= ' ';
- $html .= ' getUserValue(
- 'pma_db_filename_template',
- $GLOBALS['cfg']['Export']['file_template_database']
- )
+ if ($exportType == 'database') {
+ $filenameTemplate = $GLOBALS['PMA_Config']->getUserValue(
+ 'pma_db_filename_template',
+ $GLOBALS['cfg']['Export']['file_template_database']
);
- } elseif ($export_type == 'table') {
- $html .= htmlspecialchars(
- $GLOBALS['PMA_Config']->getUserValue(
- 'pma_table_filename_template',
- $GLOBALS['cfg']['Export']['file_template_table']
- )
+ } elseif ($exportType == 'table') {
+ $filenameTemplate = $GLOBALS['PMA_Config']->getUserValue(
+ 'pma_table_filename_template',
+ $GLOBALS['cfg']['Export']['file_template_table']
);
} else {
- $html .= htmlspecialchars(
- $GLOBALS['PMA_Config']->getUserValue(
- 'pma_server_filename_template',
- $GLOBALS['cfg']['Export']['file_template_server']
- )
+ $filenameTemplate = $GLOBALS['PMA_Config']->getUserValue(
+ 'pma_server_filename_template',
+ $GLOBALS['cfg']['Export']['file_template_server']
);
}
}
- $html .= '"';
- $html .= '/>';
- $html .= ' render([
+ 'message' => $msg->getMessage(),
+ 'filename_template' => $filenameTemplate,
+ 'is_checked' => self::checkboxCheck('remember_file_template'),
+ ]);
}
/**
@@ -566,25 +412,11 @@ class Export
public static function getHtmlForExportOptionsOutputCharset()
{
global $cfg;
- $html = ' '
- . __('Character set of the file:') . ' ' . "\n";
- $html .= '';
- foreach (Encoding::listEncodings() as $temp_charset) {
- $html .= '';
- } // end foreach
- $html .= ' ';
- return $html;
+ return Template::get('display/export/options_output_charset')->render([
+ 'encodings' => Encoding::listEncodings(),
+ 'export_charset' => $cfg['Export']['charset'],
+ ]);
}
/**
@@ -596,52 +428,29 @@ class Export
{
global $cfg;
if (isset($_GET['compression'])) {
- $selected_compression = $_GET['compression'];
+ $selectedCompression = $_GET['compression'];
} elseif (isset($cfg['Export']['compression'])) {
- $selected_compression = $cfg['Export']['compression'];
+ $selectedCompression = $cfg['Export']['compression'];
} else {
- $selected_compression = "none";
+ $selectedCompression = 'none';
}
// Since separate files export works with ZIP only
if (isset($cfg['Export']['as_separate_files'])
&& $cfg['Export']['as_separate_files']
) {
- $selected_compression = "zip";
+ $selectedCompression = 'zip';
}
- $html = "";
// zip and gzip encode features
- $is_zip = ($cfg['ZipDump'] && @function_exists('gzcompress'));
- $is_gzip = ($cfg['GZipDump'] && @function_exists('gzencode'));
- if ($is_zip || $is_gzip) {
- $html .= '';
- $html .= ''
- . __('Compression:') . ' ';
- $html .= '';
- $html .= '' . __('None') . ' ';
- if ($is_zip) {
- $html .= '';
- }
- if ($is_gzip) {
- $html .= ' ';
- }
- $html .= ' ';
- $html .= ' ';
- } else {
- $html .= ' ';
- }
+ $isZip = ($cfg['ZipDump'] && @function_exists('gzcompress'));
+ $isGzip = ($cfg['GZipDump'] && @function_exists('gzencode'));
- return $html;
+ return Template::get('display/export/options_output_compression')->render([
+ 'is_zip' => $isZip,
+ 'is_gzip' => $isGzip,
+ 'selected_compression' => $selectedCompression,
+ ]);
}
/**
@@ -651,130 +460,81 @@ class Export
*/
public static function getHtmlForExportOptionsOutputRadio()
{
- $html = '';
- $html .= ' ';
- return $html;
+ return Template::get('display/export/options_output_radio')->render([
+ 'has_repopulate' => isset($_GET['repopulate']),
+ 'export_asfile' => $GLOBALS['cfg']['Export']['asfile'],
+ ]);
}
/**
* Prints Html For Export Options Checkbox - Separate files
*
- * @param String $export_type Selected Export Type
+ * @param string $exportType Selected Export Type
*
* @return string
*/
- public static function getHtmlForExportOptionsOutputSeparateFiles($export_type)
+ public static function getHtmlForExportOptionsOutputSeparateFiles($exportType)
{
- $html = '';
- $html .= ' ';
- $html .= '';
+ $isChecked = self::checkboxCheck('as_separate_files');
- if ($export_type == 'server') {
- $html .= __('Export databases as separate files');
- } elseif ($export_type == 'database') {
- $html .= __('Export tables as separate files');
- }
-
- $html .= ' ';
-
- return $html;
+ return Template::get('display/export/options_output_separate_files')->render([
+ 'is_checked' => $isChecked,
+ 'export_type' => $exportType,
+ ]);
}
/**
* Prints Html For Export Options
*
- * @param String $export_type Selected Export Type
+ * @param string $exportType Selected Export Type
*
* @return string
*/
- public static function getHtmlForExportOptionsOutput($export_type)
+ public static function getHtmlForExportOptionsOutput($exportType)
{
global $cfg;
- $html = '';
- $html .= '
' . __('Output:') . ' ';
- $html .= '
';
-
- /*
- * @todo use sprintf() for better translatability, while keeping the
- *
principle (for screen readers)
- */
- $html .= '
'
- . __('Skip tables larger than') . ' ';
- $html .= '
' . __('MiB');
-
- $html .= '
';
-
- return $html;
+ return Template::get('display/export/options_output')->render([
+ 'has_aliases' => $hasAliases,
+ 'export_type' => $exportType,
+ 'is_checked_lock_tables' => $isCheckedLockTables,
+ 'is_checked_asfile' => $isCheckedAsfile,
+ 'repopulate' => isset($_GET['repopulate']),
+ 'lock_tables' => isset($_GET['lock_tables']),
+ 'save_dir' => isset($cfg['SaveDir']) ? $cfg['SaveDir'] : null,
+ 'is_encoding_supported' => Encoding::isSupported(),
+ 'options_output_save_dir' => $optionsOutputSaveDir,
+ 'options_output_format' => $optionsOutputFormat,
+ 'options_output_charset' => $optionsOutputCharset,
+ 'options_output_compression' => $optionsOutputCompression,
+ 'options_output_separate_files' => $optionsOutputSeparateFiles,
+ 'options_output_radio' => $optionsOutputRadio,
+ ]);
}
/**
diff --git a/templates/display/export/format_dropdown.twig b/templates/display/export/format_dropdown.twig
new file mode 100644
index 0000000000..adda19bac9
--- /dev/null
+++ b/templates/display/export/format_dropdown.twig
@@ -0,0 +1,4 @@
+
+
{% trans 'Format:' %}
+ {{ dropdown|raw }}
+
diff --git a/templates/display/export/method.twig b/templates/display/export/method.twig
new file mode 100644
index 0000000000..5521f5748d
--- /dev/null
+++ b/templates/display/export/method.twig
@@ -0,0 +1,22 @@
+{% if export_method != 'custom-no-form' %}
+
+
{% trans 'Export method:' %}
+
+
+{% endif %}
diff --git a/templates/display/export/options_format.twig b/templates/display/export/options_format.twig
new file mode 100644
index 0000000000..7cfbe13b3e
--- /dev/null
+++ b/templates/display/export/options_format.twig
@@ -0,0 +1,24 @@
+
+
+{% if can_convert_kanji %}
+ {# Japanese encoding setting #}
+
+
{% trans 'Encoding Conversion:' %}
+ {% include 'encoding/kanji_encoding_form.twig' %}
+
+{% endif %}
+
+
+ 0 %}
+ onclick="check_time_out({{ exec_time_limit }})"
+ {%- endif %}>
+
diff --git a/templates/display/export/options_output.twig b/templates/display/export/options_output.twig
new file mode 100644
index 0000000000..60d721ca02
--- /dev/null
+++ b/templates/display/export/options_output.twig
@@ -0,0 +1,54 @@
+
+
{% trans 'Output:' %}
+
+
+
+ {{- 'Skip tables larger than %s MiB'|trans|format(
+ ' '
+ )|raw }}
+
diff --git a/templates/display/export/options_output_charset.twig b/templates/display/export/options_output_charset.twig
new file mode 100644
index 0000000000..bd316bf916
--- /dev/null
+++ b/templates/display/export/options_output_charset.twig
@@ -0,0 +1,16 @@
+
+
+ {% trans 'Character set of the file:' %}
+
+
+ {% for charset in encodings %}
+
+ {{- charset -}}
+
+ {% endfor %}
+
+
diff --git a/templates/display/export/options_output_compression.twig b/templates/display/export/options_output_compression.twig
new file mode 100644
index 0000000000..19059811ca
--- /dev/null
+++ b/templates/display/export/options_output_compression.twig
@@ -0,0 +1,24 @@
+{% if is_zip or is_gzip %}
+
+
+ {% trans 'Compression:' %}
+
+
+ {% trans 'None' %}
+ {% if is_zip %}
+
+ {% trans 'zipped' %}
+
+ {% endif %}
+ {% if is_gzip %}
+
+ {% trans 'gzipped' %}
+
+ {% endif %}
+
+
+{% else %}
+
+{% endif %}
diff --git a/templates/display/export/options_output_format.twig b/templates/display/export/options_output_format.twig
new file mode 100644
index 0000000000..0039d87cd6
--- /dev/null
+++ b/templates/display/export/options_output_format.twig
@@ -0,0 +1,13 @@
+
+
+ {% trans 'File name template:' %}
+ {{ Util_showHint(message) }}
+
+
+
+
+ {% trans 'use this for future exports' %}
+
+
diff --git a/templates/display/export/options_output_radio.twig b/templates/display/export/options_output_radio.twig
new file mode 100644
index 0000000000..7adf21eef2
--- /dev/null
+++ b/templates/display/export/options_output_radio.twig
@@ -0,0 +1,7 @@
+
+
+
+ {% trans 'View output as text' %}
+
+
diff --git a/templates/display/export/options_output_save_dir.twig b/templates/display/export/options_output_save_dir.twig
new file mode 100644
index 0000000000..b4526aa4bb
--- /dev/null
+++ b/templates/display/export/options_output_save_dir.twig
@@ -0,0 +1,15 @@
+
+
+
+ {{ 'Save on server in the directory %s '|trans|format(save_dir|e)|raw }}
+
+
+
+
+
+ {% trans 'Overwrite existing file(s)' %}
+
+
diff --git a/templates/display/export/options_output_separate_files.twig b/templates/display/export/options_output_separate_files.twig
new file mode 100644
index 0000000000..fec85c4de5
--- /dev/null
+++ b/templates/display/export/options_output_separate_files.twig
@@ -0,0 +1,12 @@
+
+
+
+ {% if export_type == 'server' %}
+ {% trans 'Export databases as separate files' %}
+ {% elseif export_type == 'database' %}
+ {% trans 'Export tables as separate files' %}
+ {% endif %}
+
+
diff --git a/templates/display/export/options_quick_export.twig b/templates/display/export/options_quick_export.twig
new file mode 100644
index 0000000000..b3bd159f35
--- /dev/null
+++ b/templates/display/export/options_quick_export.twig
@@ -0,0 +1,20 @@
+
+
{% trans 'Output:' %}
+
+
diff --git a/templates/display/export/options_rows.twig b/templates/display/export/options_rows.twig
new file mode 100644
index 0000000000..5a7e39ed4b
--- /dev/null
+++ b/templates/display/export/options_rows.twig
@@ -0,0 +1,35 @@
+
+
{% trans 'Rows:' %}
+
+
diff --git a/templates/display/export/selection.twig b/templates/display/export/selection.twig
new file mode 100644
index 0000000000..6f691f5a36
--- /dev/null
+++ b/templates/display/export/selection.twig
@@ -0,0 +1,10 @@
+
+ {% if export_type == 'server' %}
+
{% trans 'Databases:' %}
+ {% elseif export_type == 'database' %}
+ {% trans 'Tables:' %}
+ {% endif %}
+ {% if multi_values is not empty %}
+ {{ multi_values|raw }}
+ {% endif %}
+
diff --git a/templates/display/export/template_options.twig b/templates/display/export/template_options.twig
new file mode 100644
index 0000000000..ddcd4f5b55
--- /dev/null
+++ b/templates/display/export/template_options.twig
@@ -0,0 +1,7 @@
+-- {% trans 'Select a template' %} --
+
+{% for template in templates %}
+
+ {{ template.name }}
+
+{% endfor %}
diff --git a/test/classes/Display/ExportTest.php b/test/classes/Display/ExportTest.php
index e98684dd04..012e1b3d2a 100644
--- a/test/classes/Display/ExportTest.php
+++ b/test/classes/Display/ExportTest.php
@@ -203,12 +203,12 @@ class ExportTest extends TestCase
//validate 4: Export::getHtmlForExportOptionsQuickExport
$this->assertContains(
- ' assertContains(
- 'Save on server in the directory ' . $dir . ' ',
+ 'Save on server in the directory ' . $dir . ' ',
$html
);