diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 340fde2e6e..a8cccdc6aa 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -570,7 +570,7 @@ parameters: - message: '#^Loose comparison via "\!\=" is not allowed\.$#' identifier: notEqual.notAllowed - count: 3 + count: 2 path: src/Config.php - @@ -2860,7 +2860,7 @@ parameters: path: src/Controllers/HomeController.php - - message: '#^Cannot access offset mixed on mixed\.$#' + message: '#^Cannot access offset string on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible count: 1 path: src/Controllers/HomeController.php @@ -3276,7 +3276,7 @@ parameters: - message: '#^Loose comparison via "\!\=" is not allowed\.$#' identifier: notEqual.notAllowed - count: 2 + count: 1 path: src/Controllers/Preferences/ManageController.php - @@ -8988,12 +8988,6 @@ parameters: count: 1 path: src/Header.php - - - message: '#^Parameter \#2 \$params of method PhpMyAdmin\\Scripts\:\:addFile\(\) expects array\, array\ given\.$#' - identifier: argument.type - count: 1 - path: src/Header.php - - message: '#^Binary operation "\." between non\-falsy\-string and mixed results in an error\.$#' identifier: binaryOp.invalid @@ -9159,12 +9153,6 @@ parameters: count: 1 path: src/Http/Middleware/DatabaseServerVersionChecking.php - - - message: '#^Cannot cast mixed to string\.$#' - identifier: cast.string - count: 1 - path: src/Http/Middleware/LanguageAndThemeCookieSaving.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\: @@ -9183,12 +9171,6 @@ parameters: count: 1 path: src/Http/Middleware/RouteParsing.php - - - message: '#^Parameter \#2 \$value of method PhpMyAdmin\\Config\:\:setCookie\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/Http/Middleware/SetupPageRedirection.php - - message: ''' #^Call to deprecated method getInstance\(\) of class PhpMyAdmin\\Dbal\\DatabaseInterface\: @@ -9282,12 +9264,6 @@ parameters: count: 2 path: src/Http/ServerRequest.php - - - message: '#^Loose comparison via "\=\=" is not allowed\.$#' - identifier: equal.notAllowed - count: 1 - path: src/I18n/Language.php - - message: '#^Binary operation "\." between mixed and ''/'' results in an error\.$#' identifier: binaryOp.invalid @@ -9321,12 +9297,6 @@ parameters: count: 1 path: src/I18n/LanguageManager.php - - - message: '#^Parameter \#1 \$string of function strtolower expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: src/I18n/LanguageManager.php - - message: '#^Parameter \#2 \$path of function _bindtextdomain expects string, mixed given\.$#' identifier: argument.type @@ -17463,7 +17433,7 @@ parameters: - message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#' identifier: empty.notAllowed - count: 4 + count: 2 path: src/Url.php - diff --git a/psalm-baseline.xml b/psalm-baseline.xml index a5b1feb379..36652f9ad7 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1555,7 +1555,7 @@ config->get('TempDir')]]> - + settings['Servers'][Current::$server]]]> @@ -1566,9 +1566,6 @@ config->get('TempDir')]]> - - - selectedServer['verbose'])]]> @@ -5552,11 +5549,6 @@ - - - - - @@ -10137,8 +10129,6 @@ get('URLQueryEncryption')]]> - - getCookie('pma_lang'))]]> getCookie('pma_lang'))]]> diff --git a/src/Config.php b/src/Config.php index 56298ff79f..eb5c445432 100644 --- a/src/Config.php +++ b/src/Config.php @@ -488,11 +488,11 @@ class Config if ($this->issetCookie('pma_lang') || isset($_POST['lang'])) { if ( (! isset($configData['lang']) - && $GLOBALS['lang'] !== 'en') + && Current::$lang !== 'en') || isset($configData['lang']) - && $GLOBALS['lang'] != $configData['lang'] + && Current::$lang !== $configData['lang'] ) { - $this->setUserValue(null, 'lang', $GLOBALS['lang'], 'en'); + $this->setUserValue(null, 'lang', Current::$lang, 'en'); } } elseif (isset($configData['lang'])) { $languageManager = LanguageManager::getInstance(); diff --git a/src/Controllers/HomeController.php b/src/Controllers/HomeController.php index 1dfde513bb..e430dd694a 100644 --- a/src/Controllers/HomeController.php +++ b/src/Controllers/HomeController.php @@ -394,8 +394,6 @@ final class HomeController implements InvocableController private function checkLanguageStats(): void { - $GLOBALS['lang'] ??= null; - /** * Warning about incomplete translations. * @@ -409,8 +407,8 @@ final class HomeController implements InvocableController include ROOT_PATH . 'app/language_stats.inc.php'; $config = Config::getInstance(); if ( - ! isset($GLOBALS['language_stats'][$GLOBALS['lang']]) - || $GLOBALS['language_stats'][$GLOBALS['lang']] >= $config->settings['TranslationWarningThreshold'] + ! isset($GLOBALS['language_stats'][Current::$lang]) + || $GLOBALS['language_stats'][Current::$lang] >= $config->settings['TranslationWarningThreshold'] ) { return; } diff --git a/src/Controllers/Preferences/ManageController.php b/src/Controllers/Preferences/ManageController.php index 10a955ab38..5dfce85b2c 100644 --- a/src/Controllers/Preferences/ManageController.php +++ b/src/Controllers/Preferences/ManageController.php @@ -10,6 +10,7 @@ use PhpMyAdmin\Config\Forms\User\UserFormList; use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\Controllers\InvocableController; use PhpMyAdmin\Core; +use PhpMyAdmin\Current; use PhpMyAdmin\File; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\Response; @@ -59,7 +60,6 @@ final class ManageController implements InvocableController public function __invoke(ServerRequest $request): Response { $GLOBALS['error'] ??= null; - $GLOBALS['lang'] ??= null; $GLOBALS['query'] ??= null; $route = $request->getRoute(); @@ -194,7 +194,7 @@ final class ManageController implements InvocableController $this->themeManager->setThemeCookie(); } - if (isset($configuration['lang']) && $configuration['lang'] != $GLOBALS['lang']) { + if (isset($configuration['lang']) && $configuration['lang'] !== Current::$lang) { $redirectParams['lang'] = $configuration['lang']; } diff --git a/src/Controllers/Setup/ConfigController.php b/src/Controllers/Setup/ConfigController.php index f2a53dfd64..bb69d71551 100644 --- a/src/Controllers/Setup/ConfigController.php +++ b/src/Controllers/Setup/ConfigController.php @@ -7,6 +7,7 @@ namespace PhpMyAdmin\Controllers\Setup; use Fig\Http\Message\StatusCodeInterface; use PhpMyAdmin\Config; use PhpMyAdmin\Controllers\InvocableController; +use PhpMyAdmin\Current; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; @@ -39,7 +40,7 @@ final class ConfigController implements InvocableController $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => __('Configuration already exists, setup is disabled!'), ])); } diff --git a/src/Controllers/Setup/FormController.php b/src/Controllers/Setup/FormController.php index b1aba66357..06cbae6239 100644 --- a/src/Controllers/Setup/FormController.php +++ b/src/Controllers/Setup/FormController.php @@ -8,6 +8,7 @@ use Fig\Http\Message\StatusCodeInterface; use PhpMyAdmin\Config; use PhpMyAdmin\Config\Forms\Setup\SetupFormList; use PhpMyAdmin\Controllers\InvocableController; +use PhpMyAdmin\Current; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; @@ -40,7 +41,7 @@ final class FormController implements InvocableController $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => __('Configuration already exists, setup is disabled!'), ])); } @@ -57,7 +58,7 @@ final class FormController implements InvocableController $formClass = SetupFormList::get($formSet); if ($formClass === null) { return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => __('Incorrect form specified!'), ])); } diff --git a/src/Controllers/Setup/HomeController.php b/src/Controllers/Setup/HomeController.php index 3383c16ac1..509b2e70b6 100644 --- a/src/Controllers/Setup/HomeController.php +++ b/src/Controllers/Setup/HomeController.php @@ -8,6 +8,7 @@ use Fig\Http\Message\StatusCodeInterface; use PhpMyAdmin\Config; use PhpMyAdmin\Config\ServerConfigChecks; use PhpMyAdmin\Controllers\InvocableController; +use PhpMyAdmin\Current; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; @@ -43,7 +44,7 @@ final class HomeController implements InvocableController $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => __('Configuration already exists, setup is disabled!'), ])); } diff --git a/src/Controllers/Setup/ServerDestroyController.php b/src/Controllers/Setup/ServerDestroyController.php index 8dc02d3f8b..1184fd0436 100644 --- a/src/Controllers/Setup/ServerDestroyController.php +++ b/src/Controllers/Setup/ServerDestroyController.php @@ -7,6 +7,7 @@ namespace PhpMyAdmin\Controllers\Setup; use Fig\Http\Message\StatusCodeInterface; use PhpMyAdmin\Config; use PhpMyAdmin\Controllers\InvocableController; +use PhpMyAdmin\Current; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; @@ -37,7 +38,7 @@ final class ServerDestroyController implements InvocableController $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => __('Configuration already exists, setup is disabled!'), ])); } diff --git a/src/Controllers/Setup/ServersController.php b/src/Controllers/Setup/ServersController.php index 7102d3b681..f893b424c3 100644 --- a/src/Controllers/Setup/ServersController.php +++ b/src/Controllers/Setup/ServersController.php @@ -8,6 +8,7 @@ use Fig\Http\Message\StatusCodeInterface; use PhpMyAdmin\Config; use PhpMyAdmin\Config\Forms\Setup\ServersForm; use PhpMyAdmin\Controllers\InvocableController; +use PhpMyAdmin\Current; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; @@ -40,7 +41,7 @@ final class ServersController implements InvocableController $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => __('Configuration already exists, setup is disabled!'), ])); } diff --git a/src/Controllers/Setup/ShowConfigController.php b/src/Controllers/Setup/ShowConfigController.php index 4536ddaa08..608c80ce10 100644 --- a/src/Controllers/Setup/ShowConfigController.php +++ b/src/Controllers/Setup/ShowConfigController.php @@ -9,6 +9,7 @@ use PhpMyAdmin\Config; use PhpMyAdmin\Config\Forms\Setup\ConfigForm; use PhpMyAdmin\Controllers\InvocableController; use PhpMyAdmin\Core; +use PhpMyAdmin\Current; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; @@ -38,7 +39,7 @@ final class ShowConfigController implements InvocableController $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => __('Configuration already exists, setup is disabled!'), ])); } diff --git a/src/Controllers/Setup/ValidateController.php b/src/Controllers/Setup/ValidateController.php index ee25efbf0d..6e944ed1b0 100644 --- a/src/Controllers/Setup/ValidateController.php +++ b/src/Controllers/Setup/ValidateController.php @@ -9,6 +9,7 @@ use PhpMyAdmin\Config; use PhpMyAdmin\Config\Validator; use PhpMyAdmin\Controllers\InvocableController; use PhpMyAdmin\Core; +use PhpMyAdmin\Current; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; @@ -41,7 +42,7 @@ final class ValidateController implements InvocableController $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => __('Configuration already exists, setup is disabled!'), ])); } diff --git a/src/Core.php b/src/Core.php index f115e36587..0726c3e54b 100644 --- a/src/Core.php +++ b/src/Core.php @@ -79,8 +79,8 @@ class Core $phpDocLanguages = ['pt_BR', 'zh_CN', 'fr', 'de', 'ja', 'ru', 'es', 'tr']; $lang = 'en'; - if (isset($GLOBALS['lang']) && in_array($GLOBALS['lang'], $phpDocLanguages, true)) { - $lang = $GLOBALS['lang'] === 'zh_CN' ? 'zh' : $GLOBALS['lang']; + if (in_array(Current::$lang, $phpDocLanguages, true)) { + $lang = Current::$lang === 'zh_CN' ? 'zh' : Current::$lang; } return self::linkURL('https://www.php.net/manual/' . $lang . '/' . $target); diff --git a/src/Current.php b/src/Current.php index 202ecb6d03..de6a24a56f 100644 --- a/src/Current.php +++ b/src/Current.php @@ -12,4 +12,5 @@ final class Current public static string $table = ''; public static string $sqlQuery = ''; public static Message|null $message = null; + public static string $lang = 'en'; } diff --git a/src/Encoding.php b/src/Encoding.php index aec79206fc..263d3ab828 100644 --- a/src/Encoding.php +++ b/src/Encoding.php @@ -171,7 +171,7 @@ class Encoding */ public static function canConvertKanji(): bool { - return $GLOBALS['lang'] === 'ja'; + return Current::$lang === 'ja'; } /** diff --git a/src/Header.php b/src/Header.php index 5044745c52..a03b4b2eb9 100644 --- a/src/Header.php +++ b/src/Header.php @@ -89,7 +89,7 @@ class Header $this->scripts->addFile('vendor/js.cookie.min.js'); $this->scripts->addFile('vendor/jquery/jquery.validate.min.js'); $this->scripts->addFile('vendor/jquery/jquery-ui-timepicker-addon.js'); - $this->scripts->addFile('index.php', ['route' => '/messages', 'l' => $GLOBALS['lang']]); + $this->scripts->addFile('index.php', ['route' => '/messages', 'l' => Current::$lang]); $this->scripts->addFile('shared.js'); $this->scripts->addFile('menu_resizer.js'); $this->scripts->addFile('main.js'); @@ -111,7 +111,7 @@ class Header // Do not add any separator, JS code will decide 'common_query' => Url::getCommonRaw([], ''), 'opendb_url' => Util::getScriptNameForOption($this->config->settings['DefaultTabDatabase'], 'database'), - 'lang' => $GLOBALS['lang'], + 'lang' => Current::$lang, 'server' => Current::$server, 'table' => Current::$table, 'db' => Current::$database, @@ -276,7 +276,7 @@ class Header $this->scripts->addFile('validator-messages.js'); return [ - 'lang' => $GLOBALS['lang'], + 'lang' => Current::$lang, 'allow_third_party_framing' => $this->config->settings['AllowThirdPartyFraming'], 'base_dir' => $baseDir, 'theme_path' => $theme->getPath(), diff --git a/src/Http/Middleware/Authentication.php b/src/Http/Middleware/Authentication.php index f7f10de54a..cb861d4e66 100644 --- a/src/Http/Middleware/Authentication.php +++ b/src/Http/Middleware/Authentication.php @@ -9,6 +9,7 @@ use PhpMyAdmin\Config; use PhpMyAdmin\Config\Settings\Server; use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\Container\ContainerBuilder; +use PhpMyAdmin\Current; use PhpMyAdmin\Dbal\ConnectionType; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Exceptions\AuthenticationFailure; @@ -53,7 +54,7 @@ final class Authentication implements MiddlewareInterface $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => $exception->getMessage(), ])); } @@ -70,7 +71,7 @@ final class Authentication implements MiddlewareInterface $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => $exception->getMessage(), ])); } diff --git a/src/Http/Middleware/ConfigErrorAndPermissionChecking.php b/src/Http/Middleware/ConfigErrorAndPermissionChecking.php index 8a603d100e..d2ac800f43 100644 --- a/src/Http/Middleware/ConfigErrorAndPermissionChecking.php +++ b/src/Http/Middleware/ConfigErrorAndPermissionChecking.php @@ -6,6 +6,7 @@ namespace PhpMyAdmin\Http\Middleware; use Fig\Http\Message\StatusCodeInterface; use PhpMyAdmin\Config; +use PhpMyAdmin\Current; use PhpMyAdmin\Exceptions\ConfigException; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Template; @@ -35,7 +36,7 @@ final class ConfigErrorAndPermissionChecking implements MiddlewareInterface $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => $exception->getMessage(), ])); } diff --git a/src/Http/Middleware/DatabaseServerVersionChecking.php b/src/Http/Middleware/DatabaseServerVersionChecking.php index ac52afaa75..17fa252e41 100644 --- a/src/Http/Middleware/DatabaseServerVersionChecking.php +++ b/src/Http/Middleware/DatabaseServerVersionChecking.php @@ -6,6 +6,7 @@ namespace PhpMyAdmin\Http\Middleware; use Fig\Http\Message\StatusCodeInterface; use PhpMyAdmin\Config; +use PhpMyAdmin\Current; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Template; @@ -36,7 +37,7 @@ final class DatabaseServerVersionChecking implements MiddlewareInterface $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => sprintf( __('You should upgrade to %s %s or later.'), 'MySQL', diff --git a/src/Http/Middleware/LanguageAndThemeCookieSaving.php b/src/Http/Middleware/LanguageAndThemeCookieSaving.php index a7c42817e7..b63b969437 100644 --- a/src/Http/Middleware/LanguageAndThemeCookieSaving.php +++ b/src/Http/Middleware/LanguageAndThemeCookieSaving.php @@ -6,6 +6,7 @@ namespace PhpMyAdmin\Http\Middleware; use PhpMyAdmin\Config; use PhpMyAdmin\Container\ContainerBuilder; +use PhpMyAdmin\Current; use PhpMyAdmin\Theme\ThemeManager; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; @@ -20,7 +21,7 @@ final class LanguageAndThemeCookieSaving implements MiddlewareInterface public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $this->config->setCookie('pma_lang', (string) $GLOBALS['lang']); + $this->config->setCookie('pma_lang', Current::$lang); /** @var ThemeManager $themeManager */ $themeManager = ContainerBuilder::getContainer()->get(ThemeManager::class); $themeManager->setThemeCookie(); diff --git a/src/Http/Middleware/RequestProblemChecking.php b/src/Http/Middleware/RequestProblemChecking.php index 50595fa4b5..00cc979c6e 100644 --- a/src/Http/Middleware/RequestProblemChecking.php +++ b/src/Http/Middleware/RequestProblemChecking.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Http\Middleware; use Fig\Http\Message\StatusCodeInterface; +use PhpMyAdmin\Current; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Template; use Psr\Http\Message\ResponseInterface; @@ -30,7 +31,7 @@ final class RequestProblemChecking implements MiddlewareInterface $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => __('GLOBALS overwrite attempt'), ])); } @@ -42,7 +43,7 @@ final class RequestProblemChecking implements MiddlewareInterface $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => __('possible exploit'), ])); } diff --git a/src/Http/Middleware/SessionHandling.php b/src/Http/Middleware/SessionHandling.php index 03ca0c795d..e52559ee73 100644 --- a/src/Http/Middleware/SessionHandling.php +++ b/src/Http/Middleware/SessionHandling.php @@ -6,6 +6,7 @@ namespace PhpMyAdmin\Http\Middleware; use Fig\Http\Message\StatusCodeInterface; use PhpMyAdmin\Config; +use PhpMyAdmin\Current; use PhpMyAdmin\Error\ErrorHandler; use PhpMyAdmin\Exceptions\SessionHandlerException; use PhpMyAdmin\Http\Factory\ResponseFactory; @@ -39,7 +40,7 @@ final class SessionHandling implements MiddlewareInterface $response = $this->responseFactory->createResponse(StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR); return $response->write($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => $exception->getMessage(), ])); } diff --git a/src/Http/Middleware/SetupPageRedirection.php b/src/Http/Middleware/SetupPageRedirection.php index 066b7276e5..fecdd94392 100644 --- a/src/Http/Middleware/SetupPageRedirection.php +++ b/src/Http/Middleware/SetupPageRedirection.php @@ -6,6 +6,7 @@ namespace PhpMyAdmin\Http\Middleware; use PhpMyAdmin\Config; use PhpMyAdmin\Container\ContainerBuilder; +use PhpMyAdmin\Current; use PhpMyAdmin\Exceptions\ExitException; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\ServerRequest; @@ -53,7 +54,7 @@ final class SetupPageRedirection implements MiddlewareInterface restore_error_handler(); // Save current language in a cookie, since it was not set in Common::run(). - $this->config->setCookie('pma_lang', $GLOBALS['lang']); + $this->config->setCookie('pma_lang', Current::$lang); $this->config->setSetup(true); // allows for redirection even after sending some data diff --git a/src/I18n/Language.php b/src/I18n/Language.php index b009cb5318..5101b49179 100644 --- a/src/I18n/Language.php +++ b/src/I18n/Language.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace PhpMyAdmin\I18n; +use PhpMyAdmin\Current; + use function addcslashes; use function in_array; use function preg_match; @@ -102,7 +104,7 @@ class Language */ public function isActive(): bool { - return $GLOBALS['lang'] == $this->code; + return Current::$lang === $this->code; } /** diff --git a/src/I18n/LanguageManager.php b/src/I18n/LanguageManager.php index bf51113c40..83c46618b6 100644 --- a/src/I18n/LanguageManager.php +++ b/src/I18n/LanguageManager.php @@ -6,7 +6,9 @@ namespace PhpMyAdmin\I18n; use PhpMyAdmin\Config; use PhpMyAdmin\Core; +use PhpMyAdmin\Current; use PhpMyAdmin\Exceptions\UnsupportedLanguageCode; +use PhpMyAdmin\SqlParser\Translator; use function __; use function _bindtextdomain; @@ -873,7 +875,7 @@ class LanguageManager */ public function getCurrentLanguage(): Language { - return $this->availableLanguages[strtolower($GLOBALS['lang'])]; + return $this->availableLanguages[strtolower(Current::$lang)]; } /** @@ -973,15 +975,17 @@ class LanguageManager */ public function activate(Language $language): void { - $GLOBALS['lang'] = $language->getCode(); + $languageCode = $language->getCode(); + Current::$lang = $languageCode; + Translator::setLocale($languageCode); // Set locale - _setlocale(0, $language->getCode()); + _setlocale(0, $languageCode); _bindtextdomain('phpmyadmin', LOCALE_PATH); _textdomain('phpmyadmin'); // Set PHP locale as well if (function_exists('setlocale')) { - setlocale(0, $language->getCode()); + setlocale(0, $languageCode); } self::$textDirection = $language->isRTL() ? TextDirection::RightToLeft : TextDirection::LeftToRight; @@ -990,7 +994,7 @@ class LanguageManager $GLOBALS['l'] = [ 'a_meta_charset' => 'UTF-8', 'a_meta_dir' => self::$textDirection->value, - 'a_meta_language' => $language->getCode(), + 'a_meta_language' => $languageCode, 'w_page' => __('Page number:'), ]; diff --git a/src/Plugins/Auth/AuthenticationCookie.php b/src/Plugins/Auth/AuthenticationCookie.php index 0ee47a84e8..2f12f62870 100644 --- a/src/Plugins/Auth/AuthenticationCookie.php +++ b/src/Plugins/Auth/AuthenticationCookie.php @@ -176,7 +176,7 @@ class AuthenticationCookie extends AuthenticationPlugin 'has_servers' => $hasServers, 'server_options' => $serversOptions, 'server' => Current::$server, - 'lang' => $GLOBALS['lang'], + 'lang' => Current::$lang, 'has_captcha' => ! empty($config->settings['CaptchaApi']) && ! empty($config->settings['CaptchaRequestParam']) && ! empty($config->settings['CaptchaResponseParam']) diff --git a/src/Plugins/Auth/AuthenticationHttp.php b/src/Plugins/Auth/AuthenticationHttp.php index 13d7531712..522c82637b 100644 --- a/src/Plugins/Auth/AuthenticationHttp.php +++ b/src/Plugins/Auth/AuthenticationHttp.php @@ -11,6 +11,7 @@ namespace PhpMyAdmin\Plugins\Auth; use Fig\Http\Message\StatusCodeInterface; use PhpMyAdmin\Config; use PhpMyAdmin\Core; +use PhpMyAdmin\Current; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Exceptions\AuthenticationFailure; use PhpMyAdmin\Http\Response; @@ -184,7 +185,7 @@ class AuthenticationHttp extends AuthenticationPlugin if ($error && $GLOBALS['errno'] != 1045) { $responseRenderer = ResponseRenderer::getInstance(); $responseRenderer->addHTML($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => $error, ])); diff --git a/src/Plugins/Auth/AuthenticationSignon.php b/src/Plugins/Auth/AuthenticationSignon.php index 30e57fe2ac..08cfe450af 100644 --- a/src/Plugins/Auth/AuthenticationSignon.php +++ b/src/Plugins/Auth/AuthenticationSignon.php @@ -9,6 +9,7 @@ namespace PhpMyAdmin\Plugins\Auth; use Fig\Http\Message\StatusCodeInterface; use PhpMyAdmin\Config; +use PhpMyAdmin\Current; use PhpMyAdmin\Exceptions\AuthenticationFailure; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\Response; @@ -45,7 +46,7 @@ class AuthenticationSignon extends AuthenticationPlugin $config = Config::getInstance(); if (empty($config->selectedServer['SignonURL'])) { $responseRenderer->addHTML($this->template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => 'You must set SignonURL!', ])); diff --git a/src/Routing/Routing.php b/src/Routing/Routing.php index 79050e7bcd..0e18c43af6 100644 --- a/src/Routing/Routing.php +++ b/src/Routing/Routing.php @@ -17,6 +17,7 @@ use PhpMyAdmin\Controllers\Setup\MainController; use PhpMyAdmin\Controllers\Setup\ShowConfigController; use PhpMyAdmin\Controllers\Setup\ValidateController; use PhpMyAdmin\Core; +use PhpMyAdmin\Current; use PhpMyAdmin\Http\Factory\ResponseFactory; use PhpMyAdmin\Http\Response; use PhpMyAdmin\Http\ServerRequest; @@ -196,7 +197,7 @@ class Routing $response = $responseFactory->createResponse(StatusCodeInterface::STATUS_NOT_FOUND); return $response->write($template->render('error/generic', [ - 'lang' => $GLOBALS['lang'] ?? 'en', + 'lang' => Current::$lang, 'error_message' => Sanitize::convertBBCode(sprintf( __('Error 404! The page %s was not found.'), '[code]' . htmlspecialchars($route) . '[/code]', diff --git a/src/Url.php b/src/Url.php index aca9e7d46e..a09f663b41 100644 --- a/src/Url.php +++ b/src/Url.php @@ -64,8 +64,8 @@ class Url $params['server'] = Current::$server; } - if (empty($config->getCookie('pma_lang')) && ! empty($GLOBALS['lang'])) { - $params['lang'] = $GLOBALS['lang']; + if (empty($config->getCookie('pma_lang')) && Current::$lang !== '') { + $params['lang'] = Current::$lang; } if (! is_array($skip)) { @@ -221,8 +221,8 @@ class Url } // Can be null when the user is missing an extension. - if (empty($config->getCookie('pma_lang')) && ! empty($GLOBALS['lang'])) { - $params['lang'] = $GLOBALS['lang']; + if (empty($config->getCookie('pma_lang')) && Current::$lang !== '') { + $params['lang'] = Current::$lang; } $query = self::buildHttpQuery($params, $encrypt); diff --git a/tests/unit/AbstractTestCase.php b/tests/unit/AbstractTestCase.php index d0eaede07c..976d38b927 100644 --- a/tests/unit/AbstractTestCase.php +++ b/tests/unit/AbstractTestCase.php @@ -78,6 +78,7 @@ abstract class AbstractTestCase extends TestCase Current::$table = ''; Current::$sqlQuery = ''; Current::$message = null; + Current::$lang = 'en'; // Config before DBI $this->setGlobalConfig(); @@ -116,7 +117,7 @@ abstract class AbstractTestCase extends TestCase protected function setLanguage(string $code = 'en'): void { - $GLOBALS['lang'] = $code; + Current::$lang = $code; $languageManager = LanguageManager::getInstance(); /* Ensure default language is active */ $languageEn = $languageManager->getLanguage($code); diff --git a/tests/unit/Container/ContainerBuilderTest.php b/tests/unit/Container/ContainerBuilderTest.php index 0de73c74d2..13acb09217 100644 --- a/tests/unit/Container/ContainerBuilderTest.php +++ b/tests/unit/Container/ContainerBuilderTest.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Container; use PhpMyAdmin\Container\ContainerBuilder; +use PhpMyAdmin\Current; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Tests\AbstractTestCase; use PHPUnit\Framework\Attributes\CoversClass; @@ -30,7 +31,7 @@ final class ContainerBuilderTest extends AbstractTestCase #[DataProvider('servicesProvider')] public function testContainerEntries(string $service): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; DatabaseInterface::$instance = $this->createDatabaseInterface(); $container = ContainerBuilder::getContainer(); self::assertNotNull($container->get($service)); diff --git a/tests/unit/Controllers/Export/ExportControllerTest.php b/tests/unit/Controllers/Export/ExportControllerTest.php index 495c12d26e..09a56ee84d 100644 --- a/tests/unit/Controllers/Export/ExportControllerTest.php +++ b/tests/unit/Controllers/Export/ExportControllerTest.php @@ -48,7 +48,7 @@ final class ExportControllerTest extends AbstractTestCase $dbi = $this->createDatabaseInterface($dbiDummy); DatabaseInterface::$instance = $dbi; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $config = Config::getInstance(); $config->selectServer('1'); $config->settings['Export']['sql_procedure_function'] = false; @@ -209,7 +209,7 @@ final class ExportControllerTest extends AbstractTestCase $dbi = $this->createDatabaseInterface($dbiDummy); DatabaseInterface::$instance = $dbi; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $config = Config::getInstance(); $config->selectServer('1'); $config->settings['Export']['sql_procedure_function'] = false; diff --git a/tests/unit/Controllers/HomeControllerTest.php b/tests/unit/Controllers/HomeControllerTest.php index 95b9bb504a..58e2510727 100644 --- a/tests/unit/Controllers/HomeControllerTest.php +++ b/tests/unit/Controllers/HomeControllerTest.php @@ -32,7 +32,10 @@ final class HomeControllerTest extends AbstractTestCase $response = $controller($request); self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode()); - self::assertSame('./index.php?route=/database/structure&db=test_db', $response->getHeaderLine('Location')); + self::assertSame( + './index.php?route=/database/structure&db=test_db&lang=en', + $response->getHeaderLine('Location'), + ); self::assertSame('', (string) $response->getBody()); } @@ -50,7 +53,10 @@ final class HomeControllerTest extends AbstractTestCase $response = $controller($request); self::assertSame(StatusCodeInterface::STATUS_FOUND, $response->getStatusCode()); - self::assertSame('./index.php?route=/sql&db=test_db&table=test_table', $response->getHeaderLine('Location')); + self::assertSame( + './index.php?route=/sql&db=test_db&table=test_table&lang=en', + $response->getHeaderLine('Location'), + ); self::assertSame('', (string) $response->getBody()); } } diff --git a/tests/unit/Controllers/Operations/TableControllerTest.php b/tests/unit/Controllers/Operations/TableControllerTest.php index 55e2b378a2..ba21828ba8 100644 --- a/tests/unit/Controllers/Operations/TableControllerTest.php +++ b/tests/unit/Controllers/Operations/TableControllerTest.php @@ -40,7 +40,7 @@ class TableControllerTest extends AbstractTestCase public function testOperationsController(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Current::$database = 'test_db'; Current::$table = 'test_table'; diff --git a/tests/unit/Controllers/Table/GisVisualizationControllerTest.php b/tests/unit/Controllers/Table/GisVisualizationControllerTest.php index bbc2841acf..e923af072f 100644 --- a/tests/unit/Controllers/Table/GisVisualizationControllerTest.php +++ b/tests/unit/Controllers/Table/GisVisualizationControllerTest.php @@ -29,7 +29,7 @@ class GisVisualizationControllerTest extends AbstractTestCase public function testGisVisualizationController(): void { Current::$server = 2; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Current::$database = 'test_db'; Current::$table = 'test_table'; $_GET['sql_query'] = null; diff --git a/tests/unit/Controllers/Table/ImportControllerTest.php b/tests/unit/Controllers/Table/ImportControllerTest.php index d972aa0aaa..72811e1406 100644 --- a/tests/unit/Controllers/Table/ImportControllerTest.php +++ b/tests/unit/Controllers/Table/ImportControllerTest.php @@ -33,7 +33,7 @@ class ImportControllerTest extends AbstractTestCase { Current::$database = 'test_db'; Current::$table = 'test_table'; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $config = Config::getInstance(); $config->selectedServer = $config->getSettings()->Servers[1]->asArray(); $_GET['format'] = 'xml'; diff --git a/tests/unit/Controllers/Table/IndexRenameControllerTest.php b/tests/unit/Controllers/Table/IndexRenameControllerTest.php index e62a18cd66..527263431b 100644 --- a/tests/unit/Controllers/Table/IndexRenameControllerTest.php +++ b/tests/unit/Controllers/Table/IndexRenameControllerTest.php @@ -25,7 +25,7 @@ class IndexRenameControllerTest extends AbstractTestCase { Current::$database = 'test_db'; Current::$table = 'test_table_index_rename'; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $dummyDbi = $this->createDbiDummy(); $dummyDbi->addSelectDb('test_db'); diff --git a/tests/unit/Controllers/Table/SqlControllerTest.php b/tests/unit/Controllers/Table/SqlControllerTest.php index d430adcbee..2db0ccc2d1 100644 --- a/tests/unit/Controllers/Table/SqlControllerTest.php +++ b/tests/unit/Controllers/Table/SqlControllerTest.php @@ -44,7 +44,7 @@ class SqlControllerTest extends AbstractTestCase Current::$server = 2; Current::$database = 'test_db'; Current::$table = 'test_table'; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $config = Config::getInstance(); $config->selectedServer = $config->getSettings()->Servers[1]->asArray(); diff --git a/tests/unit/Controllers/Table/StructureControllerTest.php b/tests/unit/Controllers/Table/StructureControllerTest.php index f506ca2f19..6c92d69b00 100644 --- a/tests/unit/Controllers/Table/StructureControllerTest.php +++ b/tests/unit/Controllers/Table/StructureControllerTest.php @@ -44,7 +44,7 @@ class StructureControllerTest extends AbstractTestCase { Current::$database = 'test_db'; Current::$table = 'test_table'; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $config = Config::getInstance(); $config->selectedServer = $config->getSettings()->Servers[1]->asArray(); $config->selectedServer['DisableIS'] = true; diff --git a/tests/unit/DatabaseInterfaceTest.php b/tests/unit/DatabaseInterfaceTest.php index 0e0e066bd8..81da15ca99 100644 --- a/tests/unit/DatabaseInterfaceTest.php +++ b/tests/unit/DatabaseInterfaceTest.php @@ -44,7 +44,7 @@ class DatabaseInterfaceTest extends AbstractTestCase { parent::tearDown(); - unset($GLOBALS['lang']); + Current::$lang = ''; unset(Config::getInstance()->selectedServer['SessionTimeZone']); Context::load(); } @@ -175,7 +175,7 @@ class DatabaseInterfaceTest extends AbstractTestCase */ public function testPostConnectShouldNotCallSetVersionIfNoVersion(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; LanguageManager::getInstance()->availableLanguages(); $mock = $this->getMockBuilder(DatabaseInterface::class) @@ -198,7 +198,7 @@ class DatabaseInterfaceTest extends AbstractTestCase */ public function testPostConnectShouldCallSetVersionOnce(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $versionQueryResult = [ '@@version' => '10.20.7-MariaDB-1:10.9.3+maria~ubu2204', '@@version_comment' => 'mariadb.org binary distribution', @@ -236,7 +236,7 @@ class DatabaseInterfaceTest extends AbstractTestCase bool $isMariaDb, bool $isPercona, ): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; LanguageManager::getInstance()->availableLanguages(); $mock = $this->getMockBuilder(DatabaseInterface::class) diff --git a/tests/unit/Error/ErrorHandlerTest.php b/tests/unit/Error/ErrorHandlerTest.php index d54a0d9f52..c3444b241f 100644 --- a/tests/unit/Error/ErrorHandlerTest.php +++ b/tests/unit/Error/ErrorHandlerTest.php @@ -6,6 +6,7 @@ namespace PhpMyAdmin\Tests\Error; use Exception; use PhpMyAdmin\Config; +use PhpMyAdmin\Current; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Error\Error; use PhpMyAdmin\Error\ErrorHandler; @@ -45,7 +46,7 @@ class ErrorHandlerTest extends AbstractTestCase { parent::setUp(); - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; DatabaseInterface::$instance = $this->createDatabaseInterface(); $this->object = new ErrorHandler(); $_SESSION['errors'] = []; @@ -257,7 +258,7 @@ class ErrorHandlerTest extends AbstractTestCase public function testHandleExceptionForDevEnv(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Config::getInstance()->set('environment', 'development'); $errorHandler = new ErrorHandler(); self::assertSame([], $errorHandler->getCurrentErrors()); @@ -280,7 +281,7 @@ class ErrorHandlerTest extends AbstractTestCase public function testHandleExceptionForProdEnv(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Config::getInstance()->set('environment', 'production'); $errorHandler = new ErrorHandler(); self::assertSame([], $errorHandler->getCurrentErrors()); @@ -302,7 +303,7 @@ class ErrorHandlerTest extends AbstractTestCase public function testAddErrorWithFatalError(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Config::getInstance()->set('environment', 'production'); $errorHandler = new ErrorHandler(); try { diff --git a/tests/unit/Export/ExportTest.php b/tests/unit/Export/ExportTest.php index cc3e706080..c143933ad5 100644 --- a/tests/unit/Export/ExportTest.php +++ b/tests/unit/Export/ExportTest.php @@ -228,7 +228,7 @@ SQL; public function testGetPageLocationAndSaveMessageForServerExportWithError(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Current::$server = 2; $_SESSION = []; $dbi = $this->createDatabaseInterface(); @@ -243,7 +243,7 @@ SQL; public function testGetPageLocationAndSaveMessageForServerExportWithSuccess(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Current::$server = 2; $_SESSION = []; $dbi = $this->createDatabaseInterface(); @@ -258,7 +258,7 @@ SQL; public function testGetPageLocationAndSaveMessageForDatabaseExportWithError(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Current::$server = 2; Current::$database = 'test_db'; $_SESSION = []; @@ -274,7 +274,7 @@ SQL; public function testGetPageLocationAndSaveMessageForDatabaseExportWithSuccess(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Current::$server = 2; Current::$database = 'test_db'; $_SESSION = []; @@ -290,7 +290,7 @@ SQL; public function testGetPageLocationAndSaveMessageForTableExportWithError(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Current::$server = 2; Current::$database = 'test_db'; Current::$table = 'test_table'; @@ -310,7 +310,7 @@ SQL; public function testGetPageLocationAndSaveMessageForTableExportWithSuccess(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Current::$server = 2; Current::$database = 'test_db'; Current::$table = 'test_table'; diff --git a/tests/unit/Html/SecurityTest.php b/tests/unit/Html/SecurityTest.php index b6aa832264..0d87d16ade 100644 --- a/tests/unit/Html/SecurityTest.php +++ b/tests/unit/Html/SecurityTest.php @@ -32,10 +32,10 @@ class SecurityTest extends AbstractTestCase { self::assertSame( '?db=%3Cscript%3Ealert%28%27%26%3D%21%3A%3B%27%29%3B%3C%2Fscr' - . 'ipt%3E&table=%26mytable%3E1%3F&server=12' + . 'ipt%3E&table=%26mytable%3E1%3F&server=12&lang=en' . "\n" . '?db=%22%27%22%3E%3Ciframe+onload%3Dalert%281%29%3E%D1%88%D0%B5%D0%BB%D0%BB%D1%8B' - . '&table=%26mytable%3E1%3F&server=12&%3Cscript%3E%26%3D=%3C%2Fscript%3E' + . '&table=%26mytable%3E1%3F&server=12&%3Cscript%3E%26%3D=%3C%2Fscript%3E&lang=en' . "\n", $this->template->render('test/add_data', [ 'variable1' => Url::getCommon([ @@ -58,14 +58,14 @@ class SecurityTest extends AbstractTestCase ]); self::assertSame( '?db=%3Cscript%3Ealert%28%27%26%3D%21%3A%3B%27%29%3B%3C%2Fscr' - . 'ipt%3E&table=%26mytable%3E1%3F&server=12', + . 'ipt%3E&table=%26mytable%3E1%3F&server=12&lang=en', $url1, ); self::assertSame( $url1 . "\n" . '?db=%22%27%22%3E%3Ciframe+onload%3Dalert%281%29%3E%D1%88%D0%B5%D0%BB%D0%BB%D1%8B' - . '&table=%26mytable%3E1%3F&server=12&%3Cscript%3E%26%3D=%3C%2Fscript%3E' + . '&table=%26mytable%3E1%3F&server=12&%3Cscript%3E%26%3D=%3C%2Fscript%3E&lang=en' . "\n", $this->template->render('test/raw_output', [ 'variable1' => $url1, diff --git a/tests/unit/ParseAnalyzeTest.php b/tests/unit/ParseAnalyzeTest.php index 3c931d2c8b..4493f871d8 100644 --- a/tests/unit/ParseAnalyzeTest.php +++ b/tests/unit/ParseAnalyzeTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests; +use PhpMyAdmin\Current; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\ParseAnalyze; use PhpMyAdmin\ResponseRenderer; @@ -21,7 +22,7 @@ class ParseAnalyzeTest extends AbstractTestCase public function testSqlQuery(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; ResponseRenderer::getInstance()->setAjax(false); $actual = ParseAnalyze::sqlQuery('SELECT * FROM `sakila`.`actor`', 'sakila_test'); @@ -37,7 +38,7 @@ class ParseAnalyzeTest extends AbstractTestCase public function testSqlQuery2(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; ResponseRenderer::getInstance()->setAjax(false); $actual = ParseAnalyze::sqlQuery('SELECT `first_name`, `title` FROM `actor`, `film`', 'sakila'); diff --git a/tests/unit/Plugins/Auth/AuthenticationHttpTest.php b/tests/unit/Plugins/Auth/AuthenticationHttpTest.php index 868d7698b8..d2ff571446 100644 --- a/tests/unit/Plugins/Auth/AuthenticationHttpTest.php +++ b/tests/unit/Plugins/Auth/AuthenticationHttpTest.php @@ -39,7 +39,7 @@ class AuthenticationHttpTest extends AbstractTestCase Config::getInstance()->settings['Servers'] = []; Current::$database = 'db'; Current::$table = 'table'; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $GLOBALS['token_provided'] = true; $GLOBALS['token_mismatch'] = false; $this->object = new AuthenticationHttp(); diff --git a/tests/unit/Plugins/AuthenticationPluginTest.php b/tests/unit/Plugins/AuthenticationPluginTest.php index e9a92fe7d2..392dfbabe9 100644 --- a/tests/unit/Plugins/AuthenticationPluginTest.php +++ b/tests/unit/Plugins/AuthenticationPluginTest.php @@ -7,6 +7,7 @@ namespace PhpMyAdmin\Tests\Plugins; use PhpMyAdmin\Config; use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\ConfigStorage\RelationParameters; +use PhpMyAdmin\Current; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Exceptions\AuthenticationFailure; use PhpMyAdmin\Exceptions\ExitException; @@ -28,7 +29,7 @@ final class AuthenticationPluginTest extends AbstractTestCase /** @psalm-suppress InaccessibleProperty */ $config->config->debug->simple2fa = true; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $dbiDummy = $this->createDbiDummy(); $dbiDummy->addResult( // phpcs:ignore Generic.Files.LineLength.TooLong @@ -91,7 +92,7 @@ final class AuthenticationPluginTest extends AbstractTestCase /** @psalm-suppress InaccessibleProperty */ $config->config->debug->simple2fa = true; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $dbiDummy = $this->createDbiDummy(); $dbiDummy->addResult( // phpcs:ignore Generic.Files.LineLength.TooLong diff --git a/tests/unit/Plugins/Export/ExportCsvTest.php b/tests/unit/Plugins/Export/ExportCsvTest.php index 1b400b86fd..a5002bdb74 100644 --- a/tests/unit/Plugins/Export/ExportCsvTest.php +++ b/tests/unit/Plugins/Export/ExportCsvTest.php @@ -42,7 +42,7 @@ class ExportCsvTest extends AbstractTestCase DatabaseInterface::$instance = $dbi; Current::$database = ''; Current::$table = ''; - $GLOBALS['lang'] = ''; + Current::$lang = ''; $GLOBALS['csv_enclosed'] = null; $GLOBALS['csv_separator'] = null; $GLOBALS['save_filename'] = null; diff --git a/tests/unit/Plugins/Export/ExportHtmlwordTest.php b/tests/unit/Plugins/Export/ExportHtmlwordTest.php index aa809d58cb..a1ae1bda85 100644 --- a/tests/unit/Plugins/Export/ExportHtmlwordTest.php +++ b/tests/unit/Plugins/Export/ExportHtmlwordTest.php @@ -69,7 +69,7 @@ class ExportHtmlwordTest extends AbstractTestCase $GLOBALS['save_on_server'] = false; Current::$database = ''; Current::$table = ''; - $GLOBALS['lang'] = ''; + Current::$lang = ''; Config::getInstance()->selectedServer['DisableIS'] = true; } diff --git a/tests/unit/Plugins/Export/ExportMediawikiTest.php b/tests/unit/Plugins/Export/ExportMediawikiTest.php index b75f6d0e5b..d0d672134e 100644 --- a/tests/unit/Plugins/Export/ExportMediawikiTest.php +++ b/tests/unit/Plugins/Export/ExportMediawikiTest.php @@ -50,7 +50,7 @@ class ExportMediawikiTest extends AbstractTestCase $GLOBALS['save_on_server'] = false; Current::$database = ''; Current::$table = ''; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $this->object = new ExportMediawiki( new Relation($dbi), new Export($dbi), diff --git a/tests/unit/Plugins/Export/ExportPhparrayTest.php b/tests/unit/Plugins/Export/ExportPhparrayTest.php index 2b4c63344c..4c258e0195 100644 --- a/tests/unit/Plugins/Export/ExportPhparrayTest.php +++ b/tests/unit/Plugins/Export/ExportPhparrayTest.php @@ -45,7 +45,7 @@ class ExportPhparrayTest extends AbstractTestCase $GLOBALS['save_on_server'] = false; Current::$database = ''; Current::$table = ''; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $this->object = new ExportPhparray( new Relation($dbi), new Export($dbi), diff --git a/tests/unit/Plugins/Export/ExportSqlTest.php b/tests/unit/Plugins/Export/ExportSqlTest.php index 96c45c4fd1..d0285e6ee9 100644 --- a/tests/unit/Plugins/Export/ExportSqlTest.php +++ b/tests/unit/Plugins/Export/ExportSqlTest.php @@ -64,7 +64,7 @@ class ExportSqlTest extends AbstractTestCase DatabaseInterface::$instance = $dbi; Current::$database = ''; Current::$table = ''; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Config::getInstance()->selectedServer['DisableIS'] = true; $GLOBALS['output_kanji_conversion'] = false; $GLOBALS['buffer_needed'] = false; diff --git a/tests/unit/Plugins/Export/ExportTexytextTest.php b/tests/unit/Plugins/Export/ExportTexytextTest.php index 375236f003..8507219de0 100644 --- a/tests/unit/Plugins/Export/ExportTexytextTest.php +++ b/tests/unit/Plugins/Export/ExportTexytextTest.php @@ -67,7 +67,7 @@ class ExportTexytextTest extends AbstractTestCase ExportPlugin::$singleTable = false; Current::$database = ''; Current::$table = ''; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Config::getInstance()->selectedServer['DisableIS'] = true; $this->object = new ExportTexytext( new Relation($this->dbi), diff --git a/tests/unit/Plugins/Export/ExportYamlTest.php b/tests/unit/Plugins/Export/ExportYamlTest.php index b1e98c5722..03b0b36de4 100644 --- a/tests/unit/Plugins/Export/ExportYamlTest.php +++ b/tests/unit/Plugins/Export/ExportYamlTest.php @@ -44,7 +44,7 @@ class ExportYamlTest extends AbstractTestCase $GLOBALS['save_on_server'] = false; Current::$database = ''; Current::$table = ''; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $this->object = new ExportYaml( new Relation($dbi), new Export($dbi), diff --git a/tests/unit/Plugins/Schema/SvgRelationSchemaTest.php b/tests/unit/Plugins/Schema/SvgRelationSchemaTest.php index d930dfcfae..694b67aea6 100644 --- a/tests/unit/Plugins/Schema/SvgRelationSchemaTest.php +++ b/tests/unit/Plugins/Schema/SvgRelationSchemaTest.php @@ -46,7 +46,7 @@ class SvgRelationSchemaTest extends AbstractTestCase Current::$database = 'test_db'; Current::$table = ''; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; Config::getInstance()->selectedServer['DisableIS'] = true; $this->object = new SvgRelationSchema(new Relation($dbi), DatabaseName::from('test_db')); diff --git a/tests/unit/Plugins/TwoFactor/WebAuthnTest.php b/tests/unit/Plugins/TwoFactor/WebAuthnTest.php index 0bf612b656..e7a084e362 100644 --- a/tests/unit/Plugins/TwoFactor/WebAuthnTest.php +++ b/tests/unit/Plugins/TwoFactor/WebAuthnTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests\Plugins\TwoFactor; +use PhpMyAdmin\Current; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Http\ServerRequest; use PhpMyAdmin\Plugins\TwoFactor\WebAuthn; @@ -42,7 +43,7 @@ class WebAuthnTest extends AbstractTestCase { (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null); - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; DatabaseInterface::$instance = $this->createDatabaseInterface(); $uri = self::createStub(UriInterface::class); @@ -105,7 +106,7 @@ class WebAuthnTest extends AbstractTestCase { (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, null); - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; DatabaseInterface::$instance = $this->createDatabaseInterface(); $uri = self::createStub(UriInterface::class); diff --git a/tests/unit/ResponseRendererTest.php b/tests/unit/ResponseRendererTest.php index 515a71cc0f..aabb22315d 100644 --- a/tests/unit/ResponseRendererTest.php +++ b/tests/unit/ResponseRendererTest.php @@ -29,7 +29,7 @@ final class ResponseRendererTest extends AbstractTestCase DatabaseInterface::$instance = $this->createDatabaseInterface(); - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; } public function testSetAjax(): void diff --git a/tests/unit/SanitizeTest.php b/tests/unit/SanitizeTest.php index 53d8ce21dd..16359c5c98 100644 --- a/tests/unit/SanitizeTest.php +++ b/tests/unit/SanitizeTest.php @@ -4,6 +4,7 @@ declare(strict_types=1); namespace PhpMyAdmin\Tests; +use PhpMyAdmin\Current; use PhpMyAdmin\Sanitize; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; @@ -38,15 +39,15 @@ class SanitizeTest extends AbstractTestCase */ public function testLink(): void { - $lang = $GLOBALS['lang']; + $lang = Current::$lang; - unset($GLOBALS['lang']); + Current::$lang = ''; self::assertSame( 'link', Sanitize::convertBBCode('[a@https://www.phpmyadmin.net/@target]link[/a]'), ); - $GLOBALS['lang'] = $lang; + Current::$lang = $lang; } /** diff --git a/tests/unit/ScriptsTest.php b/tests/unit/ScriptsTest.php index 1b7fc78022..cc462f8c8b 100644 --- a/tests/unit/ScriptsTest.php +++ b/tests/unit/ScriptsTest.php @@ -55,7 +55,7 @@ class ScriptsTest extends AbstractTestCase $actual, ); self::assertStringContainsString( - 'src="index.php?route=%2Fmessages&l=en&v=' . rawurlencode(Version::VERSION) . '"', + 'src="index.php?route=%2Fmessages&l=en&v=' . rawurlencode(Version::VERSION) . '&lang=en"', $actual, ); self::assertStringContainsString( diff --git a/tests/unit/Server/PrivilegesTest.php b/tests/unit/Server/PrivilegesTest.php index dd5e73dda7..4762ff8efc 100644 --- a/tests/unit/Server/PrivilegesTest.php +++ b/tests/unit/Server/PrivilegesTest.php @@ -8,6 +8,7 @@ use PhpMyAdmin\Config; use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\ConfigStorage\RelationCleanup; use PhpMyAdmin\ConfigStorage\RelationParameters; +use PhpMyAdmin\Current; use PhpMyAdmin\Dbal\ConnectionType; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Dbal\ResultInterface; @@ -267,7 +268,7 @@ class PrivilegesTest extends AbstractTestCase public function testGetDataForChangeOrCopyUser(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $dummyDbi = $this->createDbiDummy(); // phpcs:disable Generic.Files.LineLength.TooLong @@ -1547,7 +1548,7 @@ class PrivilegesTest extends AbstractTestCase public function testGetHtmlForUserOverview(): void { Config::getInstance()->selectedServer['DisableIS'] = false; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $userPrivileges = new UserPrivileges(isReload: true); $dummyDbi = $this->createDbiDummy(); @@ -1702,7 +1703,7 @@ class PrivilegesTest extends AbstractTestCase public function testGetHtmlForInitials(): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $dummyDbi = $this->createDbiDummy(); $dummyDbi->addResult('SELECT COUNT(*) FROM `mysql`.`user`', [[21]]); diff --git a/tests/unit/SqlQueryFormTest.php b/tests/unit/SqlQueryFormTest.php index 2459399fc2..c3ee179baf 100644 --- a/tests/unit/SqlQueryFormTest.php +++ b/tests/unit/SqlQueryFormTest.php @@ -138,7 +138,7 @@ class SqlQueryFormTest extends AbstractTestCase public function testPMAGetHtmlForSqlQueryForm(): void { //Call the test function - $GLOBALS['lang'] = 'ja'; + Current::$lang = 'ja'; $query = 'select * from PMA'; $html = $this->sqlQueryForm->getHtml('PMA_db', 'PMA_table', $query); @@ -175,6 +175,6 @@ class SqlQueryFormTest extends AbstractTestCase Encoding::kanjiEncodingForm(), $html, ); - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; } } diff --git a/tests/unit/Stubs/ResponseRenderer.php b/tests/unit/Stubs/ResponseRenderer.php index 0588983596..966f424af7 100644 --- a/tests/unit/Stubs/ResponseRenderer.php +++ b/tests/unit/Stubs/ResponseRenderer.php @@ -15,6 +15,7 @@ use PhpMyAdmin\Bookmarks\BookmarkRepository; use PhpMyAdmin\Config; use PhpMyAdmin\ConfigStorage\Relation; use PhpMyAdmin\Console; +use PhpMyAdmin\Current; use PhpMyAdmin\Dbal\DatabaseInterface; use PhpMyAdmin\Error\ErrorHandler; use PhpMyAdmin\Footer; @@ -47,7 +48,7 @@ class ResponseRenderer extends \PhpMyAdmin\ResponseRenderer */ public function __construct() { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $config = Config::getInstance(); $config->selectedServer['pmadb'] = 'phpmyadmin'; $template = new Template($config); diff --git a/tests/unit/Tracking/TrackingTest.php b/tests/unit/Tracking/TrackingTest.php index e7272527d9..ec693a9d88 100644 --- a/tests/unit/Tracking/TrackingTest.php +++ b/tests/unit/Tracking/TrackingTest.php @@ -52,7 +52,7 @@ class TrackingTest extends AbstractTestCase Current::$database = 'PMA_db'; Current::$table = 'PMA_table'; - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; $config = Config::getInstance(); $config->selectedServer['DisableIS'] = true; $config->selectedServer['tracking_default_statements'] = 'DELETE'; diff --git a/tests/unit/UserPreferencesTest.php b/tests/unit/UserPreferencesTest.php index 1cfe597622..787d2ed92f 100644 --- a/tests/unit/UserPreferencesTest.php +++ b/tests/unit/UserPreferencesTest.php @@ -319,7 +319,7 @@ class UserPreferencesTest extends AbstractTestCase $responseStub = new ResponseRendererStub(); (new ReflectionProperty(ResponseRenderer::class, 'instance'))->setValue(null, $responseStub); - $GLOBALS['lang'] = ''; + Current::$lang = ''; Current::$database = 'db'; Current::$table = 'table'; diff --git a/tests/unit/UtilTest.php b/tests/unit/UtilTest.php index bb1e069eaa..00ca79d810 100644 --- a/tests/unit/UtilTest.php +++ b/tests/unit/UtilTest.php @@ -1329,7 +1329,7 @@ SQL; #[DataProvider('dataProviderScriptNames')] public function testGetScriptNameForOption(string $target, string $location, string $finalLink): void { - $GLOBALS['lang'] = 'en'; + Current::$lang = 'en'; self::assertSame( $finalLink, Util::getScriptNameForOption($target, $location),