From 8d03fe316ac297d0c8bf32cb2c2e2afd40f215fd Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 12 May 2015 09:56:04 -0400 Subject: [PATCH 01/10] Refactor Signed-off-by: Marc Delisle --- libraries/DisplayResults.class.php | 95 ++++++++++++++++++------------ 1 file changed, 56 insertions(+), 39 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index d7f364b12e..fa28aef47b 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -738,6 +738,56 @@ class PMA_DisplayResults } // end function _getTableNavigationButton() + /** + * Possibly return a page selector for table navigation + * + * @param array $table_navigation_html the current navigation HTML + * + * @return array ($table_navigation_html, $nbTotalPage) + * + * @access private + * + */ + private function _getHtmlPageSelector($table_navigation_html) + { + $pageNow = @floor( + $_SESSION['tmpval']['pos'] + / $_SESSION['tmpval']['max_rows'] + ) + 1; + + $nbTotalPage = @ceil( + $this->__get('unlim_num_rows') + / $_SESSION['tmpval']['max_rows'] + ); + + if ($nbTotalPage > 1) { + $table_navigation_html .= ''; + $_url_params = array( + 'db' => $this->__get('db'), + 'table' => $this->__get('table'), + 'sql_query' => $this->__get('sql_query'), + 'goto' => $this->__get('goto'), + 'is_browse_distinct' => $this->__get('is_browse_distinct'), + ); + + //
to keep the form alignment of button < and << + // and also to know what to execute when the selector changes + $table_navigation_html .= ''; + + $table_navigation_html .= PMA_Util::pageselector( + 'pos', + $_SESSION['tmpval']['max_rows'], + $pageNow, $nbTotalPage, 200, 5, 5, 20, 10 + ); + + $table_navigation_html .= '
' + . ''; + } + return array($table_navigation_html, $nbTotalPage); + } + /** * Get a navigation bar to browse among the results of a SQL query * @@ -781,45 +831,12 @@ class PMA_DisplayResults $nbTotalPage = 1; //page redirection // (unless we are showing all records) - if ($_SESSION['tmpval']['max_rows'] != self::ALL_ROWS) { //if1 - - $pageNow = @floor( - $_SESSION['tmpval']['pos'] - / $_SESSION['tmpval']['max_rows'] - ) + 1; - - $nbTotalPage = @ceil( - $this->__get('unlim_num_rows') - / $_SESSION['tmpval']['max_rows'] - ); - - if ($nbTotalPage > 1) { //if2 - - $table_navigation_html .= ''; - $_url_params = array( - 'db' => $this->__get('db'), - 'table' => $this->__get('table'), - 'sql_query' => $this->__get('sql_query'), - 'goto' => $this->__get('goto'), - 'is_browse_distinct' => $this->__get('is_browse_distinct'), - ); - - //
to keep the form alignment of button < and << - // and also to know what to execute when the selector changes - $table_navigation_html .= ''; - - $table_navigation_html .= PMA_Util::pageselector( - 'pos', - $_SESSION['tmpval']['max_rows'], - $pageNow, $nbTotalPage, 200, 5, 5, 20, 10 - ); - - $table_navigation_html .= '
' - . ''; - } //_if2 - } //_if1 + if ($_SESSION['tmpval']['max_rows'] != self::ALL_ROWS) { + list( + $table_navigation_html, + $nbTotalPage + ) = $this->_getHtmlPageSelector($table_navigation_html); + } $showing_all = false; if ($_SESSION['tmpval']['max_rows'] == self::ALL_ROWS) { From 1684a1a56eedabfc0642675728cd5919f9d2eabd Mon Sep 17 00:00:00 2001 From: Tom Sommer Date: Tue, 12 May 2015 16:01:52 +0200 Subject: [PATCH 02/10] Fix undefined index 'collation_connection' Make sure $GLOBALS[$collation] is set Signed-off-by: Tom Sommer Signed-off-by: Marc Delisle --- libraries/Config.class.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/Config.class.php b/libraries/Config.class.php index b4dfa30699..1609cea772 100644 --- a/libraries/Config.class.php +++ b/libraries/Config.class.php @@ -1029,8 +1029,9 @@ class PMA_Config if (!PMA_DRIZZLE) { // just to shorten the lines $collation = 'collation_connection'; - if (isset($_COOKIE['pma_collation_connection']) - || isset($_POST[$collation]) + if (isset($GLOBALS[$collation]) + && (isset($_COOKIE['pma_collation_connection']) + || isset($_POST[$collation])) ) { if ((! isset($config_data[$collation]) && $GLOBALS[$collation] != 'utf8_general_ci') From 969b46cca52afcf63c6beb3690e3e728444b8689 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 12 May 2015 11:46:51 -0400 Subject: [PATCH 03/10] ChangeLog entry Signed-off-by: Marc Delisle --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index bef6f66fe3..f90192a1c6 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,7 @@ phpMyAdmin - ChangeLog - bug Honor proxy settings when getting Git commit information - bug Missing title on link - bug #4512 ForceSSL Redirect Check +- bug Undefined index collation_connection 4.4.6.0 (2015-05-07) - bug #4890 webkitStorageInfo and webkitIndexedDB is deprecated From 50616659e17840c57f7a2398be3fa8724691c628 Mon Sep 17 00:00:00 2001 From: Tom Sommer Date: Tue, 12 May 2015 15:44:55 +0200 Subject: [PATCH 04/10] Don't throw errors in case reports.phpmyadmin.net is down Signed-off-by: Marc Delisle --- libraries/error_report.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/error_report.lib.php b/libraries/error_report.lib.php index 9a9768a410..5766b01f36 100644 --- a/libraries/error_report.lib.php +++ b/libraries/error_report.lib.php @@ -197,7 +197,7 @@ function PMA_sendErrorReport($report) ) ); $context = PMA_Util::handleContext($context); - $response = file_get_contents( + $response = @file_get_contents( SUBMISSION_URL, false, stream_context_create($context) From 2b41e09a48ad6576699d9b3f9e025e9dd56c259d Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 12 May 2015 11:55:53 -0400 Subject: [PATCH 05/10] ChangeLog entry Signed-off-by: Marc Delisle --- ChangeLog | 1 + 1 file changed, 1 insertion(+) diff --git a/ChangeLog b/ChangeLog index f90192a1c6..78eee3c988 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ phpMyAdmin - ChangeLog - bug Missing title on link - bug #4512 ForceSSL Redirect Check - bug Undefined index collation_connection +- bug Error when the reporting server is down 4.4.6.0 (2015-05-07) - bug #4890 webkitStorageInfo and webkitIndexedDB is deprecated From 72cb48c89ecf8491c16f048bd428c312da0154aa Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 12 May 2015 13:14:59 -0400 Subject: [PATCH 06/10] Fix coding style and doc Signed-off-by: Marc Delisle --- libraries/Config.class.php | 2 +- libraries/DisplayResults.class.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/Config.class.php b/libraries/Config.class.php index a4e3154b73..1de82c2f18 100644 --- a/libraries/Config.class.php +++ b/libraries/Config.class.php @@ -1047,7 +1047,7 @@ class PMA_Config $collation = 'collation_connection'; if (isset($GLOBALS[$collation]) && (isset($_COOKIE['pma_collation_connection']) - || isset($_POST[$collation])) + || isset($_POST[$collation])) ) { if ((! isset($config_data[$collation]) && $GLOBALS[$collation] != 'utf8_general_ci') diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index fa28aef47b..71368f9653 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -741,7 +741,7 @@ class PMA_DisplayResults /** * Possibly return a page selector for table navigation * - * @param array $table_navigation_html the current navigation HTML + * @param string $table_navigation_html the current navigation HTML * * @return array ($table_navigation_html, $nbTotalPage) * From 8a3f61c07488617311947d8cf6d98bc25ac648e1 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 12 May 2015 15:05:44 -0400 Subject: [PATCH 07/10] Refactor Signed-off-by: Marc Delisle --- libraries/DisplayResults.class.php | 187 +++++++++++++++++------------ 1 file changed, 113 insertions(+), 74 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index 71368f9653..f23f075d88 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -1127,6 +1127,112 @@ class PMA_DisplayResults } // end of the '_getAdditionalFieldsForTableNavigation()' function + /** + * Get the headers of the results table, for all of the columns + * + * @param array $displayParts which elements to display + * @param array $analyzed_sql the analyzed query + * @param string $sort_expression sort expression + * @param string $sort_expression_nodirection sort expression + * without direction + * @param string $sort_direction sort direction + * @param boolean $is_limited_display with limited operations + * or not + * @param string $unsorted_sql_query query without the sort part + * + * @return string html content + * + * @access private + * + * @see getTableHeaders() + */ + private function _getTableHeadersForColumns( + $displayParts, $analyzed_sql, + $sort_expression, $sort_expression_nodirection, + $sort_direction, $is_limited_display, $unsorted_sql_query + ) { + $html = ''; + + // required to generate sort links that will remember whether the + // "Show all" button has been clicked + $sql_md5 = md5($this->__get('sql_query')); + $session_max_rows = $is_limited_display + ? 0 + : $_SESSION['tmpval']['query'][$sql_md5]['max_rows']; + + // Following variable are needed for use in isset/empty or + // use with array indexes/safe use in the for loop + $highlight_columns = $this->__get('highlight_columns'); + $fields_meta = $this->__get('fields_meta'); + + // Prepare Display column comments if enabled + // ($GLOBALS['cfg']['ShowBrowseComments']). + $comments_map = $this->_getTableCommentsArray($analyzed_sql); + + list($col_order, $col_visib) = $this->_getColumnParams($analyzed_sql); + + // optimize: avoid calling a method on each iteration + $number_of_columns = $this->__get('fields_cnt'); + + for ($j = 0; $j < $number_of_columns; $j++) { + + // assign $i with the appropriate column order + $i = $col_order ? $col_order[$j] : $j; + + // See if this column should get highlight because it's used in the + // where-query. + $condition_field = (isset($highlight_columns[$fields_meta[$i]->name]) + || isset( + $highlight_columns[PMA_Util::backquote($fields_meta[$i]->name)]) + ) + ? true + : false; + + // Prepare comment-HTML-wrappers for each row, if defined/enabled. + $comments = $this->_getCommentForRow($comments_map, $fields_meta[$i]); + $display_params = $this->__get('display_params'); + + if (($displayParts['sort_lnk'] == '1') && ! $is_limited_display) { + + list($order_link, $sorted_header_html) + = $this->_getOrderLinkAndSortedHeaderHtml( + $fields_meta[$i], $sort_expression, + $sort_expression_nodirection, $i, $unsorted_sql_query, + $session_max_rows, $comments, + $sort_direction, $col_visib, + $col_visib[$j] + ); + + $html .= $sorted_header_html; + + $display_params['desc'][] = ' ' . "\n" . $order_link . $comments . ' ' . "\n"; + } else { + // Results can't be sorted + $html + .= $this->_getDraggableClassForNonSortableColumns( + $col_visib, $col_visib[$j], $condition_field, + $fields_meta[$i], $comments + ); + + $display_params['desc'][] = ' ' . ' ' + . htmlspecialchars($fields_meta[$i]->name) + . $comments . ' '; + } // end else + + $this->__set('display_params', $display_params); + + } // end for + return $html; + } + /** * Get the headers of the results table * @@ -1152,20 +1258,11 @@ class PMA_DisplayResults ) { $table_headers_html = ''; - // Following variable are needed for use in isset/empty or + // Needed for use in isset/empty or // use with array indexes/safe use in foreach - $fields_meta = $this->__get('fields_meta'); - $highlight_columns = $this->__get('highlight_columns'); $printview = $this->__get('printview'); $display_params = $this->__get('display_params'); - // required to generate sort links that will remember whether the - // "Show all" button has been clicked - $sql_md5 = md5($this->__get('sql_query')); - $session_max_rows = $is_limited_display - ? 0 - : $_SESSION['tmpval']['query'][$sql_md5]['max_rows']; - if ($analyzed_sql == '') { $analyzed_sql = array(); } @@ -1230,74 +1327,16 @@ class PMA_DisplayResults // 2.0 If sorting links should be used, checks if the query is a "JOIN" // statement (see 2.1.3) - // 2.0.1 Prepare Display column comments if enabled - // ($GLOBALS['cfg']['ShowBrowseComments']). - $comments_map = $this->_getTableCommentsArray($analyzed_sql); - // See if we have to highlight any header fields of a WHERE query. // Uses SQL-Parser results. $this->_setHighlightedColumnGlobalField($analyzed_sql); - list($col_order, $col_visib) = $this->_getColumnParams($analyzed_sql); - - for ($j = 0; $j < $this->__get('fields_cnt'); $j++) { - - // assign $i with appropriate column order - $i = $col_order ? $col_order[$j] : $j; - - // See if this column should get highlight because it's used in the - // where-query. - $condition_field = (isset($highlight_columns[$fields_meta[$i]->name]) - || isset( - $highlight_columns[PMA_Util::backquote($fields_meta[$i]->name)]) - ) - ? true - : false; - - // 2.0 Prepare comment-HTML-wrappers for each row, if defined/enabled. - $comments = $this->_getCommentForRow($comments_map, $fields_meta[$i]); - - $display_params = $this->__get('display_params'); - - if (($displayParts['sort_lnk'] == '1') && ! $is_limited_display) { - - list($order_link, $sorted_header_html) - = $this->_getOrderLinkAndSortedHeaderHtml( - $fields_meta[$i], $sort_expression, - $sort_expression_nodirection, $i, $unsorted_sql_query, - $session_max_rows, $comments, - $sort_direction, $col_visib, - $col_visib[$j] - ); - - $table_headers_html .= $sorted_header_html; - - $display_params['desc'][] = ' ' . "\n" . $order_link . $comments . ' ' . "\n"; - } else { - // 2.2 Results can't be sorted - - $table_headers_html - .= $this->_getDraggableClassForNonSortableColumns( - $col_visib, $col_visib[$j], $condition_field, - $fields_meta[$i], $comments - ); - - $display_params['desc'][] = ' ' . "\n" . ' ' - . htmlspecialchars($fields_meta[$i]->name) - . "\n" . $comments . ' '; - } // end else (2.2) - - $this->__set('display_params', $display_params); - - } // end for + // Get the headers for all of the columns + $table_headers_html .= $this->_getTableHeadersForColumns( + $displayParts, $analyzed_sql, $sort_expression, + $sort_expression_nodirection, $sort_direction, + $is_limited_display, $unsorted_sql_query + ); // Display column at rightside - checkboxes or empty column if (! $printview) { From 268c71deac85881fae8e1002b0ba25092406c7b3 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 12 May 2015 15:32:01 -0400 Subject: [PATCH 08/10] Remove dead code Signed-off-by: Marc Delisle --- libraries/DisplayResults.class.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index f23f075d88..f19b5005f0 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -2825,7 +2825,7 @@ class PMA_DisplayResults } $table_body_html .= $this->_getRowValues( $dt_result, $row, $row_no, $col_order, $map, - $grid_edit_class, $col_visib, $where_clause, + $grid_edit_class, $col_visib, $url_sql_query, $analyzed_sql ); @@ -2935,7 +2935,6 @@ class PMA_DisplayResults * @param string $grid_edit_class the class for all editable columns * @param boolean $col_visib column is visible(false) * array column isn't visible(string array) - * @param string $where_clause where clause * @param string $url_sql_query the analyzed sql query * @param array $analyzed_sql the analyzed query * @@ -2947,7 +2946,7 @@ class PMA_DisplayResults */ private function _getRowValues( &$dt_result, $row, $row_no, $col_order, $map, - $grid_edit_class, $col_visib, $where_clause, + $grid_edit_class, $col_visib, $url_sql_query, $analyzed_sql ) { From 5027f6a4e21cf803cdd757def0e0c5554a9ff19c Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 12 May 2015 15:39:10 -0400 Subject: [PATCH 09/10] Fix execution path warning Signed-off-by: Marc Delisle --- libraries/DisplayResults.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index f19b5005f0..ce780b4e87 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -1277,6 +1277,8 @@ class PMA_DisplayResults $table_headers_html .= $drop_down_html; + } else { + $unsorted_sql_query = ''; } // Output data needed for grid editing From 49880f0d5da25a67cd4fb0e37fb4049e352d35b5 Mon Sep 17 00:00:00 2001 From: Marc Delisle Date: Tue, 12 May 2015 15:44:02 -0400 Subject: [PATCH 10/10] Fix param type Signed-off-by: Marc Delisle --- libraries/DisplayResults.class.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/DisplayResults.class.php b/libraries/DisplayResults.class.php index ce780b4e87..9b623dbe00 100644 --- a/libraries/DisplayResults.class.php +++ b/libraries/DisplayResults.class.php @@ -1935,13 +1935,13 @@ class PMA_DisplayResults * Prepare parameters and html for sorted table header fields * * @param array $fields_meta set of field properties - * @param array $sort_expression sort expression - * @param array $sort_expression_nodirection sort expression without direction + * @param string $sort_expression sort expression + * @param string $sort_expression_nodirection sort expression without direction * @param integer $column_index the index of the column * @param string $unsorted_sql_query the unsorted sql query * @param integer $session_max_rows maximum rows resulted by sql * @param string $comments comment for row - * @param array $sort_direction sort direction + * @param string $sort_direction sort direction * @param boolean $col_visib column is visible(false) * array column isn't visible(string array) * @param string $col_visib_j element of $col_visib array @@ -2032,13 +2032,13 @@ class PMA_DisplayResults /** * Prepare parameters and html for sorted table header fields * - * @param array $sort_expression sort expression - * @param array $sort_expression_nodirection sort expression without direction + * @param string $sort_expression sort expression + * @param string $sort_expression_nodirection sort expression without direction * @param string $sort_tbl The name of the table to which * the current column belongs to * @param string $name_to_use_in_sort The current column under * consideration - * @param array $sort_direction sort direction + * @param string $sort_direction sort direction * @param array $fields_meta set of field properties * @param integer $column_index The index number to current column *