replaced $PMA_errors with new PMA_Error_Handler

This commit is contained in:
Sebastian Mendel
2007-10-08 16:02:58 +00:00
parent b43ab99c15
commit 5dd96d42ce
12 changed files with 72 additions and 103 deletions

View File

@@ -413,15 +413,19 @@ class PMA_Error
public function display()
{
echo '<div class="' . $this->getLevel() . '">';
echo '<strong>' . $this->getType() . '</strong>';
echo ' in ' . $this->getFile() . '#' . $this->getLine();
echo "<br />\n";
if (! $this->isUserError()) {
echo '<strong>' . $this->getType() . '</strong>';
echo ' in ' . $this->getFile() . '#' . $this->getLine();
echo "<br />\n";
}
echo $this->getMessage();
echo "<br />\n";
echo "<br />\n";
echo "<strong>Backtrace</strong><br />\n";
echo "<br />\n";
echo $this->displayBacktrace();
if (! $this->isUserError()) {
echo "<br />\n";
echo "<br />\n";
echo "<strong>Backtrace</strong><br />\n";
echo "<br />\n";
echo $this->displayBacktrace();
}
echo '</div>';
$this->isDisplayed(true);
}

View File

@@ -126,15 +126,15 @@ class PMA_Error_Handler
case E_WARNING:
case E_CORE_WARNING:
case E_COMPILE_WARNING:
case E_USER_ERROR:
case E_RECOVERABLE_ERROR:
// just collect the error
// display is called from outside
break;
case E_USER_ERROR:
case E_ERROR:
case E_PARSE:
case E_CORE_ERROR:
case E_COMPILE_ERROR:
case E_RECOVERABLE_ERROR:
default:
// FATAL error, dislay it and exit
$this->_dispFatalError($error);
@@ -276,8 +276,12 @@ class PMA_Error_Handler
{
if ($GLOBALS['cfg']['Error_Handler']['display']) {
foreach ($this->getErrors() as $error) {
if (! $error->isDisplayed()) {
$error->display();
if ($error instanceof PMA_Error) {
if (! $error->isDisplayed()) {
$error->display();
}
} else {
var_dump($error);
}
}
} else {
@@ -295,10 +299,17 @@ class PMA_Error_Handler
protected function _checkSavedErrors()
{
if (isset($_SESSION['errors'])) {
// restore saved errors
$this->_errors = array_merge($_SESSION['errors'], $this->_errors);
foreach ($_SESSION['errors'] as $hash => $error) {
if ($error instanceof PMA_Error && ! isset($this->_errors[$hash])) {
$this->_errors[$hash] = $error;
}
}
//$this->_errors = array_merge($_SESSION['errors'], $this->_errors);
// delet stored errors
$_SESSION['errors'] = array();
unset($_SESSION['errors']);
}
}

View File

@@ -133,7 +133,6 @@ class PMA_Theme {
* @uses PMA_Theme::setImgPath()
* @uses PMA_Theme::getName()
* @uses $GLOBALS['cfg']['ThemePath']
* @uses $GLOBALS['PMA_errors']
* @uses $GLOBALS['strThemeNoValidImgPath']
* @uses is_dir()
* @uses sprintf()
@@ -147,13 +146,9 @@ class PMA_Theme {
$this->setImgPath($GLOBALS['cfg']['ThemePath'] . '/original/img/');
return true;
} else {
$GLOBALS['PMA_errors'][] =
sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName());
/*
trigger_error(
sprintf($GLOBALS['strThemeNoValidImgPath'], $this->getName()),
E_USER_WARNING);
*/
E_USER_ERROR);
return false;
}
}

View File

@@ -109,12 +109,10 @@ class PMA_Theme_Manager
if (! $this->checkTheme($GLOBALS['cfg']['ThemeDefault'])) {
$GLOBALS['PMA_errors'][] = sprintf($GLOBALS['strThemeDefaultNotFound'],
htmlspecialchars($GLOBALS['cfg']['ThemeDefault']));
trigger_error(
sprintf($GLOBALS['strThemeDefaultNotFound'],
htmlspecialchars($GLOBALS['cfg']['ThemeDefault'])),
E_USER_WARNING);
E_USER_ERROR);
$GLOBALS['cfg']['ThemeDefault'] = false;
}
@@ -149,12 +147,9 @@ class PMA_Theme_Manager
function setActiveTheme($theme = null)
{
if (! $this->checkTheme($theme)) {
$GLOBALS['PMA_errors'][] = sprintf($GLOBALS['strThemeNotFound'],
htmlspecialchars($theme));
/* Following code can lead to path disclossure, because headers will be sent later */
/* trigger_error(
trigger_error(
sprintf($GLOBALS['strThemeNotFound'], htmlspecialchars($theme)),
E_USER_WARNING);*/
E_USER_ERROR);
return false;
}
@@ -220,13 +215,10 @@ class PMA_Theme_Manager
/*private*/ function _checkThemeFolder($folder)
{
if (! is_dir($folder)) {
$GLOBALS['PMA_errors'][] =
sprintf($GLOBALS['strThemePathNotFound'],
htmlspecialchars($folder));
trigger_error(
sprintf($GLOBALS['strThemePathNotFound'],
htmlspecialchars($folder)),
E_USER_WARNING);
E_USER_ERROR);
return false;
}

View File

@@ -99,7 +99,7 @@ function PMA_auth_fails()
$GLOBALS['is_header_sent'] = TRUE;
if (isset($GLOBALS['allowDeny_forbidden']) && $GLOBALS['allowDeny_forbidden']) {
echo '<p>' . $GLOBALS['strAccessDenied'] . '</p>' . "\n";
trigger_error($GLOBALS['strAccessDenied'], E_USER_NOTICE);
} else {
// Check whether user has configured something
if ($_SESSION['PMA_Config']->source_mtime == 0) {
@@ -116,11 +116,7 @@ function PMA_auth_fails()
}
PMA_mysqlDie($conn_error, '', true, '', false);
}
if (! empty($GLOBALS['PMA_errors']) && is_array($GLOBALS['PMA_errors'])) {
foreach ($GLOBALS['PMA_errors'] as $error) {
echo '<div class="error">' . $error . '</div>' . "\n";
}
}
$GLOBALS['error_handler']->dispUserErrors();
?>
</td>
</tr>

View File

@@ -105,7 +105,7 @@ if (function_exists('mcrypt_encrypt') || PMA_dl('mcrypt')) {
/**
* display warning in main.php
*/
define('PMA_WARN_FOR_MCRYPT', 1);
trigger_error(PMA_sanitize(sprintf($strCantLoad, 'mcrypt')), E_USER_WARNING);
}
@@ -123,7 +123,6 @@ if (function_exists('mcrypt_encrypt') || PMA_dl('mcrypt')) {
* @uses $GLOBALS['target']
* @uses $GLOBALS['db']
* @uses $GLOBALS['table']
* @uses $GLOBALS['PMA_errors']
* @uses $GLOBALS['convcharset']
* @uses $GLOBALS['lang']
* @uses $GLOBALS['strWelcome']
@@ -261,8 +260,8 @@ if (top != self) {
<form method="post" action="index.php" name="login_form"<?php echo $autocomplete; ?> target="_top" class="login">
<fieldset>
<legend>
<?php
echo $GLOBALS['strLogin'];
<?php
echo $GLOBALS['strLogin'];
echo '<a href="./Documentation.html" target="documentation" ' .
'title="' . $GLOBALS['strPmaDocumentation'] . '">';
if ($GLOBALS['cfg']['ReplaceHelpImg']) {
@@ -330,13 +329,9 @@ if (top != self) {
// show the "Cookies required" message only if cookies are disabled
// (we previously tried to set some cookies)
if (empty($_COOKIE)) {
echo '<div class="notice">' . $GLOBALS['strCookiesRequired'] . '</div>' . "\n";
}
if (! empty($GLOBALS['PMA_errors']) && is_array($GLOBALS['PMA_errors'])) {
foreach ($GLOBALS['PMA_errors'] as $error) {
echo '<div class="error">' . $error . '</div>' . "\n";
}
trigger_error($GLOBALS['strCookiesRequired'], E_USER_NOTICE);
}
$GLOBALS['error_handler']->dispUserErrors();
?>
</div>
<script type="text/javascript">
@@ -433,9 +428,9 @@ function PMA_auth_check()
}
if (! empty($_REQUEST['old_usr'])) {
// The user wants to be logged out
// -> delete his choices that were stored in session
session_destroy();
// The user wants to be logged out
// -> delete his choices that were stored in session
session_destroy();
// -> delete password cookie(s)
if ($GLOBALS['cfg']['LoginCookieDeleteAll']) {
foreach($GLOBALS['cfg']['Servers'] as $key => $val) {

View File

@@ -254,12 +254,6 @@ require_once './libraries/session.inc.php';
* init some variables LABEL_variables_init
*/
/**
* holds errors
* @global array $GLOBALS['PMA_errors']
*/
$GLOBALS['PMA_errors'] = array();
/**
* holds parameters to be passed to next page
* @global array $GLOBALS['url_params']
@@ -546,7 +540,7 @@ require_once $lang_path . $available_languages[$GLOBALS['lang']][1] . '.inc.php'
* this check is done here after loading language files to present errors in locale
*/
if ($_SESSION['PMA_Config']->error_config_file) {
$GLOBALS['PMA_errors'][] = $strConfigFileError
$error = $strConfigFileError
. '<br /><br />'
. ($_SESSION['PMA_Config']->getSource() == './config.inc.php' ?
'<a href="show_config_errors.php"'
@@ -554,13 +548,15 @@ if ($_SESSION['PMA_Config']->error_config_file) {
:
'<a href="' . $_SESSION['PMA_Config']->getSource() . '"'
.' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>');
trigger_error($error, E_USER_ERROR);
}
if ($_SESSION['PMA_Config']->error_config_default_file) {
$GLOBALS['PMA_errors'][] = sprintf($strConfigDefaultFileError,
$error = sprintf($strConfigDefaultFileError,
$_SESSION['PMA_Config']->default_source);
trigger_error($error, E_USER_ERROR);
}
if ($_SESSION['PMA_Config']->error_pma_uri) {
$GLOBALS['PMA_errors'][] = sprintf($strPmaUriError);
trigger_error($strPmaUriError, E_USER_ERROR);
}
/**
@@ -586,14 +582,14 @@ if (!isset($cfg['Servers']) || count($cfg['Servers']) == 0) {
// Detect wrong configuration
if (!is_int($server_index) || $server_index < 1) {
$GLOBALS['PMA_errors'][] = sprintf($strInvalidServerIndex, $server_index);
trigger_error(sprintf($strInvalidServerIndex, $server_index), E_USER_ERROR);
}
$each_server = array_merge($default_server, $each_server);
// Don't use servers with no hostname
if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) {
$GLOBALS['PMA_errors'][] = sprintf($strInvalidServerHostname, $server_index);
trigger_error(sprintf($strInvalidServerHostname, $server_index), E_USER_ERROR);
}
// Final solution to bug #582890

View File

@@ -46,11 +46,12 @@ if (! PMA_DBI_checkAndLoadMysqlExtension($GLOBALS['cfg']['Server']['extension'])
* @todo 2.7.1: add different messages for alternativ extension
* and complete fail (no alternativ extension too)
*/
$GLOBALS['PMA_errors'][] =
$error =
sprintf(PMA_sanitize($GLOBALS['strCantLoad']),
$GLOBALS['cfg']['Server']['extension'])
.' - <a href="./Documentation.html#faqmysql" target="documentation">'
.$GLOBALS['strDocu'] . '</a>';
trigger_error($error, E_USER_ERROR);
if ($GLOBALS['cfg']['Server']['extension'] === 'mysql') {
$alternativ_extension = 'mysqli';

View File

@@ -78,9 +78,7 @@ function PMA_DBI_connect($user, $password, $is_controluser = false)
if (empty($link) && ! $is_controluser) {
if ($is_controluser) {
if (! defined('PMA_DBI_CONNECT_FAILED_CONTROLUSER')) {
define('PMA_DBI_CONNECT_FAILED_CONTROLUSER', true);
}
trigger_error($strControluserFailed, E_USER_WARNING);
return false;
}
PMA_auth_fails();

View File

@@ -108,9 +108,7 @@ function PMA_DBI_connect($user, $password, $is_controluser = false)
if ($return_value == false) {
if ($is_controluser) {
if (! defined('PMA_DBI_CONNECT_FAILED_CONTROLUSER')) {
define('PMA_DBI_CONNECT_FAILED_CONTROLUSER', true);
}
trigger_error($strControluserFailed, E_USER_WARNING);
return false;
}
PMA_auth_fails();

View File

@@ -367,13 +367,22 @@ require_once $lang_file;
// now, that we have loaded the language strings we can send the errors
if ($GLOBALS['lang_failed_cfg']) {
$GLOBALS['PMA_errors'][] = sprintf($GLOBALS['strLanguageUnknown'], htmlspecialchars($GLOBALS['lang_failed_cfg']));
trigger_error(
sprintf($GLOBALS['strLanguageUnknown'],
htmlspecialchars($GLOBALS['lang_failed_cfg'])),
E_USER_ERROR);
}
if ($GLOBALS['lang_failed_cookie']) {
$GLOBALS['PMA_errors'][] = sprintf($GLOBALS['strLanguageUnknown'], htmlspecialchars($GLOBALS['lang_failed_cookie']));
trigger_error(
sprintf($GLOBALS['strLanguageUnknown'],
htmlspecialchars($GLOBALS['lang_failed_cookie'])),
E_USER_ERROR);
}
if ($GLOBALS['lang_failed_request']) {
$GLOBALS['PMA_errors'][] = sprintf($GLOBALS['strLanguageUnknown'], htmlspecialchars($GLOBALS['lang_failed_request']));
trigger_error(
sprintf($GLOBALS['strLanguageUnknown'],
htmlspecialchars($GLOBALS['lang_failed_request'])),
E_USER_ERROR);
}
unset($line, $fall_back_lang,

View File

@@ -259,12 +259,6 @@ PMA_printListItem($strHomepageOfficial, 'li_pma_homepage', 'http://www.phpMyAdmi
</div>
<?php
if (! empty($GLOBALS['PMA_errors']) && is_array($GLOBALS['PMA_errors'])) {
foreach ($GLOBALS['PMA_errors'] as $error) {
echo '<div class="error">' . $error . '</div>' . "\n";
}
}
/**
* Warning if using the default MySQL privileged account
* modified: 2004-05-05 mkkeck
@@ -272,7 +266,7 @@ if (! empty($GLOBALS['PMA_errors']) && is_array($GLOBALS['PMA_errors'])) {
if ($server != 0
&& $cfg['Server']['user'] == 'root'
&& $cfg['Server']['password'] == '') {
echo '<div class="warning">' . $strInsecureMySQL . '</div>' . "\n";
trigger_error($strInsecureMySQL, E_USER_WARNING);
}
/**
@@ -280,7 +274,7 @@ if ($server != 0
* break it, see bug 1063821.
*/
if (@extension_loaded('mbstring') && @ini_get('mbstring.func_overload') > 1) {
echo '<div class="warning">' . $strMbOverloadWarning . '</div>' . "\n";
trigger_error($strMbOverloadWarning, E_USER_WARNING);
}
/**
@@ -288,14 +282,7 @@ if (@extension_loaded('mbstring') && @ini_get('mbstring.func_overload') > 1) {
* to tell user something might be broken without it, see bug #1063149.
*/
if ($GLOBALS['using_mb_charset'] && !@extension_loaded('mbstring')) {
echo '<div class="warning">' . $strMbExtensionMissing . '</div>' . "\n";
}
/**
* Warning for old PHP version
*/
if (PMA_PHP_INT_VERSION < 50200) {
echo '<div class="warning">' . sprintf($strUpgrade, 'PHP', '5.2.0') . '</div>' . "\n";
trigger_error($strMbExtensionMissing, E_USER_WARNING);
}
/**
@@ -303,23 +290,10 @@ if (PMA_PHP_INT_VERSION < 50200) {
* (a difference on the third digit does not count)
*/
if ($server > 0 && substr(PMA_MYSQL_CLIENT_API, 0, 3) != substr(PMA_MYSQL_INT_VERSION, 0, 3)) {
echo '<div class="notice">'
. PMA_sanitize(sprintf($strMysqlLibDiffersServerVersion,
trigger_error(PMA_sanitize(sprintf($strMysqlLibDiffersServerVersion,
PMA_DBI_get_client_info(),
substr(PMA_MYSQL_STR_VERSION, 0, strpos(PMA_MYSQL_STR_VERSION . '-', '-'))))
. '</div>' . "\n";
}
/**
* Warning about wrong controluser settings
*/
$strControluserFailed = 'Connection for controluser as defined in your config.inc.php failed.';
if (defined('PMA_DBI_CONNECT_FAILED_CONTROLUSER')) {
echo '<div class="warning">' . $strControluserFailed . '</div>' . "\n";
}
if (defined('PMA_WARN_FOR_MCRYPT')) {
echo '<div class="warning">' . PMA_sanitize(sprintf($strCantLoad, 'mcrypt')) . '</div>' . "\n";
substr(PMA_MYSQL_STR_VERSION, 0, strpos(PMA_MYSQL_STR_VERSION . '-', '-')))),
E_USER_NOTICE);
}
/**