From 15c8cb4421e8b74e405df93440f02143b28a491a Mon Sep 17 00:00:00 2001 From: Jason Date: Tue, 21 Jul 2015 00:59:30 +0800 Subject: [PATCH 1/7] Create templates for structure.lib.php Signed-off-by: Jason --- libraries/structure.lib.php | 489 +++--------------- templates/structure/add_column.phtml | 26 + .../structure/body_for_table_summary.phtml | 84 +++ templates/structure/check_all_tables.phtml | 43 ++ .../insert_empty_drop_action_links.phtml | 12 + .../structure/optional_action_links.phtml | 32 ++ .../structure/table_structure_header.phtml | 26 + templates/structure/table_structure_row.phtml | 44 ++ 8 files changed, 338 insertions(+), 418 deletions(-) create mode 100644 templates/structure/add_column.phtml create mode 100644 templates/structure/body_for_table_summary.phtml create mode 100644 templates/structure/check_all_tables.phtml create mode 100644 templates/structure/insert_empty_drop_action_links.phtml create mode 100644 templates/structure/optional_action_links.phtml create mode 100644 templates/structure/table_structure_header.phtml create mode 100644 templates/structure/table_structure_row.phtml diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index fc3c443cbd..bd16c33ba2 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -10,6 +10,8 @@ if (!defined('PHPMYADMIN')) { exit; } +require_once 'libraries/Template.class.php'; + /** * Get the HTML links for action links * Actions are, Browse, Search, Browse table label, empty table @@ -162,122 +164,22 @@ function PMA_getHtmlBodyForTableSummary($num_tables, $server_slave_status, $sum_size, $overhead_size, $create_time_all, $update_time_all, $check_time_all, $approx_rows ) { - $html_output = '' - . ''; - $html_output .= ''; - $html_output .= sprintf( - _ngettext('%s table', '%s tables', $num_tables), - PMA_Util::formatNumber($num_tables, 0) + return PMA\Template::get('structure/body_for_table_summary')->render( + array( + 'num_tables' => $num_tables, + 'server_slave_status' => $server_slave_status, + 'db_is_system_schema' => $db_is_system_schema, + 'sum_entries' => $sum_entries, + 'db_collation' => $db_collation, + 'is_show_stats' => $is_show_stats, + 'sum_size' => $sum_size, + 'overhead_size' => $overhead_size, + 'create_time_all' => $create_time_all, + 'update_time_all' => $update_time_all, + 'check_time_all' => $check_time_all, + 'approx_rows' => $approx_rows + ) ); - $html_output .= ''; - - if ($server_slave_status) { - $html_output .= '' . __('Replication') . '' . "\n"; - } - $sum_colspan = ($db_is_system_schema ? 4 : 7); - if ($GLOBALS['cfg']['NumFavoriteTables'] == 0) { - $sum_colspan--; - } - $html_output .= '' - . __('Sum') - . ''; - - $row_count_sum = PMA_Util::formatNumber($sum_entries, 0); - // If a table shows approximate rows count, display update-all-real-count anchor. - $row_sum_url = array(); - if (isset($approx_rows)) { - $row_sum_url = array( - 'ajax_request' => true, - 'db' => $GLOBALS['db'], - 'real_row_count' => 'true', - 'real_row_count_all' => 'true' - ); - } - $cell_text = ($approx_rows) - ? '' . '~' . $row_count_sum . '' - : $row_count_sum; - $html_output .= '' - . $cell_text - . ''; - - if (!($GLOBALS['cfg']['PropertiesNumColumns'] > 1)) { - $default_engine = $GLOBALS['dbi']->fetchValue( - 'SHOW VARIABLES LIKE \'storage_engine\';', - 0, - 1 - ); - $html_output .= '' . "\n" - . '' . $default_engine . '' . "\n"; - // we got a case where $db_collation was empty - $html_output .= '' . "\n"; - - if (! empty($db_collation)) { - $html_output .= '' - . $db_collation - . ''; - } - $html_output .= ''; - } - if ($is_show_stats) { - list($sum_formatted, $unit) = PMA_Util::formatByteDown( - $sum_size, 3, 1 - ); - list($overhead_formatted, $overhead_unit) - = PMA_Util::formatByteDown($overhead_size, 3, 1); - - $html_output .= '' - . $sum_formatted . ' ' . $unit - . ''; - $html_output .= '' - . $overhead_formatted . ' ' . $overhead_unit - . ''; - } - - if ($GLOBALS['cfg']['ShowDbStructureComment']) { - $html_output .= ''; - } - - if ($GLOBALS['cfg']['ShowDbStructureCreation']) { - $html_output .= '' . "\n" - . ' ' - . ($create_time_all - ? PMA_Util::localisedDate(strtotime($create_time_all)) - : '-' - ) - . ''; - } - - if ($GLOBALS['cfg']['ShowDbStructureLastUpdate']) { - $html_output .= '' . "\n" - . ' ' - . ($update_time_all - ? PMA_Util::localisedDate(strtotime($update_time_all)) - : '-' - ) - . ''; - } - - if ($GLOBALS['cfg']['ShowDbStructureLastCheck']) { - $html_output .= '' . "\n" - . ' ' - . ($check_time_all - ? PMA_Util::localisedDate(strtotime($check_time_all)) - : '-' - ) - . ''; - } - $html_output .= '' - . ''; - - return $html_output; } /** @@ -294,103 +196,17 @@ function PMA_getHtmlBodyForTableSummary($num_tables, $server_slave_status, function PMA_getHtmlForCheckAllTables($pmaThemeImage, $text_dir, $overhead_check, $db_is_system_schema, $hidden_fields ) { - $html_output = ''; - - return $html_output; + return PMA\Template::get('structure/check_all_tables')->render( + array( + 'pmaThemeImage' => $pmaThemeImage, + 'text_dir' => $text_dir, + 'overhead_check' => $overhead_check, + 'db_is_system_schema' => $db_is_system_schema, + 'hidden_fields' => $hidden_fields + ) + ); } -/** - * Get HTML code for "Check tables having overhead" link - * - * @param string $overhead_check overhead check - * - * @return string $html_output - */ -function PMA_getHtmlForCheckTablesHavingOverheadlink($overhead_check) -{ - return ' / ' - . '' - . __('Check tables having overhead') - . ''; -} - - /** * Get HTML links for "Print view" options * @@ -583,27 +399,17 @@ function PMA_getHtmlForStructureTableRow( function PMA_getHtmlForInsertEmptyDropActionLinks($tbl_url_query, $table_is_view, $titles, $empty_table, $current_table, $drop_query, $drop_message ) { - $html_output = '' - . '' - . $titles['Insert'] - . ''; - $html_output .= '' . $empty_table . ''; - $html_output .= ''; - $html_output .= '' - . $titles['Drop'] . ''; - - return $html_output; + return PMA\Template::get('structure/insert_empty_drop_action_links')->render( + array( + 'tbl_url_query' => $tbl_url_query, + 'table_is_view' => $table_is_view, + 'titles' => $titles, + 'empty_table' => $empty_table, + 'current_table' => $current_table, + 'drop_query' => $drop_query, + 'drop_message' => $drop_message + ) + ); } /** @@ -1331,34 +1137,12 @@ function PMA_getHtmlForTableStructureHeader( $db_is_system_schema, $tbl_is_view ) { - $html_output = ''; - $html_output .= ''; - $html_output .= '' - . '#' - . '' . __('Name') . '' - . '' . __('Type') . '' - . '' . __('Collation') . '' - . '' . __('Attributes') . '' - . '' . __('Null') . '' - . '' . __('Default') . '' - . '' . __('Extra') . ''; - - /* see tbl_structure.js, function moreOptsMenuResize() */ - if (! $db_is_system_schema && ! $tbl_is_view) { - $colspan = 9; - if (PMA_DRIZZLE) { - $colspan -= 2; - } - if (PMA_Util::showIcons('ActionLinksMode')) { - $colspan--; - } - $html_output .= '' . __('Action') . ''; - } - $html_output .= '' - . ''; - - return $html_output; + return PMA\Template::get('structure/table_structure_header')->render( + array( + 'db_is_system_schema' => $db_is_system_schema, + 'tbl_is_view' => $tbl_is_view + ) + ); } /** @@ -1392,65 +1176,24 @@ function PMA_getHtmlTableStructureRow($row, $rownum, $field_charset, $attribute, $tbl_is_view, $db_is_system_schema, $url_query, $field_encoded, $titles, $table ) { - $html_output = '' - . '' - . ''; - - $html_output .= '' - . $rownum - . ''; - - $html_output .= '' - . '' - . ''; - - $html_output .= '' - . '' - . $extracted_columnspec['displayed_type'] . $type_mime - . ''; - - $html_output .= ''; - if (! empty($field_charset)) { - $html_output .= '' . $field_charset . ''; - } - $html_output .= ''; - - $html_output .= '' - . $attribute . ''; - $html_output .= '' - . (($row['Null'] == 'YES') ? __('Yes') : __('No')) . ' '; - - $html_output .= ''; - if (isset($row['Default'])) { - if ($extracted_columnspec['type'] == 'bit') { - // here, $row['Default'] contains something like b'010' - $html_output .= PMA_Util::convertBitDefaultValue($row['Default']); - } else { - $html_output .= $row['Default']; - } - } else { - $html_output .= '' . _pgettext('None for default', 'None') . ''; - } - $html_output .= ''; - - $html_output .= '' - . /*overload*/mb_strtoupper($row['Extra']) . ''; - - $html_output .= PMA_getHtmlForDropColumn( - $tbl_is_view, $db_is_system_schema, - $url_query, $field_encoded, - $titles, $table, $row + return PMA\Template::get('libraries/table_structure_row')->render( + array( + 'row' => $row, + 'rownum' => $rownum, + 'displayed_field_name' => $displayed_field_name, + 'type_nowrap' => $type_nowrap, + 'extracted_columnspec' => $extracted_columnspec, + 'type_mime' => $type_mime, + 'field_charset' => $field_charset, + 'attribute' => $attribute, + 'tbl_is_view' => $tbl_is_view, + 'db_is_system_schema' => $db_is_system_schema, + 'url_query' => $url_query, + 'field_encoded' => $field_encoded, + 'titles' => $titles, + 'table' => $table + ) ); - - return $html_output; } /** @@ -1668,48 +1411,13 @@ function PMA_getHtmlForEditView($url_params) function PMA_getHtmlForOptionalActionLinks($url_query, $tbl_is_view, $db_is_system_schema ) { - $html_output = '' - . PMA_Util::getIcon('b_print.png', __('Print view'), true) - . ''; - - if (! $tbl_is_view && ! $db_is_system_schema) { - if (!PMA_DRIZZLE) { - $html_output .= '' - . PMA_Util::getIcon( - 'b_tblanalyse.png', - __('Propose table structure'), - true - ) - . ''; - $html_output .= PMA_Util::showMySQLDocu('procedure_analyse') . "\n"; - } - if (PMA_Tracker::isActive()) { - $html_output .= '' - . PMA_Util::getIcon('eye.png', __('Track table'), true) - . ''; - } - $html_output .= '' - . PMA_Util::getIcon('b_move.png', __('Move columns'), true) - . ''; - $html_output .= '' - . PMA_Util::getIcon('normalize.png', __('Improve table structure'), true) - . ''; - } - - if ($tbl_is_view && ! $db_is_system_schema) { - if (PMA_Tracker::isActive()) { - $html_output .= '' - . PMA_Util::getIcon('eye.png', __('Track view'), true) - . ''; - } - } - - return $html_output; + return PMA\Template::get('structure/optional_action_links')->render( + array( + 'url_query' => $url_query, + 'tbl_is_view' => $tbl_is_view, + 'db_is_system_schema' => $db_is_system_schema + ) + ); } /** @@ -1721,66 +1429,11 @@ function PMA_getHtmlForOptionalActionLinks($url_query, $tbl_is_view, */ function PMA_getHtmlForAddColumn($columns_list) { - $html_output = '
'; - - $html_output .= PMA_URL_getHiddenInputs( - $GLOBALS['db'], - $GLOBALS['table'] - ); - if (PMA_Util::showIcons('ActionLinksMode')) { - $html_output .=PMA_Util::getImage( - 'b_insrow.png', - __('Add column') - ); - $html_output .= ' '; - } - $num_fields = ''; - $html_output .= sprintf(__('Add %s column(s)'), $num_fields); - - // I tried displaying the drop-down inside the label but with Firefox - // the drop-down was blinking - $column_selector = ''; - $html_output .= ''; - $html_output .= ' '; - $html_output .= $column_selector; - $html_output .= '' - . '
'; - - return $html_output; + ); } /** diff --git a/templates/structure/add_column.phtml b/templates/structure/add_column.phtml new file mode 100644 index 0000000000..198b283f76 --- /dev/null +++ b/templates/structure/add_column.phtml @@ -0,0 +1,26 @@ +
+ + +   + + + +   + + + +
diff --git a/templates/structure/body_for_table_summary.phtml b/templates/structure/body_for_table_summary.phtml new file mode 100644 index 0000000000..d919ead11a --- /dev/null +++ b/templates/structure/body_for_table_summary.phtml @@ -0,0 +1,84 @@ + + + + + + + + + + + + true, + 'db' => $GLOBALS['db'], + 'real_row_count' => 'true', + 'real_row_count_all' => 'true' + ); +} +$cell_text = ($approx_rows) + ? '' . '~' . $row_count_sum . '' + : $row_count_sum; +?> + + 1)): ?> + fetchValue( + 'SHOW VARIABLES LIKE \'storage_engine\';', + 0, + 1 + ); ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/structure/check_all_tables.phtml b/templates/structure/check_all_tables.phtml new file mode 100644 index 0000000000..0aa2e5399b --- /dev/null +++ b/templates/structure/check_all_tables.phtml @@ -0,0 +1,43 @@ + \ No newline at end of file diff --git a/templates/structure/insert_empty_drop_action_links.phtml b/templates/structure/insert_empty_drop_action_links.phtml new file mode 100644 index 0000000000..58d2895825 --- /dev/null +++ b/templates/structure/insert_empty_drop_action_links.phtml @@ -0,0 +1,12 @@ + + + + + + + + + \ No newline at end of file diff --git a/templates/structure/optional_action_links.phtml b/templates/structure/optional_action_links.phtml new file mode 100644 index 0000000000..551f413b98 --- /dev/null +++ b/templates/structure/optional_action_links.phtml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/templates/structure/table_structure_header.phtml b/templates/structure/table_structure_header.phtml new file mode 100644 index 0000000000..a739e73e08 --- /dev/null +++ b/templates/structure/table_structure_header.phtml @@ -0,0 +1,26 @@ + + + + # + + + + + + + + + + + + + + diff --git a/templates/structure/table_structure_row.phtml b/templates/structure/table_structure_row.phtml new file mode 100644 index 0000000000..d3c24224a8 --- /dev/null +++ b/templates/structure/table_structure_row.phtml @@ -0,0 +1,44 @@ + + + + + + + +> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From c08c98727d7e1c32f76f0e6a909fd941e918044f Mon Sep 17 00:00:00 2001 From: Jason Date: Wed, 22 Jul 2015 01:31:19 +0800 Subject: [PATCH 2/7] Fix table structure not displaying Signed-off-by: Jason --- libraries/structure.lib.php | 2 +- templates/structure/table_structure_row.phtml | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/structure.lib.php b/libraries/structure.lib.php index bd16c33ba2..213c2d558d 100644 --- a/libraries/structure.lib.php +++ b/libraries/structure.lib.php @@ -1176,7 +1176,7 @@ function PMA_getHtmlTableStructureRow($row, $rownum, $field_charset, $attribute, $tbl_is_view, $db_is_system_schema, $url_query, $field_encoded, $titles, $table ) { - return PMA\Template::get('libraries/table_structure_row')->render( + return PMA\Template::get('structure/table_structure_row')->render( array( 'row' => $row, 'rownum' => $rownum, diff --git a/templates/structure/table_structure_row.phtml b/templates/structure/table_structure_row.phtml index d3c24224a8..af834a3fed 100644 --- a/templates/structure/table_structure_row.phtml +++ b/templates/structure/table_structure_row.phtml @@ -1,9 +1,10 @@ - + -