From 307f7069e5ed44a3ebb66c4e59690e657b90ccb7 Mon Sep 17 00:00:00 2001 From: Durgesh <007durgesh219@gmail.com> Date: Sun, 21 Feb 2016 23:34:56 +0530 Subject: [PATCH] Templating getWithSelected() and getCheckbox(), Issue #12004 Signed-off-by: Durgesh <007durgesh219@gmail.com> --- libraries/DisplayResults.php | 39 ++++-- libraries/Util.php | 64 ++------- libraries/central_columns.lib.php | 11 +- .../server/ServerDatabasesController.php | 12 +- libraries/rte/rte_list.lib.php | 12 +- libraries/server_privileges.lib.php | 82 +++++++---- libraries/tracking.lib.php | 39 ++++-- templates/checkbox.phtml | 13 ++ templates/select_all.phtml | 7 + .../table/search/search_and_replace.phtml | 17 ++- .../structure/check_all_table_column.phtml | 11 +- test/libraries/PMA_server_privileges_test.php | 15 +- test/libraries/common/PMA_checkbox_test.php | 132 ++++++++++++++++++ .../libraries/common/PMA_getCheckbox_test.php | 94 ------------- 14 files changed, 323 insertions(+), 225 deletions(-) create mode 100644 templates/checkbox.phtml create mode 100644 templates/select_all.phtml create mode 100644 test/libraries/common/PMA_checkbox_test.php delete mode 100644 test/libraries/common/PMA_getCheckbox_test.php diff --git a/libraries/DisplayResults.php b/libraries/DisplayResults.php index 99d1c6533a..cb1577963a 100644 --- a/libraries/DisplayResults.php +++ b/libraries/DisplayResults.php @@ -1746,16 +1746,26 @@ class DisplayResults } $options_html .= '
' - . Util::getCheckbox( - 'display_binary', __('Show binary contents'), - ! empty($_SESSION['tmpval']['display_binary']), false, - 'display_binary_' . $this->__get('unique_id') + . Template::get('checkbox') + ->render( + array( + 'html_field_name' => 'display_binary', + 'label' => __('Show binary contents'), + 'checked' => ! empty($_SESSION['tmpval']['display_binary']), + 'onclick' => false, + 'html_field_id' => 'display_binary_' . $this->__get('unique_id'), + ) ) . '
' - . Util::getCheckbox( - 'display_blob', __('Show BLOB contents'), - ! empty($_SESSION['tmpval']['display_blob']), false, - 'display_blob_' . $this->__get('unique_id') + . Template::get('checkbox') + ->render( + array( + 'html_field_name' => 'display_blob', + 'label' => __('Show BLOB contents'), + 'checked' => ! empty($_SESSION['tmpval']['display_blob']), + 'onclick' => false, + 'html_field_id' => 'display_blob_' . $this->__get('unique_id'), + ) ) . '
'; @@ -1764,10 +1774,15 @@ class DisplayResults // per SQL query, and at the same time have a default that displays // the transformations. $options_html .= '
' - . Util::getCheckbox( - 'hide_transformation', __('Hide browser transformation'), - ! empty($_SESSION['tmpval']['hide_transformation']), false, - 'hide_transformation_' . $this->__get('unique_id') + . Template::get('checkbox') + ->render( + array( + 'html_field_name' => 'hide_transformation', + 'label' => __('Hide browser transformation'), + 'checked' => ! empty($_SESSION['tmpval']['hide_transformation']), + 'onclick' => false, + 'html_field_id' => 'hide_transformation_' . $this->__get('unique_id'), + ) ) . '
'; diff --git a/libraries/Util.php b/libraries/Util.php index 8feb574434..226ffaf886 100644 --- a/libraries/Util.php +++ b/libraries/Util.php @@ -16,6 +16,7 @@ use stdClass; use SqlParser\Utils\Error as ParserError; use PMA\libraries\URL; use PMA\libraries\Sanitize; +use PMA\libraries\Template; if (! defined('PHPMYADMIN')) { exit; @@ -1318,12 +1319,16 @@ class Util // be checked, which would reexecute an INSERT, for example if (! empty($refresh_link) && self::profilingSupported()) { $retval .= ''; - $retval .= self::getCheckbox( - 'profiling', - __('Profiling'), - isset($_SESSION['profiling']), - true - ); + $retval .= Template::get('checkbox') + ->render( + array( + 'html_field_name' => 'profiling', + 'label' => __('Profiling'), + 'checked' => isset($_SESSION['profiling']), + 'onclick' => true, + 'html_field_id' => '', + ) + ); } $retval .= ''; @@ -2730,28 +2735,6 @@ class Util return $ext_but_html; } - /** - * Returns a HTML checkbox - * - * @param string $html_field_name the checkbox HTML field - * @param string $label label for checkbox - * @param boolean $checked is it initially checked? - * @param boolean $onclick should it submit the form on click? - * @param string $html_field_id id for the checkbox - * - * @return string HTML for the checkbox - */ - public static function getCheckbox( - $html_field_name, $label, $checked, $onclick, $html_field_id = '' - ) { - return '' - . '' . $label . ''; - } - /** * Generates a set of radio HTML fields * @@ -4590,31 +4573,6 @@ class Util return array($primary, $pk_array, $indexes_info, $indexes_data); } - /** - * Returns the HTML for check all check box and with selected text - * for multi submits - * - * @param string $pmaThemeImage path to theme's image folder - * @param string $text_dir text direction - * @param string $formName name of the enclosing form - * - * @return string HTML - */ - public static function getWithSelected($pmaThemeImage, $text_dir, $formName) - { - $html = '' . __('With selected:') . ''; - $html .= '' - . ''; - $html .= '' - . __('With selected:') . ''; - - return $html; - } - /** * Function to get html for the start row and number of rows panel * diff --git a/libraries/central_columns.lib.php b/libraries/central_columns.lib.php index f95bfc776a..2adbf7a887 100644 --- a/libraries/central_columns.lib.php +++ b/libraries/central_columns.lib.php @@ -1184,9 +1184,14 @@ function PMA_getCentralColumnsListRaw($db, $table) */ function PMA_getCentralColumnsTableFooter($pmaThemeImage, $text_dir) { - $html_output = Util::getWithSelected( - $pmaThemeImage, $text_dir, "tableslistcontainer" - ); + $html_output = PMA\libraries\Template::get('select_all') + ->render( + array( + 'pmaThemeImage' => $pmaThemeImage, + 'text_dir' => $text_dir, + 'formName' => 'tableslistcontainer', + ) + ); $html_output .= Util::getButtonOrImage( 'edit_central_columns', 'mult_submit change_central_columns', __('Edit'), 'b_edit.png', 'edit central columns' diff --git a/libraries/controllers/server/ServerDatabasesController.php b/libraries/controllers/server/ServerDatabasesController.php index 8d348be6ed..17c372fc01 100644 --- a/libraries/controllers/server/ServerDatabasesController.php +++ b/libraries/controllers/server/ServerDatabasesController.php @@ -378,9 +378,15 @@ class ServerDatabasesController extends Controller return ''; } - $html = Util::getWithSelected( - $GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], "dbStatsForm" - ); + $html = Template::get('select_all') + ->render( + array( + 'pmaThemeImage' => $GLOBALS['pmaThemeImage'], + 'text_dir' => $GLOBALS['text_dir'], + 'formName' => 'dbStatsForm', + ) + ); + $html .= Util::getButtonOrImage( '', 'mult_submit' . ' ajax', diff --git a/libraries/rte/rte_list.lib.php b/libraries/rte/rte_list.lib.php index fe9228e779..8c911dbe49 100644 --- a/libraries/rte/rte_list.lib.php +++ b/libraries/rte/rte_list.lib.php @@ -7,6 +7,7 @@ */ use SqlParser\Statements\CreateStatement; use PMA\libraries\URL; +use PMA\libraries\Template; if (! defined('PHPMYADMIN')) { @@ -143,9 +144,14 @@ function PMA_RTE_getList($type, $items) if (count($items)) { $retval .= '
'; - $retval .= PMA\libraries\Util::getWithSelected( - $GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], 'rteListForm' - ); + $retval .= Template::get('select_all') + ->render( + array( + 'pmaThemeImage' => $GLOBALS['pmaThemeImage'], + 'text_dir' => $GLOBALS['text_dir'], + 'formName' => 'rteListForm', + ) + ); $retval .= PMA\libraries\Util::getButtonOrImage( 'submit_mult', 'mult_submit', __('Export'), 'b_export.png', 'export' diff --git a/libraries/server_privileges.lib.php b/libraries/server_privileges.lib.php index d56742a527..f4ed3bb37d 100644 --- a/libraries/server_privileges.lib.php +++ b/libraries/server_privileges.lib.php @@ -2306,30 +2306,40 @@ function PMA_getHtmlForAddUser($dbname) $html_output .= '
' . "\n" . '' . __('Database for user account') . '' . "\n"; - $html_output .= Util::getCheckbox( - 'createdb-1', - __('Create database with same name and grant all privileges.'), - false, false, 'createdb-1' - ); + $html_output .= Template::get('checkbox') + ->render( + array( + 'html_field_name' => 'createdb-1', + 'label' => __('Create database with same name and grant all privileges.'), + 'checked' => false, + 'onclick' => false, + 'html_field_id' => 'createdb-1', + ) + ); $html_output .= '
' . "\n"; - $html_output .= Util::getCheckbox( - 'createdb-2', - __('Grant all privileges on wildcard name (username\\_%).'), - false, false, 'createdb-2' - ); + $html_output .= Template::get('checkbox') + ->render( + array( + 'html_field_name' => 'createdb-2', + 'label' => __('Grant all privileges on wildcard name (username\\_%).'), + 'checked' => false, + 'onclick' => false, + 'html_field_id' => 'createdb-2', + ) + ); $html_output .= '
' . "\n"; if (! empty($dbname) ) { - $html_output .= Util::getCheckbox( - 'createdb-3', - sprintf( - __('Grant all privileges on database "%s".'), - htmlspecialchars($dbname) - ), - true, - false, - 'createdb-3' - ); + $html_output .= Template::get('checkbox') + ->render( + array( + 'html_field_name' => 'createdb-3', + 'label' => sprintf(__('Grant all privileges on database %s.'), htmlspecialchars($dbname)), + 'checked' => true, + 'onclick' => false, + 'html_field_id' => 'createdb-3', + ) + ); $html_output .= '' . "\n"; $html_output .= '
' . "\n"; @@ -2506,9 +2516,14 @@ function PMA_getHtmlForSpecificDbPrivileges($db) $html_output .= ''; $html_output .= '
'; - $html_output .= Util::getWithSelected( - $GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], "usersForm" - ); + $html_output .= Template::get('select_all') + ->render( + array( + 'pmaThemeImage' => $GLOBALS['pmaThemeImage'], + 'text_dir' => $GLOBALS['text_dir'], + 'formName' => "usersForm", + ) + ); $html_output .= Util::getButtonOrImage( 'submit_mult', 'mult_submit', __('Export'), 'b_tblexport.png', 'export' @@ -2585,9 +2600,14 @@ function PMA_getHtmlForSpecificTablePrivileges($db, $table) $html_output .= ''; $html_output .= '
'; - $html_output .= Util::getWithSelected( - $GLOBALS['pmaThemeImage'], $GLOBALS['text_dir'], "usersForm" - ); + $html_output .= Template::get('select_all') + ->render( + array( + 'pmaThemeImage' => $GLOBALS['pmaThemeImage'], + 'text_dir' => $GLOBALS['text_dir'], + 'formName' => "usersForm", + ) + ); $html_output .= Util::getButtonOrImage( 'submit_mult', 'mult_submit', __('Export'), 'b_tblexport.png', 'export' @@ -3602,8 +3622,14 @@ function PMA_getUsersOverview($result, $db_rights, $pmaThemeImage, $text_dir) . '' . "\n"; $html_output .= '
' - . Util::getWithSelected($pmaThemeImage, $text_dir, "usersForm") . "\n"; - + . Template::get('select_all') + ->render( + array( + 'pmaThemeImage' => $pmaThemeImage, + 'text_dir' => $text_dir, + 'formName' => 'usersForm', + ) + ) . "\n"; $html_output .= Util::getButtonOrImage( 'submit_mult', 'mult_submit', __('Export'), 'b_tblexport.png', 'export' diff --git a/libraries/tracking.lib.php b/libraries/tracking.lib.php index 537a464eea..71e1a262c0 100644 --- a/libraries/tracking.lib.php +++ b/libraries/tracking.lib.php @@ -355,11 +355,14 @@ function PMA_getHtmlForTableVersionDetails( $html .= ''; $html .= ''; - $html .= PMA\libraries\Util::getWithSelected( - $pmaThemeImage, - $text_dir, - "versionsForm" - ); + $html .= PMA\libraries\Template::get('select_all') + ->render( + array( + 'pmaThemeImage' => $pmaThemeImage, + 'text_dir' => $text_dir, + 'formName' => 'versionsForm', + ) + ); $html .= PMA\libraries\Util::getButtonOrImage( 'submit_mult', 'mult_submit', __('Delete version'), 'b_drop.png', 'delete_version' @@ -1488,11 +1491,14 @@ function PMA_displayUntrackedTables( render( + array( + 'pmaThemeImage' => $pmaThemeImage, + 'text_dir' => $text_dir, + 'formName' => 'untrackedForm', + ) + ); echo PMA\libraries\Util::getButtonOrImage( 'submit_mult', 'mult_submit', __('Track table'), 'eye.png', 'track' @@ -1708,11 +1714,14 @@ function PMA_displayTrackedTables( render( + array( + 'pmaThemeImage' => $pmaThemeImage, + 'text_dir' => $text_dir, + 'formName' => 'trackedForm', + ) + ); echo PMA\libraries\Util::getButtonOrImage( 'submit_mult', 'mult_submit', __('Delete tracking'), 'b_drop.png', 'delete_tracking' diff --git a/templates/checkbox.phtml b/templates/checkbox.phtml new file mode 100644 index 0000000000..2145cb1d99 --- /dev/null +++ b/templates/checkbox.phtml @@ -0,0 +1,13 @@ + + id="" + + checked="checked" + + class="autosubmit" + /> + diff --git a/templates/select_all.phtml b/templates/select_all.phtml new file mode 100644 index 0000000000..b393efed26 --- /dev/null +++ b/templates/select_all.phtml @@ -0,0 +1,7 @@ +<?= __('With selected:') ; ?> + +
diff --git a/test/libraries/PMA_server_privileges_test.php b/test/libraries/PMA_server_privileges_test.php index 4d4eba295e..fbf304f8e1 100644 --- a/test/libraries/PMA_server_privileges_test.php +++ b/test/libraries/PMA_server_privileges_test.php @@ -1206,11 +1206,16 @@ class PMA_ServerPrivileges_Test extends PHPUnit_Framework_TestCase $html ); - $item = PMA\libraries\Util::getCheckbox( - 'createdb-2', - __('Grant all privileges on wildcard name (username\\_%).'), - false, false, 'createdb-2' - ); + $item = PMA\libraries\Template::get('checkbox') + ->render( + array( + 'html_field_name' => 'createdb-2', + 'label' => __('Grant all privileges on wildcard name (username\\_%).'), + 'checked' => false, + 'onclick' => false, + 'html_field_id' => 'createdb-2', + ) + ); $this->assertContains( $item, $html diff --git a/test/libraries/common/PMA_checkbox_test.php b/test/libraries/common/PMA_checkbox_test.php new file mode 100644 index 0000000000..7637be7968 --- /dev/null +++ b/test/libraries/common/PMA_checkbox_test.php @@ -0,0 +1,132 @@ + tag will make input a valid xml string + $this->assertXmlStringEqualsXmlString( + ' ' . PMA\libraries\Template::get('checkbox') + ->render( + array( + 'html_field_name' => $name, + 'label' => $label, + 'checked' => false, + 'onclick' => false, + 'html_field_id' => $name, + ) + ) . ' ', + ' ' + ); + } + + /** + * Test for checkbox.phtml + * + * @return void + */ + function testGetCheckboxChecked() + { + $name = "test_display_html_checkbox"; + $label = "text_label_for_checkbox"; + + $this->assertXmlStringEqualsXmlString( + '' . PMA\libraries\Template::get('checkbox') + ->render( + array( + 'html_field_name' => $name, + 'label' => $label, + 'checked' => true, + 'onclick' => false, + 'html_field_id' => $name, + ) + ) . '', + ' ' + ); + } + + /** + * Test for checkbox.phtml + * + * @return void + */ + function testGetCheckboxOnclick() + { + $name = "test_display_html_checkbox"; + $label = "text_label_for_checkbox"; + + $this->assertXmlStringEqualsXmlString( + '' . PMA\libraries\Template::get('checkbox') + ->render( + array( + 'html_field_name' => $name, + 'label' => $label, + 'checked' => false, + 'onclick' => true, + 'html_field_id' => $name, + ) + ) . '', + ' ' + ); + } + + /** + * Test for checkbox.phtml + * + * @return void + */ + function testGetCheckboxCheckedOnclick() + { + $name = "test_display_html_checkbox"; + $label = "text_label_for_checkbox"; + + $this->assertXmlStringEqualsXmlString( + '' . PMA\libraries\Template::get('checkbox') + ->render( + array( + 'html_field_name' => $name, + 'label' => $label, + 'checked' => true, + 'onclick' => true, + 'html_field_id' => $name, + ) + ) . '', + ' ' + ); + } +} diff --git a/test/libraries/common/PMA_getCheckbox_test.php b/test/libraries/common/PMA_getCheckbox_test.php deleted file mode 100644 index 8448118f2d..0000000000 --- a/test/libraries/common/PMA_getCheckbox_test.php +++ /dev/null @@ -1,94 +0,0 @@ -assertEquals( - PMA\libraries\Util::getCheckbox($name, $label, false, false, $name), - '' - ); - } - - /** - * Test for getCheckbox - * - * @return void - */ - function testGetCheckboxChecked() - { - $name = "test_display_html_checkbox"; - $label = "text_label_for_checkbox"; - - $this->assertEquals( - PMA\libraries\Util::getCheckbox($name, $label, true, false, $name), - '' - ); - } - - /** - * Test for getCheckbox - * - * @return void - */ - function testGetCheckboxOnclick() - { - $name = "test_display_html_checkbox"; - $label = "text_label_for_checkbox"; - - $this->assertEquals( - PMA\libraries\Util::getCheckbox($name, $label, false, true, $name), - '' - ); - } - - /** - * Test for getCheckbox - * - * @return void - */ - function testGetCheckboxCheckedOnclick() - { - $name = "test_display_html_checkbox"; - $label = "text_label_for_checkbox"; - - $this->assertEquals( - PMA\libraries\Util::getCheckbox($name, $label, true, true, $name), - '' - ); - } -}