From 3b9fb2b664632557866feb083b59743ed60d1e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 16 Nov 2017 13:04:46 +0100 Subject: [PATCH 01/11] Simplify handling of long URLs in Util::linkOrButton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We no longer create form, but rather rather tag the link to be handled as POST on the client side. This way the code is way simpler without need on any special case handling on server side. Fixes #13649 Signed-off-by: Michal Čihař --- js/ajax.js | 3 ++ js/functions.js | 24 +--------- js/gis_data_editor.js | 3 -- js/sql.js | 26 +++++------ libraries/classes/Util.php | 91 ++++++++------------------------------ libraries/common.inc.php | 68 ---------------------------- 6 files changed, 34 insertions(+), 181 deletions(-) diff --git a/js/ajax.js b/js/ajax.js index e74c4f225a..deadb4c750 100644 --- a/js/ajax.js +++ b/js/ajax.js @@ -276,6 +276,9 @@ var AJAX = { var params = 'ajax_request=true&ajax_page_request=true'; if (! isLink) { params += '&' + $(this).serialize(); + } else if (AJAX.source.attr('data-post')) { + params += '&' + AJAX.source.attr('data-post'); + isLink = false; } if (! (history && history.pushState)) { // Add a list of menu hashes that we have in the cache to the request diff --git a/js/functions.js b/js/functions.js index b02abdea92..76545a6b68 100644 --- a/js/functions.js +++ b/js/functions.js @@ -665,18 +665,7 @@ function confirmLink (theLink, theSqlQuery) { var is_confirmed = confirm(PMA_sprintf(PMA_messages.strDoYouReally, theSqlQuery)); if (is_confirmed) { - if ($(theLink).hasClass('formLinkSubmit')) { - var name = 'is_js_confirmed'; - - if ($(theLink).attr('href').indexOf('usesubform') !== -1) { - var matches = $(theLink).attr('href').substr('#').match(/usesubform\[(\d+)\]/i); - if (matches !== null) { - name = 'subform[' + matches[1] + '][is_js_confirmed]'; - } - } - - $(theLink).parents('form').append(''); - } else if (typeof(theLink.href) !== 'undefined') { + if (typeof(theLink.href) !== 'undefined') { theLink.href += '&is_js_confirmed=1'; } else if (typeof(theLink.form) !== 'undefined') { theLink.form.action += '?is_js_confirmed=1'; @@ -4074,7 +4063,6 @@ AJAX.registerOnload('functions.js', function () { */ AJAX.registerTeardown('functions.js', function () { $(document).off('change', 'select.pageselector'); - $(document).off('click', 'a.formLinkSubmit'); $('#update_recent_tables').off('ready'); $('#sync_favorite_tables').off('ready'); }); @@ -4119,16 +4107,6 @@ AJAX.registerOnload('functions.js', function () { */ PMA_init_slider(); - /** - * Enables the text generated by PhpMyAdmin\Util::linkOrButton() to be clickable - */ - $(document).on('click', 'a.formLinkSubmit', function (e) { - if (! $(this).hasClass('requireConfirm')) { - submitFormLink($(this)); - return false; - } - }); - var $updateRecentTables = $('#update_recent_tables'); if ($updateRecentTables.length) { $.get( diff --git a/js/gis_data_editor.js b/js/gis_data_editor.js index 93ac847123..977520763c 100644 --- a/js/gis_data_editor.js +++ b/js/gis_data_editor.js @@ -221,9 +221,6 @@ AJAX.registerTeardown('gis_data_editor.js', function () { }); AJAX.registerOnload('gis_data_editor.js', function () { - // Remove the class that is added due to the URL being too long. - $('span.open_gis_editor a').removeClass('formLinkSubmit'); - /** * Prepares and insert the GIS data to the input field on clicking 'copy'. */ diff --git a/js/sql.js b/js/sql.js index 7c175f9761..2a06186d18 100644 --- a/js/sql.js +++ b/js/sql.js @@ -187,22 +187,18 @@ AJAX.registerOnload('sql.js', function () { var $link = $(this); $link.PMA_confirm(question, $link.attr('href'), function (url) { $msgbox = PMA_ajaxShowMessage(); - if ($link.hasClass('formLinkSubmit')) { - submitFormLink($link); - } else { - var params = { - 'ajax_request': true, - 'is_js_confirmed': true - }; - $.post(url, params, function (data) { - if (data.success) { - PMA_ajaxShowMessage(data.message); - $link.closest('tr').remove(); - } else { - PMA_ajaxShowMessage(data.error, false); - } - }); + var params = 'ajax_request=1&is_js_confirmed=1'; + if ($link.attr('data-post')) { + params += '&' + $link.attr('data-post'); } + $.post(url, params, function (data) { + if (data.success) { + PMA_ajaxShowMessage(data.message); + $link.closest('tr').remove(); + } else { + PMA_ajaxShowMessage(data.error, false); + } + }); }); }); diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 46aaf42eff..3cdabc96c1 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1774,81 +1774,28 @@ class Util } } - if (($url_length <= $GLOBALS['cfg']['LinkLengthLimit']) - && $in_suhosin_limits - && ! $force_button + $tag_params_strings = array(); + if (($url_length > $GLOBALS['cfg']['LinkLengthLimit']) + || ! $in_suhosin_limits + || $force_button ) { - $tag_params_strings = array(); - foreach ($tag_params as $par_name => $par_value) { - $tag_params_strings[] = $par_name . '="' . htmlspecialchars($par_value) . '"'; - } + $parts = explode('?', $url, 2); + /* + * The data-post indicates that client should do POST + * this is handled in js/ajax.js + */ + $tag_params_strings[] = 'data-post="' . (isset($parts[1]) ? $parts[1] : '') . '"'; + $url = $parts[0]; + } - // no whitespace within an else Safari will make it part of the link - $ret = '' - . $message . $displayed_message . ''; - } else { - // no spaces (line breaks) at all - // or after the hidden fields - // IE will display them all + foreach ($tag_params as $par_name => $par_value) { + $tag_params_strings[] = $par_name . '="' . htmlspecialchars($par_value) . '"'; + } - if (! isset($query_parts)) { - $query_parts = self::splitURLQuery($url); - } - $url_parts = parse_url($url); - - if ($new_form) { - if ($target) { - $target = ' target="' . $target . '"'; - } - $ret = ''; - } - } // end if... else... - - return $ret; + // no whitespace within an else Safari will make it part of the link + return '' + . $message . $displayed_message . ''; } // end of the 'linkOrButton()' function /** diff --git a/libraries/common.inc.php b/libraries/common.inc.php index 6b323bffe2..2826ed254b 100644 --- a/libraries/common.inc.php +++ b/libraries/common.inc.php @@ -145,59 +145,6 @@ foreach (get_defined_vars() as $key => $value) { } unset($key, $value, $variables_whitelist); -/** - * Subforms - some functions need to be called by form, cause of the limited URL - * length, but if this functions inside another form you cannot just open a new - * form - so phpMyAdmin uses 'arrays' inside this form - * - * - *
- * ... main form elements ... - * - * ... other subform data ... - * - * ... other subforms ... - * - * ... other subform data ... - * - * ... main form elements ... - * - *
- *
- * - * so we now check if a subform is submitted - */ -$__redirect = null; -if (isset($_POST['usesubform']) && ! defined('PMA_MINIMUM_COMMON')) { - // if a subform is present and should be used - // the rest of the form is deprecated - $subform_id = key($_POST['usesubform']); - $subform = $_POST['subform'][$subform_id]; - $_POST = $subform; - $_REQUEST = $subform; - /** - * some subforms need another page than the main form, so we will just - * include this page at the end of this script - we use $__redirect to - * track this - */ - if (isset($_POST['redirect']) - && $_POST['redirect'] != basename($PMA_PHP_SELF) - ) { - $__redirect = $_POST['redirect']; - unset($_POST['redirect']); - } - unset($subform_id, $subform); -} else { - // Note: here we overwrite $_REQUEST so that it does not contain cookies, - // because another application for the same domain could have set - // a cookie (with a compatible path) that overrides a variable - // we expect from GET or POST. - // We'll refer to cookies explicitly with the $_COOKIE syntax. - $_REQUEST = array_merge($_GET, $_POST); -} -// end check if a subform is submitted - - /******************************************************************************/ /* parsing configuration file LABEL_parsing_config_file */ @@ -300,13 +247,6 @@ $goto_whitelist = array( 'user_password.php', ); -/** - * check $__redirect against whitelist - */ -if (! Core::checkPageValidity($__redirect, $goto_whitelist)) { - $__redirect = null; -} - /** * holds page that should be displayed * @global string $GLOBALS['goto'] @@ -634,14 +574,6 @@ if (! defined('PMA_MINIMUM_COMMON')) { /* Tell tracker that it can actually work */ Tracker::enable(); -if (!empty($__redirect) && in_array($__redirect, $goto_whitelist)) { - /** - * include subform target page - */ - include $__redirect; - exit(); -} - // If Zero configuration mode enabled, check PMA tables in current db. if (! defined('PMA_MINIMUM_COMMON') && ! empty($GLOBALS['server']) From 816c42665af83d8f2652c6c0e9c0d92c63526ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 16 Nov 2017 13:17:42 +0100 Subject: [PATCH 02/11] Add tests for Util::linkOrButton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- test/classes/UtilTest.php | 53 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/test/classes/UtilTest.php b/test/classes/UtilTest.php index 20415daa1d..804d31f1dd 100644 --- a/test/classes/UtilTest.php +++ b/test/classes/UtilTest.php @@ -2172,4 +2172,57 @@ class UtilTest extends PmaTestCase $no_support_types, Util::unsupportedDatatypes() ); } + + /** + * Test for Util::linkOrButton + * + * @return void + * + * @dataProvider linksOrButtons + */ + public function testLinkOrButton(array $params, $limit, $match) + { + $restore = isset($GLOBALS['cfg']['LinkLengthLimit']) ? $GLOBALS['cfg']['LinkLengthLimit'] : 1000; + $GLOBALS['cfg']['LinkLengthLimit'] = $limit; + try { + $result = call_user_func_array( + array('PhpMyAdmin\Util', 'linkOrButton'), + $params + ); + $this->assertEquals($match, $result); + } finally { + $GLOBALS['cfg']['LinkLengthLimit'] = $restore; + } + } + + /** + * Data provider for Util::linkOrButton test + * + * @return array + */ + public function linksOrButtons() + { + return [ + [ + ['index.php', 'text'], + 1000, + 'text' + ], + [ + ['index.php?some=parameter', 'text'], + 20, + 'text', + ], + [ + ['index.php', 'text', [], true, false, 'target'], + 1000, + 'text', + ], + [ + ['url.php?url=http://phpmyadmin.net/', 'text', [], true, false, '_blank'], + 1000, + 'text', + ], + ]; + } } From 50c65bc3fb9aec08b7a24e6482f885e817b5ad2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 16 Nov 2017 14:35:28 +0100 Subject: [PATCH 03/11] Remove no longer needed $new_form from Util::linkOrButton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Michal Čihař --- libraries/classes/Display/Results.php | 18 ++++++------------ libraries/classes/InsertEdit.php | 2 +- libraries/classes/Util.php | 7 +------ templates/table/search/input_box.twig | 2 +- test/classes/UtilTest.php | 4 ++-- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index a35651d461..04e7b9515f 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -1864,7 +1864,7 @@ class Results $tmp_url = 'sql.php' . Url::getCommon($url_params_full_text); return Util::linkOrButton( - $tmp_url, $tmp_image, array(), false + $tmp_url, $tmp_image, array() ); } // end of the '_getFullOrPartialTextButtonOrLink()' function @@ -2325,7 +2325,7 @@ class Results return Util::linkOrButton( $order_url, $inner_link_content, - $order_link_params, false, true + $order_link_params, true ); } // end of the '_getSortOrderLink()' function @@ -4978,7 +4978,7 @@ class Results Util::getIcon( 'b_view_add.png', __('Create view'), true ), - array('class' => 'create_view' . $ajax_class), true, true, '' + array('class' => 'create_view' . $ajax_class), true, '' ) . '' . "\n"; } @@ -5026,7 +5026,6 @@ class Results ), array('id' => 'copyToClipBoard'), true, - true, 'copy_to_clip_board' ); @@ -5049,7 +5048,6 @@ class Results ), array('id' => 'printView'), true, - true, 'print_view' ); @@ -5157,7 +5155,6 @@ class Results ), '', true, - true, '' ) . "\n"; @@ -5170,7 +5167,6 @@ class Results ), '', true, - true, '' ) . "\n"; @@ -5195,7 +5191,6 @@ class Results ), '', true, - true, '' ) . "\n"; @@ -5622,7 +5617,7 @@ class Results $ret .= '' . Util::linkOrButton( - $edit_url, $edit_str, array(), false + $edit_url, $edit_str, array() ); /* * Where clause for selecting this row uniquely is provided as @@ -5669,7 +5664,7 @@ class Results $ret .= 'center print_ignore" ' . ' >' . Util::linkOrButton( - $copy_url, $copy_str, array(), false + $copy_url, $copy_str, array() ); /* @@ -5719,8 +5714,7 @@ class Results . Util::linkOrButton( $del_url, $del_str, - array('class' => 'delete_row requireConfirm' . $ajax), - false + array('class' => 'delete_row requireConfirm' . $ajax) ) . '
' . $js_conf . '
' . ''; diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 4eb779a12b..1272bb4f5a 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -1433,7 +1433,7 @@ class InsertEdit $edit_str = Util::getIcon('b_edit.png', __('Edit/Insert')); return '' . Util::linkOrButton( - '#', $edit_str, array(), false, false, '_blank' + '#', $edit_str, array(), false, '_blank' ) . ''; } diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 3cdabc96c1..d7f13ae412 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1052,7 +1052,6 @@ class Util htmlspecialchars('url.php?url=' . urlencode($url)), sprintf(__('Analyze Explain at %s'), 'mariadb.org'), array(), - true, false, '_blank' ) . ' ]'; @@ -1085,7 +1084,6 @@ class Util 'import.php' . Url::getCommon($url_params), __('Without PHP code'), array(), - true, false, '', true @@ -1097,7 +1095,6 @@ class Util 'import.php' . Url::getCommon($url_params), __('Submit query'), array(), - true, false, '', true @@ -1710,8 +1707,6 @@ class Util * @param string $message the link message * @param mixed $tag_params string: js confirmation * array: additional tag params (f.e. style="") - * @param boolean $new_form we set this to false when we are already in - * a form, to avoid generating nested forms * @param boolean $strip_img whether to strip the image * @param string $target target * @param boolean $force_button use a button even when the URL is not too long @@ -1720,7 +1715,7 @@ class Util */ public static function linkOrButton( $url, $message, $tag_params = array(), - $new_form = true, $strip_img = false, $target = '', $force_button = false + $strip_img = false, $target = '', $force_button = false ) { $url_length = mb_strlen($url); diff --git a/templates/table/search/input_box.twig b/templates/table/search/input_box.twig index bea3180b7a..9530a7063b 100644 --- a/templates/table/search/input_box.twig +++ b/templates/table/search/input_box.twig @@ -38,7 +38,7 @@ {% set edit_url = 'gis_data_editor.php' ~ Url_getCommon() %} {% set edit_str = Util_getIcon('b_edit.png', 'Edit/Insert'|trans) %} - {{ Util_linkOrButton(edit_url, edit_str, [], false, false, '_blank') }} + {{ Util_linkOrButton(edit_url, edit_str, [], false, '_blank') }} {% endif %} {% elseif column_type starts with 'enum' diff --git a/test/classes/UtilTest.php b/test/classes/UtilTest.php index 804d31f1dd..b3aa7dbce0 100644 --- a/test/classes/UtilTest.php +++ b/test/classes/UtilTest.php @@ -2214,12 +2214,12 @@ class UtilTest extends PmaTestCase 'text', ], [ - ['index.php', 'text', [], true, false, 'target'], + ['index.php', 'text', [], false, 'target'], 1000, 'text', ], [ - ['url.php?url=http://phpmyadmin.net/', 'text', [], true, false, '_blank'], + ['url.php?url=http://phpmyadmin.net/', 'text', [], false, '_blank'], 1000, 'text', ], From 1a0bb3ebd54896383aa9de7bf5a2ca62001d249c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 16 Nov 2017 14:37:32 +0100 Subject: [PATCH 04/11] Avoid using mb_* function for URL length calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It is handled in bytes on the webserver side, so use limits in bytes not in chars as mb_strlen does. Signed-off-by: Michal Čihař --- libraries/classes/Util.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index d7f13ae412..729dee5efc 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1717,7 +1717,7 @@ class Util $url, $message, $tag_params = array(), $strip_img = false, $target = '', $force_button = false ) { - $url_length = mb_strlen($url); + $url_length = strlen($url); if (! is_array($tag_params)) { $tmp = $tag_params; @@ -1760,7 +1760,7 @@ class Util } list(, $eachval) = explode('=', $query_pair); - if (mb_strlen($eachval) > $suhosin_get_MaxValueLength + if (strlen($eachval) > $suhosin_get_MaxValueLength ) { $in_suhosin_limits = false; break; From 657ee671fc8532e5c6577474ec3856976eaab8c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 16 Nov 2017 14:40:02 +0100 Subject: [PATCH 05/11] Avoid double html encoding of link target MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is done when printing the attributes as well. Signed-off-by: Michal Čihař --- libraries/classes/Util.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 729dee5efc..ea069171cd 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1729,7 +1729,7 @@ class Util unset($tmp); } if (! empty($target)) { - $tag_params['target'] = htmlentities($target); + $tag_params['target'] = $target; if ($target === '_blank' && strncmp($url, 'url.php?', 8) == 0) { $tag_params['rel'] = 'noopener noreferrer'; } From 99e9854473155a5337fc9361d9eba4bae3d30792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 16 Nov 2017 14:41:26 +0100 Subject: [PATCH 06/11] Always use POST for links containing SQL query MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This way the SQL queries will not apper in the web server logs. Signed-off-by: Michal Čihař --- libraries/classes/Util.php | 1 + test/classes/Display/ResultsTest.php | 32 ++++++++++++++-------------- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index ea069171cd..ef228c00b6 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1773,6 +1773,7 @@ class Util if (($url_length > $GLOBALS['cfg']['LinkLengthLimit']) || ! $in_suhosin_limits || $force_button + || strpos($url, 'sql_query=') !== false ) { $parts = explode('?', $url, 2); /* diff --git a/test/classes/Display/ResultsTest.php b/test/classes/Display/ResultsTest.php index 661236638f..ed0d820019 100644 --- a/test/classes/Display/ResultsTest.php +++ b/test/classes/Display/ResultsTest.php @@ -438,11 +438,11 @@ class ResultsTest extends PmaTestCase '%60customer%60.%60id%60+%3D+1', '' . '' - . ' Edit' . '' @@ -501,11 +501,11 @@ class ResultsTest extends PmaTestCase 'klass', '' - . ' Copy' . '' @@ -564,7 +564,7 @@ class ResultsTest extends PmaTestCase 'DELETE FROM `Data`.`customer` WHERE `customer`.`id` = 1', 'klass', '' - . ' ' - . '' + . '_action=update">' . ' Edit' . '
' - . 'Copy Copy' . '' - . ' Delete
', 'DELETE FROM `data`.`new` WHERE `new`.`id` = 1', '' - . ' Delete' . '
DELETE FROM `data`.`new` WHERE `new`.' . '`id` = 1
' - . 'Copy Copy' . '' . '' - . 'Edit Edit' . ''; - } - // Suhosin: Check that each query parameter is not above maximum $in_suhosin_limits = true; if ($url_length <= $GLOBALS['cfg']['LinkLengthLimit']) { @@ -1796,7 +1783,7 @@ class Util // no whitespace within an else Safari will make it part of the link return '' - . $message . $displayed_message . ''; + . $message . ''; } // end of the 'linkOrButton()' function /** From 3cd104a45411326c01b968c8acbfc6e98300cead Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 16 Nov 2017 14:58:15 +0100 Subject: [PATCH 09/11] Remove not needed $force_button paratemet from Util::linkOrButton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It was used to force POST for few links with the SQL, but that is now done automatically. Signed-off-by: Michal Čihař --- libraries/classes/Util.php | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 6d7718fece..5e26dbce2f 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1085,8 +1085,7 @@ class Util __('Without PHP code'), array(), false, - '', - true + '' ) . ' ]'; @@ -1096,8 +1095,7 @@ class Util __('Submit query'), array(), false, - '', - true + '' ) . ' ]'; } else { @@ -1714,13 +1712,12 @@ class Util * array: additional tag params (f.e. style="") * @param boolean $strip_img whether to strip the image * @param string $target target - * @param boolean $force_button use a button even when the URL is not too long * * @return string the results to be echoed or saved in an array */ public static function linkOrButton( $url, $message, $tag_params = array(), - $strip_img = false, $target = '', $force_button = false + $strip_img = false, $target = '' ) { $url_length = strlen($url); @@ -1764,7 +1761,6 @@ class Util $tag_params_strings = array(); if (($url_length > $GLOBALS['cfg']['LinkLengthLimit']) || ! $in_suhosin_limits - || $force_button || strpos($url, 'sql_query=') !== false ) { $parts = explode('?', $url, 2); From ad72aaecc22ab6e816431a4dda88520a3d5512b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 16 Nov 2017 15:02:01 +0100 Subject: [PATCH 10/11] Avoid passing default params to Util::linkOrButton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Do not pass optional parameters with default values. Signed-off-by: Michal Čihař --- libraries/classes/Display/Results.php | 26 ++++++++------------------ libraries/classes/Util.php | 13 +++---------- 2 files changed, 11 insertions(+), 28 deletions(-) diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index 04e7b9515f..809660ab92 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -1863,9 +1863,7 @@ class Results . $tmp_txt . '" title="' . $tmp_txt . '" />'; $tmp_url = 'sql.php' . Url::getCommon($url_params_full_text); - return Util::linkOrButton( - $tmp_url, $tmp_image, array() - ); + return Util::linkOrButton($tmp_url, $tmp_image); } // end of the '_getFullOrPartialTextButtonOrLink()' function @@ -4978,7 +4976,7 @@ class Results Util::getIcon( 'b_view_add.png', __('Create view'), true ), - array('class' => 'create_view' . $ajax_class), true, '' + array('class' => 'create_view' . $ajax_class), true ) . '' . "\n"; } @@ -5025,8 +5023,7 @@ class Results 'b_insrow.png', __('Copy to clipboard'), true ), array('id' => 'copyToClipBoard'), - true, - 'copy_to_clip_board' + true ); return $html; @@ -5154,8 +5151,7 @@ class Results 'b_tblexport.png', __('Export'), true ), '', - true, - '' + true ) . "\n"; @@ -5166,8 +5162,7 @@ class Results 'b_chart.png', __('Display chart'), true ), '', - true, - '' + true ) . "\n"; @@ -5190,8 +5185,7 @@ class Results 'b_globe.gif', __('Visualize GIS data'), true ), '', - true, - '' + true ) . "\n"; } @@ -5616,9 +5610,7 @@ class Results $ret .= '' - . Util::linkOrButton( - $edit_url, $edit_str, array() - ); + . Util::linkOrButton($edit_url, $edit_str); /* * Where clause for selecting this row uniquely is provided as * a hidden input. Used by jQuery scripts for handling grid editing @@ -5663,9 +5655,7 @@ class Results } $ret .= 'center print_ignore" ' . ' >' - . Util::linkOrButton( - $copy_url, $copy_str, array() - ); + . Util::linkOrButton($copy_url, $copy_str); /* * Where clause for selecting this row uniquely is provided as diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index 5e26dbce2f..cc8fbe21c2 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1082,30 +1082,23 @@ class Util $php_link = ' [ ' . self::linkOrButton( 'import.php' . Url::getCommon($url_params), - __('Without PHP code'), - array(), - false, - '' + __('Without PHP code') ) . ' ]'; $php_link .= ' [ ' . self::linkOrButton( 'import.php' . Url::getCommon($url_params), - __('Submit query'), - array(), - false, - '' + __('Submit query') ) . ' ]'; } else { $php_params = $url_params; $php_params['show_as_php'] = 1; - $_message = __('Create PHP code'); $php_link = ' [ ' . self::linkOrButton( 'import.php' . Url::getCommon($php_params), - $_message + __('Create PHP code') ) . ' ]'; } From f29640c5d8f155e520b4ff30a769d5bf8c2d1ff1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Thu, 16 Nov 2017 15:25:01 +0100 Subject: [PATCH 11/11] Remove $strip_img parameter from Util::linkOrButton MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It did not behave as documented for ages, it only influenced whether additional text was added to the link. Callers should use parameters to Util::getIcon to achieve this (if it is actually needed somewhere) Signed-off-by: Michal Čihař --- libraries/classes/Display/Results.php | 21 ++++++--------------- libraries/classes/InsertEdit.php | 2 +- libraries/classes/Util.php | 5 +---- templates/table/search/input_box.twig | 2 +- test/classes/UtilTest.php | 4 ++-- 5 files changed, 11 insertions(+), 23 deletions(-) diff --git a/libraries/classes/Display/Results.php b/libraries/classes/Display/Results.php index 809660ab92..e01438264b 100644 --- a/libraries/classes/Display/Results.php +++ b/libraries/classes/Display/Results.php @@ -2322,8 +2322,7 @@ class Results . ''; return Util::linkOrButton( - $order_url, $inner_link_content, - $order_link_params, true + $order_url, $inner_link_content, $order_link_params ); } // end of the '_getSortOrderLink()' function @@ -4976,7 +4975,7 @@ class Results Util::getIcon( 'b_view_add.png', __('Create view'), true ), - array('class' => 'create_view' . $ajax_class), true + array('class' => 'create_view' . $ajax_class) ) . '' . "\n"; } @@ -5022,8 +5021,7 @@ class Results Util::getIcon( 'b_insrow.png', __('Copy to clipboard'), true ), - array('id' => 'copyToClipBoard'), - true + array('id' => 'copyToClipBoard') ); return $html; @@ -5044,7 +5042,6 @@ class Results 'b_print.png', __('Print'), true ), array('id' => 'printView'), - true, 'print_view' ); @@ -5149,9 +5146,7 @@ class Results 'tbl_export.php' . Url::getCommon($_url_params), Util::getIcon( 'b_tblexport.png', __('Export'), true - ), - '', - true + ) ) . "\n"; @@ -5160,9 +5155,7 @@ class Results 'tbl_chart.php' . Url::getCommon($_url_params), Util::getIcon( 'b_chart.png', __('Display chart'), true - ), - '', - true + ) ) . "\n"; @@ -5183,9 +5176,7 @@ class Results . Url::getCommon($_url_params), Util::getIcon( 'b_globe.gif', __('Visualize GIS data'), true - ), - '', - true + ) ) . "\n"; } diff --git a/libraries/classes/InsertEdit.php b/libraries/classes/InsertEdit.php index 1272bb4f5a..1aef365b57 100644 --- a/libraries/classes/InsertEdit.php +++ b/libraries/classes/InsertEdit.php @@ -1433,7 +1433,7 @@ class InsertEdit $edit_str = Util::getIcon('b_edit.png', __('Edit/Insert')); return '' . Util::linkOrButton( - '#', $edit_str, array(), false, '_blank' + '#', $edit_str, array(), '_blank' ) . ''; } diff --git a/libraries/classes/Util.php b/libraries/classes/Util.php index cc8fbe21c2..2f538dc863 100644 --- a/libraries/classes/Util.php +++ b/libraries/classes/Util.php @@ -1052,7 +1052,6 @@ class Util htmlspecialchars('url.php?url=' . urlencode($url)), sprintf(__('Analyze Explain at %s'), 'mariadb.org'), array(), - false, '_blank' ) . ' ]'; } @@ -1703,14 +1702,12 @@ class Util * @param string $message the link message * @param mixed $tag_params string: js confirmation * array: additional tag params (f.e. style="") - * @param boolean $strip_img whether to strip the image * @param string $target target * * @return string the results to be echoed or saved in an array */ public static function linkOrButton( - $url, $message, $tag_params = array(), - $strip_img = false, $target = '' + $url, $message, $tag_params = array(), $target = '' ) { $url_length = strlen($url); diff --git a/templates/table/search/input_box.twig b/templates/table/search/input_box.twig index 9530a7063b..dd0c380abb 100644 --- a/templates/table/search/input_box.twig +++ b/templates/table/search/input_box.twig @@ -38,7 +38,7 @@ {% set edit_url = 'gis_data_editor.php' ~ Url_getCommon() %} {% set edit_str = Util_getIcon('b_edit.png', 'Edit/Insert'|trans) %} - {{ Util_linkOrButton(edit_url, edit_str, [], false, '_blank') }} + {{ Util_linkOrButton(edit_url, edit_str, [], '_blank') }} {% endif %} {% elseif column_type starts with 'enum' diff --git a/test/classes/UtilTest.php b/test/classes/UtilTest.php index b3aa7dbce0..5837511f9f 100644 --- a/test/classes/UtilTest.php +++ b/test/classes/UtilTest.php @@ -2214,12 +2214,12 @@ class UtilTest extends PmaTestCase 'text', ], [ - ['index.php', 'text', [], false, 'target'], + ['index.php', 'text', [], 'target'], 1000, 'text', ], [ - ['url.php?url=http://phpmyadmin.net/', 'text', [], false, '_blank'], + ['url.php?url=http://phpmyadmin.net/', 'text', [], '_blank'], 1000, 'text', ],