diff --git a/ChangeLog b/ChangeLog index e4c48742a..83fafd9e2 100755 --- a/ChangeLog +++ b/ChangeLog @@ -29,6 +29,10 @@ $Source$ array (bug #1370414). * libraries/sql_query_form.lib.php: Require bookmark code when we use it. * libraries/export/sql.php: Backquote database name (RFE#1376336). + * libraries/plugin_interface.lib.php, import.php, + libraries/display_import.lib.php, libraries/import/*: Generic plugin + infrastructure and use it in import (needed for RFE#1325937), work in + progress. 2005-12-08 Sebastian Mendel * libraries/tbl_move_copy.php: added PMA_table_rename() diff --git a/import.php b/import.php index 979b81e00..11a94f2f4 100644 --- a/import.php +++ b/import.php @@ -15,24 +15,24 @@ if (!empty($sql_query)) { // run SQL query $import_text = $sql_query; $import_type = 'query'; - $what = 'sql'; + $format = 'sql'; unset($sql_query); } elseif (!empty($sql_localfile)) { // run SQL file on server $local_import_file = $sql_localfile; $import_type = 'queryfile'; - $what = 'sql'; + $format = 'sql'; unset($sql_localfile); } elseif (!empty($sql_file)) { // run uploaded SQL file $import_file = $sql_file; $import_type = 'queryfile'; - $what = 'sql'; + $format = 'sql'; unset($sql_file); } elseif (!empty($id_bookmark)) { // run bookmark $import_type = 'query'; - $what = 'sql'; + $format = 'sql'; } // If we didn't get any parameters, either user called this directly, or @@ -45,10 +45,10 @@ if ($_POST == array() && $_GET == array()) { } // Check needed parameters -PMA_checkParameters(array('import_type', 'what')); +PMA_checkParameters(array('import_type', 'format')); -// We don't want anything special in what -$what = PMA_securePath($what); +// We don't want anything special in format +$format = PMA_securePath($format); // Import functions require_once('./libraries/import.lib.php'); @@ -286,8 +286,10 @@ if ($import_file != 'none' && !$error) { // Convert the file's charset if necessary if ($cfg['AllowAnywhereRecoding'] && $allow_recoding - && isset($charset_of_file) && $charset_of_file != $charset) { - $charset_conversion = TRUE; + && isset($charset_of_file)) { + if ($charset_of_file != $charset) { + $charset_conversion = TRUE; + } } else if (PMA_MYSQL_INT_VERSION >= 40100 && isset($charset_of_file) && $charset_of_file != 'utf8') { PMA_DBI_query('SET NAMES \'' . $charset_of_file . '\''); @@ -309,13 +311,13 @@ if (!$error && isset($skip)) { if (!$error) { // Check for file existance - if (!file_exists('./libraries/import/' . $what . '.php')) { + if (!file_exists('./libraries/import/' . $format . '.php')) { $error = TRUE; $message = $strCanNotLoadImportPlugins; $show_error_header = TRUE; } else { // Do the real import - require('./libraries/import/' . $what . '.php'); + require('./libraries/import/' . $format . '.php'); } } diff --git a/libraries/display_import.lib.php b/libraries/display_import.lib.php index f8081f9ea..605f69366 100644 --- a/libraries/display_import.lib.php +++ b/libraries/display_import.lib.php @@ -3,19 +3,10 @@ // vim: expandtab sw=4 ts=4 sts=4: require_once('./libraries/file_listing.php'); +require_once('./libraries/plugin_interface.lib.php'); /* Scan for plugins */ -$import_list = array(); -$plugins_dir = './libraries/import/'; -if ($handle = @opendir($plugins_dir)) { - $is_first = 0; - while ($file = @readdir($handle)) { - if (is_file($plugins_dir . $file) && eregi('\.php$', $file)) { - include($plugins_dir . $file); - } - } -} -ksort($import_list); +$import_list = PMA_getPlugins('./libraries/import/', $import_type); /* Fail if we didn't find any plugin */ if (empty($import_list)) { @@ -24,39 +15,6 @@ if (empty($import_list)) { unset($GLOBALS['show_error_header']); require('./libraries/footer.inc.php'); } - -function PMA_getString($name) { - return isset($GLOBALS[$name]) ? $GLOBALS[$name] : $name; -} - -function PMA_importCheckboxCheck($opt) { - if ((isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($GLOBALS[$opt])) || - (isset($GLOBALS['cfg']['Import'][$opt]) && $GLOBALS['cfg']['Import'][$opt])) { - return ' checked="checked"'; - } - return ''; -} - -function PMA_importGetDefault($opt) { - if (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($GLOBALS[$opt])) { - return htmlspecialchars($GLOBALS[$opt]); - } elseif (isset($GLOBALS['cfg']['Import'][$opt])) { - return htmlspecialchars($GLOBALS['cfg']['Import'][$opt]); - } - return ''; -} - -function PMA_importIsActive($what, $val) { - if (isset($GLOBALS['timeout_passed']) && $GLOBALS['timeout_passed'] && isset($GLOBALS['what'])) { - if ($GLOBALS['what'] == $val) { - return ' checked="checked"'; - } - } elseif (isset($GLOBALS['cfg']['Import'][$what]) && $GLOBALS['cfg']['Import'][$what] == $val) { - return ' checked="checked"'; - } - return ''; -} - ?>
@@ -69,58 +27,9 @@ if ($import_type == 'server') { echo PMA_generate_common_hidden_inputs($db, $table, 1); } echo ' '; +echo PMA_pluginGetJavascript($import_list); ?> - -

@@ -218,13 +127,13 @@ echo "\n"; ?>
/> + id="checkbox_allow_interrupt" />
- +
@@ -233,48 +142,13 @@ echo "\n"; $val) { -?> - - /> - -

- $val) { - if (isset($val['options'])) { - echo '
'; - echo '' . PMA_getString($val['options_text']) . ''; +echo PMA_pluginGetOptions('Import', $import_list); - foreach($val['options'] as $id => $opt) { - if ($opt['type'] == 'bool') { - echo ''; - echo ''; - } elseif ($opt['type'] == 'text') { - echo ''; - echo ''; - } else { - /* This should be seen only by plugin writers, so I do not thing this needs translation. */ - echo 'UNKNOWN OPTION IN IMPORT PLUGIN ' . $key . '!'; - } - echo '
'; - } - - echo '
'; - } -} - - -?> -
- -
- 'strCSV', 'extension' => 'csv', 'options' => array( diff --git a/libraries/import/ldi.php b/libraries/import/ldi.php index 4f49ed380..77584b4c6 100644 --- a/libraries/import/ldi.php +++ b/libraries/import/ldi.php @@ -4,13 +4,13 @@ /* CSV import plugin for phpMyAdmin */ -if ($import_type == 'table') { - if (isset($import_list)) { - if ($cfg['Import']['ldi_local_option'] == 'auto') { - $cfg['Import']['ldi_local_option'] = FALSE; +if ($plugin_param == 'table') { + if (isset($plugin_list)) { + if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') { + $GLOBALS['cfg']['Import']['ldi_local_option'] = FALSE; if (PMA_MYSQL_INT_VERSION < 32349) { - $cfg['Import']['ldi_local_option'] = TRUE; + $GLOBALS['cfg']['Import']['ldi_local_option'] = TRUE; } if (PMA_MYSQL_INT_VERSION > 40003) { @@ -18,14 +18,14 @@ if ($import_type == 'table') { if ($result != FALSE && PMA_DBI_num_rows($result) > 0) { $tmp = PMA_DBI_fetch_row($result); if ($tmp[1] == 'ON') { - $cfg['Import']['ldi_local_option'] = TRUE; + $GLOBALS['cfg']['Import']['ldi_local_option'] = TRUE; } } PMA_DBI_free_result($result); unset($result); } } - $import_list['ldi'] = array( + $plugin_list['ldi'] = array( 'text' => 'strLDI', 'extension' => 'ldi', // This is nonsense, however we want to default to our parser for csv 'options' => array( diff --git a/libraries/import/sql.php b/libraries/import/sql.php index 62872d0bc..34f594e38 100644 --- a/libraries/import/sql.php +++ b/libraries/import/sql.php @@ -4,10 +4,11 @@ /* SQL import plugin for phpMyAdmin */ -if (isset($import_list)) { - $import_list['sql'] = array( +if (isset($plugin_list)) { + $plugin_list['sql'] = array( 'text' => 'strSQL', 'extension' => 'sql', + 'options_text' => 'strSQLImportOptions', ); } else { /* We do not define function when plugin is just queried for information above */