Create addNotice and addUserError

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2025-01-29 18:27:20 +00:00
parent 48ca6a188e
commit a687b114cc
4 changed files with 30 additions and 22 deletions

View File

@ -45,7 +45,6 @@ use function unserialize;
use function urldecode;
use const DATE_RFC1123;
use const E_USER_WARNING;
use const FILTER_VALIDATE_IP;
/**
@ -115,7 +114,7 @@ class Core
throw new MissingExtensionException(Sanitize::convertBBCode($message));
}
ErrorHandler::getInstance()->addError($message, E_USER_WARNING, '', 0, false);
ErrorHandler::getInstance()->addUserError($message, false);
}
/**

View File

@ -64,7 +64,6 @@ use function uasort;
use function uksort;
use function usort;
use const E_USER_WARNING;
use const LOG_INFO;
use const LOG_NDELAY;
use const LOG_PID;
@ -1046,7 +1045,7 @@ class DatabaseInterface
if (! $this->tryQuery($sqlQueryTz)) {
$errorHandler = ErrorHandler::getInstance();
$errorHandler->addError(
$errorHandler->addUserError(
sprintf(
__(
'Unable to use timezone "%1$s" for server %2$d. '
@ -1059,9 +1058,6 @@ class DatabaseInterface
Current::$server,
Current::$server,
),
E_USER_WARNING,
__FILE__,
__LINE__,
);
}
}
@ -1093,12 +1089,7 @@ class DatabaseInterface
if ($result === false) {
$errorHandler = ErrorHandler::getInstance();
$errorHandler->addError(
__('Failed to set configured collation connection!'),
E_USER_WARNING,
__FILE__,
__LINE__,
);
$errorHandler->addUserError(__('Failed to set configured collation connection!'));
return;
}
@ -1609,7 +1600,7 @@ class DatabaseInterface
try {
$result = $this->extension->connect($server);
} catch (ConnectionException $exception) {
$errorHandler->addError($exception->getMessage(), E_USER_WARNING, __FILE__, __LINE__);
$errorHandler->addUserError($exception->getMessage());
return null;
}

View File

@ -314,6 +314,30 @@ class ErrorHandler
}
}
public function addUserError(string $message, bool $escape = true): void
{
// The file name and line number are not relevant for user errors
$error = new Error(
E_USER_WARNING,
$escape ? htmlspecialchars($message) : $message,
__FILE__,
__LINE__,
);
$this->errors[$error->getHash()] = $error;
}
public function addNotice(string $message, bool $escape = true): void
{
// The file name and line number are not relevant for user errors
$error = new Error(
E_USER_NOTICE,
$escape ? htmlspecialchars($message) : $message,
__FILE__,
__LINE__,
);
$this->errors[$error->getHash()] = $error;
}
/**
* display fatal error and exit
*

View File

@ -23,9 +23,6 @@ use function ob_get_clean;
use function ob_start;
use function sprintf;
use const E_USER_NOTICE;
use const E_USER_WARNING;
/**
* Handles the config authentication method
*/
@ -92,7 +89,7 @@ class AuthenticationConfig extends AuthenticationPlugin
<td>';
$config = Config::getInstance();
if ($failure->failureType === AuthenticationFailure::ALLOW_DENIED) {
$errorHandler->addError($failure->getMessage(), E_USER_NOTICE, __FILE__, __LINE__);
$errorHandler->addNotice($failure->getMessage());
} else {
// Check whether user has configured something
if ($config->sourceMtime == 0) {
@ -113,7 +110,7 @@ class AuthenticationConfig extends AuthenticationPlugin
// rejected the connection, which is not really what happened)
// 2002 is the error given by mysqli
// 2003 is the error given by mysql
$errorHandler->addError(
$errorHandler->addUserError(
__(
'phpMyAdmin tried to connect to the MySQL server, and the'
. ' server rejected the connection. You should check the'
@ -121,9 +118,6 @@ class AuthenticationConfig extends AuthenticationPlugin
. ' make sure that they correspond to the information given'
. ' by the administrator of the MySQL server.',
),
E_USER_WARNING,
__FILE__,
__LINE__,
);
}
}