diff --git a/ChangeLog b/ChangeLog index 8d2447515f..96df065b96 100644 --- a/ChangeLog +++ b/ChangeLog @@ -123,6 +123,7 @@ phpMyAdmin - ChangeLog - issue #12542 Missing table name in account privileges editor - issue #12691 Remove ksort call on empty array in PMA_getPlugins function - issue #12443 Check parameter type before processing +- issue #12299 Avoid generating too long URLs in search 4.6.4 (2016-08-16) - issue [security] Weaknesses with cookie encryption, see PMASA-2016-29 diff --git a/js/db_search.js b/js/db_search.js index 3719d28558..e38534ae8e 100644 --- a/js/db_search.js +++ b/js/db_search.js @@ -19,6 +19,8 @@ * Unbind all event handlers before tearing down a page */ AJAX.registerTeardown('db_search.js', function () { + $('a.browse_results').unbind('click'); + $('a.delete_results').unbind('click'); $('#buttonGo').unbind('click'); $('#togglesearchresultlink').unbind('click'); $("#togglequerybox").unbind('click'); @@ -26,96 +28,6 @@ AJAX.registerTeardown('db_search.js', function () { $(document).off('submit', "#db_search_form.ajax"); }); -/** - * Loads the database search results - * - * @param result_path Url of the page to load - * @param table_name Name of table to browse - * - * @return nothing - */ -function loadResult(result_path, table_name, link) -{ - $(function () { - /** Hides the results shown by the delete criteria */ - var $msg = PMA_ajaxShowMessage(PMA_messages.strBrowsing, false); - $('#sqlqueryform').hide(); - $('#togglequerybox').hide(); - /** Load the browse results to the page */ - $("#table-info").show(); - $('#table-link').attr({"href" : 'sql.php' + link }).text(table_name); - var url = result_path + "#searchresults"; - $.get(url, {'ajax_request': true, 'is_js_confirmed': true}, function (data) { - if (typeof data !== 'undefined' && data.success) { - $('#browse-results').html(data.message); - PMA_ajaxRemoveMessage($msg); - $('.table_results').each(function () { - PMA_makegrid(this, true, true, true, true); - }); - $('#browse-results').show(); - PMA_highlightSQL($('#browse-results')); - $('html, body') - .animate({ - scrollTop: $("#browse-results").offset().top - }, 1000); - } else { - PMA_ajaxShowMessage(data.error, false); - } - }); - }); -} - -/** - * Delete the selected search results - * - * @param result_path Url of the page to load - * @param msg Text for the confirmation dialog - * - * @return nothing - */ -function deleteResult(result_path, msg) -{ - $(function () { - /** Hides the results shown by the browse criteria */ - $("#table-info").hide(); - $('#sqlqueryform').hide(); - $('#togglequerybox').hide(); - /** Conformation message for deletion */ - if (confirm(msg)) { - var $msg = PMA_ajaxShowMessage(PMA_messages.strDeleting, false); - /** Load the deleted option to the page*/ - $('#sqlqueryform').html(''); - var params = { - 'ajax_request': true, - 'is_js_confirmed': true, - 'token' : PMA_commonParams.get('token') - }; - $.post(result_path, params, - function (data) { - if (typeof data === 'undefined' || !data.success) { - PMA_ajaxShowMessage(data.error, false); - return; - } - - $('#sqlqueryform').html(data.sql_query); - /** Refresh the search results after the deletion */ - document.getElementById('buttonGo').click(); - $('#togglequerybox').html(PMA_messages.strHideQueryBox); - /** Show the results of the deletion option */ - $('#browse-results').hide(); - $('#sqlqueryform').show(); - $('#togglequerybox').show(); - $('html, body') - .animate({ - scrollTop: $("#browse-results").offset().top - }, 1000); - PMA_ajaxRemoveMessage($msg); - } - ); - } - }); -} - AJAX.registerOnload('db_search.js', function () { /** Hide the table link in the initial search result */ var icon = PMA_getImage('s_tbl.png', '', {'id': 'table-image'}).toString(); @@ -197,6 +109,97 @@ AJAX.registerOnload('db_search.js', function () { /** avoid default click action */ return false; }); + + /* + * Ajax Event handler for retrieving the results from a table + */ + $(document).on('click', 'a.browse_results', function(e){ + e.preventDefault(); + /** Hides the results shown by the delete criteria */ + var $msg = PMA_ajaxShowMessage(PMA_messages.strBrowsing, false); + $('#sqlqueryform').hide(); + $('#togglequerybox').hide(); + /** Load the browse results to the page */ + $("#table-info").show(); + var table_name = $(this).data('table-name'); + $('#table-link').attr({"href" : $(this).attr('href')}).text(table_name); + + var url = $(this).attr('href') + "#searchresults"; + var browse_sql = $(this).data('browse-sql'); + var params = { + 'ajax_request': true, + 'is_js_confirmed': true, + 'sql_query' : browse_sql, + 'token' : PMA_commonParams.get('token') + }; + $.post(url, params, function (data) { + if (typeof data !== 'undefined' && data.success) { + $('#browse-results').html(data.message); + PMA_ajaxRemoveMessage($msg); + $('.table_results').each(function () { + PMA_makegrid(this, true, true, true, true); + }); + $('#browse-results').show(); + PMA_highlightSQL($('#browse-results')); + $('html, body') + .animate({ + scrollTop: $("#browse-results").offset().top + }, 1000); + } else { + PMA_ajaxShowMessage(data.error, false); + } + }); + }); + + /* + * Ajax Event handler for deleting the results from a table + */ + $(document).on('click', 'a.delete_results', function(e){ + e.preventDefault(); + /** Hides the results shown by the browse criteria */ + $("#table-info").hide(); + $('#sqlqueryform').hide(); + $('#togglequerybox').hide(); + /** Conformation message for deletion */ + var msg = PMA_sprintf( + PMA_messages.strConfirmDeleteResults, + $(this).data('table-name') + ); + if (confirm(msg)) { + var $msg = PMA_ajaxShowMessage(PMA_messages.strDeleting, false); + /** Load the deleted option to the page*/ + $('#sqlqueryform').html(''); + var params = { + 'ajax_request': true, + 'is_js_confirmed': true, + 'sql_query': $(this).data('delete-sql'), + 'token' : PMA_commonParams.get('token') + }; + var url = $(this).attr('href'); + + $.post(url, params, function (data) { + if (typeof data === 'undefined' || !data.success) { + PMA_ajaxShowMessage(data.error, false); + return; + } + + $('#sqlqueryform').html(data.sql_query); + /** Refresh the search results after the deletion */ + document.getElementById('buttonGo').click(); + $('#togglequerybox').html(PMA_messages.strHideQueryBox); + /** Show the results of the deletion option */ + $('#browse-results').hide(); + $('#sqlqueryform').show(); + $('#togglequerybox').show(); + $('html, body') + .animate({ + scrollTop: $("#browse-results").offset().top + }, 1000); + PMA_ajaxRemoveMessage($msg); + }); + } + }); + /** * Ajax Event handler for retrieving the result of an SQL Query */ diff --git a/js/messages.php b/js/messages.php index bf4764bed6..bd807543b1 100644 --- a/js/messages.php +++ b/js/messages.php @@ -385,6 +385,7 @@ $js_messages['strHideSearchResults'] = __('Hide search results'); $js_messages['strShowSearchResults'] = __('Show search results'); $js_messages['strBrowsing'] = __('Browsing'); $js_messages['strDeleting'] = __('Deleting'); +$js_messages['strConfirmDeleteResults'] = __('Delete the matches for the %s table?'); /* For db_routines.js */ $js_messages['MissingReturn'] diff --git a/libraries/DbSearch.php b/libraries/DbSearch.php index 3362889bab..1caf9f6f39 100644 --- a/libraries/DbSearch.php +++ b/libraries/DbSearch.php @@ -334,29 +334,22 @@ class DbSearch $html_output .= ''; // Displays browse/delete link if result count > 0 if ($res_cnt > 0) { - $this_url_params['sql_query'] = $newsearchsqls['select_columns']; + $this_url_params['db'] = htmlspecialchars($GLOBALS['db']); + $this_url_params['table'] = htmlspecialchars($each_table); $browse_result_path = 'sql.php' . URL::getCommon($this_url_params); - $html_output .= '' + $html_output .= '' . __('Browse') . ''; - $this_url_params['sql_query'] = $newsearchsqls['delete']; - $delete_result_path = 'sql.php' . URL::getCommon($this_url_params); - $html_output .= '' + + $delete_result_path = $browse_result_path; + $html_output .= '' . __('Delete') . ''; } else { $html_output .= ' ' diff --git a/test/classes/DbSearchTest.php b/test/classes/DbSearchTest.php index 1493ef600b..aaa5cb9c9e 100644 --- a/test/classes/DbSearchTest.php +++ b/test/classes/DbSearchTest.php @@ -39,6 +39,7 @@ class DbSearchTest extends PMATestCase $this->object = new DbSearch('pma_test'); $GLOBALS['server'] = 0; $GLOBALS['db'] = 'pma'; + $GLOBALS['collation_connection'] = 'utf-8'; //mock DBI $dbi = $this->getMockBuilder('PMA\libraries\DatabaseInterface') @@ -162,28 +163,20 @@ class DbSearchTest extends PMATestCase 'delete' => 'column2' ), '2 matches in table1' - . 'Browse' - . 'Browse' + . 'Delete' + . '&is_js_confirmed=0&server=0&' + . 'lang=en&collation_connection=utf-8" ' + . 'data-delete-sql="column2" ' + . 'data-table-name="table1" ' + . '>Delete' ) ); }