From 32eb7582325eded6b693e8f96c55c2e97c43e303 Mon Sep 17 00:00:00 2001 From: Rouslan Placella Date: Tue, 8 May 2012 15:30:05 +0100 Subject: [PATCH] Drop output buffering from PMA_showMessage() --- libraries/common.lib.php | 87 ++++++++++++++++++---------------------- 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/libraries/common.lib.php b/libraries/common.lib.php index 3aa5af979d..eeae7c356e 100644 --- a/libraries/common.lib.php +++ b/libraries/common.lib.php @@ -980,19 +980,14 @@ if (typeof(window.parent) != 'undefined' * * @access public */ -function PMA_showMessage($message, $sql_query = null, $type = 'notice', +function PMA_showMessage( + $message, + $sql_query = null, + $type = 'notice', $is_view = false ) { - /* - * PMA_ajaxResponse uses this function to collect the string of HTML generated - * for showing the message. Use output buffering to collect it and return it - * in a string. In some special cases on sql.php, buffering has to be disabled - * and hence we check with $GLOBALS['buffer_message'] - */ - if ($GLOBALS['is_ajax_request'] == true && ! isset($GLOBALS['buffer_message'])) { - ob_start(); - } global $cfg; + $retval = ''; if (null === $sql_query) { if (! empty($GLOBALS['display_query'])) { @@ -1009,7 +1004,7 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', } if (isset($GLOBALS['using_bookmark_message'])) { - $GLOBALS['using_bookmark_message']->display(); + $retval .= $GLOBALS['using_bookmark_message']->getDisplay(); unset($GLOBALS['using_bookmark_message']); } @@ -1018,13 +1013,13 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', if (! $is_view && strlen($GLOBALS['table']) && $cfg['ShowTooltip']) { $tooltip = PMA_Table::sGetToolTip($GLOBALS['db'], $GLOBALS['table']); $uni_tbl = PMA_jsFormat($GLOBALS['db'] . '.' . $GLOBALS['table'], false); - echo "\n"; - echo '' . "\n"; + $retval .= '//]]>' . "\n"; + $retval .= '' . "\n"; } // end if ... elseif // Checks if the table needs to be repaired after a TRUNCATE query. @@ -1043,7 +1038,7 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', // In an Ajax request, $GLOBALS['cell_align_left'] may not be defined. Hence, // check for it's presence before using it - echo '
addMessage($GLOBALS['special_message']); unset($GLOBALS['special_message']); } - $message->display(); - $type = $message->getLevel(); + $retval .= $message->getDisplay(); } else { - echo '
'; - echo PMA_sanitize($message); + $retval .= '
'; + $retval .= PMA_sanitize($message); if (isset($GLOBALS['special_message'])) { - echo PMA_sanitize($GLOBALS['special_message']); + $retval .= PMA_sanitize($GLOBALS['special_message']); unset($GLOBALS['special_message']); } - echo '
'; + $retval .= '
'; } if ($cfg['ShowSQL'] == true && ! empty($sql_query)) { @@ -1153,7 +1147,7 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', try { $query_base = PMA_validateSQL($query_base); } catch (Exception $e) { - PMA_Message::error(__('Failed to connect to SQL validator!'))->display(); + $retval .= PMA_Message::error(__('Failed to connect to SQL validator!'))->getDisplay(); } } elseif (isset($parsed_sql)) { $query_base = PMA_formatSql($parsed_sql, $query_base); @@ -1283,41 +1277,41 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', } //validator if (! empty($GLOBALS['validatequery'])) { - echo '
'; + $retval .= '
'; } else { - echo ''; + $retval .= ''; } if ($query_too_big) { - echo $shortened_query_base; + $retval .= $shortened_query_base; } else { - echo $query_base; + $retval .= $query_base; } //Clean up the end of the PHP if (! empty($GLOBALS['show_as_php'])) { - echo '";'; + $retval .= '";'; } if (! empty($GLOBALS['validatequery'])) { - echo '
'; + $retval .= '
'; } else { - echo ''; + $retval .= ''; } - echo '
'; + $retval .= '
'; // avoid displaying a Profiling checkbox that could // be checked, which would reexecute an INSERT, for example if (! empty($refresh_link)) { - echo PMA_getProfilingForm($sql_query); + $retval .= PMA_getProfilingForm($sql_query); } // if needed, generate an invisible form that contains controls for the // Inline link; this way, the behavior of the Inline link does not // depend on the profiling support or on the refresh link if (empty($refresh_link) || ! PMA_profilingSupported()) { - echo '
'; - echo PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); - echo ''; + $retval .= PMA_generate_common_hidden_inputs($GLOBALS['db'], $GLOBALS['table']); + $retval .= ''; - echo '
'; + $retval .= ''; } // in the tools div, only display the Inline link when not in ajax @@ -1329,7 +1323,7 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', ) { // see in js/functions.js the jQuery code attached to id inline_edit // document.write conflicts with jQuery, hence used $().append() - echo ""; } - echo $edit_link . $explain_link . $php_link . $refresh_link . $validate_link; - echo '
'; + $retval .= $edit_link . $explain_link . $php_link . $refresh_link . $validate_link; + $retval .= '
'; } - echo '
'; + $retval .= ''; if ($GLOBALS['is_ajax_request'] === false) { - echo '
'; + $retval .= '
'; } // If we are in an Ajax request, we have most probably been called in @@ -1353,11 +1347,10 @@ function PMA_showMessage($message, $sql_query = null, $type = 'notice', if ($GLOBALS['is_ajax_request'] == true && ! isset($GLOBALS['buffer_message']) ) { - $buffer_contents = ob_get_contents(); - ob_end_clean(); - return $buffer_contents; + return $retval; + } else { + echo $retval; } - return null; } // end of the 'PMA_showMessage()' function /**