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() public function display()
{ {
echo '<div class="' . $this->getLevel() . '">'; echo '<div class="' . $this->getLevel() . '">';
echo '<strong>' . $this->getType() . '</strong>'; if (! $this->isUserError()) {
echo ' in ' . $this->getFile() . '#' . $this->getLine(); echo '<strong>' . $this->getType() . '</strong>';
echo "<br />\n"; echo ' in ' . $this->getFile() . '#' . $this->getLine();
echo "<br />\n";
}
echo $this->getMessage(); echo $this->getMessage();
echo "<br />\n"; if (! $this->isUserError()) {
echo "<br />\n"; echo "<br />\n";
echo "<strong>Backtrace</strong><br />\n"; echo "<br />\n";
echo "<br />\n"; echo "<strong>Backtrace</strong><br />\n";
echo $this->displayBacktrace(); echo "<br />\n";
echo $this->displayBacktrace();
}
echo '</div>'; echo '</div>';
$this->isDisplayed(true); $this->isDisplayed(true);
} }

View File

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

View File

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

View File

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

View File

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

View File

@@ -105,7 +105,7 @@ if (function_exists('mcrypt_encrypt') || PMA_dl('mcrypt')) {
/** /**
* display warning in main.php * 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['target']
* @uses $GLOBALS['db'] * @uses $GLOBALS['db']
* @uses $GLOBALS['table'] * @uses $GLOBALS['table']
* @uses $GLOBALS['PMA_errors']
* @uses $GLOBALS['convcharset'] * @uses $GLOBALS['convcharset']
* @uses $GLOBALS['lang'] * @uses $GLOBALS['lang']
* @uses $GLOBALS['strWelcome'] * @uses $GLOBALS['strWelcome']
@@ -330,13 +329,9 @@ if (top != self) {
// show the "Cookies required" message only if cookies are disabled // show the "Cookies required" message only if cookies are disabled
// (we previously tried to set some cookies) // (we previously tried to set some cookies)
if (empty($_COOKIE)) { if (empty($_COOKIE)) {
echo '<div class="notice">' . $GLOBALS['strCookiesRequired'] . '</div>' . "\n"; trigger_error($GLOBALS['strCookiesRequired'], E_USER_NOTICE);
}
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();
?> ?>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">

View File

@@ -254,12 +254,6 @@ require_once './libraries/session.inc.php';
* init some variables LABEL_variables_init * 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 * holds parameters to be passed to next page
* @global array $GLOBALS['url_params'] * @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 * this check is done here after loading language files to present errors in locale
*/ */
if ($_SESSION['PMA_Config']->error_config_file) { if ($_SESSION['PMA_Config']->error_config_file) {
$GLOBALS['PMA_errors'][] = $strConfigFileError $error = $strConfigFileError
. '<br /><br />' . '<br /><br />'
. ($_SESSION['PMA_Config']->getSource() == './config.inc.php' ? . ($_SESSION['PMA_Config']->getSource() == './config.inc.php' ?
'<a href="show_config_errors.php"' '<a href="show_config_errors.php"'
@@ -554,13 +548,15 @@ if ($_SESSION['PMA_Config']->error_config_file) {
: :
'<a href="' . $_SESSION['PMA_Config']->getSource() . '"' '<a href="' . $_SESSION['PMA_Config']->getSource() . '"'
.' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>'); .' target="_blank">' . $_SESSION['PMA_Config']->getSource() . '</a>');
trigger_error($error, E_USER_ERROR);
} }
if ($_SESSION['PMA_Config']->error_config_default_file) { if ($_SESSION['PMA_Config']->error_config_default_file) {
$GLOBALS['PMA_errors'][] = sprintf($strConfigDefaultFileError, $error = sprintf($strConfigDefaultFileError,
$_SESSION['PMA_Config']->default_source); $_SESSION['PMA_Config']->default_source);
trigger_error($error, E_USER_ERROR);
} }
if ($_SESSION['PMA_Config']->error_pma_uri) { 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 // Detect wrong configuration
if (!is_int($server_index) || $server_index < 1) { 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); $each_server = array_merge($default_server, $each_server);
// Don't use servers with no hostname // Don't use servers with no hostname
if ($each_server['connect_type'] == 'tcp' && empty($each_server['host'])) { 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 // 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 * @todo 2.7.1: add different messages for alternativ extension
* and complete fail (no alternativ extension too) * and complete fail (no alternativ extension too)
*/ */
$GLOBALS['PMA_errors'][] = $error =
sprintf(PMA_sanitize($GLOBALS['strCantLoad']), sprintf(PMA_sanitize($GLOBALS['strCantLoad']),
$GLOBALS['cfg']['Server']['extension']) $GLOBALS['cfg']['Server']['extension'])
.' - <a href="./Documentation.html#faqmysql" target="documentation">' .' - <a href="./Documentation.html#faqmysql" target="documentation">'
.$GLOBALS['strDocu'] . '</a>'; .$GLOBALS['strDocu'] . '</a>';
trigger_error($error, E_USER_ERROR);
if ($GLOBALS['cfg']['Server']['extension'] === 'mysql') { if ($GLOBALS['cfg']['Server']['extension'] === 'mysql') {
$alternativ_extension = 'mysqli'; $alternativ_extension = 'mysqli';

View File

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

View File

@@ -108,9 +108,7 @@ function PMA_DBI_connect($user, $password, $is_controluser = false)
if ($return_value == false) { if ($return_value == false) {
if ($is_controluser) { if ($is_controluser) {
if (! defined('PMA_DBI_CONNECT_FAILED_CONTROLUSER')) { trigger_error($strControluserFailed, E_USER_WARNING);
define('PMA_DBI_CONNECT_FAILED_CONTROLUSER', true);
}
return false; return false;
} }
PMA_auth_fails(); 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 // now, that we have loaded the language strings we can send the errors
if ($GLOBALS['lang_failed_cfg']) { 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']) { 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']) { 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, unset($line, $fall_back_lang,

View File

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