Merge pull request #17427 from mauriciofauth/global-keyword

Replace `global` keyword with `$GLOBALS`
This commit is contained in:
Maurício Meneghini Fauth 2022-03-07 17:33:07 -03:00 committed by GitHub
commit 9ff08aaa08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
311 changed files with 5996 additions and 6915 deletions

View File

@ -35,9 +35,11 @@ if (! @is_readable(AUTOLOAD_FILE)) {
require AUTOLOAD_FILE;
global $containerBuilder;
Common::run();
$dispatcher = Routing::getDispatcher();
Routing::callControllerForRoute(Common::getRequest(), Routing::getCurrentRoute(), $dispatcher, $containerBuilder);
Routing::callControllerForRoute(
Common::getRequest(),
Routing::getCurrentRoute(),
Routing::getDispatcher(),
$GLOBALS['containerBuilder']
);

View File

@ -6,9 +6,6 @@ use PhpMyAdmin\Common;
use PhpMyAdmin\Controllers\JavaScriptMessagesController;
use PhpMyAdmin\OutputBuffering;
/** @psalm-suppress InvalidGlobal */
global $containerBuilder;
if (! defined('ROOT_PATH')) {
// phpcs:disable PSR1.Files.SideEffects
define('ROOT_PATH', dirname(__DIR__) . DIRECTORY_SEPARATOR);
@ -47,7 +44,7 @@ header('Content-Type: text/javascript; charset=UTF-8');
// Cache output in client - the nocache query parameter makes sure that this file is reloaded when config changes.
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 3600) . ' GMT');
$isMinimumCommon = true;
$GLOBALS['isMinimumCommon'] = true;
// phpcs:disable PSR1.Files.SideEffects
define('PMA_PATH_TO_BASEDIR', '../');
define('PMA_NO_SESSION', true);
@ -63,5 +60,5 @@ register_shutdown_function(static function (): void {
});
/** @var JavaScriptMessagesController $controller */
$controller = $containerBuilder->get(JavaScriptMessagesController::class);
$controller = $GLOBALS['containerBuilder']->get(JavaScriptMessagesController::class);
$controller();

View File

@ -39,14 +39,12 @@ class BrowseForeigners
*/
public function __construct(Template $template)
{
global $cfg;
$this->template = $template;
$this->limitChars = (int) $cfg['LimitChars'];
$this->maxRows = (int) $cfg['MaxRows'];
$this->repeatCells = (int) $cfg['RepeatCells'];
$this->showAll = (bool) $cfg['ShowAll'];
$this->limitChars = (int) $GLOBALS['cfg']['LimitChars'];
$this->maxRows = (int) $GLOBALS['cfg']['MaxRows'];
$this->repeatCells = (int) $GLOBALS['cfg']['RepeatCells'];
$this->showAll = (bool) $GLOBALS['cfg']['ShowAll'];
}
/**
@ -71,8 +69,6 @@ class BrowseForeigners
int $indexByDescription,
string $currentValue
): array {
global $theme;
$horizontalCount++;
$output = '';
@ -126,7 +122,7 @@ class BrowseForeigners
]);
$output .= '<td width="20%"><img src="'
. ($theme instanceof Theme ? $theme->getImgPath('spacer.png') : '')
. ($GLOBALS['theme'] instanceof Theme ? $GLOBALS['theme']->getImgPath('spacer.png') : '')
. '" alt="" width="1" height="1"></td>';
$output .= $this->template->render('table/browse_foreigners/column_element', [

View File

@ -118,13 +118,11 @@ final class CacheWarmupCommand extends Command
string $environment,
bool $writeReplacements
): int {
global $cfg, $config, $dbi;
$output->writeln('Warming up the twig cache', OutputInterface::VERBOSITY_VERBOSE);
$config = new Config(CONFIG_FILE);
$cfg['environment'] = $environment;
$config->set('environment', $cfg['environment']);
$dbi = new DatabaseInterface(new DbiDummy());
$GLOBALS['config'] = new Config(CONFIG_FILE);
$GLOBALS['cfg']['environment'] = $environment;
$GLOBALS['config']->set('environment', $GLOBALS['cfg']['environment']);
$GLOBALS['dbi'] = new DatabaseInterface(new DbiDummy());
$tmpDir = ROOT_PATH . 'twig-templates';
$twig = Template::getTwigEnvironment($tmpDir);

View File

@ -81,22 +81,17 @@ final class Common
*/
public static function run(): void
{
global $containerBuilder, $errorHandler, $config, $server, $dbi;
global $lang, $cfg, $isConfigLoading, $auth_plugin, $theme;
global $urlParams, $isMinimumCommon, $sql_query, $token_mismatch;
$request = self::getRequest();
$route = Routing::getCurrentRoute();
if ($route === '/import-status') {
$isMinimumCommon = true;
$GLOBALS['isMinimumCommon'] = true;
}
$containerBuilder = Core::getContainerBuilder();
$GLOBALS['containerBuilder'] = Core::getContainerBuilder();
/** @var ErrorHandler $errorHandler */
$errorHandler = $containerBuilder->get('error_handler');
$GLOBALS['errorHandler'] = $GLOBALS['containerBuilder']->get('error_handler');
self::checkRequiredPhpExtensions();
self::configurePhpSettings();
@ -104,24 +99,22 @@ final class Common
/* parsing configuration file LABEL_parsing_config_file */
/** @var bool $isConfigLoading Indication for the error handler */
$isConfigLoading = false;
/** Indication for the error handler */
$GLOBALS['isConfigLoading'] = false;
register_shutdown_function([Config::class, 'fatalErrorHandler']);
/**
* Force reading of config file, because we removed sensitive values
* in the previous iteration.
*
* @var Config $config
*/
$config = $containerBuilder->get('config');
$GLOBALS['config'] = $GLOBALS['containerBuilder']->get('config');
/**
* include session handling after the globals, to prevent overwriting
*/
if (! defined('PMA_NO_SESSION')) {
Session::setUp($config, $errorHandler);
Session::setUp($GLOBALS['config'], $GLOBALS['errorHandler']);
}
$request = Core::populateRequestWithEncryptedQueryParams($request);
@ -135,27 +128,27 @@ final class Common
*
* @global array $urlParams
*/
$urlParams = [];
$containerBuilder->setParameter('url_params', $urlParams);
$GLOBALS['urlParams'] = [];
$GLOBALS['containerBuilder']->setParameter('url_params', $GLOBALS['urlParams']);
self::setGotoAndBackGlobals($containerBuilder, $config);
self::setGotoAndBackGlobals($GLOBALS['containerBuilder'], $GLOBALS['config']);
self::checkTokenRequestParam();
self::setDatabaseAndTableFromRequest($containerBuilder, $request);
self::setDatabaseAndTableFromRequest($GLOBALS['containerBuilder'], $request);
/**
* SQL query to be executed
*
* @global string $sql_query
*/
$sql_query = '';
$GLOBALS['sql_query'] = '';
if ($request->isPost()) {
$sql_query = $request->getParsedBodyParam('sql_query');
if (! is_string($sql_query)) {
$sql_query = '';
$GLOBALS['sql_query'] = $request->getParsedBodyParam('sql_query');
if (! is_string($GLOBALS['sql_query'])) {
$GLOBALS['sql_query'] = '';
}
}
$containerBuilder->setParameter('sql_query', $sql_query);
$GLOBALS['containerBuilder']->setParameter('sql_query', $GLOBALS['sql_query']);
//$_REQUEST['set_theme'] // checked later in this file LABEL_theme_setup
//$_REQUEST['server']; // checked later in this file
@ -173,38 +166,37 @@ final class Common
* check for errors occurred while loading configuration
* this check is done here after loading language files to present errors in locale
*/
$config->checkPermissions();
$config->checkErrors();
$GLOBALS['config']->checkPermissions();
$GLOBALS['config']->checkErrors();
self::checkServerConfiguration();
self::checkRequest();
/* setup servers LABEL_setup_servers */
$config->checkServers();
$GLOBALS['config']->checkServers();
/**
* current server
*
* @global integer $server
*/
$server = $config->selectServer();
$urlParams['server'] = $server;
$containerBuilder->setParameter('server', $server);
$containerBuilder->setParameter('url_params', $urlParams);
$GLOBALS['server'] = $GLOBALS['config']->selectServer();
$GLOBALS['urlParams']['server'] = $GLOBALS['server'];
$GLOBALS['containerBuilder']->setParameter('server', $GLOBALS['server']);
$GLOBALS['containerBuilder']->setParameter('url_params', $GLOBALS['urlParams']);
$cfg = $config->settings;
$GLOBALS['cfg'] = $GLOBALS['config']->settings;
/* setup themes LABEL_theme_setup */
$theme = ThemeManager::initializeTheme();
$GLOBALS['theme'] = ThemeManager::initializeTheme();
/** @var DatabaseInterface $dbi */
$dbi = null;
$GLOBALS['dbi'] = null;
if (isset($isMinimumCommon)) {
$config->loadUserPreferences();
$containerBuilder->set('theme_manager', ThemeManager::getInstance());
if (isset($GLOBALS['isMinimumCommon'])) {
$GLOBALS['config']->loadUserPreferences();
$GLOBALS['containerBuilder']->set('theme_manager', ThemeManager::getInstance());
Tracker::enable();
return;
@ -215,19 +207,19 @@ final class Common
*
* @todo should be done in PhpMyAdmin\Config
*/
$config->setCookie('pma_lang', (string) $lang);
$GLOBALS['config']->setCookie('pma_lang', (string) $GLOBALS['lang']);
ThemeManager::getInstance()->setThemeCookie();
$dbi = DatabaseInterface::load();
$containerBuilder->set(DatabaseInterface::class, $dbi);
$containerBuilder->setAlias('dbi', DatabaseInterface::class);
$GLOBALS['dbi'] = DatabaseInterface::load();
$GLOBALS['containerBuilder']->set(DatabaseInterface::class, $GLOBALS['dbi']);
$GLOBALS['containerBuilder']->setAlias('dbi', DatabaseInterface::class);
if (! empty($cfg['Server'])) {
$config->getLoginCookieValidityFromCache($server);
if (! empty($GLOBALS['cfg']['Server'])) {
$GLOBALS['config']->getLoginCookieValidityFromCache($GLOBALS['server']);
$auth_plugin = Plugins::getAuthPlugin();
$auth_plugin->authenticate();
$GLOBALS['auth_plugin'] = Plugins::getAuthPlugin();
$GLOBALS['auth_plugin']->authenticate();
/* Enable LOAD DATA LOCAL INFILE for LDI plugin */
if ($route === '/import' && ($_POST['format'] ?? '') === 'ldi') {
@ -237,21 +229,21 @@ final class Common
// phpcs:enable
}
self::connectToDatabaseServer($dbi, $auth_plugin);
self::connectToDatabaseServer($GLOBALS['dbi'], $GLOBALS['auth_plugin']);
$auth_plugin->rememberCredentials();
$GLOBALS['auth_plugin']->rememberCredentials();
$auth_plugin->checkTwoFactor();
$GLOBALS['auth_plugin']->checkTwoFactor();
/* Log success */
Logging::logUser($cfg['Server']['user']);
Logging::logUser($GLOBALS['cfg']['Server']['user']);
if ($dbi->getVersion() < $cfg['MysqlMinVersion']['internal']) {
if ($GLOBALS['dbi']->getVersion() < $GLOBALS['cfg']['MysqlMinVersion']['internal']) {
Core::fatalError(
__('You should upgrade to %s %s or later.'),
[
'MySQL',
$cfg['MysqlMinVersion']['human'],
$GLOBALS['cfg']['MysqlMinVersion']['human'],
]
);
}
@ -276,7 +268,7 @@ final class Common
* There is no point in even attempting to process
* an ajax request if there is a token mismatch
*/
if ($response->isAjax() && $request->isPost() && $token_mismatch) {
if ($response->isAjax() && $request->isPost() && $GLOBALS['token_mismatch']) {
$response->setRequestStatus(false);
$response->addJSON(
'message',
@ -285,25 +277,25 @@ final class Common
exit;
}
Profiling::check($dbi, $response);
Profiling::check($GLOBALS['dbi'], $response);
$containerBuilder->set('response', ResponseRenderer::getInstance());
$GLOBALS['containerBuilder']->set('response', ResponseRenderer::getInstance());
// load user preferences
$config->loadUserPreferences();
$GLOBALS['config']->loadUserPreferences();
$containerBuilder->set('theme_manager', ThemeManager::getInstance());
$GLOBALS['containerBuilder']->set('theme_manager', ThemeManager::getInstance());
/* Tell tracker that it can actually work */
Tracker::enable();
if (empty($server) || ! isset($cfg['ZeroConf']) || $cfg['ZeroConf'] !== true) {
if (empty($GLOBALS['server']) || ! isset($GLOBALS['cfg']['ZeroConf']) || $GLOBALS['cfg']['ZeroConf'] !== true) {
return;
}
/** @var Relation $relation */
$relation = $containerBuilder->get('relation');
$dbi->postConnectControl($relation);
$relation = $GLOBALS['containerBuilder']->get('relation');
$GLOBALS['dbi']->postConnectControl($relation);
}
/**
@ -381,31 +373,29 @@ final class Common
*/
public static function cleanupPathInfo(): void
{
global $PMA_PHP_SELF;
$PMA_PHP_SELF = Core::getenv('PHP_SELF');
if (empty($PMA_PHP_SELF)) {
$PMA_PHP_SELF = urldecode(Core::getenv('REQUEST_URI'));
$GLOBALS['PMA_PHP_SELF'] = Core::getenv('PHP_SELF');
if (empty($GLOBALS['PMA_PHP_SELF'])) {
$GLOBALS['PMA_PHP_SELF'] = urldecode(Core::getenv('REQUEST_URI'));
}
$_PATH_INFO = Core::getenv('PATH_INFO');
if (! empty($_PATH_INFO) && ! empty($PMA_PHP_SELF)) {
$question_pos = mb_strpos($PMA_PHP_SELF, '?');
if (! empty($_PATH_INFO) && ! empty($GLOBALS['PMA_PHP_SELF'])) {
$question_pos = mb_strpos($GLOBALS['PMA_PHP_SELF'], '?');
if ($question_pos != false) {
$PMA_PHP_SELF = mb_substr($PMA_PHP_SELF, 0, $question_pos);
$GLOBALS['PMA_PHP_SELF'] = mb_substr($GLOBALS['PMA_PHP_SELF'], 0, $question_pos);
}
$path_info_pos = mb_strrpos($PMA_PHP_SELF, $_PATH_INFO);
$path_info_pos = mb_strrpos($GLOBALS['PMA_PHP_SELF'], $_PATH_INFO);
if ($path_info_pos !== false) {
$path_info_part = mb_substr($PMA_PHP_SELF, $path_info_pos, mb_strlen($_PATH_INFO));
$path_info_part = mb_substr($GLOBALS['PMA_PHP_SELF'], $path_info_pos, mb_strlen($_PATH_INFO));
if ($path_info_part == $_PATH_INFO) {
$PMA_PHP_SELF = mb_substr($PMA_PHP_SELF, 0, $path_info_pos);
$GLOBALS['PMA_PHP_SELF'] = mb_substr($GLOBALS['PMA_PHP_SELF'], 0, $path_info_pos);
}
}
}
$path = [];
foreach (explode('/', $PMA_PHP_SELF) as $part) {
foreach (explode('/', $GLOBALS['PMA_PHP_SELF']) as $part) {
// ignore parts that have no value
if (empty($part) || $part === '.') {
continue;
@ -423,22 +413,20 @@ final class Common
// as there is nothing sane to do
}
$PMA_PHP_SELF = htmlspecialchars('/' . implode('/', $path));
$GLOBALS['PMA_PHP_SELF'] = htmlspecialchars('/' . implode('/', $path));
}
private static function setGotoAndBackGlobals(ContainerInterface $container, Config $config): void
{
global $goto, $back, $urlParams;
// Holds page that should be displayed.
$goto = '';
$container->setParameter('goto', $goto);
$GLOBALS['goto'] = '';
$container->setParameter('goto', $GLOBALS['goto']);
if (isset($_REQUEST['goto']) && Core::checkPageValidity($_REQUEST['goto'])) {
$goto = $_REQUEST['goto'];
$urlParams['goto'] = $goto;
$container->setParameter('goto', $goto);
$container->setParameter('url_params', $urlParams);
$GLOBALS['goto'] = $_REQUEST['goto'];
$GLOBALS['urlParams']['goto'] = $GLOBALS['goto'];
$container->setParameter('goto', $GLOBALS['goto']);
$container->setParameter('url_params', $GLOBALS['urlParams']);
} else {
if ($config->issetCookie('goto')) {
$config->removeCookie('goto');
@ -449,8 +437,8 @@ final class Common
if (isset($_REQUEST['back']) && Core::checkPageValidity($_REQUEST['back'])) {
// Returning page.
$back = $_REQUEST['back'];
$container->setParameter('back', $back);
$GLOBALS['back'] = $_REQUEST['back'];
$container->setParameter('back', $GLOBALS['back']);
return;
}
@ -472,21 +460,19 @@ final class Common
*/
public static function checkTokenRequestParam(): void
{
global $token_mismatch, $token_provided;
$token_mismatch = true;
$token_provided = false;
$GLOBALS['token_mismatch'] = true;
$GLOBALS['token_provided'] = false;
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
return;
}
if (isset($_POST['token']) && is_scalar($_POST['token']) && strlen((string) $_POST['token']) > 0) {
$token_provided = true;
$token_mismatch = ! @hash_equals($_SESSION[' PMA_token '], (string) $_POST['token']);
$GLOBALS['token_provided'] = true;
$GLOBALS['token_mismatch'] = ! @hash_equals($_SESSION[' PMA_token '], (string) $_POST['token']);
}
if (! $token_mismatch) {
if (! $GLOBALS['token_mismatch']) {
return;
}
@ -512,28 +498,26 @@ final class Common
ContainerInterface $containerBuilder,
ServerRequest $request
): void {
global $db, $table, $urlParams;
try {
$db = DatabaseName::fromValue($request->getParam('db'))->getName();
$GLOBALS['db'] = DatabaseName::fromValue($request->getParam('db'))->getName();
} catch (InvalidArgumentException $exception) {
$db = '';
$GLOBALS['db'] = '';
}
try {
Assert::stringNotEmpty($db);
$table = TableName::fromValue($request->getParam('table'))->getName();
Assert::stringNotEmpty($GLOBALS['db']);
$GLOBALS['table'] = TableName::fromValue($request->getParam('table'))->getName();
} catch (InvalidArgumentException $exception) {
$table = '';
$GLOBALS['table'] = '';
}
if (! is_array($urlParams)) {
$urlParams = [];
if (! is_array($GLOBALS['urlParams'])) {
$GLOBALS['urlParams'] = [];
}
$urlParams['db'] = $db;
$urlParams['table'] = $table;
$containerBuilder->setParameter('url_params', $urlParams);
$GLOBALS['urlParams']['db'] = $GLOBALS['db'];
$GLOBALS['urlParams']['table'] = $GLOBALS['table'];
$containerBuilder->setParameter('url_params', $GLOBALS['urlParams']);
}
/**
@ -594,14 +578,12 @@ final class Common
private static function connectToDatabaseServer(DatabaseInterface $dbi, AuthenticationPlugin $auth): void
{
global $cfg;
/**
* Try to connect MySQL with the control user profile (will be used to get the privileges list for the current
* user but the true user link must be open after this one so it would be default one for all the scripts).
*/
$controlLink = false;
if ($cfg['Server']['controluser'] !== '') {
if ($GLOBALS['cfg']['Server']['controluser'] !== '') {
$controlLink = $dbi->connect(DatabaseInterface::CONNECT_CONTROL);
}

View File

@ -344,8 +344,6 @@ class Config
*/
public function load(?string $source = null): bool
{
global $isConfigLoading;
$this->loadDefaults();
if ($source !== null) {
@ -369,10 +367,10 @@ class Config
}
ob_start();
$isConfigLoading = true;
$GLOBALS['isConfigLoading'] = true;
/** @psalm-suppress UnresolvableInclude */
$eval_result = include $this->getSource();
$isConfigLoading = false;
$GLOBALS['isConfigLoading'] = false;
ob_end_clean();
if ($canUseErrorReporting) {
@ -415,14 +413,12 @@ class Config
*/
private function setConnectionCollation(): void
{
global $dbi;
$collation_connection = $this->get('DefaultConnectionCollation');
if (empty($collation_connection) || $collation_connection == $GLOBALS['collation_connection']) {
return;
}
$dbi->setCollation($collation_connection);
$GLOBALS['dbi']->setCollation($collation_connection);
}
/**
@ -431,15 +427,13 @@ class Config
*/
public function loadUserPreferences(): void
{
global $isMinimumCommon;
// index.php should load these settings, so that phpmyadmin.css.php
// will have everything available in session cache
$server = $GLOBALS['server'] ?? (! empty($GLOBALS['cfg']['ServerDefault'])
? $GLOBALS['cfg']['ServerDefault']
: 0);
$cache_key = 'server_' . $server;
if ($server > 0 && ! isset($isMinimumCommon)) {
if ($server > 0 && ! isset($GLOBALS['isMinimumCommon'])) {
// cache user preferences, use database only when needed
if (
! isset($_SESSION['cache'][$cache_key]['userprefs'])
@ -467,7 +461,7 @@ class Config
$this->settings = array_replace_recursive($this->settings, $config_data);
$GLOBALS['cfg'] = array_replace_recursive($GLOBALS['cfg'], $config_data);
if (isset($isMinimumCommon)) {
if (isset($GLOBALS['isMinimumCommon'])) {
return;
}
@ -1036,9 +1030,7 @@ class Config
*/
public static function fatalErrorHandler(): void
{
global $isConfigLoading;
if (! isset($isConfigLoading) || ! $isConfigLoading) {
if (! isset($GLOBALS['isConfigLoading']) || ! $GLOBALS['isConfigLoading']) {
return;
}
@ -1258,31 +1250,29 @@ class Config
*/
public static function getConnectionParams(int $mode, ?array $server = null): array
{
global $cfg;
$user = null;
$password = null;
if ($mode == DatabaseInterface::CONNECT_USER) {
$user = $cfg['Server']['user'];
$password = $cfg['Server']['password'];
$server = $cfg['Server'];
$user = $GLOBALS['cfg']['Server']['user'];
$password = $GLOBALS['cfg']['Server']['password'];
$server = $GLOBALS['cfg']['Server'];
} elseif ($mode == DatabaseInterface::CONNECT_CONTROL) {
$user = $cfg['Server']['controluser'];
$password = $cfg['Server']['controlpass'];
$user = $GLOBALS['cfg']['Server']['controluser'];
$password = $GLOBALS['cfg']['Server']['controlpass'];
$server = [];
$server['hide_connection_errors'] = $cfg['Server']['hide_connection_errors'];
$server['hide_connection_errors'] = $GLOBALS['cfg']['Server']['hide_connection_errors'];
if (! empty($cfg['Server']['controlhost'])) {
$server['host'] = $cfg['Server']['controlhost'];
if (! empty($GLOBALS['cfg']['Server']['controlhost'])) {
$server['host'] = $GLOBALS['cfg']['Server']['controlhost'];
} else {
$server['host'] = $cfg['Server']['host'];
$server['host'] = $GLOBALS['cfg']['Server']['host'];
}
// Share the settings if the host is same
if ($server['host'] == $cfg['Server']['host']) {
if ($server['host'] == $GLOBALS['cfg']['Server']['host']) {
$shared = [
'port',
'socket',
@ -1296,21 +1286,21 @@ class Config
'ssl_verify',
];
foreach ($shared as $item) {
if (! isset($cfg['Server'][$item])) {
if (! isset($GLOBALS['cfg']['Server'][$item])) {
continue;
}
$server[$item] = $cfg['Server'][$item];
$server[$item] = $GLOBALS['cfg']['Server'][$item];
}
}
// Set configured port
if (! empty($cfg['Server']['controlport'])) {
$server['port'] = $cfg['Server']['controlport'];
if (! empty($GLOBALS['cfg']['Server']['controlport'])) {
$server['port'] = $GLOBALS['cfg']['Server']['controlport'];
}
// Set any configuration with control_ prefix
foreach ($cfg['Server'] as $key => $val) {
foreach ($GLOBALS['cfg']['Server'] as $key => $val) {
if (substr($key, 0, 8) !== 'control_') {
continue;
}
@ -1375,8 +1365,6 @@ class Config
*/
public function getLoginCookieValidityFromCache(int $server): void
{
global $cfg;
$cacheKey = 'server_' . $server;
if (! isset($_SESSION['cache'][$cacheKey]['userprefs']['LoginCookieValidity'])) {
@ -1385,6 +1373,6 @@ class Config
$value = $_SESSION['cache'][$cacheKey]['userprefs']['LoginCookieValidity'];
$this->set('LoginCookieValidity', $value);
$cfg['LoginCookieValidity'] = $value;
$GLOBALS['cfg']['LoginCookieValidity'] = $value;
}
}

View File

@ -64,9 +64,7 @@ class SpecialSchemaLinks
*/
public static function get(): array
{
global $cfg;
$defaultPage = './' . Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
$defaultPage = './' . Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
return [
'mysql' => [

View File

@ -1778,9 +1778,7 @@ class Relation
public function getConfigurationStorageDbName(): string
{
global $cfg;
$cfgStorageDbName = $cfg['Server']['pmadb'] ?? '';
$cfgStorageDbName = $GLOBALS['cfg']['Server']['pmadb'] ?? '';
// Use "phpmyadmin" as a default database name to check to keep the behavior consistent
return empty($cfgStorageDbName) ? 'phpmyadmin' : $cfgStorageDbName;

View File

@ -37,8 +37,6 @@ class UserGroups
ConfigurableMenusFeature $configurableMenusFeature,
string $userGroup
): string {
global $dbi;
$users = [];
$numRows = 0;
@ -46,9 +44,9 @@ class UserGroups
$usersTable = Util::backquote($configurableMenusFeature->database)
. '.' . Util::backquote($configurableMenusFeature->users);
$sql_query = 'SELECT `username` FROM ' . $usersTable
. " WHERE `usergroup`='" . $dbi->escapeString($userGroup)
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "'";
$result = $dbi->tryQueryAsControlUser($sql_query);
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sql_query);
if ($result) {
$i = 0;
while ($row = $result->fetchRow()) {
@ -75,12 +73,10 @@ class UserGroups
*/
public static function getHtmlForUserGroupsTable(ConfigurableMenusFeature $configurableMenusFeature): string
{
global $dbi;
$groupTable = Util::backquote($configurableMenusFeature->database)
. '.' . Util::backquote($configurableMenusFeature->userGroups);
$sql_query = 'SELECT * FROM ' . $groupTable . ' ORDER BY `usergroup` ASC';
$result = $dbi->tryQueryAsControlUser($sql_query);
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sql_query);
$userGroups = [];
$userGroupsValues = [];
$action = Url::getFromRoute('/server/privileges');
@ -171,20 +167,18 @@ class UserGroups
*/
public static function delete(ConfigurableMenusFeature $configurableMenusFeature, string $userGroup): void
{
global $dbi;
$userTable = Util::backquote($configurableMenusFeature->database)
. '.' . Util::backquote($configurableMenusFeature->users);
$groupTable = Util::backquote($configurableMenusFeature->database)
. '.' . Util::backquote($configurableMenusFeature->userGroups);
$sql_query = 'DELETE FROM ' . $userTable
. " WHERE `usergroup`='" . $dbi->escapeString($userGroup)
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "'";
$dbi->queryAsControlUser($sql_query);
$GLOBALS['dbi']->queryAsControlUser($sql_query);
$sql_query = 'DELETE FROM ' . $groupTable
. " WHERE `usergroup`='" . $dbi->escapeString($userGroup)
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "'";
$dbi->queryAsControlUser($sql_query);
$GLOBALS['dbi']->queryAsControlUser($sql_query);
}
/**
@ -198,8 +192,6 @@ class UserGroups
ConfigurableMenusFeature $configurableMenusFeature,
?string $userGroup = null
): string {
global $dbi;
$urlParams = [];
$editUserGroupSpecialChars = '';
@ -223,9 +215,9 @@ class UserGroups
$groupTable = Util::backquote($configurableMenusFeature->database)
. '.' . Util::backquote($configurableMenusFeature->userGroups);
$sql_query = 'SELECT * FROM ' . $groupTable
. " WHERE `usergroup`='" . $dbi->escapeString($userGroup)
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "'";
$result = $dbi->tryQueryAsControlUser($sql_query);
$result = $GLOBALS['dbi']->tryQueryAsControlUser($sql_query);
if ($result) {
foreach ($result as $row) {
$key = $row['tab'];
@ -312,17 +304,15 @@ class UserGroups
string $userGroup,
bool $new = false
): void {
global $dbi;
$tabs = Util::getMenuTabList();
$groupTable = Util::backquote($configurableMenusFeature->database)
. '.' . Util::backquote($configurableMenusFeature->userGroups);
if (! $new) {
$sql_query = 'DELETE FROM ' . $groupTable
. " WHERE `usergroup`='" . $dbi->escapeString($userGroup)
. " WHERE `usergroup`='" . $GLOBALS['dbi']->escapeString($userGroup)
. "';";
$dbi->queryAsControlUser($sql_query);
$GLOBALS['dbi']->queryAsControlUser($sql_query);
}
$sql_query = 'INSERT INTO ' . $groupTable
@ -338,13 +328,13 @@ class UserGroups
$tabName = $tabGroupName . '_' . $tab;
$allowed = isset($_POST[$tabName]) && $_POST[$tabName] === 'Y';
$sql_query .= "('" . $dbi->escapeString($userGroup) . "', '" . $tabName . "', '"
$sql_query .= "('" . $GLOBALS['dbi']->escapeString($userGroup) . "', '" . $tabName . "', '"
. ($allowed ? 'Y' : 'N') . "')";
$first = false;
}
}
$sql_query .= ';';
$dbi->queryAsControlUser($sql_query);
$GLOBALS['dbi']->queryAsControlUser($sql_query);
}
}

View File

@ -44,10 +44,8 @@ class Console
*/
public function __construct()
{
global $dbi;
$this->isEnabled = true;
$this->relation = new Relation($dbi);
$this->relation = new Relation($GLOBALS['dbi']);
$this->template = new Template();
}
@ -75,16 +73,14 @@ class Console
*/
public static function getBookmarkContent(): string
{
global $dbi;
$template = new Template();
$relation = new Relation($dbi);
$relation = new Relation($GLOBALS['dbi']);
$bookmarkFeature = $relation->getRelationParameters()->bookmarkFeature;
if ($bookmarkFeature === null) {
return '';
}
$bookmarks = Bookmark::getList($bookmarkFeature, $dbi, $GLOBALS['cfg']['Server']['user']);
$bookmarks = Bookmark::getList($bookmarkFeature, $GLOBALS['dbi'], $GLOBALS['cfg']['Server']['user']);
$count_bookmarks = count($bookmarks);
if ($count_bookmarks > 0) {
$welcomeMessage = sprintf(

View File

@ -48,25 +48,23 @@ abstract class AbstractController
protected function hasDatabase(): bool
{
global $db, $is_db, $errno, $dbi, $message;
if (isset($is_db) && $is_db) {
if (isset($GLOBALS['is_db']) && $GLOBALS['is_db']) {
return true;
}
$is_db = false;
if (strlen($db) > 0) {
$is_db = $dbi->selectDb($db);
$GLOBALS['is_db'] = false;
if (strlen($GLOBALS['db']) > 0) {
$GLOBALS['is_db'] = $GLOBALS['dbi']->selectDb($GLOBALS['db']);
// This "Command out of sync" 2014 error may happen, for example
// after calling a MySQL procedure; at this point we can't select
// the db but it's not necessarily wrong
if ($dbi->getError() && $errno == 2014) {
$is_db = true;
unset($errno);
if ($GLOBALS['dbi']->getError() && $GLOBALS['errno'] == 2014) {
$GLOBALS['is_db'] = true;
unset($GLOBALS['errno']);
}
}
if (strlen($db) === 0 || ! $is_db) {
if (strlen($GLOBALS['db']) === 0 || ! $GLOBALS['is_db']) {
if ($this->response->isAjax()) {
$this->response->setRequestStatus(false);
$this->response->addJSON(
@ -79,8 +77,8 @@ abstract class AbstractController
// Not a valid db name -> back to the welcome page
$params = ['reload' => '1'];
if (isset($message)) {
$params['message'] = $message;
if (isset($GLOBALS['message'])) {
$params['message'] = $GLOBALS['message'];
}
$this->redirect('/', $params);
@ -88,7 +86,7 @@ abstract class AbstractController
return false;
}
return $is_db;
return $GLOBALS['is_db'];
}
/**

View File

@ -27,8 +27,6 @@ class CheckRelationsController extends AbstractController
public function __invoke(ServerRequest $request): void
{
global $db, $cfg;
/** @var string|null $createPmaDb */
$createPmaDb = $request->getParsedBodyParam('create_pmadb');
/** @var string|null $fixAllPmaDb */
@ -45,7 +43,7 @@ class CheckRelationsController extends AbstractController
// If request for creating all PMA tables.
if (isset($fixAllPmaDb)) {
$this->relation->fixPmaTables($db);
$this->relation->fixPmaTables($GLOBALS['db']);
}
// If request for creating missing PMA tables.
@ -58,8 +56,8 @@ class CheckRelationsController extends AbstractController
$relationParameters = $this->relation->getRelationParameters();
$this->render('relation/check_relations', [
'db' => $db,
'zero_conf' => $cfg['ZeroConf'],
'db' => $GLOBALS['db'],
'zero_conf' => $GLOBALS['cfg']['ZeroConf'],
'relation_parameters' => $relationParameters->toArray(),
'sql_dir' => SQL_DIR,
'config_storage_database_name' => $cfgStorageDbName,

View File

@ -35,8 +35,6 @@ class CentralColumnsController extends AbstractController
public function __invoke(): void
{
global $cfg, $db, $message, $pos, $num_cols;
if (isset($_POST['edit_save'])) {
echo $this->editSave([
'col_name' => $_POST['col_name'] ?? null,
@ -99,7 +97,7 @@ class CentralColumnsController extends AbstractController
}
if (isset($_POST['multi_edit_central_column_save'])) {
$message = $this->updateMultipleColumn([
$GLOBALS['message'] = $this->updateMultipleColumn([
'db' => $_POST['db'] ?? null,
'orig_col_name' => $_POST['orig_col_name'] ?? null,
'field_name' => $_POST['field_name'] ?? null,
@ -112,9 +110,9 @@ class CentralColumnsController extends AbstractController
'field_null' => $_POST['field_null'] ?? null,
'col_extra' => $_POST['col_extra'] ?? null,
]);
if (! is_bool($message)) {
if (! is_bool($GLOBALS['message'])) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);
$this->response->addJSON('message', $GLOBALS['message']);
}
}
@ -130,20 +128,24 @@ class CentralColumnsController extends AbstractController
'total_rows' => $_POST['total_rows'] ?? null,
]);
$pos = 0;
$GLOBALS['pos'] = 0;
if (isset($_POST['pos']) && is_numeric($_POST['pos'])) {
$pos = (int) $_POST['pos'];
$GLOBALS['pos'] = (int) $_POST['pos'];
}
$num_cols = $this->centralColumns->getColumnsCount($db, $pos, (int) $cfg['MaxRows']);
$message = Message::success(
sprintf(__('Showing rows %1$s - %2$s.'), $pos + 1, $pos + $num_cols)
$GLOBALS['num_cols'] = $this->centralColumns->getColumnsCount(
$GLOBALS['db'],
$GLOBALS['pos'],
(int) $GLOBALS['cfg']['MaxRows']
);
$GLOBALS['message'] = Message::success(
sprintf(__('Showing rows %1$s - %2$s.'), $GLOBALS['pos'] + 1, $GLOBALS['pos'] + $GLOBALS['num_cols'])
);
if (! isset($tmp_msg) || $tmp_msg === true) {
return;
}
$message = $tmp_msg;
$GLOBALS['message'] = $tmp_msg;
}
/**
@ -151,8 +153,6 @@ class CentralColumnsController extends AbstractController
*/
public function main(array $params): void
{
global $text_dir;
if (! empty($params['total_rows']) && is_numeric($params['total_rows'])) {
$totalRows = (int) $params['total_rows'];
} else {
@ -164,7 +164,12 @@ class CentralColumnsController extends AbstractController
$pos = (int) $params['pos'];
}
$variables = $this->centralColumns->getTemplateVariablesForMain($GLOBALS['db'], $totalRows, $pos, $text_dir);
$variables = $this->centralColumns->getTemplateVariablesForMain(
$GLOBALS['db'],
$totalRows,
$pos,
$GLOBALS['text_dir']
);
$this->render('database/central_columns/main', $variables);
}

View File

@ -38,11 +38,6 @@ class DesignerController extends AbstractController
public function __invoke(): void
{
global $db, $script_display_field, $tab_column, $tables_all_keys, $tables_pk_or_unique_keys;
global $success, $page, $message, $display_page, $selected_page, $tab_pos, $fullTableNames, $script_tables;
global $script_contr, $params, $tables, $num_tables, $total_num_tables, $sub_part;
global $tooltip_truename, $tooltip_aliasname, $pos, $classes_side_menu, $cfg, $errorUrl;
if (isset($_POST['dialog'])) {
if ($_POST['dialog'] === 'edit') {
$html = $this->databaseDesigner->getHtmlForEditOrDeletePages($_POST['db'], 'editPage');
@ -54,19 +49,21 @@ class DesignerController extends AbstractController
$html = $this->databaseDesigner->getHtmlForSchemaExport($_POST['db'], $_POST['selected_page']);
} elseif ($_POST['dialog'] === 'add_table') {
// Pass the db and table to the getTablesInfo so we only have the table we asked for
$script_display_field = $this->designerCommon->getTablesInfo($_POST['db'], $_POST['table']);
$tab_column = $this->designerCommon->getColumnsInfo($script_display_field);
$tables_all_keys = $this->designerCommon->getAllKeys($script_display_field);
$tables_pk_or_unique_keys = $this->designerCommon->getPkOrUniqueKeys($script_display_field);
$GLOBALS['script_display_field'] = $this->designerCommon->getTablesInfo($_POST['db'], $_POST['table']);
$GLOBALS['tab_column'] = $this->designerCommon->getColumnsInfo($GLOBALS['script_display_field']);
$GLOBALS['tables_all_keys'] = $this->designerCommon->getAllKeys($GLOBALS['script_display_field']);
$GLOBALS['tables_pk_or_unique_keys'] = $this->designerCommon->getPkOrUniqueKeys(
$GLOBALS['script_display_field']
);
$html = $this->databaseDesigner->getDatabaseTables(
$_POST['db'],
$script_display_field,
$GLOBALS['script_display_field'],
[],
-1,
$tab_column,
$tables_all_keys,
$tables_pk_or_unique_keys
$GLOBALS['tab_column'],
$GLOBALS['tables_all_keys'],
$GLOBALS['tables_pk_or_unique_keys']
);
}
@ -79,11 +76,11 @@ class DesignerController extends AbstractController
if (isset($_POST['operation'])) {
if ($_POST['operation'] === 'deletePage') {
$success = $this->designerCommon->deletePage($_POST['selected_page']);
$this->response->setRequestStatus($success);
$GLOBALS['success'] = $this->designerCommon->deletePage($_POST['selected_page']);
$this->response->setRequestStatus($GLOBALS['success']);
} elseif ($_POST['operation'] === 'savePage') {
if ($_POST['save_page'] === 'same') {
$page = $_POST['selected_page'];
$GLOBALS['page'] = $_POST['selected_page'];
} elseif ($this->designerCommon->getPageExists($_POST['selected_value'])) {
$this->response->addJSON(
'message',
@ -99,21 +96,21 @@ class DesignerController extends AbstractController
return;
} else {
$page = $this->designerCommon->createNewPage($_POST['selected_value'], $_POST['db']);
$this->response->addJSON('id', $page);
$GLOBALS['page'] = $this->designerCommon->createNewPage($_POST['selected_value'], $_POST['db']);
$this->response->addJSON('id', $GLOBALS['page']);
}
$success = $this->designerCommon->saveTablePositions($page);
$this->response->setRequestStatus($success);
$GLOBALS['success'] = $this->designerCommon->saveTablePositions($GLOBALS['page']);
$this->response->setRequestStatus($GLOBALS['success']);
} elseif ($_POST['operation'] === 'setDisplayField') {
[
$success,
$message,
$GLOBALS['success'],
$GLOBALS['message'],
] = $this->designerCommon->saveDisplayField($_POST['db'], $_POST['table'], $_POST['field']);
$this->response->setRequestStatus($success);
$this->response->addJSON('message', $message);
$this->response->setRequestStatus($GLOBALS['success']);
$this->response->addJSON('message', $GLOBALS['message']);
} elseif ($_POST['operation'] === 'addNewRelation') {
[$success, $message] = $this->designerCommon->addNewRelation(
[$GLOBALS['success'], $GLOBALS['message']] = $this->designerCommon->addNewRelation(
$_POST['db'],
$_POST['T1'],
$_POST['F1'],
@ -124,20 +121,20 @@ class DesignerController extends AbstractController
$_POST['DB1'],
$_POST['DB2']
);
$this->response->setRequestStatus($success);
$this->response->addJSON('message', $message);
$this->response->setRequestStatus($GLOBALS['success']);
$this->response->addJSON('message', $GLOBALS['message']);
} elseif ($_POST['operation'] === 'removeRelation') {
[$success, $message] = $this->designerCommon->removeRelation(
[$GLOBALS['success'], $GLOBALS['message']] = $this->designerCommon->removeRelation(
$_POST['T1'],
$_POST['F1'],
$_POST['T2'],
$_POST['F2']
);
$this->response->setRequestStatus($success);
$this->response->addJSON('message', $message);
$this->response->setRequestStatus($GLOBALS['success']);
$this->response->addJSON('message', $GLOBALS['message']);
} elseif ($_POST['operation'] === 'save_setting_value') {
$success = $this->designerCommon->saveSetting($_POST['index'], $_POST['value']);
$this->response->setRequestStatus($success);
$GLOBALS['success'] = $this->designerCommon->saveSetting($_POST['index'], $_POST['value']);
$this->response->setRequestStatus($GLOBALS['success']);
}
return;
@ -145,62 +142,64 @@ class DesignerController extends AbstractController
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
$script_display_field = $this->designerCommon->getTablesInfo();
$GLOBALS['script_display_field'] = $this->designerCommon->getTablesInfo();
$display_page = -1;
$selected_page = null;
$GLOBALS['display_page'] = -1;
$GLOBALS['selected_page'] = null;
$visualBuilderMode = isset($_GET['query']);
if ($visualBuilderMode) {
$display_page = $this->designerCommon->getDefaultPage($_GET['db']);
$GLOBALS['display_page'] = $this->designerCommon->getDefaultPage($_GET['db']);
} elseif (! empty($_GET['page'])) {
$display_page = $_GET['page'];
$GLOBALS['display_page'] = $_GET['page'];
} else {
$display_page = $this->designerCommon->getLoadingPage($_GET['db']);
$GLOBALS['display_page'] = $this->designerCommon->getLoadingPage($_GET['db']);
}
if ($display_page != -1) {
$selected_page = $this->designerCommon->getPageName($display_page);
if ($GLOBALS['display_page'] != -1) {
$GLOBALS['selected_page'] = $this->designerCommon->getPageName($GLOBALS['display_page']);
}
$tab_pos = $this->designerCommon->getTablePositions($display_page);
$GLOBALS['tab_pos'] = $this->designerCommon->getTablePositions($GLOBALS['display_page']);
$fullTableNames = [];
$GLOBALS['fullTableNames'] = [];
foreach ($script_display_field as $designerTable) {
$fullTableNames[] = $designerTable->getDbTableString();
foreach ($GLOBALS['script_display_field'] as $designerTable) {
$GLOBALS['fullTableNames'][] = $designerTable->getDbTableString();
}
foreach ($tab_pos as $position) {
if (in_array($position['dbName'] . '.' . $position['tableName'], $fullTableNames)) {
foreach ($GLOBALS['tab_pos'] as $position) {
if (in_array($position['dbName'] . '.' . $position['tableName'], $GLOBALS['fullTableNames'])) {
continue;
}
$designerTables = $this->designerCommon->getTablesInfo($position['dbName'], $position['tableName']);
foreach ($designerTables as $designerTable) {
$script_display_field[] = $designerTable;
$GLOBALS['script_display_field'][] = $designerTable;
}
}
$tab_column = $this->designerCommon->getColumnsInfo($script_display_field);
$script_tables = $this->designerCommon->getScriptTabs($script_display_field);
$tables_pk_or_unique_keys = $this->designerCommon->getPkOrUniqueKeys($script_display_field);
$tables_all_keys = $this->designerCommon->getAllKeys($script_display_field);
$classes_side_menu = $this->databaseDesigner->returnClassNamesFromMenuButtons();
$GLOBALS['tab_column'] = $this->designerCommon->getColumnsInfo($GLOBALS['script_display_field']);
$GLOBALS['script_tables'] = $this->designerCommon->getScriptTabs($GLOBALS['script_display_field']);
$GLOBALS['tables_pk_or_unique_keys'] = $this->designerCommon->getPkOrUniqueKeys(
$GLOBALS['script_display_field']
);
$GLOBALS['tables_all_keys'] = $this->designerCommon->getAllKeys($GLOBALS['script_display_field']);
$GLOBALS['classes_side_menu'] = $this->databaseDesigner->returnClassNamesFromMenuButtons();
$script_contr = $this->designerCommon->getScriptContr($script_display_field);
$GLOBALS['script_contr'] = $this->designerCommon->getScriptContr($GLOBALS['script_display_field']);
$params = ['lang' => $GLOBALS['lang']];
$GLOBALS['params'] = ['lang' => $GLOBALS['lang']];
if (isset($_GET['db'])) {
$params['db'] = $_GET['db'];
$GLOBALS['params']['db'] = $_GET['db'];
}
$this->response->getFooter()->setMinimal();
@ -217,33 +216,33 @@ class DesignerController extends AbstractController
]);
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part ?? '');
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,,
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part'] ?? '');
// Embed some data into HTML, later it will be read
// by designer/init.js and converted to JS variables.
$this->response->addHTML(
$this->databaseDesigner->getHtmlForMain(
$db,
$GLOBALS['db'],
$_GET['db'],
$script_display_field,
$script_tables,
$script_contr,
$script_display_field,
$display_page,
$GLOBALS['script_display_field'],
$GLOBALS['script_tables'],
$GLOBALS['script_contr'],
$GLOBALS['script_display_field'],
$GLOBALS['display_page'],
$visualBuilderMode,
$selected_page,
$classes_side_menu,
$tab_pos,
$tab_column,
$tables_all_keys,
$tables_pk_or_unique_keys
$GLOBALS['selected_page'],
$GLOBALS['classes_side_menu'],
$GLOBALS['tab_pos'],
$GLOBALS['tab_column'],
$GLOBALS['tables_all_keys'],
$GLOBALS['tables_pk_or_unique_keys']
)
);

View File

@ -35,51 +35,48 @@ final class EventsController extends AbstractController
public function __invoke(): void
{
global $db, $tables, $num_tables, $total_num_tables, $sub_part, $errors, $text_dir;
global $tooltip_truename, $tooltip_aliasname, $pos, $cfg, $errorUrl;
$this->addScriptFiles(['database/events.js']);
if (! $this->response->isAjax()) {
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part ?? '');
} elseif (strlen($db) > 0) {
$this->dbi->selectDb($db);
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,,
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part'] ?? '');
} elseif (strlen($GLOBALS['db']) > 0) {
$this->dbi->selectDb($GLOBALS['db']);
}
/**
* Keep a list of errors that occurred while
* processing an 'Add' or 'Edit' operation.
*/
$errors = [];
$GLOBALS['errors'] = [];
$this->events->handleEditor();
$this->events->export();
$items = $this->dbi->getEvents($db);
$items = $this->dbi->getEvents($GLOBALS['db']);
$this->render('database/events/index', [
'db' => $db,
'db' => $GLOBALS['db'],
'items' => $items,
'has_privilege' => Util::currentUserHasPrivilege('EVENT', $db),
'has_privilege' => Util::currentUserHasPrivilege('EVENT', $GLOBALS['db']),
'scheduler_state' => $this->events->getEventSchedulerStatus(),
'text_dir' => $text_dir,
'text_dir' => $GLOBALS['text_dir'],
'is_ajax' => $this->response->isAjax() && empty($_REQUEST['ajax_page_request']),
]);
}

View File

@ -40,10 +40,6 @@ final class ExportController extends AbstractController
public function __invoke(): void
{
global $db, $table, $sub_part, $urlParams, $sql_query;
global $tables, $num_tables, $total_num_tables, $tooltip_truename;
global $tooltip_aliasname, $pos, $table_select, $unlim_num_rows, $cfg, $errorUrl;
$pageSettings = new PageSettings('Export');
$pageSettingsErrorHtml = $pageSettings->getErrorHTML();
$pageSettingsHtml = $pageSettings->getHTML();
@ -52,31 +48,31 @@ final class ExportController extends AbstractController
// $sub_part is used in Util::getDbInfo() to see if we are coming from
// /database/export, in which case we don't obey $cfg['MaxTableList']
$sub_part = '_export';
$GLOBALS['sub_part'] = '_export';
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
$urlParams['goto'] = Url::getFromRoute('/database/export');
$GLOBALS['urlParams']['goto'] = Url::getFromRoute('/database/export');
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part);
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,,
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part']);
// exit if no tables in db found
if ($num_tables < 1) {
if ($GLOBALS['num_tables'] < 1) {
$this->response->addHTML(
Message::error(__('No tables found in database.'))->getDisplay()
);
@ -84,17 +80,17 @@ final class ExportController extends AbstractController
return;
}
if (! empty($_POST['selected_tbl']) && empty($table_select)) {
$table_select = $_POST['selected_tbl'];
if (! empty($_POST['selected_tbl']) && empty($GLOBALS['table_select'])) {
$GLOBALS['table_select'] = $_POST['selected_tbl'];
}
$tablesForMultiValues = [];
foreach ($tables as $each_table) {
foreach ($GLOBALS['tables'] as $each_table) {
if (isset($_POST['table_select']) && is_array($_POST['table_select'])) {
$is_checked = $this->export->getCheckedClause($each_table['Name'], $_POST['table_select']);
} elseif (isset($table_select)) {
$is_checked = $this->export->getCheckedClause($each_table['Name'], $table_select);
} elseif (isset($GLOBALS['table_select'])) {
$is_checked = $this->export->getCheckedClause($each_table['Name'], $GLOBALS['table_select']);
} else {
$is_checked = true;
}
@ -119,12 +115,12 @@ final class ExportController extends AbstractController
];
}
if (! isset($sql_query)) {
$sql_query = '';
if (! isset($GLOBALS['sql_query'])) {
$GLOBALS['sql_query'] = '';
}
if (! isset($unlim_num_rows)) {
$unlim_num_rows = 0;
if (! isset($GLOBALS['unlim_num_rows'])) {
$GLOBALS['unlim_num_rows'] = 0;
}
$isReturnBackFromRawExport = isset($_POST['export_type']) && $_POST['export_type'] === 'raw';
@ -148,11 +144,11 @@ final class ExportController extends AbstractController
$options = $this->exportOptions->getOptions(
$export_type,
$db,
$table,
$sql_query,
$num_tables,
$unlim_num_rows,
$GLOBALS['db'],
$GLOBALS['table'],
$GLOBALS['sql_query'],
$GLOBALS['num_tables'],
$GLOBALS['unlim_num_rows'],
$exportList
);

View File

@ -36,9 +36,6 @@ final class ImportController extends AbstractController
public function __invoke(): void
{
global $db, $table, $tables, $num_tables, $total_num_tables, $cfg;
global $tooltip_truename, $tooltip_aliasname, $pos, $sub_part, $SESSION_KEY, $errorUrl;
$pageSettings = new PageSettings('Import');
$pageSettingsErrorHtml = $pageSettings->getErrorHTML();
$pageSettingsHtml = $pageSettings->getHTML();
@ -47,24 +44,24 @@ final class ImportController extends AbstractController
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part ?? '');
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,,
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part'] ?? '');
[$SESSION_KEY, $uploadId] = Ajax::uploadProgressSetup();
[$GLOBALS['SESSION_KEY'], $uploadId] = Ajax::uploadProgressSetup();
$importList = Plugins::getImport('database');
@ -85,13 +82,13 @@ final class ImportController extends AbstractController
$localImportFile = $_REQUEST['local_import_file'] ?? null;
$compressions = Import::getCompressions();
$charsets = Charsets::getCharsets($this->dbi, $cfg['Server']['DisableIS']);
$charsets = Charsets::getCharsets($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$idKey = $_SESSION[$SESSION_KEY]['handler']::getIdKey();
$idKey = $_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getIdKey();
$hiddenInputs = [
$idKey => $uploadId,
'import_type' => 'database',
'db' => $db,
'db' => $GLOBALS['db'],
];
$default = isset($_GET['format']) ? (string) $_GET['format'] : Plugins::getDefault('Import', 'format');
@ -105,10 +102,10 @@ final class ImportController extends AbstractController
'page_settings_error_html' => $pageSettingsErrorHtml,
'page_settings_html' => $pageSettingsHtml,
'upload_id' => $uploadId,
'handler' => $_SESSION[$SESSION_KEY]['handler'],
'handler' => $_SESSION[$GLOBALS['SESSION_KEY']]['handler'],
'hidden_inputs' => $hiddenInputs,
'db' => $db,
'table' => $table,
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'max_upload_size' => $maxUploadSize,
'formatted_maximum_upload_size' => Util::getFormattedMaximumUploadSize($maxUploadSize),
'plugins_choice' => $choice,
@ -117,18 +114,18 @@ final class ImportController extends AbstractController
'is_allow_interrupt_checked' => $isAllowInterruptChecked,
'local_import_file' => $localImportFile,
'is_upload' => $GLOBALS['config']->get('enable_upload'),
'upload_dir' => $cfg['UploadDir'] ?? null,
'upload_dir' => $GLOBALS['cfg']['UploadDir'] ?? null,
'timeout_passed_global' => $GLOBALS['timeout_passed'] ?? null,
'compressions' => $compressions,
'is_encoding_supported' => Encoding::isSupported(),
'encodings' => Encoding::listEncodings(),
'import_charset' => $cfg['Import']['charset'] ?? null,
'import_charset' => $GLOBALS['cfg']['Import']['charset'] ?? null,
'timeout_passed' => $timeoutPassed,
'offset' => $offset,
'can_convert_kanji' => Encoding::canConvertKanji(),
'charsets' => $charsets,
'is_foreign_key_check' => ForeignKey::isCheckEnabled(),
'user_upload_dir' => Util::userDir((string) ($cfg['UploadDir'] ?? '')),
'user_upload_dir' => Util::userDir((string) ($GLOBALS['cfg']['UploadDir'] ?? '')),
'local_files' => Import::getLocalFiles($importList),
]);
}

View File

@ -36,8 +36,6 @@ final class CollationController extends AbstractController
public function __invoke(): void
{
global $db, $cfg, $errorUrl;
if (! $this->response->isAjax()) {
return;
}
@ -51,14 +49,14 @@ final class CollationController extends AbstractController
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
$sql_query = 'ALTER DATABASE ' . Util::backquote($db)
$sql_query = 'ALTER DATABASE ' . Util::backquote($GLOBALS['db'])
. ' DEFAULT' . Util::getCharsetQueryPart($_POST['db_collation'] ?? '');
$this->dbi->query($sql_query);
$message = Message::success();
@ -67,16 +65,16 @@ final class CollationController extends AbstractController
* Changes tables charset if requested by the user
*/
if (isset($_POST['change_all_tables_collations']) && $_POST['change_all_tables_collations'] === 'on') {
[$tables] = Util::getDbInfo($db, '');
[$tables] = Util::getDbInfo($GLOBALS['db'], '');
foreach ($tables as ['Name' => $tableName]) {
if ($this->dbi->getTable($db, $tableName)->isView()) {
if ($this->dbi->getTable($GLOBALS['db'], $tableName)->isView()) {
// Skip views, we can not change the collation of a view.
// issue #15283
continue;
}
$sql_query = 'ALTER TABLE '
. Util::backquote($db)
. Util::backquote($GLOBALS['db'])
. '.'
. Util::backquote($tableName)
. ' DEFAULT '
@ -93,7 +91,7 @@ final class CollationController extends AbstractController
continue;
}
$this->operations->changeAllColumnsCollation($db, $tableName, $_POST['db_collation']);
$this->operations->changeAllColumnsCollation($GLOBALS['db'], $tableName, $_POST['db_collation']);
}
}

View File

@ -14,7 +14,6 @@ use PhpMyAdmin\Html\Generator;
use PhpMyAdmin\Message;
use PhpMyAdmin\Operations;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\Export\ExportSql;
use PhpMyAdmin\Query\Utilities;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Template;
@ -65,29 +64,24 @@ class OperationsController extends AbstractController
public function __invoke(): void
{
global $cfg, $db, $server, $sql_query, $move, $message, $tables_full, $errorUrl;
global $export_sql_plugin, $views, $sqlConstratints, $local_query, $reload, $urlParams, $tables;
global $total_num_tables, $sub_part, $tooltip_truename;
global $db_collation, $tooltip_aliasname, $pos, $is_information_schema, $single_table, $num_tables;
$this->checkUserPrivileges->getPrivileges();
$this->addScriptFiles(['database/operations.js']);
$sql_query = '';
$GLOBALS['sql_query'] = '';
/**
* Rename/move or copy database
*/
if (strlen($db) > 0 && (! empty($_POST['db_rename']) || ! empty($_POST['db_copy']))) {
if (strlen($GLOBALS['db']) > 0 && (! empty($_POST['db_rename']) || ! empty($_POST['db_copy']))) {
if (! empty($_POST['db_rename'])) {
$move = true;
$GLOBALS['move'] = true;
} else {
$move = false;
$GLOBALS['move'] = false;
}
if (! isset($_POST['newname']) || strlen($_POST['newname']) === 0) {
$message = Message::error(__('The database name is empty!'));
$GLOBALS['message'] = Message::error(__('The database name is empty!'));
} else {
// lower_case_table_names=1 `DB` becomes `db`
if ($this->dbi->getLowerCaseNames() === '1') {
@ -95,12 +89,12 @@ class OperationsController extends AbstractController
}
if ($_POST['newname'] === $_REQUEST['db']) {
$message = Message::error(
$GLOBALS['message'] = Message::error(
__('Cannot copy database to the same name. Change the name and try again.')
);
} else {
$_error = false;
if ($move || ! empty($_POST['create_database_before_copying'])) {
if ($GLOBALS['move'] || ! empty($_POST['create_database_before_copying'])) {
$this->operations->createDbBeforeCopy();
}
@ -110,97 +104,104 @@ class OperationsController extends AbstractController
// to avoid selecting alternatively the current and new db
// we would need to modify the CREATE definitions to qualify
// the db name
$this->operations->runProcedureAndFunctionDefinitions($db);
$this->operations->runProcedureAndFunctionDefinitions($GLOBALS['db']);
// go back to current db, just in case
$this->dbi->selectDb($db);
$this->dbi->selectDb($GLOBALS['db']);
$tables_full = $this->dbi->getTablesFull($db);
$GLOBALS['tables_full'] = $this->dbi->getTablesFull($GLOBALS['db']);
// remove all foreign key constraints, otherwise we can get errors
/** @var ExportSql $export_sql_plugin */
$export_sql_plugin = Plugins::getPlugin('export', 'sql', [
$GLOBALS['export_sql_plugin'] = Plugins::getPlugin('export', 'sql', [
'export_type' => 'database',
'single_table' => isset($single_table),
'single_table' => isset($GLOBALS['single_table']),
]);
// create stand-in tables for views
$views = $this->operations->getViewsAndCreateSqlViewStandIn($tables_full, $export_sql_plugin, $db);
$GLOBALS['views'] = $this->operations->getViewsAndCreateSqlViewStandIn(
$GLOBALS['tables_full'],
$GLOBALS['export_sql_plugin'],
$GLOBALS['db']
);
// copy tables
$sqlConstratints = $this->operations->copyTables($tables_full, $move, $db);
$GLOBALS['sqlConstratints'] = $this->operations->copyTables(
$GLOBALS['tables_full'],
$GLOBALS['move'],
$GLOBALS['db']
);
// handle the views
if (! $_error) {
$this->operations->handleTheViews($views, $move, $db);
$this->operations->handleTheViews($GLOBALS['views'], $GLOBALS['move'], $GLOBALS['db']);
}
unset($views);
unset($GLOBALS['views']);
// now that all tables exist, create all the accumulated constraints
if (! $_error && count($sqlConstratints) > 0) {
$this->operations->createAllAccumulatedConstraints($sqlConstratints);
if (! $_error && count($GLOBALS['sqlConstratints']) > 0) {
$this->operations->createAllAccumulatedConstraints($GLOBALS['sqlConstratints']);
}
unset($sqlConstratints);
unset($GLOBALS['sqlConstratints']);
if ($this->dbi->getVersion() >= 50100) {
// here DELIMITER is not used because it's not part of the
// language; each statement is sent one by one
$this->operations->runEventDefinitionsForDb($db);
$this->operations->runEventDefinitionsForDb($GLOBALS['db']);
}
// go back to current db, just in case
$this->dbi->selectDb($db);
$this->dbi->selectDb($GLOBALS['db']);
// Duplicate the bookmarks for this db (done once for each db)
$this->operations->duplicateBookmarks($_error, $db);
$this->operations->duplicateBookmarks($_error, $GLOBALS['db']);
if (! $_error && $move) {
if (! $_error && $GLOBALS['move']) {
if (isset($_POST['adjust_privileges']) && ! empty($_POST['adjust_privileges'])) {
$this->operations->adjustPrivilegesMoveDb($db, $_POST['newname']);
$this->operations->adjustPrivilegesMoveDb($GLOBALS['db'], $_POST['newname']);
}
/**
* cleanup pmadb stuff for this db
*/
$this->relationCleanup->database($db);
$this->relationCleanup->database($GLOBALS['db']);
// if someday the RENAME DATABASE reappears, do not DROP
$local_query = 'DROP DATABASE '
. Util::backquote($db) . ';';
$sql_query .= "\n" . $local_query;
$this->dbi->query($local_query);
$GLOBALS['local_query'] = 'DROP DATABASE '
. Util::backquote($GLOBALS['db']) . ';';
$GLOBALS['sql_query'] .= "\n" . $GLOBALS['local_query'];
$this->dbi->query($GLOBALS['local_query']);
$message = Message::success(
$GLOBALS['message'] = Message::success(
__('Database %1$s has been renamed to %2$s.')
);
$message->addParam($db);
$message->addParam($_POST['newname']);
$GLOBALS['message']->addParam($GLOBALS['db']);
$GLOBALS['message']->addParam($_POST['newname']);
} elseif (! $_error) {
if (isset($_POST['adjust_privileges']) && ! empty($_POST['adjust_privileges'])) {
$this->operations->adjustPrivilegesCopyDb($db, $_POST['newname']);
$this->operations->adjustPrivilegesCopyDb($GLOBALS['db'], $_POST['newname']);
}
$message = Message::success(
$GLOBALS['message'] = Message::success(
__('Database %1$s has been copied to %2$s.')
);
$message->addParam($db);
$message->addParam($_POST['newname']);
$GLOBALS['message']->addParam($GLOBALS['db']);
$GLOBALS['message']->addParam($_POST['newname']);
} else {
$message = Message::error();
$GLOBALS['message'] = Message::error();
}
$reload = true;
$GLOBALS['reload'] = true;
/* Change database to be used */
if (! $_error && $move) {
$db = $_POST['newname'];
if (! $_error && $GLOBALS['move']) {
$GLOBALS['db'] = $_POST['newname'];
} elseif (! $_error) {
if (isset($_POST['switch_to_new']) && $_POST['switch_to_new'] === 'true') {
$_SESSION['pma_switch_to_new'] = true;
$db = $_POST['newname'];
$GLOBALS['db'] = $_POST['newname'];
} else {
$_SESSION['pma_switch_to_new'] = false;
}
@ -213,14 +214,14 @@ class OperationsController extends AbstractController
* generate the output with {@link ResponseRenderer} and exit
*/
if ($this->response->isAjax()) {
$this->response->setRequestStatus($message->isSuccess());
$this->response->addJSON('message', $message);
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
$this->response->addJSON('message', $GLOBALS['message']);
$this->response->addJSON('newname', $_POST['newname']);
$this->response->addJSON(
'sql_query',
Generator::getMessage('', $sql_query)
Generator::getMessage('', $GLOBALS['sql_query'])
);
$this->response->addJSON('db', $db);
$this->response->addJSON('db', $GLOBALS['db']);
return;
}
@ -233,86 +234,86 @@ class OperationsController extends AbstractController
* (must be done before displaying the menu tabs)
*/
if (isset($_POST['comment'])) {
$this->relation->setDbComment($db, $_POST['comment']);
$this->relation->setDbComment($GLOBALS['db'], $_POST['comment']);
}
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
$urlParams['goto'] = Url::getFromRoute('/database/operations');
$GLOBALS['urlParams']['goto'] = Url::getFromRoute('/database/operations');
// Gets the database structure
$sub_part = '_structure';
$GLOBALS['sub_part'] = '_structure';
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,
$isSystemSchema,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part);
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part']);
$oldMessage = '';
if (isset($message)) {
$oldMessage = Generator::getMessage($message, $sql_query);
unset($message);
if (isset($GLOBALS['message'])) {
$oldMessage = Generator::getMessage($GLOBALS['message'], $GLOBALS['sql_query']);
unset($GLOBALS['message']);
}
$db_collation = $this->dbi->getDbCollation($db);
$is_information_schema = Utilities::isSystemSchema($db);
$GLOBALS['db_collation'] = $this->dbi->getDbCollation($GLOBALS['db']);
$GLOBALS['is_information_schema'] = Utilities::isSystemSchema($GLOBALS['db']);
if ($is_information_schema) {
if ($GLOBALS['is_information_schema']) {
return;
}
$databaseComment = '';
if ($relationParameters->columnCommentsFeature !== null) {
$databaseComment = $this->relation->getDbComment($db);
$databaseComment = $this->relation->getDbComment($GLOBALS['db']);
}
$hasAdjustPrivileges = $GLOBALS['db_priv'] && $GLOBALS['table_priv']
&& $GLOBALS['col_priv'] && $GLOBALS['proc_priv'] && $GLOBALS['is_reload_priv'];
$isDropDatabaseAllowed = ($this->dbi->isSuperUser() || $cfg['AllowUserDropDatabase'])
&& ! $isSystemSchema && $db !== 'mysql';
$isDropDatabaseAllowed = ($this->dbi->isSuperUser() || $GLOBALS['cfg']['AllowUserDropDatabase'])
&& ! $isSystemSchema && $GLOBALS['db'] !== 'mysql';
$switchToNew = isset($_SESSION['pma_switch_to_new']) && $_SESSION['pma_switch_to_new'];
$charsets = Charsets::getCharsets($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$collations = Charsets::getCollations($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
if (! $relationParameters->hasAllFeatures() && $cfg['PmaNoRelation_DisableWarning'] == false) {
$message = Message::notice(
if (! $relationParameters->hasAllFeatures() && $GLOBALS['cfg']['PmaNoRelation_DisableWarning'] == false) {
$GLOBALS['message'] = Message::notice(
__(
'The phpMyAdmin configuration storage has been deactivated. %sFind out why%s.'
)
);
$message->addParamHtml(
$GLOBALS['message']->addParamHtml(
'<a href="' . Url::getFromRoute('/check-relations')
. '" data-post="' . Url::getCommon(['db' => $db]) . '">'
. '" data-post="' . Url::getCommon(['db' => $GLOBALS['db']]) . '">'
);
$message->addParamHtml('</a>');
$GLOBALS['message']->addParamHtml('</a>');
/* Show error if user has configured something, notice elsewhere */
if (! empty($cfg['Servers'][$server]['pmadb'])) {
$message->isError(true);
if (! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['pmadb'])) {
$GLOBALS['message']->isError(true);
}
}
$this->render('database/operations/index', [
'message' => $oldMessage,
'db' => $db,
'db' => $GLOBALS['db'],
'has_comment' => $relationParameters->columnCommentsFeature !== null,
'db_comment' => $databaseComment,
'db_collation' => $db_collation,
'db_collation' => $GLOBALS['db_collation'],
'has_adjust_privileges' => $hasAdjustPrivileges,
'is_drop_database_allowed' => $isDropDatabaseAllowed,
'switch_to_new' => $switchToNew,

View File

@ -41,9 +41,7 @@ class PrivilegesController extends AbstractController
*/
public function __invoke(array $params): string
{
global $cfg, $text_dir;
$scriptName = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$scriptName = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$privileges = [];
if ($this->dbi->isSuperUser()) {
@ -54,7 +52,7 @@ class PrivilegesController extends AbstractController
'is_superuser' => $this->dbi->isSuperUser(),
'db' => $params['checkprivsdb'],
'database_url' => $scriptName,
'text_dir' => $text_dir,
'text_dir' => $GLOBALS['text_dir'],
'is_createuser' => $this->dbi->isCreateUser(),
'is_grantuser' => $this->dbi->isGrantUser(),
'privileges' => $privileges,

View File

@ -41,70 +41,66 @@ class QueryByExampleController extends AbstractController
public function __invoke(): void
{
global $db, $savedSearchList, $savedSearch, $currentSearchId;
global $sql_query, $goto, $sub_part, $tables, $num_tables, $total_num_tables;
global $tooltip_truename, $tooltip_aliasname, $pos, $urlParams, $cfg, $errorUrl;
$savedQbeSearchesFeature = $this->relation->getRelationParameters()->savedQueryByExampleSearchesFeature;
$savedSearchList = [];
$savedSearch = null;
$currentSearchId = null;
$GLOBALS['savedSearchList'] = [];
$GLOBALS['savedSearch'] = null;
$GLOBALS['currentSearchId'] = null;
$this->addScriptFiles(['database/qbe.js']);
if ($savedQbeSearchesFeature !== null) {
//Get saved search list.
$savedSearch = new SavedSearches();
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
->setDbname($db);
$GLOBALS['savedSearch'] = new SavedSearches();
$GLOBALS['savedSearch']->setUsername($GLOBALS['cfg']['Server']['user'])
->setDbname($GLOBALS['db']);
if (! empty($_POST['searchId'])) {
$savedSearch->setId($_POST['searchId']);
$GLOBALS['savedSearch']->setId($_POST['searchId']);
}
//Action field is sent.
if (isset($_POST['action'])) {
$savedSearch->setSearchName($_POST['searchName']);
$GLOBALS['savedSearch']->setSearchName($_POST['searchName']);
if ($_POST['action'] === 'create') {
$savedSearch->setId(null)
$GLOBALS['savedSearch']->setId(null)
->setCriterias($_POST)
->save($savedQbeSearchesFeature);
} elseif ($_POST['action'] === 'update') {
$savedSearch->setCriterias($_POST)
$GLOBALS['savedSearch']->setCriterias($_POST)
->save($savedQbeSearchesFeature);
} elseif ($_POST['action'] === 'delete') {
$savedSearch->delete($savedQbeSearchesFeature);
$GLOBALS['savedSearch']->delete($savedQbeSearchesFeature);
//After deletion, reset search.
$savedSearch = new SavedSearches();
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
->setDbname($db);
$GLOBALS['savedSearch'] = new SavedSearches();
$GLOBALS['savedSearch']->setUsername($GLOBALS['cfg']['Server']['user'])
->setDbname($GLOBALS['db']);
$_POST = [];
} elseif ($_POST['action'] === 'load') {
if (empty($_POST['searchId'])) {
//when not loading a search, reset the object.
$savedSearch = new SavedSearches();
$savedSearch->setUsername($GLOBALS['cfg']['Server']['user'])
->setDbname($db);
$GLOBALS['savedSearch'] = new SavedSearches();
$GLOBALS['savedSearch']->setUsername($GLOBALS['cfg']['Server']['user'])
->setDbname($GLOBALS['db']);
$_POST = [];
} else {
$savedSearch->load($savedQbeSearchesFeature);
$GLOBALS['savedSearch']->load($savedQbeSearchesFeature);
}
}
//Else, it's an "update query"
}
$savedSearchList = $savedSearch->getList($savedQbeSearchesFeature);
$currentSearchId = $savedSearch->getId();
$GLOBALS['savedSearchList'] = $GLOBALS['savedSearch']->getList($savedQbeSearchesFeature);
$GLOBALS['currentSearchId'] = $GLOBALS['savedSearch']->getId();
}
/**
* A query has been submitted -> (maybe) execute it
*/
$hasMessageToDisplay = false;
if (isset($_POST['submit_sql']) && ! empty($sql_query)) {
if (stripos($sql_query, 'SELECT') !== 0) {
if (isset($_POST['submit_sql']) && ! empty($GLOBALS['sql_query'])) {
if (stripos($GLOBALS['sql_query'], 'SELECT') !== 0) {
$hasMessageToDisplay = true;
} else {
$goto = Url::getFromRoute('/database/sql');
$GLOBALS['goto'] = Url::getFromRoute('/database/sql');
$sql = new Sql(
$this->dbi,
@ -125,42 +121,49 @@ class QueryByExampleController extends AbstractController
null, // extra_data
null, // message_to_show
null, // sql_data
$goto, // goto
$GLOBALS['goto'], // goto
null, // disp_query
null, // disp_message
$sql_query, // sql_query
$GLOBALS['sql_query'], // sql_query
null // complete_query
));
}
}
$sub_part = '_qbe';
$GLOBALS['sub_part'] = '_qbe';
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
$urlParams['goto'] = Url::getFromRoute('/database/qbe');
$GLOBALS['urlParams']['goto'] = Url::getFromRoute('/database/qbe');
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part);
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,,
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part']);
$databaseQbe = new Qbe($this->relation, $this->template, $this->dbi, $db, $savedSearchList, $savedSearch);
$databaseQbe = new Qbe(
$this->relation,
$this->template,
$this->dbi,
$GLOBALS['db'],
$GLOBALS['savedSearchList'],
$GLOBALS['savedSearch']
);
$this->render('database/qbe/index', [
'url_params' => $urlParams,
'url_params' => $GLOBALS['urlParams'],
'has_message_to_display' => $hasMessageToDisplay,
'selection_form_html' => $databaseQbe->getSelectionForm(),
]);

View File

@ -41,10 +41,6 @@ class RoutinesController extends AbstractController
public function __invoke(): void
{
global $db, $table, $tables, $num_tables, $total_num_tables, $sub_part;
global $tooltip_truename, $tooltip_aliasname, $pos;
global $errors, $errorUrl, $urlParams, $cfg;
$this->addScriptFiles(['database/routines.js']);
$type = $_REQUEST['type'] ?? null;
@ -55,45 +51,45 @@ class RoutinesController extends AbstractController
/**
* Displays the header and tabs
*/
if (! empty($table) && in_array($table, $this->dbi->getTables($db))) {
if (! empty($GLOBALS['table']) && in_array($GLOBALS['table'], $this->dbi->getTables($GLOBALS['db']))) {
Util::checkParameters(['db', 'table']);
$urlParams = ['db' => $db, 'table' => $table];
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
$errorUrl .= Url::getCommon($urlParams, '&');
$GLOBALS['urlParams'] = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
$GLOBALS['errorUrl'] .= Url::getCommon($GLOBALS['urlParams'], '&');
DbTableExists::check($db, $table);
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
} else {
$table = '';
$GLOBALS['table'] = '';
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part ?? '');
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,,
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part'] ?? '');
}
} elseif (strlen($db) > 0) {
$this->dbi->selectDb($db);
} elseif (strlen($GLOBALS['db']) > 0) {
$this->dbi->selectDb($GLOBALS['db']);
}
/**
* Keep a list of errors that occurred while
* processing an 'Add' or 'Edit' operation.
*/
$errors = [];
$GLOBALS['errors'] = [];
$routines = new Routines($this->dbi, $this->template, $this->response);
@ -105,7 +101,7 @@ class RoutinesController extends AbstractController
$type = null;
}
$items = $this->dbi->getRoutines($db, $type);
$items = $this->dbi->getRoutines($GLOBALS['db'], $type);
$isAjax = $this->response->isAjax() && empty($_REQUEST['ajax_page_request']);
$rows = '';
@ -114,11 +110,11 @@ class RoutinesController extends AbstractController
}
$this->render('database/routines/index', [
'db' => $db,
'table' => $table,
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'items' => $items,
'rows' => $rows,
'has_privilege' => Util::currentUserHasPrivilege('CREATE ROUTINE', $db, $table),
'has_privilege' => Util::currentUserHasPrivilege('CREATE ROUTINE', $GLOBALS['db'], $GLOBALS['table']),
]);
}
}

View File

@ -28,9 +28,6 @@ class SearchController extends AbstractController
public function __invoke(): void
{
global $cfg, $db, $errorUrl, $urlParams, $tables, $num_tables, $total_num_tables, $sub_part;
global $tooltip_truename, $tooltip_aliasname, $pos;
$this->addScriptFiles([
'database/search.js',
'vendor/stickyfill.min.js',
@ -40,39 +37,39 @@ class SearchController extends AbstractController
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
// If config variable $cfg['UseDbSearch'] is on false : exit.
if (! $cfg['UseDbSearch']) {
if (! $GLOBALS['cfg']['UseDbSearch']) {
Generator::mysqlDie(
__('Access denied!'),
'',
false,
$errorUrl
$GLOBALS['errorUrl']
);
}
$urlParams['goto'] = Url::getFromRoute('/database/search');
$GLOBALS['urlParams']['goto'] = Url::getFromRoute('/database/search');
// Create a database search instance
$databaseSearch = new Search($this->dbi, $db, $this->template);
$databaseSearch = new Search($this->dbi, $GLOBALS['db'], $this->template);
// Display top links if we are not in an Ajax request
if (! $this->response->isAjax()) {
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part ?? '');
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,,
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part'] ?? '');
}
// Main search form has been submitted, get results

View File

@ -27,20 +27,18 @@ class SqlAutoCompleteController extends AbstractController
public function __invoke(): void
{
global $cfg, $db, $sql_autocomplete;
$sql_autocomplete = true;
if ($cfg['EnableAutocompleteForTablesAndColumns']) {
$db = $_POST['db'] ?? $db;
$sql_autocomplete = [];
if ($db) {
$tableNames = $this->dbi->getTables($db);
$GLOBALS['sql_autocomplete'] = true;
if ($GLOBALS['cfg']['EnableAutocompleteForTablesAndColumns']) {
$GLOBALS['db'] = $_POST['db'] ?? $GLOBALS['db'];
$GLOBALS['sql_autocomplete'] = [];
if ($GLOBALS['db']) {
$tableNames = $this->dbi->getTables($GLOBALS['db']);
foreach ($tableNames as $tableName) {
$sql_autocomplete[$tableName] = $this->dbi->getColumns($db, $tableName);
$GLOBALS['sql_autocomplete'][$tableName] = $this->dbi->getColumns($GLOBALS['db'], $tableName);
}
}
}
$this->response->addJSON(['tables' => json_encode($sql_autocomplete)]);
$this->response->addJSON(['tables' => json_encode($GLOBALS['sql_autocomplete'])]);
}
}

View File

@ -30,8 +30,6 @@ class SqlController extends AbstractController
public function __invoke(): void
{
global $goto, $back, $db, $cfg, $errorUrl;
$this->addScriptFiles([
'makegrid.js',
'vendor/jquery/jquery.uitablefilter.js',
@ -45,8 +43,8 @@ class SqlController extends AbstractController
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
@ -56,11 +54,11 @@ class SqlController extends AbstractController
* After a syntax error, we return to this script
* with the typed query in the textarea.
*/
$goto = Url::getFromRoute('/database/sql');
$back = $goto;
$GLOBALS['goto'] = Url::getFromRoute('/database/sql');
$GLOBALS['back'] = $GLOBALS['goto'];
$this->response->addHTML($this->sqlQueryForm->getHtml(
$db,
$GLOBALS['db'],
'',
true,
false,

View File

@ -12,8 +12,6 @@ final class AddPrefixController extends AbstractController
{
public function __invoke(): void
{
global $db;
$selected = $_POST['selected_tbl'] ?? [];
if (empty($selected)) {
@ -23,7 +21,7 @@ final class AddPrefixController extends AbstractController
return;
}
$params = ['db' => $db];
$params = ['db' => $GLOBALS['db']];
foreach ($selected as $selectedValue) {
$params['selected'][] = $selectedValue;
}

View File

@ -35,11 +35,9 @@ final class AddPrefixTableController extends AbstractController
public function __invoke(): void
{
global $db, $message, $sql_query;
$selected = $_POST['selected'] ?? [];
$sql_query = '';
$GLOBALS['sql_query'] = '';
$selectedCount = count($selected);
for ($i = 0; $i < $selectedCount; $i++) {
@ -47,15 +45,15 @@ final class AddPrefixTableController extends AbstractController
$aQuery = 'ALTER TABLE ' . Util::backquote($selected[$i])
. ' RENAME ' . Util::backquote($newTableName);
$sql_query .= $aQuery . ';' . "\n";
$this->dbi->selectDb($db);
$GLOBALS['sql_query'] .= $aQuery . ';' . "\n";
$this->dbi->selectDb($GLOBALS['db']);
$this->dbi->query($aQuery);
}
$message = Message::success();
$GLOBALS['message'] = Message::success();
if (empty($_POST['message'])) {
$_POST['message'] = $message;
$_POST['message'] = $GLOBALS['message'];
}
($this->structureController)();

View File

@ -35,8 +35,6 @@ final class AddController extends AbstractController
public function __invoke(): void
{
global $message;
$selected = $_POST['selected_tbl'] ?? [];
if (empty($selected)) {
@ -49,7 +47,7 @@ final class AddController extends AbstractController
$centralColumns = new CentralColumns($this->dbi);
$error = $centralColumns->syncUniqueColumns($selected);
$message = $error instanceof Message ? $error : Message::success(__('Success!'));
$GLOBALS['message'] = $error instanceof Message ? $error : Message::success(__('Success!'));
unset($_POST['submit_mult']);

View File

@ -35,8 +35,6 @@ final class MakeConsistentController extends AbstractController
public function __invoke(): void
{
global $db, $message;
$selected = $_POST['selected_tbl'] ?? [];
if (empty($selected)) {
@ -47,9 +45,9 @@ final class MakeConsistentController extends AbstractController
}
$centralColumns = new CentralColumns($this->dbi);
$error = $centralColumns->makeConsistentWithList($db, $selected);
$error = $centralColumns->makeConsistentWithList($GLOBALS['db'], $selected);
$message = $error instanceof Message ? $error : Message::success(__('Success!'));
$GLOBALS['message'] = $error instanceof Message ? $error : Message::success(__('Success!'));
unset($_POST['submit_mult']);

View File

@ -35,8 +35,6 @@ final class RemoveController extends AbstractController
public function __invoke(): void
{
global $message;
$selected = $_POST['selected_tbl'] ?? [];
if (empty($selected)) {
@ -49,7 +47,7 @@ final class RemoveController extends AbstractController
$centralColumns = new CentralColumns($this->dbi);
$error = $centralColumns->deleteColumnsFromList($_POST['db'], $selected);
$message = $error instanceof Message ? $error : Message::success(__('Success!'));
$GLOBALS['message'] = $error instanceof Message ? $error : Message::success(__('Success!'));
unset($_POST['submit_mult']);

View File

@ -12,8 +12,6 @@ final class ChangePrefixFormController extends AbstractController
{
public function __invoke(): void
{
global $db;
$selected = $_POST['selected_tbl'] ?? [];
$submitMult = $_POST['submit_mult'] ?? '';
@ -29,7 +27,7 @@ final class ChangePrefixFormController extends AbstractController
$route = '/database/structure/copy-table-with-prefix';
}
$urlParams = ['db' => $db];
$urlParams = ['db' => $GLOBALS['db']];
foreach ($selected as $selectedValue) {
$urlParams['selected'][] = $selectedValue;
}

View File

@ -12,8 +12,6 @@ final class CopyFormController extends AbstractController
{
public function __invoke(): void
{
global $db, $dblist;
$selected = $_POST['selected_tbl'] ?? [];
if (empty($selected)) {
@ -23,14 +21,14 @@ final class CopyFormController extends AbstractController
return;
}
$urlParams = ['db' => $db];
$urlParams = ['db' => $GLOBALS['db']];
foreach ($selected as $selectedValue) {
$urlParams['selected'][] = $selectedValue;
}
$databasesList = $dblist->databases;
$databasesList = $GLOBALS['dblist']->databases;
foreach ($databasesList as $key => $databaseName) {
if ($databaseName == $db) {
if ($databaseName == $GLOBALS['db']) {
$databasesList->offsetUnset($key);
break;
}

View File

@ -35,15 +35,13 @@ final class CopyTableController extends AbstractController
public function __invoke(): void
{
global $db, $message;
$selected = $_POST['selected'] ?? [];
$targetDb = $_POST['target_db'] ?? null;
$selectedCount = count($selected);
for ($i = 0; $i < $selectedCount; $i++) {
Table::moveCopy(
$db,
$GLOBALS['db'],
$selected[$i],
$targetDb,
$selected[$i],
@ -57,13 +55,13 @@ final class CopyTableController extends AbstractController
continue;
}
$this->operations->adjustPrivilegesCopyTable($db, $selected[$i], $targetDb, $selected[$i]);
$this->operations->adjustPrivilegesCopyTable($GLOBALS['db'], $selected[$i], $targetDb, $selected[$i]);
}
$message = Message::success();
$GLOBALS['message'] = Message::success();
if (empty($_POST['message'])) {
$_POST['message'] = $message;
$_POST['message'] = $GLOBALS['message'];
}
($this->structureController)();

View File

@ -31,8 +31,6 @@ final class CopyTableWithPrefixController extends AbstractController
public function __invoke(): void
{
global $db, $message;
$selected = $_POST['selected'] ?? [];
$fromPrefix = $_POST['from_prefix'] ?? null;
$toPrefix = $_POST['to_prefix'] ?? null;
@ -44,9 +42,9 @@ final class CopyTableWithPrefixController extends AbstractController
$newTableName = $toPrefix . mb_substr($current, mb_strlen((string) $fromPrefix));
Table::moveCopy(
$db,
$GLOBALS['db'],
$current,
$db,
$GLOBALS['db'],
$newTableName,
'data',
false,
@ -55,10 +53,10 @@ final class CopyTableWithPrefixController extends AbstractController
);
}
$message = Message::success();
$GLOBALS['message'] = Message::success();
if (empty($_POST['message'])) {
$_POST['message'] = $message;
$_POST['message'] = $GLOBALS['message'];
}
($this->structureController)();

View File

@ -28,8 +28,6 @@ final class DropFormController extends AbstractController
public function __invoke(): void
{
global $db;
$selected = $_POST['selected_tbl'] ?? [];
if (empty($selected)) {
@ -39,7 +37,7 @@ final class DropFormController extends AbstractController
return;
}
$views = $this->dbi->getVirtualTables($db);
$views = $this->dbi->getVirtualTables($GLOBALS['db']);
$fullQueryViews = '';
$fullQuery = '';
@ -63,7 +61,7 @@ final class DropFormController extends AbstractController
$fullQuery .= $fullQueryViews . ';<br>' . "\n";
}
$urlParams = ['db' => $db];
$urlParams = ['db' => $GLOBALS['db']];
foreach ($selected as $selectedValue) {
$urlParams['selected'][] = $selectedValue;
}

View File

@ -44,16 +44,14 @@ final class DropTableController extends AbstractController
public function __invoke(): void
{
global $db, $message, $reload, $sql_query;
$reload = $_POST['reload'] ?? $reload ?? null;
$GLOBALS['reload'] = $_POST['reload'] ?? $GLOBALS['reload'] ?? null;
$multBtn = $_POST['mult_btn'] ?? '';
$selected = $_POST['selected'] ?? [];
$views = $this->dbi->getVirtualTables($db);
$views = $this->dbi->getVirtualTables($GLOBALS['db']);
if ($multBtn !== __('Yes')) {
$message = Message::success(__('No change'));
$GLOBALS['message'] = Message::success(__('No change'));
if (empty($_POST['message'])) {
$_POST['message'] = Message::success();
@ -67,27 +65,28 @@ final class DropTableController extends AbstractController
}
$defaultFkCheckValue = ForeignKey::handleDisableCheckInit();
$sql_query = '';
$GLOBALS['sql_query'] = '';
$sqlQueryViews = '';
$selectedCount = count($selected);
for ($i = 0; $i < $selectedCount; $i++) {
$this->relationCleanup->table($db, $selected[$i]);
$this->relationCleanup->table($GLOBALS['db'], $selected[$i]);
$current = $selected[$i];
if (! empty($views) && in_array($current, $views)) {
$sqlQueryViews .= (empty($sqlQueryViews) ? 'DROP VIEW ' : ', ') . Util::backquote($current);
} else {
$sql_query .= (empty($sql_query) ? 'DROP TABLE ' : ', ') . Util::backquote($current);
$GLOBALS['sql_query'] .= (empty($GLOBALS['sql_query']) ? 'DROP TABLE ' : ', ')
. Util::backquote($current);
}
$reload = 1;
$GLOBALS['reload'] = 1;
}
if (! empty($sql_query)) {
$sql_query .= ';';
if (! empty($GLOBALS['sql_query'])) {
$GLOBALS['sql_query'] .= ';';
} elseif (! empty($sqlQueryViews)) {
$sql_query = $sqlQueryViews . ';';
$GLOBALS['sql_query'] = $sqlQueryViews . ';';
unset($sqlQueryViews);
}
@ -102,25 +101,25 @@ final class DropTableController extends AbstractController
}
}
$this->dbi->selectDb($db);
$result = $this->dbi->tryQuery($sql_query);
$this->dbi->selectDb($GLOBALS['db']);
$result = $this->dbi->tryQuery($GLOBALS['sql_query']);
if ($result && ! empty($sqlQueryViews)) {
$sql_query .= ' ' . $sqlQueryViews . ';';
$GLOBALS['sql_query'] .= ' ' . $sqlQueryViews . ';';
$result = $this->dbi->tryQuery($sqlQueryViews);
unset($sqlQueryViews);
}
if (! $result) {
$message = Message::error($this->dbi->getError());
$GLOBALS['message'] = Message::error($this->dbi->getError());
}
ForeignKey::handleDisableCheckCleanup($defaultFkCheckValue);
$message = Message::success();
$GLOBALS['message'] = Message::success();
if (empty($_POST['message'])) {
$_POST['message'] = $message;
$_POST['message'] = $GLOBALS['message'];
}
unset($_POST['mult_btn']);

View File

@ -15,8 +15,6 @@ final class EmptyFormController extends AbstractController
{
public function __invoke(): void
{
global $db;
$selected = $_POST['selected_tbl'] ?? [];
if (empty($selected)) {
@ -27,7 +25,7 @@ final class EmptyFormController extends AbstractController
}
$fullQuery = '';
$urlParams = ['db' => $db];
$urlParams = ['db' => $GLOBALS['db']];
foreach ($selected as $selectedValue) {
$fullQuery .= 'TRUNCATE ';

View File

@ -63,29 +63,27 @@ final class EmptyTableController extends AbstractController
public function __invoke(): void
{
global $db, $table, $message, $sql_query;
$multBtn = $_POST['mult_btn'] ?? '';
$selected = $_POST['selected'] ?? [];
if ($multBtn !== __('Yes')) {
$this->flash->addMessage('success', __('No change'));
$this->redirect('/database/structure', ['db' => $db]);
$this->redirect('/database/structure', ['db' => $GLOBALS['db']]);
return;
}
$defaultFkCheckValue = ForeignKey::handleDisableCheckInit();
$sql_query = '';
$GLOBALS['sql_query'] = '';
$selectedCount = count($selected);
for ($i = 0; $i < $selectedCount; $i++) {
$aQuery = 'TRUNCATE ';
$aQuery .= Util::backquote($selected[$i]);
$sql_query .= $aQuery . ';' . "\n";
$this->dbi->selectDb($db);
$GLOBALS['sql_query'] .= $aQuery . ';' . "\n";
$this->dbi->selectDb($GLOBALS['db']);
$this->dbi->query($aQuery);
}
@ -99,15 +97,15 @@ final class EmptyTableController extends AbstractController
$this->template
);
$_REQUEST['pos'] = $sql->calculatePosForLastPage($db, $table, $_REQUEST['pos']);
$_REQUEST['pos'] = $sql->calculatePosForLastPage($GLOBALS['db'], $GLOBALS['table'], $_REQUEST['pos']);
}
ForeignKey::handleDisableCheckCleanup($defaultFkCheckValue);
$message = Message::success();
$GLOBALS['message'] = Message::success();
if (empty($_POST['message'])) {
$_POST['message'] = $message;
$_POST['message'] = $GLOBALS['message'];
}
unset($_POST['mult_btn']);

View File

@ -32,8 +32,6 @@ final class FavoriteTableController extends AbstractController
public function __invoke(): void
{
global $cfg, $db, $errorUrl;
$parameters = [
'favorite_table' => $_REQUEST['favorite_table'] ?? null,
'favoriteTables' => $_REQUEST['favoriteTables'] ?? null,
@ -42,8 +40,8 @@ final class FavoriteTableController extends AbstractController
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase() || ! $this->response->isAjax()) {
return;
@ -57,7 +55,7 @@ final class FavoriteTableController extends AbstractController
}
// Required to keep each user's preferences separate.
$user = sha1($cfg['Server']['user']);
$user = sha1($GLOBALS['cfg']['Server']['user']);
// Request for Synchronization of favorite tables.
if (isset($parameters['sync_favorite_tables'])) {
@ -86,7 +84,7 @@ final class FavoriteTableController extends AbstractController
} elseif (isset($_REQUEST['add_favorite'])) {
if (! $alreadyFavorite) {
$numTables = count($favoriteInstance->getTables());
if ($numTables == $cfg['NumFavoriteTables']) {
if ($numTables == $GLOBALS['cfg']['NumFavoriteTables']) {
$changes = false;
} else {
// Otherwise add to favorite list.

View File

@ -29,8 +29,6 @@ final class RealRowCountController extends AbstractController
public function __invoke(): void
{
global $cfg, $db, $errorUrl;
$parameters = [
'real_row_count_all' => $_REQUEST['real_row_count_all'] ?? null,
'table' => $_REQUEST['table'] ?? null,
@ -38,8 +36,8 @@ final class RealRowCountController extends AbstractController
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase() || ! $this->response->isAjax()) {
return;

View File

@ -37,13 +37,11 @@ final class ReplacePrefixController extends AbstractController
public function __invoke(): void
{
global $db, $message, $sql_query;
$selected = $_POST['selected'] ?? [];
$fromPrefix = $_POST['from_prefix'] ?? '';
$toPrefix = $_POST['to_prefix'] ?? '';
$sql_query = '';
$GLOBALS['sql_query'] = '';
$selectedCount = count($selected);
for ($i = 0; $i < $selectedCount; $i++) {
@ -59,15 +57,15 @@ final class ReplacePrefixController extends AbstractController
$aQuery = 'ALTER TABLE ' . Util::backquote($selected[$i])
. ' RENAME ' . Util::backquote($newTableName);
$sql_query .= $aQuery . ';' . "\n";
$this->dbi->selectDb($db);
$GLOBALS['sql_query'] .= $aQuery . ';' . "\n";
$this->dbi->selectDb($GLOBALS['db']);
$this->dbi->query($aQuery);
}
$message = Message::success();
$GLOBALS['message'] = Message::success();
if (empty($_POST['message'])) {
$_POST['message'] = $message;
$_POST['message'] = $GLOBALS['message'];
}
($this->structureController)();

View File

@ -135,8 +135,6 @@ class StructureController extends AbstractController
public function __invoke(): void
{
global $cfg, $db, $errorUrl;
$parameters = [
'sort' => $_REQUEST['sort'] ?? null,
'sort_order' => $_REQUEST['sort_order'] ?? null,
@ -144,8 +142,8 @@ class StructureController extends AbstractController
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
@ -162,7 +160,7 @@ class StructureController extends AbstractController
if ($this->totalNumTables > 0 && $this->position > $this->totalNumTables) {
$this->redirect('/database/structure', [
'db' => $GLOBALS['db'],
'pos' => max(0, $this->totalNumTables - $cfg['MaxTableList']),
'pos' => max(0, $this->totalNumTables - $GLOBALS['cfg']['MaxTableList']),
'reload' => 1,
]);
}
@ -193,7 +191,7 @@ class StructureController extends AbstractController
$urlParams,
Url::getFromRoute('/database/structure'),
'frame_content',
$cfg['MaxTableList']
$GLOBALS['cfg']['MaxTableList']
);
$tableList = $this->displayTableList($replicaInfo);

View File

@ -45,45 +45,41 @@ class TrackingController extends AbstractController
public function __invoke(): void
{
global $db, $text_dir, $urlParams, $tables, $num_tables;
global $total_num_tables, $sub_part, $pos, $data, $cfg;
global $tooltip_truename, $tooltip_aliasname, $errorUrl;
$this->addScriptFiles(['vendor/jquery/jquery.tablesorter.js', 'database/tracking.js']);
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
$urlParams['goto'] = Url::getFromRoute('/table/tracking');
$urlParams['back'] = Url::getFromRoute('/database/tracking');
$GLOBALS['urlParams']['goto'] = Url::getFromRoute('/table/tracking');
$GLOBALS['urlParams']['back'] = Url::getFromRoute('/database/tracking');
// Get the database structure
$sub_part = '_structure';
$GLOBALS['sub_part'] = '_structure';
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,
$isSystemSchema,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part);
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part']);
if (isset($_POST['delete_tracking'], $_POST['table'])) {
Tracker::deleteTracking($db, $_POST['table']);
Tracker::deleteTracking($GLOBALS['db'], $_POST['table']);
echo Message::success(
__('Tracking data deleted successfully.')
)->getDisplay();
} elseif (isset($_POST['submit_create_version'])) {
$this->tracking->createTrackingForMultipleTables($db, $_POST['selected']);
$this->tracking->createTrackingForMultipleTables($GLOBALS['db'], $_POST['selected']);
echo Message::success(
sprintf(
__(
@ -96,7 +92,7 @@ class TrackingController extends AbstractController
if (! empty($_POST['selected_tbl'])) {
if ($_POST['submit_mult'] === 'delete_tracking') {
foreach ($_POST['selected_tbl'] as $table) {
Tracker::deleteTracking($db, $table);
Tracker::deleteTracking($GLOBALS['db'], $table);
}
echo Message::success(
@ -105,12 +101,12 @@ class TrackingController extends AbstractController
} elseif ($_POST['submit_mult'] === 'track') {
echo $this->template->render('create_tracking_version', [
'route' => '/database/tracking',
'url_params' => $urlParams,
'url_params' => $GLOBALS['urlParams'],
'last_version' => 0,
'db' => $db,
'db' => $GLOBALS['db'],
'selected' => $_POST['selected_tbl'],
'type' => 'both',
'default_statements' => $cfg['Server']['tracking_default_statements'],
'default_statements' => $GLOBALS['cfg']['Server']['tracking_default_statements'],
]);
return;
@ -123,31 +119,31 @@ class TrackingController extends AbstractController
}
// Get tracked data about the database
$data = Tracker::getTrackedData($db, '', '1');
$GLOBALS['data'] = Tracker::getTrackedData($GLOBALS['db'], '', '1');
// No tables present and no log exist
if ($num_tables == 0 && count($data['ddlog']) === 0) {
if ($GLOBALS['num_tables'] == 0 && count($GLOBALS['data']['ddlog']) === 0) {
echo '<p>' , __('No tables found in database.') , '</p>' , "\n";
if (empty($isSystemSchema)) {
$checkUserPrivileges = new CheckUserPrivileges($this->dbi);
$checkUserPrivileges->getPrivileges();
echo $this->template->render('database/create_table', ['db' => $db]);
echo $this->template->render('database/create_table', ['db' => $GLOBALS['db']]);
}
return;
}
echo $this->tracking->getHtmlForDbTrackingTables($db, $urlParams, $text_dir);
echo $this->tracking->getHtmlForDbTrackingTables($GLOBALS['db'], $GLOBALS['urlParams'], $GLOBALS['text_dir']);
// If available print out database log
if (count($data['ddlog']) <= 0) {
if (count($GLOBALS['data']['ddlog']) <= 0) {
return;
}
$log = '';
foreach ($data['ddlog'] as $entry) {
foreach ($GLOBALS['data']['ddlog'] as $entry) {
$log .= '# ' . $entry['date'] . ' ' . $entry['username'] . "\n"
. $entry['statement'] . "\n";
}

View File

@ -32,55 +32,51 @@ class TriggersController extends AbstractController
public function __invoke(): void
{
global $db, $table, $tables, $num_tables, $total_num_tables, $sub_part;
global $tooltip_truename, $tooltip_aliasname, $pos;
global $errors, $urlParams, $errorUrl, $cfg;
$this->addScriptFiles(['database/triggers.js']);
if (! $this->response->isAjax()) {
/**
* Displays the header and tabs
*/
if (! empty($table) && in_array($table, $this->dbi->getTables($db))) {
if (! empty($GLOBALS['table']) && in_array($GLOBALS['table'], $this->dbi->getTables($GLOBALS['db']))) {
Util::checkParameters(['db', 'table']);
$urlParams = ['db' => $db, 'table' => $table];
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
$errorUrl .= Url::getCommon($urlParams, '&');
$GLOBALS['urlParams'] = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
$GLOBALS['errorUrl'] .= Url::getCommon($GLOBALS['urlParams'], '&');
DbTableExists::check($db, $table);
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
} else {
$table = '';
$GLOBALS['table'] = '';
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part ?? '');
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,,
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part'] ?? '');
}
} elseif (strlen($db) > 0) {
$this->dbi->selectDb($db);
} elseif (strlen($GLOBALS['db']) > 0) {
$this->dbi->selectDb($GLOBALS['db']);
}
/**
* Keep a list of errors that occurred while
* processing an 'Add' or 'Edit' operation.
*/
$errors = [];
$GLOBALS['errors'] = [];
$triggers = new Triggers($this->dbi, $this->template, $this->response);
$triggers->main();

View File

@ -8,8 +8,6 @@ final class DatabaseController extends AbstractController
{
public function __invoke(): void
{
global $dblist;
$this->response->addJSON(['databases' => $dblist->databases]);
$this->response->addJSON(['databases' => $GLOBALS['dblist']->databases]);
}
}

View File

@ -46,8 +46,6 @@ class ErrorReportController extends AbstractController
public function __invoke(ServerRequest $request): void
{
global $cfg;
/** @var string $exceptionType */
$exceptionType = $request->getParsedBodyParam('exception_type', '');
/** @var string|null $sendErrorReport */
@ -101,7 +99,7 @@ class ErrorReportController extends AbstractController
/* Message to show to the user */
if ($success) {
if ($automatic === 'true' || $cfg['SendErrorReports'] === 'always') {
if ($automatic === 'true' || $GLOBALS['cfg']['SendErrorReports'] === 'always') {
$msg = __(
'An error has been detected and an error report has been '
. 'automatically submitted based on your settings.'
@ -152,7 +150,7 @@ class ErrorReportController extends AbstractController
}
}
} elseif ($getSettings) {
$this->response->addJSON('report_setting', $cfg['SendErrorReports']);
$this->response->addJSON('report_setting', $GLOBALS['cfg']['SendErrorReports']);
} elseif ($exceptionType === 'js') {
$this->response->addJSON('report_modal', $this->errorReport->getEmptyModal());
$this->response->addHTML($this->errorReport->getForm());

View File

@ -13,7 +13,6 @@ use PhpMyAdmin\Export;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\Plugins;
use PhpMyAdmin\Plugins\ExportPlugin;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\SqlParser\Parser;
@ -51,15 +50,6 @@ final class ExportController extends AbstractController
public function __invoke(ServerRequest $request): void
{
global $containerBuilder, $db, $export_type, $filename_template, $sql_query, $errorUrl, $message;
global $compression, $crlf, $asfile, $buffer_needed, $save_on_server, $file_handle, $separate_files;
global $output_charset_conversion, $output_kanji_conversion, $table, $what, $export_plugin, $single_table;
global $compression_methods, $onserver, $back_button, $refreshButton, $save_filename, $filename;
global $quick_export, $cfg, $tables, $table_select, $aliases;
global $time_start, $charset, $remember_template, $mime_type, $num_tables;
global $active_page, $do_relation, $do_comments, $do_mime, $do_dates, $whatStrucOrData, $db_select;
global $table_structure, $table_data, $lock_tables, $allrows, $limit_to, $limit_from;
/** @var array<string, string> $postParams */
$postParams = $request->getParsedBody();
@ -225,76 +215,75 @@ final class ExportController extends AbstractController
Util::checkParameters(['what', 'export_type']);
// sanitize this parameter which will be used below in a file inclusion
$what = Core::securePath($whatParam);
$GLOBALS['what'] = Core::securePath($whatParam);
// export class instance, not array of properties, as before
/** @var ExportPlugin $export_plugin */
$export_plugin = Plugins::getPlugin('export', $what, [
'export_type' => (string) $export_type,
'single_table' => isset($single_table),
$GLOBALS['export_plugin'] = Plugins::getPlugin('export', $GLOBALS['what'], [
'export_type' => (string) $GLOBALS['export_type'],
'single_table' => isset($GLOBALS['single_table']),
]);
// Check export type
if (empty($export_plugin)) {
if (empty($GLOBALS['export_plugin'])) {
Core::fatalError(__('Bad type!'));
}
/**
* valid compression methods
*/
$compression_methods = [];
$GLOBALS['compression_methods'] = [];
if ($GLOBALS['cfg']['ZipDump'] && function_exists('gzcompress')) {
$compression_methods[] = 'zip';
$GLOBALS['compression_methods'][] = 'zip';
}
if ($GLOBALS['cfg']['GZipDump'] && function_exists('gzencode')) {
$compression_methods[] = 'gzip';
$GLOBALS['compression_methods'][] = 'gzip';
}
/**
* init and variable checking
*/
$compression = '';
$onserver = false;
$save_on_server = false;
$buffer_needed = false;
$back_button = '';
$refreshButton = '';
$save_filename = '';
$file_handle = '';
$errorUrl = '';
$filename = '';
$separate_files = '';
$GLOBALS['compression'] = '';
$GLOBALS['onserver'] = false;
$GLOBALS['save_on_server'] = false;
$GLOBALS['buffer_needed'] = false;
$GLOBALS['back_button'] = '';
$GLOBALS['refreshButton'] = '';
$GLOBALS['save_filename'] = '';
$GLOBALS['file_handle'] = '';
$GLOBALS['errorUrl'] = '';
$GLOBALS['filename'] = '';
$GLOBALS['separate_files'] = '';
// Is it a quick or custom export?
if ($quickOrCustom === 'quick') {
$quick_export = true;
$GLOBALS['quick_export'] = true;
} else {
$quick_export = false;
$GLOBALS['quick_export'] = false;
}
if ($outputFormat === 'astext') {
$asfile = false;
$GLOBALS['asfile'] = false;
} else {
$asfile = true;
$GLOBALS['asfile'] = true;
if ($asSeparateFiles && $compressionParam === 'zip') {
$separate_files = $asSeparateFiles;
$GLOBALS['separate_files'] = $asSeparateFiles;
}
if (in_array($compressionParam, $compression_methods)) {
$compression = $compressionParam;
$buffer_needed = true;
if (in_array($compressionParam, $GLOBALS['compression_methods'])) {
$GLOBALS['compression'] = $compressionParam;
$GLOBALS['buffer_needed'] = true;
}
if (($quick_export && $quickExportOnServer) || (! $quick_export && $onServerParam)) {
if ($quick_export) {
$onserver = $quickExportOnServer;
if (($GLOBALS['quick_export'] && $quickExportOnServer) || (! $GLOBALS['quick_export'] && $onServerParam)) {
if ($GLOBALS['quick_export']) {
$GLOBALS['onserver'] = $quickExportOnServer;
} else {
$onserver = $onServerParam;
$GLOBALS['onserver'] = $onServerParam;
}
// Will we save dump on server?
$save_on_server = ! empty($cfg['SaveDir']);
$GLOBALS['save_on_server'] = ! empty($GLOBALS['cfg']['SaveDir']);
}
}
@ -302,7 +291,7 @@ final class ExportController extends AbstractController
* If we are sending the export file (as opposed to just displaying it
* as text), we have to bypass the usual PhpMyAdmin\Response mechanism
*/
if ($outputFormat === 'sendit' && ! $save_on_server) {
if ($outputFormat === 'sendit' && ! $GLOBALS['save_on_server']) {
$this->response->disable();
//Disable all active buffers (see: ob_get_status(true) at this point)
do {
@ -314,21 +303,21 @@ final class ExportController extends AbstractController
} while ($hasBuffer);
}
$tables = [];
$GLOBALS['tables'] = [];
// Generate error url and check for needed variables
if ($export_type === 'server') {
$errorUrl = Url::getFromRoute('/server/export');
} elseif ($export_type === 'database' && strlen($db) > 0) {
$errorUrl = Url::getFromRoute('/database/export', ['db' => $db]);
if ($GLOBALS['export_type'] === 'server') {
$GLOBALS['errorUrl'] = Url::getFromRoute('/server/export');
} elseif ($GLOBALS['export_type'] === 'database' && strlen($GLOBALS['db']) > 0) {
$GLOBALS['errorUrl'] = Url::getFromRoute('/database/export', ['db' => $GLOBALS['db']]);
// Check if we have something to export
$tables = $table_select ?? [];
} elseif ($export_type === 'table' && strlen($db) > 0 && strlen($table) > 0) {
$errorUrl = Url::getFromRoute('/table/export', [
'db' => $db,
'table' => $table,
$GLOBALS['tables'] = $GLOBALS['table_select'] ?? [];
} elseif ($GLOBALS['export_type'] === 'table' && strlen($GLOBALS['db']) > 0 && strlen($GLOBALS['table']) > 0) {
$GLOBALS['errorUrl'] = Url::getFromRoute('/table/export', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
]);
} elseif ($export_type === 'raw') {
$errorUrl = Url::getFromRoute('/server/export', ['sql_query' => $sql_query]);
} elseif ($GLOBALS['export_type'] === 'raw') {
$GLOBALS['errorUrl'] = Url::getFromRoute('/server/export', ['sql_query' => $GLOBALS['sql_query']]);
} else {
Core::fatalError(__('Bad parameters!'));
}
@ -336,14 +325,14 @@ final class ExportController extends AbstractController
// Merge SQL Query aliases with Export aliases from
// export page, Export page aliases are given more
// preference over SQL Query aliases.
$parser = new Parser($sql_query);
$aliases = [];
$parser = new Parser($GLOBALS['sql_query']);
$GLOBALS['aliases'] = [];
if (! empty($parser->statements[0]) && ($parser->statements[0] instanceof SelectStatement)) {
$aliases = Misc::getAliases($parser->statements[0], $db);
$GLOBALS['aliases'] = Misc::getAliases($parser->statements[0], $GLOBALS['db']);
}
if (! empty($aliasesParam)) {
$aliases = $this->export->mergeAliases($aliases, $aliasesParam);
$GLOBALS['aliases'] = $this->export->mergeAliases($GLOBALS['aliases'], $aliasesParam);
$_SESSION['tmpval']['aliases'] = $aliasesParam;
}
@ -351,8 +340,8 @@ final class ExportController extends AbstractController
* Increase time limit for script execution and initializes some variables
*/
Util::setTimeLimit();
if (! empty($cfg['MemoryLimit'])) {
ini_set('memory_limit', $cfg['MemoryLimit']);
if (! empty($GLOBALS['cfg']['MemoryLimit'])) {
ini_set('memory_limit', $GLOBALS['cfg']['MemoryLimit']);
}
register_shutdown_function([$this->export, 'shutdown']);
@ -364,59 +353,67 @@ final class ExportController extends AbstractController
$this->export->dumpBufferObjects = [];
// We send fake headers to avoid browser timeout when buffering
$time_start = time();
$GLOBALS['time_start'] = time();
// Defines the default <CR><LF> format.
// For SQL always use \n as MySQL wants this on all platforms.
if ($what === 'sql') {
$crlf = "\n";
if ($GLOBALS['what'] === 'sql') {
$GLOBALS['crlf'] = "\n";
} else {
$crlf = PHP_EOL;
$GLOBALS['crlf'] = PHP_EOL;
}
$output_kanji_conversion = Encoding::canConvertKanji();
$GLOBALS['output_kanji_conversion'] = Encoding::canConvertKanji();
// Do we need to convert charset?
$output_charset_conversion = $asfile
$GLOBALS['output_charset_conversion'] = $GLOBALS['asfile']
&& Encoding::isSupported()
&& isset($charset) && $charset !== 'utf-8';
&& isset($GLOBALS['charset']) && $GLOBALS['charset'] !== 'utf-8';
// Use on the fly compression?
$GLOBALS['onfly_compression'] = $GLOBALS['cfg']['CompressOnFly']
&& $compression === 'gzip';
&& $GLOBALS['compression'] === 'gzip';
if ($GLOBALS['onfly_compression']) {
$GLOBALS['memory_limit'] = $this->export->getMemoryLimit();
}
// Generate filename and mime type if needed
if ($asfile) {
if (empty($remember_template)) {
$remember_template = '';
if ($GLOBALS['asfile']) {
if (empty($GLOBALS['remember_template'])) {
$GLOBALS['remember_template'] = '';
}
[$filename, $mime_type] = $this->export->getFilenameAndMimetype(
$export_type,
$remember_template,
$export_plugin,
$compression,
$filename_template
[$GLOBALS['filename'], $GLOBALS['mime_type']] = $this->export->getFilenameAndMimetype(
$GLOBALS['export_type'],
$GLOBALS['remember_template'],
$GLOBALS['export_plugin'],
$GLOBALS['compression'],
$GLOBALS['filename_template']
);
} else {
$mime_type = '';
$GLOBALS['mime_type'] = '';
}
// For raw query export, filename will be export.extension
if ($export_type === 'raw') {
[$filename] = $this->export->getFinalFilenameAndMimetypeForFilename($export_plugin, $compression, 'export');
if ($GLOBALS['export_type'] === 'raw') {
[$GLOBALS['filename']] = $this->export->getFinalFilenameAndMimetypeForFilename(
$GLOBALS['export_plugin'],
$GLOBALS['compression'],
'export'
);
}
// Open file on server if needed
if ($save_on_server) {
[$save_filename, $message, $file_handle] = $this->export->openFile($filename, $quick_export);
if ($GLOBALS['save_on_server']) {
[
$GLOBALS['save_filename'],
$GLOBALS['message'],
$GLOBALS['file_handle'],
] = $this->export->openFile($GLOBALS['filename'], $GLOBALS['quick_export']);
// problem opening export file on server?
if (! empty($message)) {
$this->export->showPage($export_type);
if (! empty($GLOBALS['message'])) {
$this->export->showPage($GLOBALS['export_type']);
return;
}
@ -425,34 +422,38 @@ final class ExportController extends AbstractController
* Send headers depending on whether the user chose to download a dump file
* or not
*/
if ($asfile) {
if ($GLOBALS['asfile']) {
// Download
// (avoid rewriting data containing HTML with anchors and forms;
// this was reported to happen under Plesk)
ini_set('url_rewriter.tags', '');
$filename = Sanitize::sanitizeFilename($filename);
$GLOBALS['filename'] = Sanitize::sanitizeFilename($GLOBALS['filename']);
Core::downloadHeader($filename, $mime_type);
Core::downloadHeader($GLOBALS['filename'], $GLOBALS['mime_type']);
} else {
// HTML
if ($export_type === 'database') {
$num_tables = count($tables);
if ($num_tables === 0) {
$message = Message::error(
if ($GLOBALS['export_type'] === 'database') {
$GLOBALS['num_tables'] = count($GLOBALS['tables']);
if ($GLOBALS['num_tables'] === 0) {
$GLOBALS['message'] = Message::error(
__('No tables found in database.')
);
$active_page = Url::getFromRoute('/database/export');
$GLOBALS['active_page'] = Url::getFromRoute('/database/export');
/** @var DatabaseExportController $controller */
$controller = $containerBuilder->get(DatabaseExportController::class);
$controller = $GLOBALS['containerBuilder']->get(DatabaseExportController::class);
$controller();
exit;
}
}
[$html, $back_button, $refreshButton] = $this->export->getHtmlForDisplayedExportHeader(
$export_type,
$db,
$table
[
$html,
$GLOBALS['back_button'],
$GLOBALS['refreshButton'],
] = $this->export->getHtmlForDisplayedExportHeader(
$GLOBALS['export_type'],
$GLOBALS['db'],
$GLOBALS['table']
);
echo $html;
unset($html);
@ -465,175 +466,182 @@ final class ExportController extends AbstractController
$this->export->dumpBufferLength = 0;
// Add possibly some comments to export
if (! $export_plugin->exportHeader()) {
if (! $GLOBALS['export_plugin']->exportHeader()) {
throw new ExportException('Failure during header export.');
}
// Will we need relation & co. setup?
$do_relation = isset($GLOBALS[$what . '_relation']);
$do_comments = isset($GLOBALS[$what . '_include_comments'])
|| isset($GLOBALS[$what . '_comments']);
$do_mime = isset($GLOBALS[$what . '_mime']);
$GLOBALS['do_relation'] = isset($GLOBALS[$GLOBALS['what'] . '_relation']);
$GLOBALS['do_comments'] = isset($GLOBALS[$GLOBALS['what'] . '_include_comments'])
|| isset($GLOBALS[$GLOBALS['what'] . '_comments']);
$GLOBALS['do_mime'] = isset($GLOBALS[$GLOBALS['what'] . '_mime']);
// Include dates in export?
$do_dates = isset($GLOBALS[$what . '_dates']);
$GLOBALS['do_dates'] = isset($GLOBALS[$GLOBALS['what'] . '_dates']);
$whatStrucOrData = $GLOBALS[$what . '_structure_or_data'];
$GLOBALS['whatStrucOrData'] = $GLOBALS[$GLOBALS['what'] . '_structure_or_data'];
if ($export_type === 'raw') {
$whatStrucOrData = 'raw';
if ($GLOBALS['export_type'] === 'raw') {
$GLOBALS['whatStrucOrData'] = 'raw';
}
/**
* Builds the dump
*/
if ($export_type === 'server') {
if (! isset($db_select)) {
$db_select = '';
if ($GLOBALS['export_type'] === 'server') {
if (! isset($GLOBALS['db_select'])) {
$GLOBALS['db_select'] = '';
}
$this->export->exportServer(
$db_select,
$whatStrucOrData,
$export_plugin,
$crlf,
$errorUrl,
$export_type,
$do_relation,
$do_comments,
$do_mime,
$do_dates,
$aliases,
$separate_files
$GLOBALS['db_select'],
$GLOBALS['whatStrucOrData'],
$GLOBALS['export_plugin'],
$GLOBALS['crlf'],
$GLOBALS['errorUrl'],
$GLOBALS['export_type'],
$GLOBALS['do_relation'],
$GLOBALS['do_comments'],
$GLOBALS['do_mime'],
$GLOBALS['do_dates'],
$GLOBALS['aliases'],
$GLOBALS['separate_files']
);
} elseif ($export_type === 'database') {
if (! isset($table_structure) || ! is_array($table_structure)) {
$table_structure = [];
} elseif ($GLOBALS['export_type'] === 'database') {
if (! isset($GLOBALS['table_structure']) || ! is_array($GLOBALS['table_structure'])) {
$GLOBALS['table_structure'] = [];
}
if (! isset($table_data) || ! is_array($table_data)) {
$table_data = [];
if (! isset($GLOBALS['table_data']) || ! is_array($GLOBALS['table_data'])) {
$GLOBALS['table_data'] = [];
}
if ($structureOrDataForced) {
$table_structure = $tables;
$table_data = $tables;
$GLOBALS['table_structure'] = $GLOBALS['tables'];
$GLOBALS['table_data'] = $GLOBALS['tables'];
}
if (isset($lock_tables)) {
$this->export->lockTables($db, $tables, 'READ');
if (isset($GLOBALS['lock_tables'])) {
$this->export->lockTables($GLOBALS['db'], $GLOBALS['tables'], 'READ');
try {
$this->export->exportDatabase(
$db,
$tables,
$whatStrucOrData,
$table_structure,
$table_data,
$export_plugin,
$crlf,
$errorUrl,
$export_type,
$do_relation,
$do_comments,
$do_mime,
$do_dates,
$aliases,
$separate_files
$GLOBALS['db'],
$GLOBALS['tables'],
$GLOBALS['whatStrucOrData'],
$GLOBALS['table_structure'],
$GLOBALS['table_data'],
$GLOBALS['export_plugin'],
$GLOBALS['crlf'],
$GLOBALS['errorUrl'],
$GLOBALS['export_type'],
$GLOBALS['do_relation'],
$GLOBALS['do_comments'],
$GLOBALS['do_mime'],
$GLOBALS['do_dates'],
$GLOBALS['aliases'],
$GLOBALS['separate_files']
);
} finally {
$this->export->unlockTables();
}
} else {
$this->export->exportDatabase(
$db,
$tables,
$whatStrucOrData,
$table_structure,
$table_data,
$export_plugin,
$crlf,
$errorUrl,
$export_type,
$do_relation,
$do_comments,
$do_mime,
$do_dates,
$aliases,
$separate_files
$GLOBALS['db'],
$GLOBALS['tables'],
$GLOBALS['whatStrucOrData'],
$GLOBALS['table_structure'],
$GLOBALS['table_data'],
$GLOBALS['export_plugin'],
$GLOBALS['crlf'],
$GLOBALS['errorUrl'],
$GLOBALS['export_type'],
$GLOBALS['do_relation'],
$GLOBALS['do_comments'],
$GLOBALS['do_mime'],
$GLOBALS['do_dates'],
$GLOBALS['aliases'],
$GLOBALS['separate_files']
);
}
} elseif ($export_type === 'raw') {
Export::exportRaw($whatStrucOrData, $export_plugin, $crlf, $errorUrl, $sql_query, $export_type);
} elseif ($GLOBALS['export_type'] === 'raw') {
Export::exportRaw(
$GLOBALS['whatStrucOrData'],
$GLOBALS['export_plugin'],
$GLOBALS['crlf'],
$GLOBALS['errorUrl'],
$GLOBALS['sql_query'],
$GLOBALS['export_type']
);
} else {
// We export just one table
// $allrows comes from the form when "Dump all rows" has been selected
if (! isset($allrows)) {
$allrows = '';
if (! isset($GLOBALS['allrows'])) {
$GLOBALS['allrows'] = '';
}
if (! isset($limit_to)) {
$limit_to = '0';
if (! isset($GLOBALS['limit_to'])) {
$GLOBALS['limit_to'] = '0';
}
if (! isset($limit_from)) {
$limit_from = '0';
if (! isset($GLOBALS['limit_from'])) {
$GLOBALS['limit_from'] = '0';
}
if (isset($lock_tables)) {
if (isset($GLOBALS['lock_tables'])) {
try {
$this->export->lockTables($db, [$table], 'READ');
$this->export->lockTables($GLOBALS['db'], [$GLOBALS['table']], 'READ');
$this->export->exportTable(
$db,
$table,
$whatStrucOrData,
$export_plugin,
$crlf,
$errorUrl,
$export_type,
$do_relation,
$do_comments,
$do_mime,
$do_dates,
$allrows,
$limit_to,
$limit_from,
$sql_query,
$aliases
$GLOBALS['db'],
$GLOBALS['table'],
$GLOBALS['whatStrucOrData'],
$GLOBALS['export_plugin'],
$GLOBALS['crlf'],
$GLOBALS['errorUrl'],
$GLOBALS['export_type'],
$GLOBALS['do_relation'],
$GLOBALS['do_comments'],
$GLOBALS['do_mime'],
$GLOBALS['do_dates'],
$GLOBALS['allrows'],
$GLOBALS['limit_to'],
$GLOBALS['limit_from'],
$GLOBALS['sql_query'],
$GLOBALS['aliases']
);
} finally {
$this->export->unlockTables();
}
} else {
$this->export->exportTable(
$db,
$table,
$whatStrucOrData,
$export_plugin,
$crlf,
$errorUrl,
$export_type,
$do_relation,
$do_comments,
$do_mime,
$do_dates,
$allrows,
$limit_to,
$limit_from,
$sql_query,
$aliases
$GLOBALS['db'],
$GLOBALS['table'],
$GLOBALS['whatStrucOrData'],
$GLOBALS['export_plugin'],
$GLOBALS['crlf'],
$GLOBALS['errorUrl'],
$GLOBALS['export_type'],
$GLOBALS['do_relation'],
$GLOBALS['do_comments'],
$GLOBALS['do_mime'],
$GLOBALS['do_dates'],
$GLOBALS['allrows'],
$GLOBALS['limit_to'],
$GLOBALS['limit_from'],
$GLOBALS['sql_query'],
$GLOBALS['aliases']
);
}
}
if (! $export_plugin->exportFooter()) {
if (! $GLOBALS['export_plugin']->exportFooter()) {
throw new ExportException('Failure during footer export.');
}
} catch (ExportException $e) {
// Ignore
}
if ($save_on_server && ! empty($message)) {
$this->export->showPage($export_type);
if ($GLOBALS['save_on_server'] && ! empty($GLOBALS['message'])) {
$this->export->showPage($GLOBALS['export_type']);
return;
}
@ -641,14 +649,14 @@ final class ExportController extends AbstractController
/**
* Send the dump as a file...
*/
if (empty($asfile)) {
echo $this->export->getHtmlForDisplayedExportFooter($back_button, $refreshButton);
if (empty($GLOBALS['asfile'])) {
echo $this->export->getHtmlForDisplayedExportFooter($GLOBALS['back_button'], $GLOBALS['refreshButton']);
return;
}
// Convert the charset if required.
if ($output_charset_conversion) {
if ($GLOBALS['output_charset_conversion']) {
$this->export->dumpBuffer = Encoding::convertString(
'utf-8',
$GLOBALS['charset'],
@ -657,22 +665,30 @@ final class ExportController extends AbstractController
}
// Compression needed?
if ($compression) {
if (! empty($separate_files)) {
if ($GLOBALS['compression']) {
if (! empty($GLOBALS['separate_files'])) {
$this->export->dumpBuffer = $this->export->compress(
$this->export->dumpBufferObjects,
$compression,
$filename
$GLOBALS['compression'],
$GLOBALS['filename']
);
} else {
$this->export->dumpBuffer = $this->export->compress($this->export->dumpBuffer, $compression, $filename);
$this->export->dumpBuffer = $this->export->compress(
$this->export->dumpBuffer,
$GLOBALS['compression'],
$GLOBALS['filename']
);
}
}
/* If we saved on server, we have to close file now */
if ($save_on_server) {
$message = $this->export->closeFile($file_handle, $this->export->dumpBuffer, $save_filename);
$this->export->showPage($export_type);
if ($GLOBALS['save_on_server']) {
$GLOBALS['message'] = $this->export->closeFile(
$GLOBALS['file_handle'],
$this->export->dumpBuffer,
$GLOBALS['save_filename']
);
$this->export->showPage($GLOBALS['export_type']);
return;
}

View File

@ -35,8 +35,6 @@ final class CreateController extends AbstractController
public function __invoke(ServerRequest $request): void
{
global $cfg;
/** @var string $exportType */
$exportType = $request->getParsedBodyParam('exportType', '');
/** @var string $templateName */
@ -52,7 +50,7 @@ final class CreateController extends AbstractController
}
$template = ExportTemplate::fromArray([
'username' => $cfg['Server']['user'],
'username' => $GLOBALS['cfg']['Server']['user'],
'exportType' => $exportType,
'name' => $templateName,
'data' => $templateData,

View File

@ -32,8 +32,6 @@ final class DeleteController extends AbstractController
public function __invoke(ServerRequest $request): void
{
global $cfg;
$templateId = (int) $request->getParsedBodyParam('templateId');
$exportTemplatesFeature = $this->relation->getRelationParameters()->exportTemplatesFeature;
@ -44,7 +42,7 @@ final class DeleteController extends AbstractController
$result = $this->model->delete(
$exportTemplatesFeature->database,
$exportTemplatesFeature->exportTemplates,
$cfg['Server']['user'],
$GLOBALS['cfg']['Server']['user'],
$templateId
);

View File

@ -33,8 +33,6 @@ final class LoadController extends AbstractController
public function __invoke(ServerRequest $request): void
{
global $cfg;
$templateId = (int) $request->getParsedBodyParam('templateId');
$exportTemplatesFeature = $this->relation->getRelationParameters()->exportTemplatesFeature;
@ -45,7 +43,7 @@ final class LoadController extends AbstractController
$template = $this->model->load(
$exportTemplatesFeature->database,
$exportTemplatesFeature->exportTemplates,
$cfg['Server']['user'],
$GLOBALS['cfg']['Server']['user'],
$templateId
);

View File

@ -33,8 +33,6 @@ final class UpdateController extends AbstractController
public function __invoke(ServerRequest $request): void
{
global $cfg;
$templateId = (int) $request->getParsedBodyParam('templateId');
/** @var string $templateData */
$templateData = $request->getParsedBodyParam('templateData', '');
@ -46,7 +44,7 @@ final class UpdateController extends AbstractController
$template = ExportTemplate::fromArray([
'id' => $templateId,
'username' => $cfg['Server']['user'],
'username' => $GLOBALS['cfg']['Server']['user'],
'data' => $templateData,
]);
$result = $this->model->update(

View File

@ -28,9 +28,6 @@ class GisDataEditorController extends AbstractController
{
public function __invoke(ServerRequest $request): void
{
global $gis_data, $gis_types, $start, $geom_type, $gis_obj, $srid, $wkt, $wkt_with_zero;
global $result, $visualizationSettings, $data, $visualization, $open_layers, $geom_count, $dbi;
/** @var string|null $field */
$field = $request->getParsedBodyParam('field');
/** @var array|null $gisDataParam */
@ -49,12 +46,12 @@ class GisDataEditorController extends AbstractController
}
// Get data if any posted
$gis_data = [];
$GLOBALS['gis_data'] = [];
if (is_array($gisDataParam)) {
$gis_data = $gisDataParam;
$GLOBALS['gis_data'] = $gisDataParam;
}
$gis_types = [
$GLOBALS['gis_types'] = [
'POINT',
'MULTIPOINT',
'LINESTRING',
@ -66,95 +63,103 @@ class GisDataEditorController extends AbstractController
// Extract type from the initial call and make sure that it's a valid one.
// Extract from field's values if available, if not use the column type passed.
if (! isset($gis_data['gis_type'])) {
if (! isset($GLOBALS['gis_data']['gis_type'])) {
if ($type !== '') {
$gis_data['gis_type'] = mb_strtoupper($type);
$GLOBALS['gis_data']['gis_type'] = mb_strtoupper($type);
}
if (isset($value) && trim($value) !== '') {
$start = substr($value, 0, 1) == "'" ? 1 : 0;
$gis_data['gis_type'] = mb_substr($value, $start, (int) mb_strpos($value, '(') - $start);
$GLOBALS['start'] = substr($value, 0, 1) == "'" ? 1 : 0;
$GLOBALS['gis_data']['gis_type'] = mb_substr(
$value,
$GLOBALS['start'],
(int) mb_strpos($value, '(') - $GLOBALS['start']
);
}
if (! isset($gis_data['gis_type']) || (! in_array($gis_data['gis_type'], $gis_types))) {
$gis_data['gis_type'] = $gis_types[0];
if (
! isset($GLOBALS['gis_data']['gis_type'])
|| (! in_array($GLOBALS['gis_data']['gis_type'], $GLOBALS['gis_types']))
) {
$GLOBALS['gis_data']['gis_type'] = $GLOBALS['gis_types'][0];
}
}
$geom_type = $gis_data['gis_type'];
$GLOBALS['geom_type'] = $GLOBALS['gis_data']['gis_type'];
// Generate parameters from value passed.
$gis_obj = GisFactory::factory($geom_type);
if ($gis_obj === false) {
$GLOBALS['gis_obj'] = GisFactory::factory($GLOBALS['geom_type']);
if ($GLOBALS['gis_obj'] === false) {
return;
}
if (isset($value)) {
$gis_data = array_merge(
$gis_data,
$gis_obj->generateParams($value)
$GLOBALS['gis_data'] = array_merge(
$GLOBALS['gis_data'],
$GLOBALS['gis_obj']->generateParams($value)
);
}
// Generate Well Known Text
$srid = isset($gis_data['srid']) && $gis_data['srid'] != '' ? (int) $gis_data['srid'] : 0;
$wkt = $gis_obj->generateWkt($gis_data, 0);
$wkt_with_zero = $gis_obj->generateWkt($gis_data, 0, '0');
$result = "'" . $wkt . "'," . $srid;
$GLOBALS['srid'] = isset($GLOBALS['gis_data']['srid']) && $GLOBALS['gis_data']['srid'] != ''
? (int) $GLOBALS['gis_data']['srid'] : 0;
$GLOBALS['wkt'] = $GLOBALS['gis_obj']->generateWkt($GLOBALS['gis_data'], 0);
$GLOBALS['wkt_with_zero'] = $GLOBALS['gis_obj']->generateWkt($GLOBALS['gis_data'], 0, '0');
$GLOBALS['result'] = "'" . $GLOBALS['wkt'] . "'," . $GLOBALS['srid'];
// Generate SVG based visualization
$visualizationSettings = [
$GLOBALS['visualizationSettings'] = [
'width' => 450,
'height' => 300,
'spatialColumn' => 'wkt',
'mysqlVersion' => $dbi->getVersion(),
'isMariaDB' => $dbi->isMariaDB(),
'mysqlVersion' => $GLOBALS['dbi']->getVersion(),
'isMariaDB' => $GLOBALS['dbi']->isMariaDB(),
];
$data = [
$GLOBALS['data'] = [
[
'wkt' => $wkt_with_zero,
'srid' => $srid,
'wkt' => $GLOBALS['wkt_with_zero'],
'srid' => $GLOBALS['srid'],
],
];
$visualization = GisVisualization::getByData($data, $visualizationSettings)
$GLOBALS['visualization'] = GisVisualization::getByData($GLOBALS['data'], $GLOBALS['visualizationSettings'])
->toImage('svg');
$open_layers = GisVisualization::getByData($data, $visualizationSettings)
$GLOBALS['open_layers'] = GisVisualization::getByData($GLOBALS['data'], $GLOBALS['visualizationSettings'])
->asOl();
// If the call is to update the WKT and visualization make an AJAX response
if ($generate) {
$this->response->addJSON([
'result' => $result,
'visualization' => $visualization,
'openLayers' => $open_layers,
'result' => $GLOBALS['result'],
'visualization' => $GLOBALS['visualization'],
'openLayers' => $GLOBALS['open_layers'],
]);
return;
}
$geom_count = 1;
if ($geom_type === 'GEOMETRYCOLLECTION') {
$geom_count = isset($gis_data[$geom_type]['geom_count'])
? intval($gis_data[$geom_type]['geom_count']) : 1;
if (isset($gis_data[$geom_type]['add_geom'])) {
$geom_count++;
$GLOBALS['geom_count'] = 1;
if ($GLOBALS['geom_type'] === 'GEOMETRYCOLLECTION') {
$GLOBALS['geom_count'] = isset($GLOBALS['gis_data'][$GLOBALS['geom_type']]['geom_count'])
? intval($GLOBALS['gis_data'][$GLOBALS['geom_type']]['geom_count']) : 1;
if (isset($GLOBALS['gis_data'][$GLOBALS['geom_type']]['add_geom'])) {
$GLOBALS['geom_count']++;
}
}
$templateOutput = $this->template->render('gis_data_editor_form', [
'width' => $visualizationSettings['width'],
'height' => $visualizationSettings['height'],
'width' => $GLOBALS['visualizationSettings']['width'],
'height' => $GLOBALS['visualizationSettings']['height'],
'field' => $field,
'input_name' => $inputName,
'srid' => $srid,
'visualization' => $visualization,
'open_layers' => $open_layers,
'gis_types' => $gis_types,
'geom_type' => $geom_type,
'geom_count' => $geom_count,
'gis_data' => $gis_data,
'result' => $result,
'srid' => $GLOBALS['srid'],
'visualization' => $GLOBALS['visualization'],
'open_layers' => $GLOBALS['open_layers'],
'gis_types' => $GLOBALS['gis_types'],
'geom_type' => $GLOBALS['geom_type'],
'geom_count' => $GLOBALS['geom_count'],
'gis_data' => $GLOBALS['gis_data'],
'result' => $GLOBALS['result'],
]);
$this->response->addJSON(['gis_editor' => $templateOutput]);

View File

@ -63,8 +63,6 @@ class HomeController extends AbstractController
public function __invoke(): void
{
global $cfg, $server, $collation_connection, $message, $show_query, $db, $table, $errorUrl;
if ($this->response->isAjax() && ! empty($_REQUEST['access_time'])) {
return;
}
@ -74,20 +72,20 @@ class HomeController extends AbstractController
// This is for $cfg['ShowDatabasesNavigationAsTree'] = false;
// See: https://github.com/phpmyadmin/phpmyadmin/issues/16520
// The DB is defined here and sent to the JS front-end to refresh the DB tree
$db = $_POST['db'] ?? '';
$table = '';
$show_query = '1';
$errorUrl = Url::getFromRoute('/');
$GLOBALS['db'] = $_POST['db'] ?? '';
$GLOBALS['table'] = '';
$GLOBALS['show_query'] = '1';
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($server > 0 && $this->dbi->isSuperUser()) {
if ($GLOBALS['server'] > 0 && $this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');
}
$languageManager = LanguageManager::getInstance();
if (! empty($message)) {
$displayMessage = Generator::getMessage($message);
unset($message);
if (! empty($GLOBALS['message'])) {
$displayMessage = Generator::getMessage($GLOBALS['message']);
unset($GLOBALS['message']);
}
if (isset($_SESSION['partial_logout'])) {
@ -101,22 +99,22 @@ class HomeController extends AbstractController
$syncFavoriteTables = RecentFavoriteTable::getInstance('favorite')
->getHtmlSyncFavoriteTables();
$hasServer = $server > 0 || count($cfg['Servers']) > 1;
$hasServer = $GLOBALS['server'] > 0 || count($GLOBALS['cfg']['Servers']) > 1;
if ($hasServer) {
$hasServerSelection = $cfg['ServerDefault'] == 0
|| (! $cfg['NavigationDisplayServers']
&& (count($cfg['Servers']) > 1
|| ($server == 0 && count($cfg['Servers']) === 1)));
$hasServerSelection = $GLOBALS['cfg']['ServerDefault'] == 0
|| (! $GLOBALS['cfg']['NavigationDisplayServers']
&& (count($GLOBALS['cfg']['Servers']) > 1
|| ($GLOBALS['server'] == 0 && count($GLOBALS['cfg']['Servers']) === 1)));
if ($hasServerSelection) {
$serverSelection = Select::render(true, true);
}
if ($server > 0) {
if ($GLOBALS['server'] > 0) {
$checkUserPrivileges = new CheckUserPrivileges($this->dbi);
$checkUserPrivileges->getPrivileges();
$charsets = Charsets::getCharsets($this->dbi, $cfg['Server']['DisableIS']);
$collations = Charsets::getCollations($this->dbi, $cfg['Server']['DisableIS']);
$charsets = Charsets::getCharsets($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$collations = Charsets::getCollations($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$charsetsList = [];
foreach ($charsets as $charset) {
$collationsList = [];
@ -124,7 +122,7 @@ class HomeController extends AbstractController
$collationsList[] = [
'name' => $collation->getName(),
'description' => $collation->getDescription(),
'is_selected' => $collation_connection === $collation->getName(),
'is_selected' => $GLOBALS['collation_connection'] === $collation->getName(),
];
}
@ -138,29 +136,29 @@ class HomeController extends AbstractController
}
$availableLanguages = [];
if (empty($cfg['Lang']) && $languageManager->hasChoice()) {
if (empty($GLOBALS['cfg']['Lang']) && $languageManager->hasChoice()) {
$availableLanguages = $languageManager->sortedLanguages();
}
$databaseServer = [];
if ($server > 0) {
if ($GLOBALS['server'] > 0) {
$hostInfo = '';
if (! empty($cfg['Server']['verbose'])) {
$hostInfo .= $cfg['Server']['verbose'];
if ($cfg['ShowServerInfo']) {
if (! empty($GLOBALS['cfg']['Server']['verbose'])) {
$hostInfo .= $GLOBALS['cfg']['Server']['verbose'];
if ($GLOBALS['cfg']['ShowServerInfo']) {
$hostInfo .= ' (';
}
}
if ($cfg['ShowServerInfo'] || empty($cfg['Server']['verbose'])) {
if ($GLOBALS['cfg']['ShowServerInfo'] || empty($GLOBALS['cfg']['Server']['verbose'])) {
$hostInfo .= $this->dbi->getHostInfo();
}
if (! empty($cfg['Server']['verbose']) && $cfg['ShowServerInfo']) {
if (! empty($GLOBALS['cfg']['Server']['verbose']) && $GLOBALS['cfg']['ShowServerInfo']) {
$hostInfo .= ')';
}
$serverCharset = Charsets::getServerCharset($this->dbi, $cfg['Server']['DisableIS']);
$serverCharset = Charsets::getServerCharset($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$databaseServer = [
'host' => $hostInfo,
'type' => Util::getServerType(),
@ -173,10 +171,10 @@ class HomeController extends AbstractController
}
$webServer = [];
if ($cfg['ShowServerInfo']) {
if ($GLOBALS['cfg']['ShowServerInfo']) {
$webServer['software'] = $_SERVER['SERVER_SOFTWARE'] ?? null;
if ($server > 0) {
if ($GLOBALS['server'] > 0) {
$clientVersion = $this->dbi->getClientInfo();
if (preg_match('#\d+\.\d+\.\d+#', $clientVersion)) {
$clientVersion = 'libmysql - ' . $clientVersion;
@ -189,15 +187,15 @@ class HomeController extends AbstractController
}
$relation = new Relation($this->dbi);
if ($server > 0) {
if ($GLOBALS['server'] > 0) {
$relationParameters = $relation->getRelationParameters();
if (! $relationParameters->hasAllFeatures() && $cfg['PmaNoRelation_DisableWarning'] == false) {
if (! $relationParameters->hasAllFeatures() && $GLOBALS['cfg']['PmaNoRelation_DisableWarning'] == false) {
$messageText = __(
'The phpMyAdmin configuration storage is not completely '
. 'configured, some extended features have been deactivated. '
. '%sFind out why%s. '
);
if ($cfg['ZeroConf'] == true) {
if ($GLOBALS['cfg']['ZeroConf'] == true) {
$messageText .= '<br>' .
__('Or alternately go to \'Operations\' tab of any database to set it up there.');
}
@ -209,7 +207,7 @@ class HomeController extends AbstractController
);
$messageInstance->addParamHtml('</a>');
/* Show error if user has configured something, notice elsewhere */
if (! empty($cfg['Servers'][$server]['pmadb'])) {
if (! empty($GLOBALS['cfg']['Servers'][$GLOBALS['server']]['pmadb'])) {
$messageInstance->isError(true);
}
@ -222,44 +220,43 @@ class HomeController extends AbstractController
$git = new Git($this->config->get('ShowGitRevision') ?? true);
$this->render('home/index', [
'db' => $db,
'table' => $table,
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'message' => $displayMessage ?? '',
'partial_logout' => $partialLogout ?? '',
'is_git_revision' => $git->isGitRevision(),
'server' => $server,
'server' => $GLOBALS['server'],
'sync_favorite_tables' => $syncFavoriteTables,
'has_server' => $hasServer,
'is_demo' => $cfg['DBG']['demo'],
'is_demo' => $GLOBALS['cfg']['DBG']['demo'],
'has_server_selection' => $hasServerSelection ?? false,
'server_selection' => $serverSelection ?? '',
'has_change_password_link' => $cfg['Server']['auth_type'] !== 'config' && $cfg['ShowChgPassword'],
'has_change_password_link' => $GLOBALS['cfg']['Server']['auth_type'] !== 'config'
&& $GLOBALS['cfg']['ShowChgPassword'],
'charsets' => $charsetsList ?? [],
'available_languages' => $availableLanguages,
'database_server' => $databaseServer,
'web_server' => $webServer,
'show_php_info' => $cfg['ShowPhpInfo'],
'is_version_checked' => $cfg['VersionCheck'],
'show_php_info' => $GLOBALS['cfg']['ShowPhpInfo'],
'is_version_checked' => $GLOBALS['cfg']['VersionCheck'],
'phpmyadmin_version' => Version::VERSION,
'phpmyadmin_major_version' => Version::SERIES,
'config_storage_message' => $configStorageMessage ?? '',
'has_theme_manager' => $cfg['ThemeManager'],
'has_theme_manager' => $GLOBALS['cfg']['ThemeManager'],
'themes' => $this->themeManager->getThemesArray(),
]);
}
private function checkRequirements(): void
{
global $cfg, $server;
$this->checkPhpExtensionsRequirements();
if ($cfg['LoginCookieValidityDisableWarning'] == false) {
if ($GLOBALS['cfg']['LoginCookieValidityDisableWarning'] == false) {
/**
* Check whether session.gc_maxlifetime limits session validity.
*/
$gc_time = (int) ini_get('session.gc_maxlifetime');
if ($gc_time < $cfg['LoginCookieValidity']) {
if ($gc_time < $GLOBALS['cfg']['LoginCookieValidity']) {
trigger_error(
__(
'Your PHP parameter [a@https://www.php.net/manual/en/session.' .
@ -276,7 +273,10 @@ class HomeController extends AbstractController
/**
* Check whether LoginCookieValidity is limited by LoginCookieStore.
*/
if ($cfg['LoginCookieStore'] != 0 && $cfg['LoginCookieStore'] < $cfg['LoginCookieValidity']) {
if (
$GLOBALS['cfg']['LoginCookieStore'] != 0
&& $GLOBALS['cfg']['LoginCookieStore'] < $GLOBALS['cfg']['LoginCookieValidity']
) {
trigger_error(
__(
'Login cookie store is lower than cookie validity configured in ' .
@ -291,10 +291,10 @@ class HomeController extends AbstractController
* Warning if using the default MySQL controluser account
*/
if (
isset($cfg['Server']['controluser'], $cfg['Server']['controlpass'])
&& $server != 0
&& $cfg['Server']['controluser'] === 'pma'
&& $cfg['Server']['controlpass'] === 'pmapass'
isset($GLOBALS['cfg']['Server']['controluser'], $GLOBALS['cfg']['Server']['controlpass'])
&& $GLOBALS['server'] != 0
&& $GLOBALS['cfg']['Server']['controluser'] === 'pma'
&& $GLOBALS['cfg']['Server']['controlpass'] === 'pmapass'
) {
trigger_error(
__(
@ -311,14 +311,14 @@ class HomeController extends AbstractController
* Check if user does not have defined blowfish secret and it is being used.
*/
if (! empty($_SESSION['encryption_key'])) {
if (empty($cfg['blowfish_secret'])) {
if (empty($GLOBALS['cfg']['blowfish_secret'])) {
trigger_error(
__(
'The configuration file now needs a secret passphrase (blowfish_secret).'
),
E_USER_WARNING
);
} elseif (mb_strlen($cfg['blowfish_secret'], '8bit') !== SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
} elseif (mb_strlen($GLOBALS['cfg']['blowfish_secret'], '8bit') !== SODIUM_CRYPTO_SECRETBOX_KEYBYTES) {
trigger_error(
sprintf(
__(
@ -353,7 +353,7 @@ class HomeController extends AbstractController
* Warning about Suhosin only if its simulation mode is not enabled
*/
if (
$cfg['SuhosinDisableWarning'] == false
$GLOBALS['cfg']['SuhosinDisableWarning'] == false
&& ini_get('suhosin.request.max_value_length')
&& ini_get('suhosin.simulation') == '0'
) {
@ -389,8 +389,6 @@ class HomeController extends AbstractController
private function checkLanguageStats(): void
{
global $cfg, $lang;
/**
* Warning about incomplete translations.
*
@ -408,8 +406,8 @@ class HomeController extends AbstractController
* speaking users.
*/
if (
! isset($GLOBALS['language_stats'][$lang])
|| $GLOBALS['language_stats'][$lang] >= $cfg['TranslationWarningThreshold']
! isset($GLOBALS['language_stats'][$GLOBALS['lang']])
|| $GLOBALS['language_stats'][$GLOBALS['lang']] >= $GLOBALS['cfg']['TranslationWarningThreshold']
) {
return;
}

View File

@ -72,25 +72,16 @@ final class ImportController extends AbstractController
public function __invoke(): void
{
global $cfg, $collation_connection, $db, $import_type, $table, $goto, $display_query;
global $format, $local_import_file, $ajax_reload, $import_text, $sql_query, $message, $errorUrl, $urlParams;
global $memory_limit, $read_limit, $finished, $offset, $charset_conversion, $charset_of_file;
global $timestamp, $maximum_time, $timeout_passed, $import_file, $go_sql, $sql_file, $error, $max_sql_len, $msg;
global $sql_query_disabled, $executed_queries, $run_query, $reset_charset;
global $result, $import_file_name, $sql_data, $import_notice, $read_multiply, $my_die, $active_page;
global $show_as_php, $reload, $charset_connection, $is_js_confirmed, $MAX_FILE_SIZE, $message_to_show;
global $noplugin, $skip_queries;
$charset_of_file = $_POST['charset_of_file'] ?? null;
$format = $_POST['format'] ?? '';
$import_type = $_POST['import_type'] ?? null;
$is_js_confirmed = $_POST['is_js_confirmed'] ?? null;
$MAX_FILE_SIZE = $_POST['MAX_FILE_SIZE'] ?? null;
$message_to_show = $_POST['message_to_show'] ?? null;
$noplugin = $_POST['noplugin'] ?? null;
$skip_queries = $_POST['skip_queries'] ?? null;
$local_import_file = $_POST['local_import_file'] ?? null;
$show_as_php = $_POST['show_as_php'] ?? null;
$GLOBALS['charset_of_file'] = $_POST['charset_of_file'] ?? null;
$GLOBALS['format'] = $_POST['format'] ?? '';
$GLOBALS['import_type'] = $_POST['import_type'] ?? null;
$GLOBALS['is_js_confirmed'] = $_POST['is_js_confirmed'] ?? null;
$GLOBALS['MAX_FILE_SIZE'] = $_POST['MAX_FILE_SIZE'] ?? null;
$GLOBALS['message_to_show'] = $_POST['message_to_show'] ?? null;
$GLOBALS['noplugin'] = $_POST['noplugin'] ?? null;
$GLOBALS['skip_queries'] = $_POST['skip_queries'] ?? null;
$GLOBALS['local_import_file'] = $_POST['local_import_file'] ?? null;
$GLOBALS['show_as_php'] = $_POST['show_as_php'] ?? null;
// If it's a refresh console bookmarks request
if (isset($_GET['console_bookmark_refresh'])) {
@ -112,7 +103,7 @@ final class ImportController extends AbstractController
$bookmarkFields = [
'bkm_database' => $_POST['db'],
'bkm_user' => $cfg['Server']['user'],
'bkm_user' => $GLOBALS['cfg']['Server']['user'],
'bkm_sql_query' => $_POST['bookmark_query'],
'bkm_label' => $_POST['label'],
];
@ -133,7 +124,7 @@ final class ImportController extends AbstractController
$_SESSION['Import_message']['message'] = null;
$_SESSION['Import_message']['go_back_url'] = null;
// default values
$reload = false;
$GLOBALS['reload'] = false;
// Use to identify current cycle is executing
// a multiquery statement or stored routine
@ -141,11 +132,11 @@ final class ImportController extends AbstractController
$_SESSION['is_multi_query'] = false;
}
$ajax_reload = [];
$import_text = '';
$GLOBALS['ajax_reload'] = [];
$GLOBALS['import_text'] = '';
// Are we just executing plain query or sql file?
// (eg. non import, but query box/window run)
if (! empty($sql_query)) {
if (! empty($GLOBALS['sql_query'])) {
// apply values for parameters
if (! empty($_POST['parameterized']) && ! empty($_POST['parameters']) && is_array($_POST['parameters'])) {
$parameters = $_POST['parameters'];
@ -157,76 +148,86 @@ final class ImportController extends AbstractController
$quoted = preg_quote($parameter, '/');
// making sure that :param does not apply values to :param1
$sql_query = preg_replace(
$GLOBALS['sql_query'] = preg_replace(
'/' . $quoted . '([^a-zA-Z0-9_])/',
$replacementValue . '${1}',
$sql_query
$GLOBALS['sql_query']
);
// for parameters the appear at the end of the string
$sql_query = preg_replace('/' . $quoted . '$/', $replacementValue, $sql_query);
$GLOBALS['sql_query'] = preg_replace(
'/' . $quoted . '$/',
$replacementValue,
$GLOBALS['sql_query']
);
}
}
// run SQL query
$import_text = $sql_query;
$import_type = 'query';
$format = 'sql';
$GLOBALS['import_text'] = $GLOBALS['sql_query'];
$GLOBALS['import_type'] = 'query';
$GLOBALS['format'] = 'sql';
$_SESSION['sql_from_query_box'] = true;
// If there is a request to ROLLBACK when finished.
if (isset($_POST['rollback_query'])) {
$this->import->handleRollbackRequest($import_text);
$this->import->handleRollbackRequest($GLOBALS['import_text']);
}
// refresh navigation and main panels
if (preg_match('/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $sql_query)) {
$reload = true;
$ajax_reload['reload'] = true;
if (preg_match('/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $GLOBALS['sql_query'])) {
$GLOBALS['reload'] = true;
$GLOBALS['ajax_reload']['reload'] = true;
}
// refresh navigation panel only
if (preg_match('/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $sql_query)) {
$ajax_reload['reload'] = true;
if (preg_match('/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $GLOBALS['sql_query'])) {
$GLOBALS['ajax_reload']['reload'] = true;
}
// do a dynamic reload if table is RENAMED
// (by sending the instruction to the AJAX response handler)
if (preg_match('/^RENAME\s+TABLE\s+(.*?)\s+TO\s+(.*?)($|;|\s)/i', $sql_query, $rename_table_names)) {
$ajax_reload['reload'] = true;
$ajax_reload['table_name'] = Util::unQuote($rename_table_names[2]);
if (
preg_match(
'/^RENAME\s+TABLE\s+(.*?)\s+TO\s+(.*?)($|;|\s)/i',
$GLOBALS['sql_query'],
$rename_table_names
)
) {
$GLOBALS['ajax_reload']['reload'] = true;
$GLOBALS['ajax_reload']['table_name'] = Util::unQuote($rename_table_names[2]);
}
$sql_query = '';
} elseif (! empty($sql_file)) {
$GLOBALS['sql_query'] = '';
} elseif (! empty($GLOBALS['sql_file'])) {
// run uploaded SQL file
$import_file = $sql_file;
$import_type = 'queryfile';
$format = 'sql';
unset($sql_file);
$GLOBALS['import_file'] = $GLOBALS['sql_file'];
$GLOBALS['import_type'] = 'queryfile';
$GLOBALS['format'] = 'sql';
unset($GLOBALS['sql_file']);
} elseif (! empty($_POST['id_bookmark'])) {
// run bookmark
$import_type = 'query';
$format = 'sql';
$GLOBALS['import_type'] = 'query';
$GLOBALS['format'] = 'sql';
}
// If we didn't get any parameters, either user called this directly, or
// upload limit has been reached, let's assume the second possibility.
if ($_POST == [] && $_GET == []) {
$message = Message::error(
$GLOBALS['message'] = Message::error(
__(
'You probably tried to upload a file that is too large. Please refer ' .
'to %sdocumentation%s for a workaround for this limit.'
)
);
$message->addParam('[doc@faq1-16]');
$message->addParam('[/doc]');
$GLOBALS['message']->addParam('[doc@faq1-16]');
$GLOBALS['message']->addParam('[/doc]');
// so we can obtain the message
$_SESSION['Import_message']['message'] = $message->getDisplay();
$_SESSION['Import_message']['go_back_url'] = $goto;
$_SESSION['Import_message']['message'] = $GLOBALS['message']->getDisplay();
$_SESSION['Import_message']['go_back_url'] = $GLOBALS['goto'];
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message);
$this->response->addJSON('message', $GLOBALS['message']);
return; // the footer is displayed automatically
}
@ -241,7 +242,7 @@ final class ImportController extends AbstractController
* We only need to load the selected plugin
*/
if (! in_array($format, ['csv', 'ldi', 'mediawiki', 'ods', 'shp', 'sql', 'xml'])) {
if (! in_array($GLOBALS['format'], ['csv', 'ldi', 'mediawiki', 'ods', 'shp', 'sql', 'xml'])) {
// this should not happen for a normal user
// but only during an attack
Core::fatalError('Incorrect format parameter');
@ -249,7 +250,7 @@ final class ImportController extends AbstractController
$post_patterns = [
'/^force_file_/',
'/^' . $format . '_/',
'/^' . $GLOBALS['format'] . '_/',
];
Core::setPostAsGlobal($post_patterns);
@ -258,73 +259,72 @@ final class ImportController extends AbstractController
Util::checkParameters(['import_type', 'format']);
// We don't want anything special in format
$format = Core::securePath($format);
$GLOBALS['format'] = Core::securePath($GLOBALS['format']);
if (strlen($table) > 0 && strlen($db) > 0) {
$urlParams = [
'db' => $db,
'table' => $table,
if (strlen($GLOBALS['table']) > 0 && strlen($GLOBALS['db']) > 0) {
$GLOBALS['urlParams'] = [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
];
} elseif (strlen($db) > 0) {
$urlParams = ['db' => $db];
} elseif (strlen($GLOBALS['db']) > 0) {
$GLOBALS['urlParams'] = ['db' => $GLOBALS['db']];
} else {
$urlParams = [];
$GLOBALS['urlParams'] = [];
}
// Create error and goto url
if ($import_type === 'table') {
$goto = Url::getFromRoute('/table/import');
} elseif ($import_type === 'database') {
$goto = Url::getFromRoute('/database/import');
} elseif ($import_type === 'server') {
$goto = Url::getFromRoute('/server/import');
} elseif (empty($goto) || ! preg_match('@^index\.php$@i', $goto)) {
if (strlen($table) > 0 && strlen($db) > 0) {
$goto = Url::getFromRoute('/table/structure');
} elseif (strlen($db) > 0) {
$goto = Url::getFromRoute('/database/structure');
if ($GLOBALS['import_type'] === 'table') {
$GLOBALS['goto'] = Url::getFromRoute('/table/import');
} elseif ($GLOBALS['import_type'] === 'database') {
$GLOBALS['goto'] = Url::getFromRoute('/database/import');
} elseif ($GLOBALS['import_type'] === 'server') {
$GLOBALS['goto'] = Url::getFromRoute('/server/import');
} elseif (empty($GLOBALS['goto']) || ! preg_match('@^index\.php$@i', $GLOBALS['goto'])) {
if (strlen($GLOBALS['table']) > 0 && strlen($GLOBALS['db']) > 0) {
$GLOBALS['goto'] = Url::getFromRoute('/table/structure');
} elseif (strlen($GLOBALS['db']) > 0) {
$GLOBALS['goto'] = Url::getFromRoute('/database/structure');
} else {
$goto = Url::getFromRoute('/server/sql');
$GLOBALS['goto'] = Url::getFromRoute('/server/sql');
}
}
$errorUrl = $goto . Url::getCommon($urlParams, '&');
$_SESSION['Import_message']['go_back_url'] = $errorUrl;
$GLOBALS['errorUrl'] = $GLOBALS['goto'] . Url::getCommon($GLOBALS['urlParams'], '&');
$_SESSION['Import_message']['go_back_url'] = $GLOBALS['errorUrl'];
if (strlen($db) > 0) {
$this->dbi->selectDb($db);
if (strlen($GLOBALS['db']) > 0) {
$this->dbi->selectDb($GLOBALS['db']);
}
Util::setTimeLimit();
if (! empty($cfg['MemoryLimit'])) {
ini_set('memory_limit', $cfg['MemoryLimit']);
if (! empty($GLOBALS['cfg']['MemoryLimit'])) {
ini_set('memory_limit', $GLOBALS['cfg']['MemoryLimit']);
}
$timestamp = time();
$GLOBALS['timestamp'] = time();
if (isset($_POST['allow_interrupt'])) {
$maximum_time = ini_get('max_execution_time');
$GLOBALS['maximum_time'] = ini_get('max_execution_time');
} else {
$maximum_time = 0;
$GLOBALS['maximum_time'] = 0;
}
// set default values
$timeout_passed = false;
$error = false;
$read_multiply = 1;
$finished = false;
$offset = 0;
$max_sql_len = 0;
$sql_query = '';
$sql_query_disabled = false;
$go_sql = false;
$executed_queries = 0;
$run_query = true;
$charset_conversion = false;
$reset_charset = false;
$msg = 'Sorry an unexpected error happened!';
$GLOBALS['timeout_passed'] = false;
$GLOBALS['error'] = false;
$GLOBALS['read_multiply'] = 1;
$GLOBALS['finished'] = false;
$GLOBALS['offset'] = 0;
$GLOBALS['max_sql_len'] = 0;
$GLOBALS['sql_query'] = '';
$GLOBALS['sql_query_disabled'] = false;
$GLOBALS['go_sql'] = false;
$GLOBALS['executed_queries'] = 0;
$GLOBALS['run_query'] = true;
$GLOBALS['charset_conversion'] = false;
$GLOBALS['reset_charset'] = false;
$GLOBALS['msg'] = 'Sorry an unexpected error happened!';
/** @var bool|mixed $result */
$result = false;
$GLOBALS['result'] = false;
// Bookmark Support: get a query back from bookmark if required
if (! empty($_POST['id_bookmark'])) {
@ -333,8 +333,8 @@ final class ImportController extends AbstractController
case 0: // bookmarked query that have to be run
$bookmark = Bookmark::get(
$this->dbi,
$cfg['Server']['user'],
$db,
$GLOBALS['cfg']['Server']['user'],
$GLOBALS['db'],
$id_bookmark,
'id',
isset($_POST['action_bookmark_all'])
@ -344,63 +344,73 @@ final class ImportController extends AbstractController
}
if (! empty($_POST['bookmark_variable'])) {
$import_text = $bookmark->applyVariables($_POST['bookmark_variable']);
$GLOBALS['import_text'] = $bookmark->applyVariables($_POST['bookmark_variable']);
} else {
$import_text = $bookmark->getQuery();
$GLOBALS['import_text'] = $bookmark->getQuery();
}
// refresh navigation and main panels
if (preg_match('/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $import_text)) {
$reload = true;
$ajax_reload['reload'] = true;
if (preg_match('/^(DROP)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $GLOBALS['import_text'])) {
$GLOBALS['reload'] = true;
$GLOBALS['ajax_reload']['reload'] = true;
}
// refresh navigation panel only
if (preg_match('/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $import_text)) {
$ajax_reload['reload'] = true;
if (preg_match('/^(CREATE|ALTER)\s+(VIEW|TABLE|DATABASE|SCHEMA)\s+/i', $GLOBALS['import_text'])) {
$GLOBALS['ajax_reload']['reload'] = true;
}
break;
case 1: // bookmarked query that have to be displayed
$bookmark = Bookmark::get($this->dbi, $cfg['Server']['user'], $db, $id_bookmark);
$bookmark = Bookmark::get(
$this->dbi,
$GLOBALS['cfg']['Server']['user'],
$GLOBALS['db'],
$id_bookmark
);
if (! $bookmark instanceof Bookmark) {
break;
}
$import_text = $bookmark->getQuery();
$GLOBALS['import_text'] = $bookmark->getQuery();
if ($this->response->isAjax()) {
$message = Message::success(__('Showing bookmark'));
$this->response->setRequestStatus($message->isSuccess());
$this->response->addJSON('message', $message);
$this->response->addJSON('sql_query', $import_text);
$GLOBALS['message'] = Message::success(__('Showing bookmark'));
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
$this->response->addJSON('message', $GLOBALS['message']);
$this->response->addJSON('sql_query', $GLOBALS['import_text']);
$this->response->addJSON('action_bookmark', $_POST['action_bookmark']);
return;
} else {
$run_query = false;
$GLOBALS['run_query'] = false;
}
break;
case 2: // bookmarked query that have to be deleted
$bookmark = Bookmark::get($this->dbi, $cfg['Server']['user'], $db, $id_bookmark);
$bookmark = Bookmark::get(
$this->dbi,
$GLOBALS['cfg']['Server']['user'],
$GLOBALS['db'],
$id_bookmark
);
if (! $bookmark instanceof Bookmark) {
break;
}
$bookmark->delete();
if ($this->response->isAjax()) {
$message = Message::success(
$GLOBALS['message'] = Message::success(
__('The bookmark has been deleted.')
);
$this->response->setRequestStatus($message->isSuccess());
$this->response->addJSON('message', $message);
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
$this->response->addJSON('message', $GLOBALS['message']);
$this->response->addJSON('action_bookmark', $_POST['action_bookmark']);
$this->response->addJSON('id_bookmark', $id_bookmark);
return;
} else {
$run_query = false;
$error = true; // this is kind of hack to skip processing the query
$GLOBALS['run_query'] = false;
$GLOBALS['error'] = true; // this is kind of hack to skip processing the query
}
break;
@ -408,70 +418,70 @@ final class ImportController extends AbstractController
}
// Do no run query if we show PHP code
if (isset($show_as_php)) {
$run_query = false;
$go_sql = true;
if (isset($GLOBALS['show_as_php'])) {
$GLOBALS['run_query'] = false;
$GLOBALS['go_sql'] = true;
}
// We can not read all at once, otherwise we can run out of memory
$memory_limit = trim((string) ini_get('memory_limit'));
$GLOBALS['memory_limit'] = trim((string) ini_get('memory_limit'));
// 2 MB as default
if (empty($memory_limit)) {
$memory_limit = 2 * 1024 * 1024;
if (empty($GLOBALS['memory_limit'])) {
$GLOBALS['memory_limit'] = 2 * 1024 * 1024;
}
// In case no memory limit we work on 10MB chunks
if ($memory_limit === '-1') {
$memory_limit = 10 * 1024 * 1024;
if ($GLOBALS['memory_limit'] === '-1') {
$GLOBALS['memory_limit'] = 10 * 1024 * 1024;
}
// Calculate value of the limit
$memoryUnit = mb_strtolower(substr((string) $memory_limit, -1));
$memoryUnit = mb_strtolower(substr((string) $GLOBALS['memory_limit'], -1));
if ($memoryUnit === 'm') {
$memory_limit = (int) substr((string) $memory_limit, 0, -1) * 1024 * 1024;
$GLOBALS['memory_limit'] = (int) substr((string) $GLOBALS['memory_limit'], 0, -1) * 1024 * 1024;
} elseif ($memoryUnit === 'k') {
$memory_limit = (int) substr((string) $memory_limit, 0, -1) * 1024;
$GLOBALS['memory_limit'] = (int) substr((string) $GLOBALS['memory_limit'], 0, -1) * 1024;
} elseif ($memoryUnit === 'g') {
$memory_limit = (int) substr((string) $memory_limit, 0, -1) * 1024 * 1024 * 1024;
$GLOBALS['memory_limit'] = (int) substr((string) $GLOBALS['memory_limit'], 0, -1) * 1024 * 1024 * 1024;
} else {
$memory_limit = (int) $memory_limit;
$GLOBALS['memory_limit'] = (int) $GLOBALS['memory_limit'];
}
// Just to be sure, there might be lot of memory needed for uncompression
$read_limit = $memory_limit / 8;
$GLOBALS['read_limit'] = $GLOBALS['memory_limit'] / 8;
// handle filenames
if (isset($_FILES['import_file'])) {
$import_file = $_FILES['import_file']['tmp_name'];
$import_file_name = $_FILES['import_file']['name'];
$GLOBALS['import_file'] = $_FILES['import_file']['tmp_name'];
$GLOBALS['import_file_name'] = $_FILES['import_file']['name'];
}
if (! empty($local_import_file) && ! empty($cfg['UploadDir'])) {
if (! empty($GLOBALS['local_import_file']) && ! empty($GLOBALS['cfg']['UploadDir'])) {
// sanitize $local_import_file as it comes from a POST
$local_import_file = Core::securePath($local_import_file);
$GLOBALS['local_import_file'] = Core::securePath($GLOBALS['local_import_file']);
$import_file = Util::userDir((string) $cfg['UploadDir'])
. $local_import_file;
$GLOBALS['import_file'] = Util::userDir((string) $GLOBALS['cfg']['UploadDir'])
. $GLOBALS['local_import_file'];
/*
* Do not allow symlinks to avoid security issues
* (user can create symlink to file they can not access,
* but phpMyAdmin can).
*/
if (@is_link($import_file)) {
$import_file = 'none';
if (@is_link($GLOBALS['import_file'])) {
$GLOBALS['import_file'] = 'none';
}
} elseif (empty($import_file) || ! is_uploaded_file($import_file)) {
$import_file = 'none';
} elseif (empty($GLOBALS['import_file']) || ! is_uploaded_file($GLOBALS['import_file'])) {
$GLOBALS['import_file'] = 'none';
}
// Do we have file to import?
if ($import_file !== 'none' && ! $error) {
if ($GLOBALS['import_file'] !== 'none' && ! $GLOBALS['error']) {
/**
* Handle file compression
*/
$importHandle = new File($import_file);
$importHandle = new File($GLOBALS['import_file']);
$importHandle->checkUploadedFile();
if ($importHandle->isError()) {
/** @var Message $errorMessage */
@ -504,8 +514,8 @@ final class ImportController extends AbstractController
return;
}
} elseif (! $error && (! isset($import_text) || empty($import_text))) {
$message = Message::error(
} elseif (! $GLOBALS['error'] && (! isset($GLOBALS['import_text']) || empty($GLOBALS['import_text']))) {
$GLOBALS['message'] = Message::error(
__(
'No data was received to import. Either no file name was ' .
'submitted, or the file size exceeded the maximum size permitted ' .
@ -513,35 +523,38 @@ final class ImportController extends AbstractController
)
);
$_SESSION['Import_message']['message'] = $message->getDisplay();
$_SESSION['Import_message']['message'] = $GLOBALS['message']->getDisplay();
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message->getDisplay());
$this->response->addHTML($message->getDisplay());
$this->response->addJSON('message', $GLOBALS['message']->getDisplay());
$this->response->addHTML($GLOBALS['message']->getDisplay());
return;
}
// Convert the file's charset if necessary
if (Encoding::isSupported() && isset($charset_of_file)) {
if ($charset_of_file !== 'utf-8') {
$charset_conversion = true;
if (Encoding::isSupported() && isset($GLOBALS['charset_of_file'])) {
if ($GLOBALS['charset_of_file'] !== 'utf-8') {
$GLOBALS['charset_conversion'] = true;
}
} elseif (isset($charset_of_file) && $charset_of_file !== 'utf-8') {
$this->dbi->query('SET NAMES \'' . $charset_of_file . '\'');
} elseif (isset($GLOBALS['charset_of_file']) && $GLOBALS['charset_of_file'] !== 'utf-8') {
$this->dbi->query('SET NAMES \'' . $GLOBALS['charset_of_file'] . '\'');
// We can not show query in this case, it is in different charset
$sql_query_disabled = true;
$reset_charset = true;
$GLOBALS['sql_query_disabled'] = true;
$GLOBALS['reset_charset'] = true;
}
// Something to skip? (because timeout has passed)
if (! $error && isset($_POST['skip'])) {
if (! $GLOBALS['error'] && isset($_POST['skip'])) {
$original_skip = $skip = intval($_POST['skip']);
while ($skip > 0 && ! $finished) {
$this->import->getNextChunk($importHandle ?? null, $skip < $read_limit ? $skip : $read_limit);
while ($skip > 0 && ! $GLOBALS['finished']) {
$this->import->getNextChunk(
$importHandle ?? null,
$skip < $GLOBALS['read_limit'] ? $skip : $GLOBALS['read_limit']
);
// Disable read progressivity, otherwise we eat all memory!
$read_multiply = 1;
$skip -= $read_limit;
$GLOBALS['read_multiply'] = 1;
$skip -= $GLOBALS['read_limit'];
}
unset($skip);
@ -549,26 +562,26 @@ final class ImportController extends AbstractController
// This array contain the data like number of valid sql queries in the statement
// and complete valid sql statement (which affected for rows)
$sql_data = [
$GLOBALS['sql_data'] = [
'valid_sql' => [],
'valid_queries' => 0,
];
if (! $error) {
if (! $GLOBALS['error']) {
/**
* @var ImportPlugin $import_plugin
*/
$import_plugin = Plugins::getPlugin('import', $format, $import_type);
$import_plugin = Plugins::getPlugin('import', $GLOBALS['format'], $GLOBALS['import_type']);
if ($import_plugin == null) {
$message = Message::error(
$GLOBALS['message'] = Message::error(
__('Could not load import plugins, please check your installation!')
);
$_SESSION['Import_message']['message'] = $message->getDisplay();
$_SESSION['Import_message']['message'] = $GLOBALS['message']->getDisplay();
$this->response->setRequestStatus(false);
$this->response->addJSON('message', $message->getDisplay());
$this->response->addHTML($message->getDisplay());
$this->response->addJSON('message', $GLOBALS['message']->getDisplay());
$this->response->addHTML($GLOBALS['message']->getDisplay());
return;
}
@ -576,7 +589,7 @@ final class ImportController extends AbstractController
// Do the real import
$default_fk_check = ForeignKey::handleDisableCheckInit();
try {
$import_plugin->doImport($importHandle ?? null, $sql_data);
$import_plugin->doImport($importHandle ?? null, $GLOBALS['sql_data']);
ForeignKey::handleDisableCheckCleanup($default_fk_check);
} catch (Throwable $e) {
ForeignKey::handleDisableCheckCleanup($default_fk_check);
@ -590,66 +603,66 @@ final class ImportController extends AbstractController
}
// Reset charset back, if we did some changes
if ($reset_charset) {
$this->dbi->query('SET CHARACTER SET ' . $charset_connection);
$this->dbi->setCollation($collation_connection);
if ($GLOBALS['reset_charset']) {
$this->dbi->query('SET CHARACTER SET ' . $GLOBALS['charset_connection']);
$this->dbi->setCollation($GLOBALS['collation_connection']);
}
// Show correct message
if (! empty($id_bookmark) && $_POST['action_bookmark'] == 2) {
$message = Message::success(__('The bookmark has been deleted.'));
$display_query = $import_text;
$error = false; // unset error marker, it was used just to skip processing
$GLOBALS['message'] = Message::success(__('The bookmark has been deleted.'));
$GLOBALS['display_query'] = $GLOBALS['import_text'];
$GLOBALS['error'] = false; // unset error marker, it was used just to skip processing
} elseif (! empty($id_bookmark) && $_POST['action_bookmark'] == 1) {
$message = Message::notice(__('Showing bookmark'));
} elseif ($finished && ! $error) {
$GLOBALS['message'] = Message::notice(__('Showing bookmark'));
} elseif ($GLOBALS['finished'] && ! $GLOBALS['error']) {
// Do not display the query with message, we do it separately
$display_query = ';';
if ($import_type !== 'query') {
$message = Message::success(
$GLOBALS['display_query'] = ';';
if ($GLOBALS['import_type'] !== 'query') {
$GLOBALS['message'] = Message::success(
'<em>'
. _ngettext(
'Import has been successfully finished, %d query executed.',
'Import has been successfully finished, %d queries executed.',
$executed_queries
$GLOBALS['executed_queries']
)
. '</em>'
);
$message->addParam($executed_queries);
$GLOBALS['message']->addParam($GLOBALS['executed_queries']);
if (! empty($import_notice)) {
$message->addHtml($import_notice);
if (! empty($GLOBALS['import_notice'])) {
$GLOBALS['message']->addHtml($GLOBALS['import_notice']);
}
if (! empty($local_import_file)) {
$message->addText('(' . $local_import_file . ')');
if (! empty($GLOBALS['local_import_file'])) {
$GLOBALS['message']->addText('(' . $GLOBALS['local_import_file'] . ')');
} else {
$message->addText('(' . $_FILES['import_file']['name'] . ')');
$GLOBALS['message']->addText('(' . $_FILES['import_file']['name'] . ')');
}
}
}
// Did we hit timeout? Tell it user.
if ($timeout_passed) {
$urlParams['timeout_passed'] = '1';
$urlParams['offset'] = $offset;
if (isset($local_import_file)) {
$urlParams['local_import_file'] = $local_import_file;
if ($GLOBALS['timeout_passed']) {
$GLOBALS['urlParams']['timeout_passed'] = '1';
$GLOBALS['urlParams']['offset'] = $GLOBALS['offset'];
if (isset($GLOBALS['local_import_file'])) {
$GLOBALS['urlParams']['local_import_file'] = $GLOBALS['local_import_file'];
}
$importUrl = $errorUrl = $goto . Url::getCommon($urlParams, '&');
$importUrl = $GLOBALS['errorUrl'] = $GLOBALS['goto'] . Url::getCommon($GLOBALS['urlParams'], '&');
$message = Message::error(
$GLOBALS['message'] = Message::error(
__(
'Script timeout passed, if you want to finish import,'
. ' please %sresubmit the same file%s and import will resume.'
)
);
$message->addParamHtml('<a href="' . $importUrl . '">');
$message->addParamHtml('</a>');
$GLOBALS['message']->addParamHtml('<a href="' . $importUrl . '">');
$GLOBALS['message']->addParamHtml('</a>');
if ($offset == 0 || (isset($original_skip) && $original_skip == $offset)) {
$message->addText(
if ($GLOBALS['offset'] == 0 || (isset($original_skip) && $original_skip == $GLOBALS['offset'])) {
$GLOBALS['message']->addText(
__(
'However on last run no data has been parsed,'
. ' this usually means phpMyAdmin won\'t be able to'
@ -661,63 +674,63 @@ final class ImportController extends AbstractController
// if there is any message, copy it into $_SESSION as well,
// so we can obtain it by AJAX call
if (isset($message)) {
$_SESSION['Import_message']['message'] = $message->getDisplay();
if (isset($GLOBALS['message'])) {
$_SESSION['Import_message']['message'] = $GLOBALS['message']->getDisplay();
}
// Parse and analyze the query, for correct db and table name
// in case of a query typed in the query window
// (but if the query is too large, in case of an imported file, the parser
// can choke on it so avoid parsing)
$sqlLength = mb_strlen($sql_query);
if ($sqlLength <= $cfg['MaxCharactersInDisplayedSQL']) {
$sqlLength = mb_strlen($GLOBALS['sql_query']);
if ($sqlLength <= $GLOBALS['cfg']['MaxCharactersInDisplayedSQL']) {
[
$analyzed_sql_results,
$db,
$GLOBALS['db'],
$table_from_sql,
] = ParseAnalyze::sqlQuery($sql_query, $db);
] = ParseAnalyze::sqlQuery($GLOBALS['sql_query'], $GLOBALS['db']);
$reload = $analyzed_sql_results['reload'];
$offset = $analyzed_sql_results['offset'];
$GLOBALS['reload'] = $analyzed_sql_results['reload'];
$GLOBALS['offset'] = $analyzed_sql_results['offset'];
if ($table != $table_from_sql && ! empty($table_from_sql)) {
$table = $table_from_sql;
if ($GLOBALS['table'] != $table_from_sql && ! empty($table_from_sql)) {
$GLOBALS['table'] = $table_from_sql;
}
}
// There was an error?
if (isset($my_die)) {
foreach ($my_die as $die) {
Generator::mysqlDie($die['error'], $die['sql'], false, $errorUrl, $error);
if (isset($GLOBALS['my_die'])) {
foreach ($GLOBALS['my_die'] as $die) {
Generator::mysqlDie($die['error'], $die['sql'], false, $GLOBALS['errorUrl'], $GLOBALS['error']);
}
}
if ($go_sql) {
if (! empty($sql_data) && ($sql_data['valid_queries'] > 1)) {
if ($GLOBALS['go_sql']) {
if (! empty($GLOBALS['sql_data']) && ($GLOBALS['sql_data']['valid_queries'] > 1)) {
$_SESSION['is_multi_query'] = true;
$sql_queries = $sql_data['valid_sql'];
$sql_queries = $GLOBALS['sql_data']['valid_sql'];
} else {
$sql_queries = [$sql_query];
$sql_queries = [$GLOBALS['sql_query']];
}
$html_output = '';
foreach ($sql_queries as $sql_query) {
foreach ($sql_queries as $GLOBALS['sql_query']) {
// parse sql query
[
$analyzed_sql_results,
$db,
$GLOBALS['db'],
$table_from_sql,
] = ParseAnalyze::sqlQuery($sql_query, $db);
] = ParseAnalyze::sqlQuery($GLOBALS['sql_query'], $GLOBALS['db']);
$offset = $analyzed_sql_results['offset'];
$reload = $analyzed_sql_results['reload'];
$GLOBALS['offset'] = $analyzed_sql_results['offset'];
$GLOBALS['reload'] = $analyzed_sql_results['reload'];
// Check if User is allowed to issue a 'DROP DATABASE' Statement
if (
$this->sql->hasNoRightsToDropDatabase(
$analyzed_sql_results,
$cfg['AllowUserDropDatabase'],
$GLOBALS['cfg']['AllowUserDropDatabase'],
$this->dbi->isSuperUser()
)
) {
@ -731,24 +744,24 @@ final class ImportController extends AbstractController
return;
}
if ($table != $table_from_sql && ! empty($table_from_sql)) {
$table = $table_from_sql;
if ($GLOBALS['table'] != $table_from_sql && ! empty($table_from_sql)) {
$GLOBALS['table'] = $table_from_sql;
}
$html_output .= $this->sql->executeQueryAndGetQueryResponse(
$analyzed_sql_results, // analyzed_sql_results
false, // is_gotofile
$db, // db
$table, // table
$GLOBALS['db'], // db
$GLOBALS['table'], // table
null, // find_real_end
null, // sql_query_for_bookmark - see below
null, // extra_data
null, // message_to_show
null, // sql_data
$goto, // goto
$GLOBALS['goto'], // goto
null, // disp_query
null, // disp_message
$sql_query, // sql_query
$GLOBALS['sql_query'], // sql_query
null // complete_query
);
}
@ -756,34 +769,34 @@ final class ImportController extends AbstractController
// sql_query_for_bookmark is not included in Sql::executeQueryAndGetQueryResponse
// since only one bookmark has to be added for all the queries submitted through
// the SQL tab
if (! empty($_POST['bkm_label']) && ! empty($import_text)) {
if (! empty($_POST['bkm_label']) && ! empty($GLOBALS['import_text'])) {
$relation = new Relation($this->dbi);
$this->sql->storeTheQueryAsBookmark(
$relation->getRelationParameters()->bookmarkFeature,
$db,
$cfg['Server']['user'],
$GLOBALS['db'],
$GLOBALS['cfg']['Server']['user'],
$_POST['sql_query'],
$_POST['bkm_label'],
isset($_POST['bkm_replace'])
);
}
$this->response->addJSON('ajax_reload', $ajax_reload);
$this->response->addJSON('ajax_reload', $GLOBALS['ajax_reload']);
$this->response->addHTML($html_output);
return;
}
if ($result) {
if ($GLOBALS['result']) {
// Save a Bookmark with more than one queries (if Bookmark label given).
if (! empty($_POST['bkm_label']) && ! empty($import_text)) {
if (! empty($_POST['bkm_label']) && ! empty($GLOBALS['import_text'])) {
$relation = new Relation($this->dbi);
$this->sql->storeTheQueryAsBookmark(
$relation->getRelationParameters()->bookmarkFeature,
$db,
$cfg['Server']['user'],
$GLOBALS['db'],
$GLOBALS['cfg']['Server']['user'],
$_POST['sql_query'],
$_POST['bkm_label'],
isset($_POST['bkm_replace'])
@ -791,18 +804,18 @@ final class ImportController extends AbstractController
}
$this->response->setRequestStatus(true);
$this->response->addJSON('message', Message::success($msg));
$this->response->addJSON('message', Message::success($GLOBALS['msg']));
$this->response->addJSON(
'sql_query',
Generator::getMessage($msg, $sql_query, 'success')
Generator::getMessage($GLOBALS['msg'], $GLOBALS['sql_query'], 'success')
);
} elseif ($result === false) {
} elseif ($GLOBALS['result'] === false) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', Message::error($msg));
$this->response->addJSON('message', Message::error($GLOBALS['msg']));
} else {
$active_page = $goto;
$GLOBALS['active_page'] = $GLOBALS['goto'];
/** @psalm-suppress UnresolvableInclude */
include ROOT_PATH . $goto;
include ROOT_PATH . $GLOBALS['goto'];
}
// If there is request for ROLLBACK in the end.

View File

@ -32,12 +32,10 @@ class StatusController
public function __invoke(): void
{
global $SESSION_KEY, $upload_id, $plugins, $timestamp;
[
$SESSION_KEY,
$upload_id,
$plugins,
$GLOBALS['SESSION_KEY'],
$GLOBALS['upload_id'],
$GLOBALS['plugins'],
] = Ajax::uploadProgressSetup();
// $_GET["message"] is used for asking for an import message
@ -51,7 +49,7 @@ class StatusController
usleep(300000);
$maximumTime = ini_get('max_execution_time');
$timestamp = time();
$GLOBALS['timestamp'] = time();
// wait until message is available
while (($_SESSION['Import_message']['message'] ?? null) == null) {
// close session before sleeping
@ -61,7 +59,7 @@ class StatusController
// reopen session
session_start();
if (time() - $timestamp > $maximumTime) {
if (time() - $GLOBALS['timestamp'] > $maximumTime) {
$_SESSION['Import_message']['message'] = Message::error(
__('Could not load the progress of the import.')
)->getDisplay();

View File

@ -10,14 +10,12 @@ class LogoutController
{
public function __invoke(): void
{
global $auth_plugin, $token_mismatch;
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST' || $token_mismatch) {
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST' || $GLOBALS['token_mismatch']) {
Core::sendHeaderLocation('./index.php?route=/');
return;
}
$auth_plugin->logOut();
$GLOBALS['auth_plugin']->logOut();
}
}

View File

@ -34,15 +34,13 @@ class NormalizationController extends AbstractController
public function __invoke(): void
{
global $db, $table;
if (isset($_POST['getColumns'])) {
$html = '<option selected disabled>' . __('Select one…') . '</option>'
. '<option value="no_such_col">' . __('No such column') . '</option>';
//get column whose datatype falls under string category
$html .= $this->normalization->getHtmlForColumnsList(
$db,
$table,
$GLOBALS['db'],
$GLOBALS['table'],
_pgettext('string types', 'String')
);
echo $html;
@ -52,8 +50,8 @@ class NormalizationController extends AbstractController
if (isset($_POST['splitColumn'])) {
$num_fields = min(4096, intval($_POST['numFields']));
$html = $this->normalization->getHtmlForCreateNewColumn($num_fields, $db, $table);
$html .= Url::getHiddenInputs($db, $table);
$html = $this->normalization->getHtmlForCreateNewColumn($num_fields, $GLOBALS['db'], $GLOBALS['table']);
$html .= Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
echo $html;
return;
@ -62,18 +60,23 @@ class NormalizationController extends AbstractController
if (isset($_POST['addNewPrimary'])) {
$num_fields = 1;
$columnMeta = [
'Field' => $table . '_id',
'Field' => $GLOBALS['table'] . '_id',
'Extra' => 'auto_increment',
];
$html = $this->normalization->getHtmlForCreateNewColumn($num_fields, $db, $table, $columnMeta);
$html .= Url::getHiddenInputs($db, $table);
$html = $this->normalization->getHtmlForCreateNewColumn(
$num_fields,
$GLOBALS['db'],
$GLOBALS['table'],
$columnMeta
);
$html .= Url::getHiddenInputs($GLOBALS['db'], $GLOBALS['table']);
echo $html;
return;
}
if (isset($_POST['findPdl'])) {
$html = $this->normalization->findPartialDependencies($table, $db);
$html = $this->normalization->findPartialDependencies($GLOBALS['table'], $GLOBALS['db']);
echo $html;
return;
@ -81,7 +84,7 @@ class NormalizationController extends AbstractController
if (isset($_POST['getNewTables2NF'])) {
$partialDependencies = json_decode($_POST['pd'], true);
$html = $this->normalization->getHtmlForNewTables2NF($partialDependencies, $table);
$html = $this->normalization->getHtmlForNewTables2NF($partialDependencies, $GLOBALS['table']);
echo $html;
return;
@ -90,7 +93,7 @@ class NormalizationController extends AbstractController
if (isset($_POST['getNewTables3NF'])) {
$dependencies = json_decode($_POST['pd']);
$tables = json_decode($_POST['tables'], true);
$newTables = $this->normalization->getHtmlForNewTables3NF($dependencies, $tables, $db);
$newTables = $this->normalization->getHtmlForNewTables3NF($dependencies, $tables, $GLOBALS['db']);
$this->response->disable();
Core::headerJSON();
echo json_encode($newTables);
@ -108,7 +111,12 @@ class NormalizationController extends AbstractController
if (isset($_POST['createNewTables2NF'])) {
$partialDependencies = json_decode($_POST['pd'], true);
$tablesName = json_decode($_POST['newTablesName']);
$res = $this->normalization->createNewTablesFor2NF($partialDependencies, $tablesName, $table, $db);
$res = $this->normalization->createNewTablesFor2NF(
$partialDependencies,
$tablesName,
$GLOBALS['table'],
$GLOBALS['db']
);
$this->response->addJSON($res);
return;
@ -116,7 +124,7 @@ class NormalizationController extends AbstractController
if (isset($_POST['createNewTables3NF'])) {
$newtables = json_decode($_POST['newTables'], true);
$res = $this->normalization->createNewTablesFor3NF($newtables, $db);
$res = $this->normalization->createNewTablesFor3NF($newtables, $GLOBALS['db']);
$this->response->addJSON($res);
return;
@ -132,8 +140,8 @@ class NormalizationController extends AbstractController
$primary_columns,
$newTable,
$newColumn,
$table,
$db
$GLOBALS['table'],
$GLOBALS['db']
);
$this->response->addJSON($res);
@ -141,23 +149,23 @@ class NormalizationController extends AbstractController
}
if (isset($_POST['step1'])) {
$html = $this->normalization->getHtmlFor1NFStep1($db, $table, $normalForm);
$html = $this->normalization->getHtmlFor1NFStep1($GLOBALS['db'], $GLOBALS['table'], $normalForm);
$this->response->addHTML($html);
} elseif (isset($_POST['step2'])) {
$res = $this->normalization->getHtmlContentsFor1NFStep2($db, $table);
$res = $this->normalization->getHtmlContentsFor1NFStep2($GLOBALS['db'], $GLOBALS['table']);
$this->response->addJSON($res);
} elseif (isset($_POST['step3'])) {
$res = $this->normalization->getHtmlContentsFor1NFStep3($db, $table);
$res = $this->normalization->getHtmlContentsFor1NFStep3($GLOBALS['db'], $GLOBALS['table']);
$this->response->addJSON($res);
} elseif (isset($_POST['step4'])) {
$res = $this->normalization->getHtmlContentsFor1NFStep4($db, $table);
$res = $this->normalization->getHtmlContentsFor1NFStep4($GLOBALS['db'], $GLOBALS['table']);
$this->response->addJSON($res);
} elseif (isset($_POST['step']) && $_POST['step'] == '2.1') {
$res = $this->normalization->getHtmlFor2NFstep1($db, $table);
$res = $this->normalization->getHtmlFor2NFstep1($GLOBALS['db'], $GLOBALS['table']);
$this->response->addJSON($res);
} elseif (isset($_POST['step']) && $_POST['step'] == '3.1') {
$tables = $_POST['tables'];
$res = $this->normalization->getHtmlFor3NFstep1($db, $tables);
$res = $this->normalization->getHtmlFor3NFstep1($GLOBALS['db'], $tables);
$this->response->addJSON($res);
} else {
$this->response->addHTML($this->normalization->getHtmlForNormalizeTable());

View File

@ -20,12 +20,10 @@ class PhpInfoController extends AbstractController
{
public function __invoke(): void
{
global $cfg;
$this->response->disable();
$this->response->getHeader()->sendHttpHeaders();
if (! $cfg['ShowPhpInfo']) {
if (! $GLOBALS['cfg']['ShowPhpInfo']) {
return;
}

View File

@ -45,14 +45,12 @@ class ExportController extends AbstractController
public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server;
$route = Routing::getCurrentRoute();
$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$formDisplay = new ExportForm($cf, 1);
$formDisplay = new ExportForm($GLOBALS['cf'], 1);
if (isset($_POST['revert'])) {
// revert erroneous fields to their default values
@ -62,25 +60,25 @@ class ExportController extends AbstractController
return;
}
$error = null;
$GLOBALS['error'] = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor($cfg['Server']['user']);
$twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
// save settings
$result = $this->userPreferences->save($cf->getConfigArray());
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {
// reload config
$this->config->loadUserPreferences();
$tabHash = $_POST['tab_hash'] ?? null;
$hash = ltrim($tabHash, '#');
$this->userPreferences->redirect('index.php?route=/preferences/export', null, $hash);
$GLOBALS['tabHash'] = $_POST['tab_hash'] ?? null;
$GLOBALS['hash'] = ltrim($GLOBALS['tabHash'], '#');
$this->userPreferences->redirect('index.php?route=/preferences/export', null, $GLOBALS['hash']);
return;
}
$error = $result;
$GLOBALS['error'] = $result;
}
$this->addScriptFiles(['config.js']);
@ -98,13 +96,13 @@ class ExportController extends AbstractController
}
$this->render('preferences/forms/main', [
'error' => $error ? $error->getDisplay() : '',
'error' => $GLOBALS['error'] ? $GLOBALS['error']->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors ?? null,
'form' => $formDisplay->getDisplay(
true,
Url::getFromRoute('/preferences/export'),
['server' => $server]
['server' => $GLOBALS['server']]
),
]);

View File

@ -45,14 +45,12 @@ class FeaturesController extends AbstractController
public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server;
$route = Routing::getCurrentRoute();
$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$formDisplay = new FeaturesForm($cf, 1);
$formDisplay = new FeaturesForm($GLOBALS['cf'], 1);
if (isset($_POST['revert'])) {
// revert erroneous fields to their default values
@ -62,25 +60,25 @@ class FeaturesController extends AbstractController
return;
}
$error = null;
$GLOBALS['error'] = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor($cfg['Server']['user']);
$twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
// save settings
$result = $this->userPreferences->save($cf->getConfigArray());
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {
// reload config
$this->config->loadUserPreferences();
$tabHash = $_POST['tab_hash'] ?? null;
$hash = ltrim($tabHash, '#');
$this->userPreferences->redirect('index.php?route=/preferences/features', null, $hash);
$GLOBALS['tabHash'] = $_POST['tab_hash'] ?? null;
$GLOBALS['hash'] = ltrim($GLOBALS['tabHash'], '#');
$this->userPreferences->redirect('index.php?route=/preferences/features', null, $GLOBALS['hash']);
return;
}
$error = $result;
$GLOBALS['error'] = $result;
}
$this->addScriptFiles(['config.js']);
@ -98,13 +96,13 @@ class FeaturesController extends AbstractController
}
$this->render('preferences/forms/main', [
'error' => $error ? $error->getDisplay() : '',
'error' => $GLOBALS['error'] ? $GLOBALS['error']->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors ?? null,
'form' => $formDisplay->getDisplay(
true,
Url::getFromRoute('/preferences/features'),
['server' => $server]
['server' => $GLOBALS['server']]
),
]);

View File

@ -45,14 +45,12 @@ class ImportController extends AbstractController
public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server;
$route = Routing::getCurrentRoute();
$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$formDisplay = new ImportForm($cf, 1);
$formDisplay = new ImportForm($GLOBALS['cf'], 1);
if (isset($_POST['revert'])) {
// revert erroneous fields to their default values
@ -62,25 +60,25 @@ class ImportController extends AbstractController
return;
}
$error = null;
$GLOBALS['error'] = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor($cfg['Server']['user']);
$twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
// save settings
$result = $this->userPreferences->save($cf->getConfigArray());
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {
// reload config
$this->config->loadUserPreferences();
$tabHash = $_POST['tab_hash'] ?? null;
$hash = ltrim($tabHash, '#');
$this->userPreferences->redirect('index.php?route=/preferences/import', null, $hash);
$GLOBALS['tabHash'] = $_POST['tab_hash'] ?? null;
$GLOBALS['hash'] = ltrim($GLOBALS['tabHash'], '#');
$this->userPreferences->redirect('index.php?route=/preferences/import', null, $GLOBALS['hash']);
return;
}
$error = $result;
$GLOBALS['error'] = $result;
}
$this->addScriptFiles(['config.js']);
@ -98,13 +96,13 @@ class ImportController extends AbstractController
}
$this->render('preferences/forms/main', [
'error' => $error ? $error->getDisplay() : '',
'error' => $GLOBALS['error'] ? $GLOBALS['error']->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors ?? null,
'form' => $formDisplay->getDisplay(
true,
Url::getFromRoute('/preferences/import'),
['server' => $server]
['server' => $GLOBALS['server']]
),
]);

View File

@ -45,14 +45,12 @@ class MainPanelController extends AbstractController
public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server;
$route = Routing::getCurrentRoute();
$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$formDisplay = new MainForm($cf, 1);
$formDisplay = new MainForm($GLOBALS['cf'], 1);
if (isset($_POST['revert'])) {
// revert erroneous fields to their default values
@ -62,25 +60,25 @@ class MainPanelController extends AbstractController
return;
}
$error = null;
$GLOBALS['error'] = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor($cfg['Server']['user']);
$twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
// save settings
$result = $this->userPreferences->save($cf->getConfigArray());
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {
// reload config
$this->config->loadUserPreferences();
$tabHash = $_POST['tab_hash'] ?? null;
$hash = ltrim($tabHash, '#');
$this->userPreferences->redirect('index.php?route=/preferences/main-panel', null, $hash);
$GLOBALS['tabHash'] = $_POST['tab_hash'] ?? null;
$GLOBALS['hash'] = ltrim($GLOBALS['tabHash'], '#');
$this->userPreferences->redirect('index.php?route=/preferences/main-panel', null, $GLOBALS['hash']);
return;
}
$error = $result;
$GLOBALS['error'] = $result;
}
$this->addScriptFiles(['config.js']);
@ -98,13 +96,13 @@ class MainPanelController extends AbstractController
}
$this->render('preferences/forms/main', [
'error' => $error ? $error->getDisplay() : '',
'error' => $GLOBALS['error'] ? $GLOBALS['error']->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors ?? null,
'form' => $formDisplay->getDisplay(
true,
Url::getFromRoute('/preferences/main-panel'),
['server' => $server]
['server' => $GLOBALS['server']]
),
]);

View File

@ -67,20 +67,17 @@ class ManageController extends AbstractController
public function __invoke(): void
{
global $cf, $error, $filename, $json, $lang;
global $new_config, $return_url, $form_display, $all_ok, $params, $query;
$route = Routing::getCurrentRoute();
$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$error = '';
$GLOBALS['error'] = '';
if (isset($_POST['submit_export'], $_POST['export_type']) && $_POST['export_type'] === 'text_file') {
// export to JSON file
$this->response->disable();
$filename = 'phpMyAdmin-config-' . urlencode(Core::getenv('HTTP_HOST')) . '.json';
Core::downloadHeader($filename, 'application/json');
$GLOBALS['filename'] = 'phpMyAdmin-config-' . urlencode(Core::getenv('HTTP_HOST')) . '.json';
Core::downloadHeader($GLOBALS['filename'], 'application/json');
$settings = $this->userPreferences->load();
echo json_encode($settings['config_data'], JSON_PRETTY_PRINT);
@ -90,8 +87,8 @@ class ManageController extends AbstractController
if (isset($_POST['submit_export'], $_POST['export_type']) && $_POST['export_type'] === 'php_file') {
// export to JSON file
$this->response->disable();
$filename = 'phpMyAdmin-config-' . urlencode(Core::getenv('HTTP_HOST')) . '.php';
Core::downloadHeader($filename, 'application/php');
$GLOBALS['filename'] = 'phpMyAdmin-config-' . urlencode(Core::getenv('HTTP_HOST')) . '.php';
Core::downloadHeader($GLOBALS['filename'], 'application/php');
$settings = $this->userPreferences->load();
echo '/* ' . __('phpMyAdmin configuration snippet') . " */\n\n";
echo '/* ' . __('Paste it to your config.inc.php') . " */\n\n";
@ -113,7 +110,7 @@ class ManageController extends AbstractController
if (isset($_POST['submit_import'])) {
// load from JSON file
$json = '';
$GLOBALS['json'] = '';
if (
isset($_POST['import_type'], $_FILES['import_file'])
&& $_POST['import_type'] === 'text_file'
@ -123,51 +120,51 @@ class ManageController extends AbstractController
$importHandle = new File($_FILES['import_file']['tmp_name']);
$importHandle->checkUploadedFile();
if ($importHandle->isError()) {
$error = $importHandle->getError();
$GLOBALS['error'] = $importHandle->getError();
} else {
// read JSON from uploaded file
$json = $importHandle->getRawContent();
$GLOBALS['json'] = $importHandle->getRawContent();
}
} else {
// read from POST value (json)
$json = $_POST['json'] ?? null;
$GLOBALS['json'] = $_POST['json'] ?? null;
}
// hide header message
$_SESSION['userprefs_autoload'] = true;
$configuration = json_decode($json, true);
$return_url = $_POST['return_url'] ?? null;
$configuration = json_decode($GLOBALS['json'], true);
$GLOBALS['return_url'] = $_POST['return_url'] ?? null;
if (! is_array($configuration)) {
if (! isset($error)) {
$error = __('Could not import configuration');
if (! isset($GLOBALS['error'])) {
$GLOBALS['error'] = __('Could not import configuration');
}
} else {
// sanitize input values: treat them as though
// they came from HTTP POST request
$form_display = new UserFormList($cf);
$new_config = $cf->getFlatDefaultConfig();
$GLOBALS['form_display'] = new UserFormList($GLOBALS['cf']);
$GLOBALS['new_config'] = $GLOBALS['cf']->getFlatDefaultConfig();
if (! empty($_POST['import_merge'])) {
$new_config = array_merge($new_config, $cf->getConfigArray());
$GLOBALS['new_config'] = array_merge($GLOBALS['new_config'], $GLOBALS['cf']->getConfigArray());
}
$new_config = array_merge($new_config, $configuration);
$GLOBALS['new_config'] = array_merge($GLOBALS['new_config'], $configuration);
$_POST_bak = $_POST;
foreach ($new_config as $k => $v) {
foreach ($GLOBALS['new_config'] as $k => $v) {
$_POST[str_replace('/', '-', (string) $k)] = $v;
}
$cf->resetConfigData();
$all_ok = $form_display->process(true, false);
$all_ok = $all_ok && ! $form_display->hasErrors();
$GLOBALS['cf']->resetConfigData();
$GLOBALS['all_ok'] = $GLOBALS['form_display']->process(true, false);
$GLOBALS['all_ok'] = $GLOBALS['all_ok'] && ! $GLOBALS['form_display']->hasErrors();
$_POST = $_POST_bak;
if (! $all_ok && isset($_POST['fix_errors'])) {
$form_display->fixErrors();
$all_ok = true;
if (! $GLOBALS['all_ok'] && isset($_POST['fix_errors'])) {
$GLOBALS['form_display']->fixErrors();
$GLOBALS['all_ok'] = true;
}
if (! $all_ok) {
if (! $GLOBALS['all_ok']) {
// mimic original form and post json in a hidden field
$relationParameters = $this->relation->getRelationParameters();
@ -178,17 +175,17 @@ class ManageController extends AbstractController
]);
echo $this->template->render('preferences/manage/error', [
'form_errors' => $form_display->displayErrors(),
'json' => $json,
'form_errors' => $GLOBALS['form_display']->displayErrors(),
'json' => $GLOBALS['json'],
'import_merge' => $_POST['import_merge'] ?? null,
'return_url' => $return_url,
'return_url' => $GLOBALS['return_url'],
]);
return;
}
// check for ThemeDefault
$params = [];
$GLOBALS['params'] = [];
$tmanager = ThemeManager::getInstance();
if (
isset($configuration['ThemeDefault'])
@ -199,50 +196,50 @@ class ManageController extends AbstractController
$tmanager->setThemeCookie();
}
if (isset($configuration['lang']) && $configuration['lang'] != $lang) {
$params['lang'] = $configuration['lang'];
if (isset($configuration['lang']) && $configuration['lang'] != $GLOBALS['lang']) {
$GLOBALS['params']['lang'] = $configuration['lang'];
}
// save settings
$result = $this->userPreferences->save($cf->getConfigArray());
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
if ($result === true) {
if ($return_url) {
$query = Util::splitURLQuery($return_url);
$return_url = parse_url($return_url, PHP_URL_PATH);
if ($GLOBALS['return_url']) {
$GLOBALS['query'] = Util::splitURLQuery($GLOBALS['return_url']);
$GLOBALS['return_url'] = parse_url($GLOBALS['return_url'], PHP_URL_PATH);
foreach ($query as $q) {
foreach ($GLOBALS['query'] as $q) {
$pos = mb_strpos($q, '=');
$k = mb_substr($q, 0, (int) $pos);
if ($k === 'token') {
continue;
}
$params[$k] = mb_substr($q, $pos + 1);
$GLOBALS['params'][$k] = mb_substr($q, $pos + 1);
}
} else {
$return_url = 'index.php?route=/preferences/manage';
$GLOBALS['return_url'] = 'index.php?route=/preferences/manage';
}
// reload config
$this->config->loadUserPreferences();
$this->userPreferences->redirect($return_url ?? '', $params);
$this->userPreferences->redirect($GLOBALS['return_url'] ?? '', $GLOBALS['params']);
return;
}
$error = $result;
$GLOBALS['error'] = $result;
}
} elseif (isset($_POST['submit_clear'])) {
$result = $this->userPreferences->save([]);
if ($result === true) {
$params = [];
$GLOBALS['params'] = [];
$this->config->removeCookie('pma_collaction_connection');
$this->config->removeCookie('pma_lang');
$this->userPreferences->redirect('index.php?route=/preferences/manage', $params);
$this->userPreferences->redirect('index.php?route=/preferences/manage', $GLOBALS['params']);
return;
} else {
$error = $result;
$GLOBALS['error'] = $result;
}
return;
@ -258,16 +255,16 @@ class ManageController extends AbstractController
'has_config_storage' => $relationParameters->userPreferencesFeature !== null,
]);
if ($error) {
if (! $error instanceof Message) {
$error = Message::error($error);
if ($GLOBALS['error']) {
if (! $GLOBALS['error'] instanceof Message) {
$GLOBALS['error'] = Message::error($GLOBALS['error']);
}
$error->getDisplay();
$GLOBALS['error']->getDisplay();
}
echo $this->template->render('preferences/manage/main', [
'error' => $error,
'error' => $GLOBALS['error'],
'max_upload_size' => $GLOBALS['config']->get('max_upload_size'),
'exists_setup_and_not_exists_config' => @file_exists(ROOT_PATH . 'setup/index.php')
&& ! @file_exists(CONFIG_FILE),

View File

@ -45,14 +45,12 @@ class NavigationController extends AbstractController
public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server;
$route = Routing::getCurrentRoute();
$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$formDisplay = new NaviForm($cf, 1);
$formDisplay = new NaviForm($GLOBALS['cf'], 1);
if (isset($_POST['revert'])) {
// revert erroneous fields to their default values
@ -62,25 +60,25 @@ class NavigationController extends AbstractController
return;
}
$error = null;
$GLOBALS['error'] = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor($cfg['Server']['user']);
$twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
// save settings
$result = $this->userPreferences->save($cf->getConfigArray());
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {
// reload config
$this->config->loadUserPreferences();
$tabHash = $_POST['tab_hash'] ?? null;
$hash = ltrim($tabHash, '#');
$this->userPreferences->redirect('index.php?route=/preferences/navigation', null, $hash);
$GLOBALS['tabHash'] = $_POST['tab_hash'] ?? null;
$GLOBALS['hash'] = ltrim($GLOBALS['tabHash'], '#');
$this->userPreferences->redirect('index.php?route=/preferences/navigation', null, $GLOBALS['hash']);
return;
}
$error = $result;
$GLOBALS['error'] = $result;
}
$this->addScriptFiles(['config.js']);
@ -98,13 +96,13 @@ class NavigationController extends AbstractController
}
$this->render('preferences/forms/main', [
'error' => $error ? $error->getDisplay() : '',
'error' => $GLOBALS['error'] ? $GLOBALS['error']->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors ?? null,
'form' => $formDisplay->getDisplay(
true,
Url::getFromRoute('/preferences/navigation'),
['server' => $server]
['server' => $GLOBALS['server']]
),
]);

View File

@ -45,14 +45,12 @@ class SqlController extends AbstractController
public function __invoke(): void
{
global $cfg, $cf, $error, $tabHash, $hash, $server;
$route = Routing::getCurrentRoute();
$cf = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($cf);
$GLOBALS['cf'] = new ConfigFile($this->config->baseSettings);
$this->userPreferences->pageInit($GLOBALS['cf']);
$formDisplay = new SqlForm($cf, 1);
$formDisplay = new SqlForm($GLOBALS['cf'], 1);
if (isset($_POST['revert'])) {
// revert erroneous fields to their default values
@ -62,25 +60,25 @@ class SqlController extends AbstractController
return;
}
$error = null;
$GLOBALS['error'] = null;
if ($formDisplay->process(false) && ! $formDisplay->hasErrors()) {
// Load 2FA settings
$twoFactor = new TwoFactor($cfg['Server']['user']);
$twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
// save settings
$result = $this->userPreferences->save($cf->getConfigArray());
$result = $this->userPreferences->save($GLOBALS['cf']->getConfigArray());
// save back the 2FA setting only
$twoFactor->save();
if ($result === true) {
// reload config
$this->config->loadUserPreferences();
$tabHash = $_POST['tab_hash'] ?? null;
$hash = ltrim($tabHash, '#');
$this->userPreferences->redirect('index.php?route=/preferences/sql', null, $hash);
$GLOBALS['tabHash'] = $_POST['tab_hash'] ?? null;
$GLOBALS['hash'] = ltrim($GLOBALS['tabHash'], '#');
$this->userPreferences->redirect('index.php?route=/preferences/sql', null, $GLOBALS['hash']);
return;
}
$error = $result;
$GLOBALS['error'] = $result;
}
$this->addScriptFiles(['config.js']);
@ -98,13 +96,13 @@ class SqlController extends AbstractController
}
$this->render('preferences/forms/main', [
'error' => $error ? $error->getDisplay() : '',
'error' => $GLOBALS['error'] ? $GLOBALS['error']->getDisplay() : '',
'has_errors' => $formDisplay->hasErrors(),
'errors' => $formErrors ?? null,
'form' => $formDisplay->getDisplay(
true,
Url::getFromRoute('/preferences/sql'),
['server' => $server]
['server' => $GLOBALS['server']]
),
]);

View File

@ -28,8 +28,6 @@ class TwoFactorController extends AbstractController
public function __invoke(): void
{
global $cfg;
$route = Routing::getCurrentRoute();
$relationParameters = $this->relation->getRelationParameters();
@ -40,7 +38,7 @@ class TwoFactorController extends AbstractController
'has_config_storage' => $relationParameters->userPreferencesFeature !== null,
]);
$twoFactor = new TwoFactor($cfg['Server']['user']);
$twoFactor = new TwoFactor($GLOBALS['cfg']['Server']['user']);
if (isset($_POST['2fa_remove'])) {
if (! $twoFactor->check(true)) {

View File

@ -43,14 +43,12 @@ class BinlogController extends AbstractController
public function __invoke(): void
{
global $cfg, $errorUrl;
$params = [
'log' => $_POST['log'] ?? null,
'pos' => $_POST['pos'] ?? null,
'is_full_query' => $_POST['is_full_query'] ?? null,
];
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');
@ -69,7 +67,7 @@ class BinlogController extends AbstractController
$urlParams['is_full_query'] = 1;
}
$sqlQuery = $this->getSqlQuery($params['log'] ?? '', $position, (int) $cfg['MaxRows']);
$sqlQuery = $this->getSqlQuery($params['log'] ?? '', $position, (int) $GLOBALS['cfg']['MaxRows']);
$result = $this->dbi->query($sqlQuery);
$numRows = $result->numRows();
@ -79,8 +77,8 @@ class BinlogController extends AbstractController
$nextParams = $urlParams;
if ($position > 0) {
$fullQueriesParams['pos'] = $position;
if ($position > $cfg['MaxRows']) {
$previousParams['pos'] = $position - $cfg['MaxRows'];
if ($position > $GLOBALS['cfg']['MaxRows']) {
$previousParams['pos'] = $position - $GLOBALS['cfg']['MaxRows'];
}
}
@ -89,8 +87,8 @@ class BinlogController extends AbstractController
unset($fullQueriesParams['is_full_query']);
}
if ($numRows >= $cfg['MaxRows']) {
$nextParams['pos'] = $position + $cfg['MaxRows'];
if ($numRows >= $GLOBALS['cfg']['MaxRows']) {
$nextParams['pos'] = $position + $GLOBALS['cfg']['MaxRows'];
}
$values = $result->fetchAllAssoc();
@ -102,7 +100,7 @@ class BinlogController extends AbstractController
'sql_message' => Generator::getMessage(Message::success(), $sqlQuery),
'values' => $values,
'has_previous' => $position > 0,
'has_next' => $numRows >= $cfg['MaxRows'],
'has_next' => $numRows >= $GLOBALS['cfg']['MaxRows'],
'previous_params' => $previousParams,
'full_queries_params' => $fullQueriesParams,
'next_params' => $nextParams,

View File

@ -38,20 +38,16 @@ class CollationsController extends AbstractController
?array $charsets = null,
?array $collations = null
) {
global $cfg;
parent::__construct($response, $template);
$this->dbi = $dbi;
$this->charsets = $charsets ?? Charsets::getCharsets($this->dbi, $cfg['Server']['DisableIS']);
$this->collations = $collations ?? Charsets::getCollations($this->dbi, $cfg['Server']['DisableIS']);
$this->charsets = $charsets ?? Charsets::getCharsets($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$this->collations = $collations ?? Charsets::getCollations($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
}
public function __invoke(): void
{
global $errorUrl;
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -34,8 +34,6 @@ final class CreateController extends AbstractController
public function __invoke(): void
{
global $cfg, $db;
$params = [
'new_db' => $_POST['new_db'] ?? null,
'db_collation' => $_POST['db_collation'] ?? null,
@ -58,8 +56,8 @@ final class CreateController extends AbstractController
$sqlQuery = 'CREATE DATABASE ' . Util::backquote($params['new_db']);
if (! empty($params['db_collation'])) {
[$databaseCharset] = explode('_', $params['db_collation']);
$charsets = Charsets::getCharsets($this->dbi, $cfg['Server']['DisableIS']);
$collations = Charsets::getCollations($this->dbi, $cfg['Server']['DisableIS']);
$charsets = Charsets::getCharsets($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$collations = Charsets::getCollations($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
if (
array_key_exists($databaseCharset, $charsets)
&& array_key_exists($params['db_collation'], $collations[$databaseCharset])
@ -75,19 +73,19 @@ final class CreateController extends AbstractController
if (! $result) {
// avoid displaying the not-created db name in header or navi panel
$db = '';
$GLOBALS['db'] = '';
$message = Message::rawError($this->dbi->getError());
$json = ['message' => $message];
$this->response->setRequestStatus(false);
} else {
$db = $params['new_db'];
$GLOBALS['db'] = $params['new_db'];
$message = Message::success(__('Database %1$s has been created.'));
$message->addParam($params['new_db']);
$scriptName = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$scriptName = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$json = [
'message' => $message,

View File

@ -45,13 +45,11 @@ final class DestroyController extends AbstractController
public function __invoke(): void
{
global $selected, $errorUrl, $cfg, $dblist, $reload;
$selected_dbs = $_POST['selected_dbs'] ?? null;
if (
! $this->response->isAjax()
|| (! $this->dbi->isSuperUser() && ! $cfg['AllowUserDropDatabase'])
|| (! $this->dbi->isSuperUser() && ! $GLOBALS['cfg']['AllowUserDropDatabase'])
) {
$message = Message::error();
$json = ['message' => $message];
@ -73,20 +71,20 @@ final class DestroyController extends AbstractController
return;
}
$errorUrl = Url::getFromRoute('/server/databases');
$selected = $selected_dbs;
$GLOBALS['errorUrl'] = Url::getFromRoute('/server/databases');
$GLOBALS['selected'] = $selected_dbs;
$numberOfDatabases = count($selected_dbs);
foreach ($selected_dbs as $database) {
$this->relationCleanup->database($database);
$aQuery = 'DROP DATABASE ' . Util::backquote($database);
$reload = true;
$GLOBALS['reload'] = true;
$this->dbi->query($aQuery);
$this->transformations->clear($database);
}
$dblist->databases->build();
$GLOBALS['dblist']->databases->build();
$message = Message::success(
_ngettext(

View File

@ -76,9 +76,6 @@ class DatabasesController extends AbstractController
public function __invoke(): void
{
global $cfg, $server, $dblist, $is_create_db_priv;
global $db_to_create, $text_dir, $errorUrl;
$params = [
'statistics' => $_REQUEST['statistics'] ?? null,
'pos' => $_REQUEST['pos'] ?? null,
@ -87,7 +84,7 @@ class DatabasesController extends AbstractController
];
$this->addScriptFiles(['server/databases.js']);
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');
@ -106,7 +103,7 @@ class DatabasesController extends AbstractController
/**
* Gets the databases list
*/
if ($server > 0) {
if ($GLOBALS['server'] > 0) {
$this->databases = $this->dbi->getDatabasesFull(
null,
$this->hasStatistics,
@ -116,7 +113,7 @@ class DatabasesController extends AbstractController
$this->position,
true
);
$this->databaseCount = count($dblist->databases);
$this->databaseCount = count($GLOBALS['dblist']->databases);
}
$urlParams = [
@ -129,9 +126,9 @@ class DatabasesController extends AbstractController
$databases = $this->getDatabases($primaryInfo, $replicaInfo);
$charsetsList = [];
if ($cfg['ShowCreateDb'] && $is_create_db_priv) {
$charsets = Charsets::getCharsets($this->dbi, $cfg['Server']['DisableIS']);
$collations = Charsets::getCollations($this->dbi, $cfg['Server']['DisableIS']);
if ($GLOBALS['cfg']['ShowCreateDb'] && $GLOBALS['is_create_db_priv']) {
$charsets = Charsets::getCharsets($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$collations = Charsets::getCollations($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$serverCollation = $this->dbi->getServerCollation();
foreach ($charsets as $charset) {
$collationsList = [];
@ -154,10 +151,10 @@ class DatabasesController extends AbstractController
$headerStatistics = $this->getStatisticsColumns();
$this->render('server/databases/index', [
'is_create_database_shown' => $cfg['ShowCreateDb'],
'has_create_database_privileges' => $is_create_db_priv,
'is_create_database_shown' => $GLOBALS['cfg']['ShowCreateDb'],
'has_create_database_privileges' => $GLOBALS['is_create_db_priv'],
'has_statistics' => $this->hasStatistics,
'database_to_create' => $db_to_create,
'database_to_create' => $GLOBALS['db_to_create'],
'databases' => $databases['databases'],
'total_statistics' => $databases['total_statistics'],
'header_statistics' => $headerStatistics,
@ -165,11 +162,11 @@ class DatabasesController extends AbstractController
'database_count' => $this->databaseCount,
'pos' => $this->position,
'url_params' => $urlParams,
'max_db_list' => $cfg['MaxDbList'],
'max_db_list' => $GLOBALS['cfg']['MaxDbList'],
'has_primary_replication' => $primaryInfo['status'],
'has_replica_replication' => $replicaInfo['status'],
'is_drop_allowed' => $this->dbi->isSuperUser() || $cfg['AllowUserDropDatabase'],
'text_dir' => $text_dir,
'is_drop_allowed' => $this->dbi->isSuperUser() || $GLOBALS['cfg']['AllowUserDropDatabase'],
'text_dir' => $GLOBALS['text_dir'],
]);
}
@ -216,8 +213,6 @@ class DatabasesController extends AbstractController
*/
private function getDatabases($primaryInfo, $replicaInfo): array
{
global $cfg;
$databases = [];
$totalStatistics = $this->getStatisticsColumns();
foreach ($this->databases as $database) {
@ -260,7 +255,7 @@ class DatabasesController extends AbstractController
}
}
$url = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$url = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$url .= Url::getCommonRaw(
['db' => $database['SCHEMA_NAME']],
! str_contains($url, '?') ? '?' : '&'
@ -271,12 +266,12 @@ class DatabasesController extends AbstractController
'statistics' => $statistics,
'replication' => $replication,
'is_system_schema' => Utilities::isSystemSchema($database['SCHEMA_NAME'], true),
'is_pmadb' => $database['SCHEMA_NAME'] === ($cfg['Server']['pmadb'] ?? ''),
'is_pmadb' => $database['SCHEMA_NAME'] === ($GLOBALS['cfg']['Server']['pmadb'] ?? ''),
'url' => $url,
];
$collation = Charsets::findCollationByName(
$this->dbi,
$cfg['Server']['DisableIS'],
$GLOBALS['cfg']['Server']['DisableIS'],
$database['DEFAULT_COLLATION_NAME']
);
if ($collation === null) {

View File

@ -27,9 +27,7 @@ class EnginesController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -34,10 +34,7 @@ final class ExportController extends AbstractController
public function __invoke(): void
{
global $db, $table, $sql_query, $num_tables, $unlim_num_rows;
global $tmp_select, $select_item, $errorUrl;
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');
@ -49,19 +46,19 @@ final class ExportController extends AbstractController
$this->addScriptFiles(['export.js']);
$select_item = $tmp_select ?? '';
$databases = $this->export->getDatabasesForSelectOptions($select_item);
$GLOBALS['select_item'] = $GLOBALS['tmp_select'] ?? '';
$databases = $this->export->getDatabasesForSelectOptions($GLOBALS['select_item']);
if (! isset($sql_query)) {
$sql_query = '';
if (! isset($GLOBALS['sql_query'])) {
$GLOBALS['sql_query'] = '';
}
if (! isset($num_tables)) {
$num_tables = 0;
if (! isset($GLOBALS['num_tables'])) {
$GLOBALS['num_tables'] = 0;
}
if (! isset($unlim_num_rows)) {
$unlim_num_rows = 0;
if (! isset($GLOBALS['unlim_num_rows'])) {
$GLOBALS['unlim_num_rows'] = 0;
}
$GLOBALS['single_table'] = $_POST['single_table'] ?? $_GET['single_table'] ?? $GLOBALS['single_table'] ?? null;
@ -78,11 +75,11 @@ final class ExportController extends AbstractController
$options = $this->export->getOptions(
'server',
$db,
$table,
$sql_query,
$num_tables,
$unlim_num_rows,
$GLOBALS['db'],
$GLOBALS['table'],
$GLOBALS['sql_query'],
$GLOBALS['num_tables'],
$GLOBALS['unlim_num_rows'],
$exportList
);

View File

@ -36,20 +36,18 @@ final class ImportController extends AbstractController
public function __invoke(): void
{
global $db, $table, $SESSION_KEY, $cfg, $errorUrl;
$pageSettings = new PageSettings('Import');
$pageSettingsErrorHtml = $pageSettings->getErrorHTML();
$pageSettingsHtml = $pageSettings->getHTML();
$this->addScriptFiles(['import.js']);
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');
}
[$SESSION_KEY, $uploadId] = Ajax::uploadProgressSetup();
[$GLOBALS['SESSION_KEY'], $uploadId] = Ajax::uploadProgressSetup();
$importList = Plugins::getImport('server');
@ -70,9 +68,9 @@ final class ImportController extends AbstractController
$localImportFile = $_REQUEST['local_import_file'] ?? null;
$compressions = Import::getCompressions();
$charsets = Charsets::getCharsets($this->dbi, $cfg['Server']['DisableIS']);
$charsets = Charsets::getCharsets($this->dbi, $GLOBALS['cfg']['Server']['DisableIS']);
$idKey = $_SESSION[$SESSION_KEY]['handler']::getIdKey();
$idKey = $_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getIdKey();
$hiddenInputs = [
$idKey => $uploadId,
'import_type' => 'server',
@ -89,10 +87,10 @@ final class ImportController extends AbstractController
'page_settings_error_html' => $pageSettingsErrorHtml,
'page_settings_html' => $pageSettingsHtml,
'upload_id' => $uploadId,
'handler' => $_SESSION[$SESSION_KEY]['handler'],
'handler' => $_SESSION[$GLOBALS['SESSION_KEY']]['handler'],
'hidden_inputs' => $hiddenInputs,
'db' => $db,
'table' => $table,
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'max_upload_size' => $maxUploadSize,
'formatted_maximum_upload_size' => Util::getFormattedMaximumUploadSize($maxUploadSize),
'plugins_choice' => $choice,
@ -101,18 +99,18 @@ final class ImportController extends AbstractController
'is_allow_interrupt_checked' => $isAllowInterruptChecked,
'local_import_file' => $localImportFile,
'is_upload' => $GLOBALS['config']->get('enable_upload'),
'upload_dir' => $cfg['UploadDir'] ?? null,
'upload_dir' => $GLOBALS['cfg']['UploadDir'] ?? null,
'timeout_passed_global' => $GLOBALS['timeout_passed'] ?? null,
'compressions' => $compressions,
'is_encoding_supported' => Encoding::isSupported(),
'encodings' => Encoding::listEncodings(),
'import_charset' => $cfg['Import']['charset'] ?? null,
'import_charset' => $GLOBALS['cfg']['Import']['charset'] ?? null,
'timeout_passed' => $timeoutPassed,
'offset' => $offset,
'can_convert_kanji' => Encoding::canConvertKanji(),
'charsets' => $charsets,
'is_foreign_key_check' => ForeignKey::isCheckEnabled(),
'user_upload_dir' => Util::userDir((string) ($cfg['UploadDir'] ?? '')),
'user_upload_dir' => Util::userDir((string) ($GLOBALS['cfg']['UploadDir'] ?? '')),
'local_files' => Import::getLocalFiles($importList),
]);
}

View File

@ -40,9 +40,7 @@ class PluginsController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -56,12 +56,6 @@ class PrivilegesController extends AbstractController
public function __invoke(): void
{
global $db, $errorUrl, $message, $text_dir, $post_patterns;
global $username, $hostname, $dbname, $tablename, $routinename, $db_and_table, $dbname_is_wildcard;
global $queries, $password, $ret_message, $ret_queries, $queries_for_display, $sql_query, $_add_user_error;
global $itemType, $tables, $num_tables, $total_num_tables, $sub_part;
global $tooltip_truename, $tooltip_aliasname, $pos, $title, $export, $grants, $one_grant, $url_dbname;
$checkUserPrivileges = new CheckUserPrivileges($this->dbi);
$checkUserPrivileges->getPrivileges();
@ -97,32 +91,32 @@ class PrivilegesController extends AbstractController
/**
* Sets globals from $_POST patterns, for privileges and max_* vars
*/
$post_patterns = [
$GLOBALS['post_patterns'] = [
'/_priv$/i',
'/^max_/i',
];
Core::setPostAsGlobal($post_patterns);
Core::setPostAsGlobal($GLOBALS['post_patterns']);
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');
}
$_add_user_error = false;
$GLOBALS['_add_user_error'] = false;
/**
* Get DB information: username, hostname, dbname,
* tablename, db_and_table, dbname_is_wildcard
*/
[
$username,
$hostname,
$dbname,
$tablename,
$routinename,
$db_and_table,
$dbname_is_wildcard,
$GLOBALS['username'],
$GLOBALS['hostname'],
$GLOBALS['dbname'],
$GLOBALS['tablename'],
$GLOBALS['routinename'],
$GLOBALS['db_and_table'],
$GLOBALS['dbname_is_wildcard'],
] = $serverPrivileges->getDataForDBInfo();
/**
@ -155,8 +149,8 @@ class PrivilegesController extends AbstractController
* only to update the password
*/
if (
isset($_POST['change_copy']) && $username == $_POST['old_username']
&& $hostname == $_POST['old_hostname']
isset($_POST['change_copy']) && $GLOBALS['username'] == $_POST['old_username']
&& $GLOBALS['hostname'] == $_POST['old_hostname']
) {
$this->response->addHTML(
Message::error(
@ -175,71 +169,75 @@ class PrivilegesController extends AbstractController
/**
* Changes / copies a user, part I
*/
[$queries, $password] = $serverPrivileges->getDataForChangeOrCopyUser();
[$GLOBALS['queries'], $GLOBALS['password']] = $serverPrivileges->getDataForChangeOrCopyUser();
/**
* Adds a user
* (Changes / copies a user, part II)
*/
[
$ret_message,
$ret_queries,
$queries_for_display,
$sql_query,
$_add_user_error,
$GLOBALS['ret_message'],
$GLOBALS['ret_queries'],
$GLOBALS['queries_for_display'],
$GLOBALS['sql_query'],
$GLOBALS['_add_user_error'],
] = $serverPrivileges->addUser(
$dbname ?? null,
$username ?? '',
$hostname ?? '',
$password ?? null,
$GLOBALS['dbname'] ?? null,
$GLOBALS['username'] ?? '',
$GLOBALS['hostname'] ?? '',
$GLOBALS['password'] ?? null,
$relationParameters->configurableMenusFeature !== null
);
//update the old variables
if (isset($ret_queries)) {
$queries = $ret_queries;
unset($ret_queries);
if (isset($GLOBALS['ret_queries'])) {
$GLOBALS['queries'] = $GLOBALS['ret_queries'];
unset($GLOBALS['ret_queries']);
}
if (isset($ret_message)) {
$message = $ret_message;
unset($ret_message);
if (isset($GLOBALS['ret_message'])) {
$GLOBALS['message'] = $GLOBALS['ret_message'];
unset($GLOBALS['ret_message']);
}
/**
* Changes / copies a user, part III
*/
if (isset($_POST['change_copy']) && $username !== null && $hostname !== null) {
$queries = $serverPrivileges->getDbSpecificPrivsQueriesForChangeOrCopyUser($queries, $username, $hostname);
if (isset($_POST['change_copy']) && $GLOBALS['username'] !== null && $GLOBALS['hostname'] !== null) {
$GLOBALS['queries'] = $serverPrivileges->getDbSpecificPrivsQueriesForChangeOrCopyUser(
$GLOBALS['queries'],
$GLOBALS['username'],
$GLOBALS['hostname']
);
}
$itemType = '';
if (! empty($routinename) && is_string($dbname)) {
$itemType = $serverPrivileges->getRoutineType($dbname, $routinename);
$GLOBALS['itemType'] = '';
if (! empty($GLOBALS['routinename']) && is_string($GLOBALS['dbname'])) {
$GLOBALS['itemType'] = $serverPrivileges->getRoutineType($GLOBALS['dbname'], $GLOBALS['routinename']);
}
/**
* Updates privileges
*/
if (! empty($_POST['update_privs'])) {
if (is_array($dbname)) {
foreach ($dbname as $key => $db_name) {
[$sql_query[$key], $message] = $serverPrivileges->updatePrivileges(
($username ?? ''),
($hostname ?? ''),
($tablename ?? ($routinename ?? '')),
if (is_array($GLOBALS['dbname'])) {
foreach ($GLOBALS['dbname'] as $key => $db_name) {
[$GLOBALS['sql_query'][$key], $GLOBALS['message']] = $serverPrivileges->updatePrivileges(
($GLOBALS['username'] ?? ''),
($GLOBALS['hostname'] ?? ''),
($GLOBALS['tablename'] ?? ($GLOBALS['routinename'] ?? '')),
($db_name ?? ''),
$itemType
$GLOBALS['itemType']
);
}
$sql_query = implode("\n", $sql_query);
$GLOBALS['sql_query'] = implode("\n", $GLOBALS['sql_query']);
} else {
[$sql_query, $message] = $serverPrivileges->updatePrivileges(
($username ?? ''),
($hostname ?? ''),
($tablename ?? ($routinename ?? '')),
($dbname ?? ''),
$itemType
[$GLOBALS['sql_query'], $GLOBALS['message']] = $serverPrivileges->updatePrivileges(
($GLOBALS['username'] ?? ''),
($GLOBALS['hostname'] ?? ''),
($GLOBALS['tablename'] ?? ($GLOBALS['routinename'] ?? '')),
($GLOBALS['dbname'] ?? ''),
$GLOBALS['itemType']
);
}
}
@ -251,20 +249,20 @@ class PrivilegesController extends AbstractController
! empty($_POST['changeUserGroup']) && $relationParameters->configurableMenusFeature !== null
&& $this->dbi->isSuperUser() && $this->dbi->isCreateUser()
) {
$serverPrivileges->setUserGroup($username ?? '', $_POST['userGroup']);
$message = Message::success();
$serverPrivileges->setUserGroup($GLOBALS['username'] ?? '', $_POST['userGroup']);
$GLOBALS['message'] = Message::success();
}
/**
* Revokes Privileges
*/
if (isset($_POST['revokeall'])) {
[$message, $sql_query] = $serverPrivileges->getMessageAndSqlQueryForPrivilegesRevoke(
(is_string($dbname) ? $dbname : ''),
($tablename ?? ($routinename ?? '')),
$username ?? '',
$hostname ?? '',
$itemType
[$GLOBALS['message'], $GLOBALS['sql_query']] = $serverPrivileges->getMessageAndSqlQueryForPrivilegesRevoke(
(is_string($GLOBALS['dbname']) ? $GLOBALS['dbname'] : ''),
($GLOBALS['tablename'] ?? ($GLOBALS['routinename'] ?? '')),
$GLOBALS['username'] ?? '',
$GLOBALS['hostname'] ?? '',
$GLOBALS['itemType']
);
}
@ -272,7 +270,11 @@ class PrivilegesController extends AbstractController
* Updates the password
*/
if (isset($_POST['change_pw'])) {
$message = $serverPrivileges->updatePassword($errorUrl, $username ?? '', $hostname ?? '');
$GLOBALS['message'] = $serverPrivileges->updatePassword(
$GLOBALS['errorUrl'],
$GLOBALS['username'] ?? '',
$GLOBALS['hostname'] ?? ''
);
}
/**
@ -280,9 +282,9 @@ class PrivilegesController extends AbstractController
* (Changes / copies a user, part IV)
*/
if (isset($_POST['delete']) || (isset($_POST['change_copy']) && $_POST['mode'] < 4)) {
$queries = $serverPrivileges->getDataForDeleteUsers($queries);
$GLOBALS['queries'] = $serverPrivileges->getDataForDeleteUsers($GLOBALS['queries']);
if (empty($_POST['change_copy'])) {
[$sql_query, $message] = $serverPrivileges->deleteUser($queries);
[$GLOBALS['sql_query'], $GLOBALS['message']] = $serverPrivileges->deleteUser($GLOBALS['queries']);
}
}
@ -290,9 +292,12 @@ class PrivilegesController extends AbstractController
* Changes / copies a user, part V
*/
if (isset($_POST['change_copy'])) {
$queries = $serverPrivileges->getDataForQueries($queries, $queries_for_display);
$message = Message::success();
$sql_query = implode("\n", $queries);
$GLOBALS['queries'] = $serverPrivileges->getDataForQueries(
$GLOBALS['queries'],
$GLOBALS['queries_for_display']
);
$GLOBALS['message'] = Message::success();
$GLOBALS['sql_query'] = implode("\n", $GLOBALS['queries']);
}
/**
@ -300,7 +305,7 @@ class PrivilegesController extends AbstractController
*/
$message_ret = $serverPrivileges->updateMessageForReload();
if ($message_ret !== null) {
$message = $message_ret;
$GLOBALS['message'] = $message_ret;
unset($message_ret);
}
@ -318,15 +323,15 @@ class PrivilegesController extends AbstractController
&& ! isset($_GET['showall'])
) {
$extra_data = $serverPrivileges->getExtraDataForAjaxBehavior(
($password ?? ''),
($sql_query ?? ''),
($hostname ?? ''),
($username ?? '')
($GLOBALS['password'] ?? ''),
($GLOBALS['sql_query'] ?? ''),
($GLOBALS['hostname'] ?? ''),
($GLOBALS['username'] ?? '')
);
if (! empty($message) && $message instanceof Message) {
$this->response->setRequestStatus($message->isSuccess());
$this->response->addJSON('message', $message);
if (! empty($GLOBALS['message']) && $GLOBALS['message'] instanceof Message) {
$this->response->setRequestStatus($GLOBALS['message']->isSuccess());
$this->response->addJSON('message', $GLOBALS['message']);
$this->response->addJSON($extra_data);
return;
@ -337,21 +342,21 @@ class PrivilegesController extends AbstractController
* Displays the links
*/
if (isset($_GET['viewing_mode']) && $_GET['viewing_mode'] === 'db') {
$db = $_REQUEST['db'] = $_GET['checkprivsdb'];
$GLOBALS['db'] = $_REQUEST['db'] = $_GET['checkprivsdb'];
// Gets the database structure
$sub_part = '_structure';
$GLOBALS['sub_part'] = '_structure';
ob_start();
[
$tables,
$num_tables,
$total_num_tables,
$sub_part,,,
$tooltip_truename,
$tooltip_aliasname,
$pos,
] = Util::getDbInfo($db, $sub_part);
$GLOBALS['tables'],
$GLOBALS['num_tables'],
$GLOBALS['total_num_tables'],
$GLOBALS['sub_part'],,,
$GLOBALS['tooltip_truename'],
$GLOBALS['tooltip_aliasname'],
$GLOBALS['pos'],
] = Util::getDbInfo($GLOBALS['db'], $GLOBALS['sub_part']);
$content = ob_get_clean();
$this->response->addHTML($content . "\n");
@ -362,26 +367,29 @@ class PrivilegesController extends AbstractController
// export user definition
if (isset($_GET['export']) || (isset($_POST['submit_mult']) && $_POST['submit_mult'] === 'export')) {
[$title, $export] = $serverPrivileges->getListForExportUserDefinition($username ?? '', $hostname ?? '');
[$GLOBALS['title'], $GLOBALS['export']] = $serverPrivileges->getListForExportUserDefinition(
$GLOBALS['username'] ?? '',
$GLOBALS['hostname'] ?? ''
);
unset($username, $hostname, $grants, $one_grant);
unset($GLOBALS['username'], $GLOBALS['hostname'], $GLOBALS['grants'], $GLOBALS['one_grant']);
if ($this->response->isAjax()) {
$this->response->addJSON('message', $export);
$this->response->addJSON('title', $title);
$this->response->addJSON('message', $GLOBALS['export']);
$this->response->addJSON('title', $GLOBALS['title']);
return;
}
$this->response->addHTML('<h2>' . $title . '</h2>' . $export);
$this->response->addHTML('<h2>' . $GLOBALS['title'] . '</h2>' . $GLOBALS['export']);
}
// Show back the form if an error occurred
if (isset($_GET['adduser']) || $_add_user_error === true) {
if (isset($_GET['adduser']) || $GLOBALS['_add_user_error'] === true) {
// Add user
$this->response->addHTML(
$serverPrivileges->getHtmlForAddUser(Util::escapeMysqlWildcards(is_string($dbname) ? $dbname : ''))
);
$this->response->addHTML($serverPrivileges->getHtmlForAddUser(
Util::escapeMysqlWildcards(is_string($GLOBALS['dbname']) ? $GLOBALS['dbname'] : '')
));
} elseif (isset($_GET['checkprivsdb'])) {
if (isset($_GET['checkprivstable'])) {
$this->response->addHTML($tableController([
@ -390,8 +398,8 @@ class PrivilegesController extends AbstractController
]));
$this->render('export_modal');
} elseif ($this->response->isAjax() === true && empty($_REQUEST['ajax_page_request'])) {
$message = Message::success(__('User has been added.'));
$this->response->addJSON('message', $message);
$GLOBALS['message'] = Message::success(__('User has been added.'));
$this->response->addJSON('message', $GLOBALS['message']);
return;
} else {
@ -399,8 +407,8 @@ class PrivilegesController extends AbstractController
$this->render('export_modal');
}
} else {
if (isset($dbname) && ! is_array($dbname)) {
$url_dbname = urlencode(
if (isset($GLOBALS['dbname']) && ! is_array($GLOBALS['dbname'])) {
$GLOBALS['url_dbname'] = urlencode(
str_replace(
[
'\_',
@ -410,24 +418,24 @@ class PrivilegesController extends AbstractController
'_',
'%',
],
$dbname
$GLOBALS['dbname']
)
);
}
if (! isset($username)) {
if (! isset($GLOBALS['username'])) {
// No username is given --> display the overview
$this->response->addHTML(
$serverPrivileges->getHtmlForUserOverview($text_dir)
$serverPrivileges->getHtmlForUserOverview($GLOBALS['text_dir'])
);
} elseif (! empty($routinename)) {
} elseif (! empty($GLOBALS['routinename'])) {
$this->response->addHTML(
$serverPrivileges->getHtmlForRoutineSpecificPrivileges(
$username,
$hostname ?? '',
is_string($dbname) ? $dbname : '',
$routinename,
Util::escapeMysqlWildcards($url_dbname ?? '')
$GLOBALS['username'],
$GLOBALS['hostname'] ?? '',
is_string($GLOBALS['dbname']) ? $GLOBALS['dbname'] : '',
$GLOBALS['routinename'],
Util::escapeMysqlWildcards($GLOBALS['url_dbname'] ?? '')
)
);
} else {
@ -439,12 +447,12 @@ class PrivilegesController extends AbstractController
$this->response->addHTML(
$serverPrivileges->getHtmlForUserProperties(
$dbname_is_wildcard,
Util::escapeMysqlWildcards($url_dbname ?? ''),
$username,
$hostname ?? '',
$dbname ?? '',
$tablename ?? ''
$GLOBALS['dbname_is_wildcard'],
Util::escapeMysqlWildcards($GLOBALS['url_dbname'] ?? ''),
$GLOBALS['username'],
$GLOBALS['hostname'] ?? '',
$GLOBALS['dbname'] ?? '',
$GLOBALS['tablename'] ?? ''
)
);
}

View File

@ -41,15 +41,13 @@ class ReplicationController extends AbstractController
public function __invoke(): void
{
global $urlParams, $errorUrl;
$params = [
'url_params' => $_POST['url_params'] ?? null,
'primary_configure' => $_POST['primary_configure'] ?? null,
'replica_configure' => $_POST['replica_configure'] ?? null,
'repl_clear_scr' => $_POST['repl_clear_scr'] ?? null,
];
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');
@ -64,7 +62,7 @@ class ReplicationController extends AbstractController
$this->addScriptFiles(['server/privileges.js', 'replication.js', 'vendor/zxcvbn-ts.js']);
if (isset($params['url_params']) && is_array($params['url_params'])) {
$urlParams = $params['url_params'];
$GLOBALS['urlParams'] = $params['url_params'];
}
if ($this->dbi->isSuperUser()) {
@ -93,7 +91,7 @@ class ReplicationController extends AbstractController
}
$this->render('server/replication/index', [
'url_params' => $urlParams,
'url_params' => $GLOBALS['urlParams'],
'is_super_user' => $this->dbi->isSuperUser(),
'error_messages' => $errorMessages,
'is_primary' => $primaryInfo['status'],

View File

@ -32,9 +32,7 @@ final class ShowEngineController extends AbstractController
*/
public function __invoke(ServerRequest $request, array $params): void
{
global $errorUrl;
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -36,8 +36,6 @@ class SqlController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$this->addScriptFiles([
'makegrid.js',
'vendor/jquery/jquery.uitablefilter.js',
@ -48,7 +46,7 @@ class SqlController extends AbstractController
$pageSettings = new PageSettings('Sql');
$this->response->addHTML($pageSettings->getErrorHTML());
$this->response->addHTML($pageSettings->getHTML());
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -34,10 +34,8 @@ final class ChartingDataController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$params = ['requiredData' => $_POST['requiredData'] ?? null];
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -34,15 +34,13 @@ final class GeneralLogController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$params = [
'time_start' => $_POST['time_start'] ?? null,
'time_end' => $_POST['time_end'] ?? null,
'limitTypes' => $_POST['limitTypes'] ?? null,
'removeVariables' => $_POST['removeVariables'] ?? null,
];
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -34,13 +34,11 @@ final class LogVarsController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$params = [
'varName' => $_POST['varName'] ?? null,
'varValue' => $_POST['varValue'] ?? null,
];
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -34,13 +34,11 @@ final class QueryAnalyzerController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$params = [
'database' => $_POST['database'] ?? null,
'query' => $_POST['query'] ?? null,
];
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -34,13 +34,11 @@ final class SlowLogController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$params = [
'time_start' => $_POST['time_start'] ?? null,
'time_end' => $_POST['time_end'] ?? null,
];
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -27,9 +27,7 @@ class MonitorController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -33,8 +33,6 @@ class ProcessesController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$params = [
'showExecuting' => $_POST['showExecuting'] ?? null,
'full' => $_POST['full'] ?? null,
@ -42,7 +40,7 @@ class ProcessesController extends AbstractController
'order_by_field' => $_POST['order_by_field'] ?? null,
'sort_order' => $_POST['sort_order'] ?? null,
];
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -32,9 +32,7 @@ class QueriesController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -40,9 +40,7 @@ class StatusController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -32,8 +32,6 @@ class VariablesController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$params = [
'flush' => $_POST['flush'] ?? null,
'filterAlert' => $_POST['filterAlert'] ?? null,
@ -41,7 +39,7 @@ class VariablesController extends AbstractController
'filterCategory' => $_POST['filterCategory'] ?? null,
'dontFormat' => $_POST['dontFormat'] ?? null,
];
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -36,10 +36,8 @@ class VariablesController extends AbstractController
public function __invoke(): void
{
global $errorUrl;
$params = ['filter' => $_GET['filter'] ?? null];
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');

View File

@ -38,11 +38,9 @@ final class ColumnPreferencesController extends AbstractController
public function __invoke(): void
{
global $db, $table;
$this->checkUserPrivileges->getPrivileges();
$tableObject = $this->dbi->getTable($db, $table);
$tableObject = $this->dbi->getTable($GLOBALS['db'], $GLOBALS['table']);
$status = false;
// set column order

View File

@ -39,13 +39,11 @@ final class EnumValuesController extends AbstractController
*/
public function __invoke(): void
{
global $db, $table;
$this->checkUserPrivileges->getPrivileges();
$column = $_POST['column'];
$curr_value = $_POST['curr_value'];
$values = $this->sql->getValuesForColumn($db, $table, $column);
$values = $this->sql->getValuesForColumn($GLOBALS['db'], $GLOBALS['table'], $column);
if ($values === null) {
$this->response->addJSON('message', __('Error in processing request'));

View File

@ -36,8 +36,6 @@ final class RelationalValuesController extends AbstractController
*/
public function __invoke(): void
{
global $db, $table;
$this->checkUserPrivileges->getPrivileges();
$column = $_POST['column'];
@ -51,7 +49,12 @@ final class RelationalValuesController extends AbstractController
$curr_value = $_POST['curr_value'];
}
$dropdown = $this->sql->getHtmlForRelationalColumnDropdown($db, $table, $column, $curr_value);
$dropdown = $this->sql->getHtmlForRelationalColumnDropdown(
$GLOBALS['db'],
$GLOBALS['table'],
$column,
$curr_value
);
$this->response->addJSON('dropdown', $dropdown);
}
}

View File

@ -39,8 +39,6 @@ final class SetValuesController extends AbstractController
*/
public function __invoke(): void
{
global $db, $table;
$this->checkUserPrivileges->getPrivileges();
$column = $_POST['column'];
@ -48,7 +46,7 @@ final class SetValuesController extends AbstractController
$fullValues = $_POST['get_full_values'] ?? false;
$whereClause = $_POST['where_clause'] ?? null;
$values = $this->sql->getValuesForColumn($db, $table, $column);
$values = $this->sql->getValuesForColumn($GLOBALS['db'], $GLOBALS['table'], $column);
if ($values === null) {
$this->response->addJSON('message', __('Error in processing request'));
@ -59,7 +57,12 @@ final class SetValuesController extends AbstractController
// If the $currentValue was truncated, we should fetch the correct full values from the table.
if ($fullValues && ! empty($whereClause)) {
$currentValue = $this->sql->getFullValuesForSetColumn($db, $table, $column, $whereClause);
$currentValue = $this->sql->getFullValuesForSetColumn(
$GLOBALS['db'],
$GLOBALS['table'],
$column,
$whereClause
);
}
// Converts characters of $currentValue to HTML entities.

View File

@ -51,11 +51,6 @@ class SqlController extends AbstractController
public function __invoke(): void
{
global $cfg, $db, $display_query, $sql_query, $table;
global $ajax_reload, $goto, $errorUrl, $find_real_end, $unlim_num_rows, $import_text, $disp_query;
global $extra_data, $message_to_show, $sql_data, $disp_message, $complete_query;
global $is_gotofile, $back, $table_from_sql;
$this->checkUserPrivileges->getPrivileges();
$pageSettings = new PageSettings('Browse');
@ -74,59 +69,60 @@ class SqlController extends AbstractController
/**
* Set ajax_reload in the response if it was already set
*/
if (isset($ajax_reload) && $ajax_reload['reload'] === true) {
$this->response->addJSON('ajax_reload', $ajax_reload);
if (isset($GLOBALS['ajax_reload']) && $GLOBALS['ajax_reload']['reload'] === true) {
$this->response->addJSON('ajax_reload', $GLOBALS['ajax_reload']);
}
/**
* Defines the url to return to in case of error in a sql statement
*/
$is_gotofile = true;
if (empty($goto)) {
if (empty($table)) {
$goto = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$GLOBALS['is_gotofile'] = true;
if (empty($GLOBALS['goto'])) {
if (empty($GLOBALS['table'])) {
$GLOBALS['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
} else {
$goto = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
$GLOBALS['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
}
}
if (! isset($errorUrl)) {
$errorUrl = ! empty($back) ? $back : $goto;
$errorUrl .= Url::getCommon(
if (! isset($GLOBALS['errorUrl'])) {
$GLOBALS['errorUrl'] = ! empty($GLOBALS['back']) ? $GLOBALS['back'] : $GLOBALS['goto'];
$GLOBALS['errorUrl'] .= Url::getCommon(
['db' => $GLOBALS['db']],
! str_contains($errorUrl, '?') ? '?' : '&'
! str_contains($GLOBALS['errorUrl'], '?') ? '?' : '&'
);
if (
(mb_strpos(' ' . $errorUrl, 'db_') !== 1 || ! str_contains($errorUrl, '?route=/database/'))
&& strlen($table) > 0
(mb_strpos(' ' . $GLOBALS['errorUrl'], 'db_') !== 1
|| ! str_contains($GLOBALS['errorUrl'], '?route=/database/'))
&& strlen($GLOBALS['table']) > 0
) {
$errorUrl .= '&amp;table=' . urlencode($table);
$GLOBALS['errorUrl'] .= '&amp;table=' . urlencode($GLOBALS['table']);
}
}
// Coming from a bookmark dialog
if (isset($_POST['bkm_fields']['bkm_sql_query'])) {
$sql_query = $_POST['bkm_fields']['bkm_sql_query'];
$GLOBALS['sql_query'] = $_POST['bkm_fields']['bkm_sql_query'];
} elseif (isset($_POST['sql_query'])) {
$sql_query = $_POST['sql_query'];
$GLOBALS['sql_query'] = $_POST['sql_query'];
} elseif (isset($_GET['sql_query'], $_GET['sql_signature'])) {
if (Core::checkSqlQuerySignature($_GET['sql_query'], $_GET['sql_signature'])) {
$sql_query = $_GET['sql_query'];
$GLOBALS['sql_query'] = $_GET['sql_query'];
}
}
// This one is just to fill $db
if (isset($_POST['bkm_fields']['bkm_database'])) {
$db = $_POST['bkm_fields']['bkm_database'];
$GLOBALS['db'] = $_POST['bkm_fields']['bkm_database'];
}
// Default to browse if no query set and we have table
// (needed for browsing from DefaultTabTable)
if (empty($sql_query) && strlen($table) > 0 && strlen($db) > 0) {
$sql_query = $this->sql->getDefaultSqlQueryForBrowse($db, $table);
if (empty($GLOBALS['sql_query']) && strlen($GLOBALS['table']) > 0 && strlen($GLOBALS['db']) > 0) {
$GLOBALS['sql_query'] = $this->sql->getDefaultSqlQueryForBrowse($GLOBALS['db'], $GLOBALS['table']);
// set $goto to what will be displayed if query returns 0 rows
$goto = '';
$GLOBALS['goto'] = '';
} else {
// Now we can check the parameters
Util::checkParameters(['sql_query']);
@ -137,12 +133,12 @@ class SqlController extends AbstractController
*/
[
$analyzed_sql_results,
$db,
$table_from_sql,
] = ParseAnalyze::sqlQuery($sql_query, $db);
$GLOBALS['db'],
$GLOBALS['table_from_sql'],
] = ParseAnalyze::sqlQuery($GLOBALS['sql_query'], $GLOBALS['db']);
if ($table != $table_from_sql && ! empty($table_from_sql)) {
$table = $table_from_sql;
if ($GLOBALS['table'] != $GLOBALS['table_from_sql'] && ! empty($GLOBALS['table_from_sql'])) {
$GLOBALS['table'] = $GLOBALS['table_from_sql'];
}
/**
@ -155,7 +151,7 @@ class SqlController extends AbstractController
if (
$this->sql->hasNoRightsToDropDatabase(
$analyzed_sql_results,
$cfg['AllowUserDropDatabase'],
$GLOBALS['cfg']['AllowUserDropDatabase'],
$this->dbi->isSuperUser()
)
) {
@ -163,22 +159,22 @@ class SqlController extends AbstractController
__('"DROP DATABASE" statements are disabled.'),
'',
false,
$errorUrl
$GLOBALS['errorUrl']
);
}
/**
* Need to find the real end of rows?
*/
if (isset($find_real_end) && $find_real_end) {
$unlim_num_rows = $this->sql->findRealEndOfRows($db, $table);
if (isset($GLOBALS['find_real_end']) && $GLOBALS['find_real_end']) {
$GLOBALS['unlim_num_rows'] = $this->sql->findRealEndOfRows($GLOBALS['db'], $GLOBALS['table']);
}
/**
* Bookmark add
*/
if (isset($_POST['store_bkm'])) {
$this->addBookmark($goto);
$this->addBookmark($GLOBALS['goto']);
return;
}
@ -186,30 +182,30 @@ class SqlController extends AbstractController
/**
* Sets or modifies the $goto variable if required
*/
if ($goto === Url::getFromRoute('/sql')) {
$is_gotofile = false;
$goto = Url::getFromRoute('/sql', [
'db' => $db,
'table' => $table,
'sql_query' => $sql_query,
if ($GLOBALS['goto'] === Url::getFromRoute('/sql')) {
$GLOBALS['is_gotofile'] = false;
$GLOBALS['goto'] = Url::getFromRoute('/sql', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'sql_query' => $GLOBALS['sql_query'],
]);
}
$this->response->addHTML($this->sql->executeQueryAndSendQueryResponse(
$analyzed_sql_results,
$is_gotofile,
$db,
$table,
$find_real_end ?? null,
$import_text ?? null,
$extra_data ?? null,
$message_to_show ?? null,
$sql_data ?? null,
$goto,
isset($disp_query) ? $display_query : null,
$disp_message ?? null,
$sql_query,
$complete_query ?? null
$GLOBALS['is_gotofile'],
$GLOBALS['db'],
$GLOBALS['table'],
$GLOBALS['find_real_end'] ?? null,
$GLOBALS['import_text'] ?? null,
$GLOBALS['extra_data'] ?? null,
$GLOBALS['message_to_show'] ?? null,
$GLOBALS['sql_data'] ?? null,
$GLOBALS['goto'],
isset($GLOBALS['disp_query']) ? $GLOBALS['display_query'] : null,
$GLOBALS['disp_message'] ?? null,
$GLOBALS['sql_query'],
$GLOBALS['complete_query'] ?? null
));
}

View File

@ -59,9 +59,6 @@ class AddFieldController extends AbstractController
public function __invoke(): void
{
global $errorUrl, $message, $active_page, $sql_query;
global $num_fields, $regenerate, $result, $db, $table;
$this->addScriptFiles(['table/structure.js']);
// Check parameters
@ -72,9 +69,9 @@ class AddFieldController extends AbstractController
/**
* Defines the url to return to in case of error in a sql statement
*/
$errorUrl = Url::getFromRoute('/table/sql', [
'db' => $db,
'table' => $table,
$GLOBALS['errorUrl'] = Url::getFromRoute('/table/sql', [
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
]);
// check number of fields to be created
@ -87,15 +84,15 @@ class AddFieldController extends AbstractController
$_POST['field_where'] = $_POST['orig_field_where'];
}
$num_fields = min(
$GLOBALS['num_fields'] = min(
intval($_POST['orig_num_fields']) + intval($_POST['added_fields']),
4096
);
$regenerate = true;
$GLOBALS['regenerate'] = true;
} elseif (isset($_POST['num_fields']) && intval($_POST['num_fields']) > 0) {
$num_fields = min(4096, intval($_POST['num_fields']));
$GLOBALS['num_fields'] = min(4096, intval($_POST['num_fields']));
} else {
$num_fields = 1;
$GLOBALS['num_fields'] = 1;
}
if (isset($_POST['do_save_data'])) {
@ -105,19 +102,23 @@ class AddFieldController extends AbstractController
$createAddField = new CreateAddField($this->dbi);
$sql_query = $createAddField->getColumnCreationQuery($table);
$GLOBALS['sql_query'] = $createAddField->getColumnCreationQuery($GLOBALS['table']);
// If there is a request for SQL previewing.
if (isset($_POST['preview_sql'])) {
Core::previewSQL($sql_query);
Core::previewSQL($GLOBALS['sql_query']);
return;
}
$result = $createAddField->tryColumnCreationQuery($db, $sql_query, $errorUrl);
$GLOBALS['result'] = $createAddField->tryColumnCreationQuery(
$GLOBALS['db'],
$GLOBALS['sql_query'],
$GLOBALS['errorUrl']
);
if ($result !== true) {
$error_message_html = Generator::mysqlDie('', '', false, $errorUrl, false);
if ($GLOBALS['result'] !== true) {
$error_message_html = Generator::mysqlDie('', '', false, $GLOBALS['errorUrl'], false);
$this->response->addHTML($error_message_html ?? '');
$this->response->setRequestStatus(false);
@ -132,8 +133,8 @@ class AddFieldController extends AbstractController
}
$this->transformations->setMime(
$db,
$table,
$GLOBALS['db'],
$GLOBALS['table'],
$_POST['field_name'][$fieldindex],
$mimetype,
$_POST['field_transformation'][$fieldindex],
@ -145,21 +146,21 @@ class AddFieldController extends AbstractController
}
// Go back to the structure sub-page
$message = Message::success(
$GLOBALS['message'] = Message::success(
__('Table %1$s has been altered successfully.')
);
$message->addParam($table);
$GLOBALS['message']->addParam($GLOBALS['table']);
$this->response->addJSON(
'message',
Generator::getMessage($message, $sql_query, 'success')
Generator::getMessage($GLOBALS['message'], $GLOBALS['sql_query'], 'success')
);
// Give an URL to call and use to appends the structure after the success message
$this->response->addJSON(
'structure_refresh_route',
Url::getFromRoute('/table/structure', [
'db' => $db,
'table' => $table,
'db' => $GLOBALS['db'],
'table' => $GLOBALS['table'],
'ajax_request' => '1',
])
);
@ -167,17 +168,21 @@ class AddFieldController extends AbstractController
return;
}
$url_params = ['db' => $db, 'table' => $table];
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
$errorUrl .= Url::getCommon($url_params, '&');
$url_params = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
$GLOBALS['errorUrl'] .= Url::getCommon($url_params, '&');
DbTableExists::check($db, $table);
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
$active_page = Url::getFromRoute('/table/structure');
$GLOBALS['active_page'] = Url::getFromRoute('/table/structure');
$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js', 'indexes.js']);
$templateData = $this->columnsDefinition->displayForm('/table/add-field', $num_fields, $regenerate);
$templateData = $this->columnsDefinition->displayForm(
'/table/add-field',
$GLOBALS['num_fields'],
$GLOBALS['regenerate']
);
$this->render('columns_definitions/column_definitions_form', $templateData);
}

View File

@ -46,35 +46,32 @@ class ChangeController extends AbstractController
public function __invoke(): void
{
global $cfg, $db, $table, $text_dir, $disp_message, $urlParams;
global $errorUrl, $where_clause, $unsaved_values, $insert_mode, $where_clause_array, $where_clauses;
global $result, $rows, $found_unique_key, $after_insert, $comments_map, $table_columns;
global $chg_evt_handler, $timestamp_seen, $columns_cnt, $tabindex;
global $tabindex_for_value, $o_rows, $biggest_max_file_size, $has_blob_field;
global $jsvkey, $vkey, $current_result, $repopulate, $checked;
$pageSettings = new PageSettings('Edit');
$this->response->addHTML($pageSettings->getErrorHTML());
$this->response->addHTML($pageSettings->getHTML());
DbTableExists::check($db, $table);
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
/**
* Determine whether Insert or Edit and set global variables
*/
[
$insert_mode,
$where_clause,
$where_clause_array,
$where_clauses,
$result,
$rows,
$found_unique_key,
$after_insert,
] = $this->insertEdit->determineInsertOrEdit($where_clause ?? null, $db, $table);
$GLOBALS['insert_mode'],
$GLOBALS['where_clause'],
$GLOBALS['where_clause_array'],
$GLOBALS['where_clauses'],
$GLOBALS['result'],
$GLOBALS['rows'],
$GLOBALS['found_unique_key'],
$GLOBALS['after_insert'],
] = $this->insertEdit->determineInsertOrEdit(
$GLOBALS['where_clause'] ?? null,
$GLOBALS['db'],
$GLOBALS['table']
);
// Increase number of rows if unsaved rows are more
if (! empty($unsaved_values) && count($rows) < count($unsaved_values)) {
$rows = array_fill(0, count($unsaved_values), false);
if (! empty($GLOBALS['unsaved_values']) && count($GLOBALS['rows']) < count($GLOBALS['unsaved_values'])) {
$GLOBALS['rows'] = array_fill(0, count($GLOBALS['unsaved_values']), false);
}
/**
@ -82,7 +79,7 @@ class ChangeController extends AbstractController
* (at this point, $GLOBALS['goto'] will be set but could be empty)
*/
if (empty($GLOBALS['goto'])) {
if (strlen($table) > 0) {
if (strlen($GLOBALS['table']) > 0) {
// avoid a problem (see bug #2202709)
$GLOBALS['goto'] = Url::getFromRoute('/table/sql');
} else {
@ -90,22 +87,22 @@ class ChangeController extends AbstractController
}
}
$urlParams = [
'db' => $db,
$GLOBALS['urlParams'] = [
'db' => $GLOBALS['db'],
'sql_query' => $_POST['sql_query'] ?? '',
];
if (strpos($GLOBALS['goto'] ?? '', 'index.php?route=/table') === 0) {
$urlParams['table'] = $table;
$GLOBALS['urlParams']['table'] = $GLOBALS['table'];
}
$errorUrl = $GLOBALS['goto'] . Url::getCommon(
$urlParams,
$GLOBALS['errorUrl'] = $GLOBALS['goto'] . Url::getCommon(
$GLOBALS['urlParams'],
! str_contains($GLOBALS['goto'], '?') ? '?' : '&'
);
unset($urlParams);
unset($GLOBALS['urlParams']);
$comments_map = $this->insertEdit->getCommentsMap($db, $table);
$GLOBALS['comments_map'] = $this->insertEdit->getCommentsMap($GLOBALS['db'], $GLOBALS['table']);
/**
* START REGULAR OUTPUT
@ -125,22 +122,22 @@ class ChangeController extends AbstractController
*
* $disp_message come from /table/replace
*/
if (! empty($disp_message)) {
$this->response->addHTML(Generator::getMessage($disp_message, null));
if (! empty($GLOBALS['disp_message'])) {
$this->response->addHTML(Generator::getMessage($GLOBALS['disp_message'], null));
}
$table_columns = $this->insertEdit->getTableColumns($db, $table);
$GLOBALS['table_columns'] = $this->insertEdit->getTableColumns($GLOBALS['db'], $GLOBALS['table']);
// retrieve keys into foreign fields, if any
$foreigners = $this->relation->getForeigners($db, $table);
$foreigners = $this->relation->getForeigners($GLOBALS['db'], $GLOBALS['table']);
// Retrieve form parameters for insert/edit form
$_form_params = $this->insertEdit->getFormParametersForInsertForm(
$db,
$table,
$where_clauses,
$where_clause_array,
$errorUrl
$GLOBALS['db'],
$GLOBALS['table'],
$GLOBALS['where_clauses'],
$GLOBALS['where_clause_array'],
$GLOBALS['errorUrl']
);
/**
@ -148,28 +145,31 @@ class ChangeController extends AbstractController
*/
// autocomplete feature of IE kills the "onchange" event handler and it
// must be replaced by the "onpropertychange" one in this case
$chg_evt_handler = 'onchange';
$GLOBALS['chg_evt_handler'] = 'onchange';
// Had to put the URI because when hosted on an https server,
// some browsers send wrongly this form to the http server.
$html_output = '';
// Set if we passed the first timestamp field
$timestamp_seen = false;
$columns_cnt = count($table_columns);
$GLOBALS['timestamp_seen'] = false;
$GLOBALS['columns_cnt'] = count($GLOBALS['table_columns']);
$tabindex = 0;
$tabindex_for_value = 0;
$o_rows = 0;
$biggest_max_file_size = 0;
$GLOBALS['tabindex'] = 0;
$GLOBALS['tabindex_for_value'] = 0;
$GLOBALS['o_rows'] = 0;
$GLOBALS['biggest_max_file_size'] = 0;
$urlParams['db'] = $db;
$urlParams['table'] = $table;
$urlParams = $this->insertEdit->urlParamsInEditMode($urlParams, $where_clause_array);
$GLOBALS['urlParams']['db'] = $GLOBALS['db'];
$GLOBALS['urlParams']['table'] = $GLOBALS['table'];
$GLOBALS['urlParams'] = $this->insertEdit->urlParamsInEditMode(
$GLOBALS['urlParams'],
$GLOBALS['where_clause_array']
);
$has_blob_field = false;
foreach ($table_columns as $column) {
$GLOBALS['has_blob_field'] = false;
foreach ($GLOBALS['table_columns'] as $column) {
if ($this->insertEdit->isColumn($column, ['blob', 'tinyblob', 'mediumblob', 'longblob'])) {
$has_blob_field = true;
$GLOBALS['has_blob_field'] = true;
break;
}
}
@ -177,92 +177,94 @@ class ChangeController extends AbstractController
//Insert/Edit form
//If table has blob fields we have to disable ajax.
$isUpload = $GLOBALS['config']->get('enable_upload');
$html_output .= $this->insertEdit->getHtmlForInsertEditFormHeader($has_blob_field, $isUpload);
$html_output .= $this->insertEdit->getHtmlForInsertEditFormHeader($GLOBALS['has_blob_field'], $isUpload);
$html_output .= Url::getHiddenInputs($_form_params);
// user can toggle the display of Function column and column types
// (currently does not work for multi-edits)
if (! $cfg['ShowFunctionFields'] || ! $cfg['ShowFieldTypesInDataEditView']) {
if (! $GLOBALS['cfg']['ShowFunctionFields'] || ! $GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
$html_output .= __('Show');
}
if (! $cfg['ShowFunctionFields']) {
$html_output .= $this->insertEdit->showTypeOrFunction('function', $urlParams, false);
if (! $GLOBALS['cfg']['ShowFunctionFields']) {
$html_output .= $this->insertEdit->showTypeOrFunction('function', $GLOBALS['urlParams'], false);
}
if (! $cfg['ShowFieldTypesInDataEditView']) {
$html_output .= $this->insertEdit->showTypeOrFunction('type', $urlParams, false);
if (! $GLOBALS['cfg']['ShowFieldTypesInDataEditView']) {
$html_output .= $this->insertEdit->showTypeOrFunction('type', $GLOBALS['urlParams'], false);
}
$GLOBALS['plugin_scripts'] = [];
foreach ($rows as $row_id => $current_row) {
foreach ($GLOBALS['rows'] as $row_id => $current_row) {
if (empty($current_row)) {
$current_row = [];
}
$jsvkey = $row_id;
$vkey = '[multi_edit][' . $jsvkey . ']';
$GLOBALS['jsvkey'] = $row_id;
$GLOBALS['vkey'] = '[multi_edit][' . $GLOBALS['jsvkey'] . ']';
$current_result = (isset($result) && is_array($result) && isset($result[$row_id])
? $result[$row_id]
: $result);
$repopulate = [];
$checked = true;
if (isset($unsaved_values[$row_id])) {
$repopulate = $unsaved_values[$row_id];
$checked = false;
$GLOBALS['current_result'] = (isset($GLOBALS['result'])
&& is_array($GLOBALS['result']) && isset($GLOBALS['result'][$row_id])
? $GLOBALS['result'][$row_id]
: $GLOBALS['result']);
$GLOBALS['repopulate'] = [];
$GLOBALS['checked'] = true;
if (isset($GLOBALS['unsaved_values'][$row_id])) {
$GLOBALS['repopulate'] = $GLOBALS['unsaved_values'][$row_id];
$GLOBALS['checked'] = false;
}
if ($insert_mode && $row_id > 0) {
$html_output .= $this->insertEdit->getHtmlForIgnoreOption($row_id, $checked);
if ($GLOBALS['insert_mode'] && $row_id > 0) {
$html_output .= $this->insertEdit->getHtmlForIgnoreOption($row_id, $GLOBALS['checked']);
}
$html_output .= $this->insertEdit->getHtmlForInsertEditRow(
$urlParams,
$table_columns,
$comments_map,
$timestamp_seen,
$current_result,
$chg_evt_handler,
$jsvkey,
$vkey,
$insert_mode,
$GLOBALS['urlParams'],
$GLOBALS['table_columns'],
$GLOBALS['comments_map'],
$GLOBALS['timestamp_seen'],
$GLOBALS['current_result'],
$GLOBALS['chg_evt_handler'],
$GLOBALS['jsvkey'],
$GLOBALS['vkey'],
$GLOBALS['insert_mode'],
$current_row,
$o_rows,
$tabindex,
$columns_cnt,
$GLOBALS['o_rows'],
$GLOBALS['tabindex'],
$GLOBALS['columns_cnt'],
$isUpload,
$foreigners,
$tabindex_for_value,
$table,
$db,
$GLOBALS['tabindex_for_value'],
$GLOBALS['table'],
$GLOBALS['db'],
$row_id,
$biggest_max_file_size,
$text_dir,
$repopulate,
$where_clause_array
$GLOBALS['biggest_max_file_size'],
$GLOBALS['text_dir'],
$GLOBALS['repopulate'],
$GLOBALS['where_clause_array']
);
}
$this->addScriptFiles($GLOBALS['plugin_scripts']);
unset($unsaved_values, $checked, $repopulate, $GLOBALS['plugin_scripts']);
unset($GLOBALS['unsaved_values'], $GLOBALS['checked'], $GLOBALS['repopulate'], $GLOBALS['plugin_scripts']);
if (! isset($after_insert)) {
$after_insert = 'back';
if (! isset($GLOBALS['after_insert'])) {
$GLOBALS['after_insert'] = 'back';
}
$isNumeric = InsertEdit::isWhereClauseNumeric($where_clause);
$isNumeric = InsertEdit::isWhereClauseNumeric($GLOBALS['where_clause']);
$html_output .= $this->template->render('table/insert/actions_panel', [
'where_clause' => $where_clause,
'after_insert' => $after_insert,
'found_unique_key' => $found_unique_key,
'where_clause' => $GLOBALS['where_clause'],
'after_insert' => $GLOBALS['after_insert'],
'found_unique_key' => $GLOBALS['found_unique_key'],
'is_numeric' => $isNumeric,
]);
if ($biggest_max_file_size > 0) {
$html_output .= '<input type="hidden" name="MAX_FILE_SIZE" value="' . $biggest_max_file_size . '">' . "\n";
if ($GLOBALS['biggest_max_file_size'] > 0) {
$html_output .= '<input type="hidden" name="MAX_FILE_SIZE" value="'
. $GLOBALS['biggest_max_file_size'] . '">' . "\n";
}
$html_output .= '</form>';
@ -270,9 +272,14 @@ class ChangeController extends AbstractController
$html_output .= $this->insertEdit->getHtmlForGisEditor();
// end Insert/Edit form
if ($insert_mode) {
if ($GLOBALS['insert_mode']) {
//Continue insertion form
$html_output .= $this->insertEdit->getContinueInsertionForm($table, $db, $where_clause_array, $errorUrl);
$html_output .= $this->insertEdit->getContinueInsertionForm(
$GLOBALS['table'],
$GLOBALS['db'],
$GLOBALS['where_clause_array'],
$GLOBALS['errorUrl']
);
}
$this->response->addHTML($html_output);

View File

@ -28,8 +28,6 @@ final class ChangeRowsController extends AbstractController
public function __invoke(): void
{
global $active_page, $where_clause;
if (isset($_POST['goto']) && (! isset($_POST['rows_to_delete']) || ! is_array($_POST['rows_to_delete']))) {
$this->response->setRequestStatus(false);
$this->response->addJSON('message', __('No row selected.'));
@ -41,14 +39,14 @@ final class ChangeRowsController extends AbstractController
// 'rows_to_delete' checkbox, we use the index of it as the
// indicating WHERE clause. Then we build the array which is used
// for the /table/change script.
$where_clause = [];
$GLOBALS['where_clause'] = [];
if (isset($_POST['rows_to_delete']) && is_array($_POST['rows_to_delete'])) {
foreach ($_POST['rows_to_delete'] as $i_where_clause) {
$where_clause[] = $i_where_clause;
$GLOBALS['where_clause'][] = $i_where_clause;
}
}
$active_page = Url::getFromRoute('/table/change');
$GLOBALS['active_page'] = Url::getFromRoute('/table/change');
($this->changeController)();
}

View File

@ -44,8 +44,6 @@ class ChartController extends AbstractController
public function __invoke(): void
{
global $db, $table, $cfg, $sql_query, $errorUrl;
if (isset($_REQUEST['pos'], $_REQUEST['session_max_rows']) && $this->response->isAjax()) {
$this->ajax();
@ -53,7 +51,7 @@ class ChartController extends AbstractController
}
// Throw error if no sql query is set
if (! isset($sql_query) || $sql_query == '') {
if (! isset($GLOBALS['sql_query']) || $GLOBALS['sql_query'] == '') {
$this->response->setRequestStatus(false);
$this->response->addHTML(
Message::error(__('No SQL query was set to fetch data.'))->getDisplay()
@ -82,41 +80,41 @@ class ChartController extends AbstractController
/**
* Runs common work
*/
if (strlen($table) > 0) {
if (strlen($GLOBALS['table']) > 0) {
Util::checkParameters(['db', 'table']);
$url_params = ['db' => $db, 'table' => $table];
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
$errorUrl .= Url::getCommon($url_params, '&');
$url_params = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
$GLOBALS['errorUrl'] .= Url::getCommon($url_params, '&');
DbTableExists::check($db, $table);
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
$url_params['goto'] = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
$url_params['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
$url_params['back'] = Url::getFromRoute('/table/sql');
$this->dbi->selectDb($db);
} elseif (strlen($db) > 0) {
$url_params['goto'] = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$this->dbi->selectDb($GLOBALS['db']);
} elseif (strlen($GLOBALS['db']) > 0) {
$url_params['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$url_params['back'] = Url::getFromRoute('/sql');
Util::checkParameters(['db']);
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabDatabase'], 'database');
$errorUrl .= Url::getCommon(['db' => $db], '&');
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabDatabase'], 'database');
$GLOBALS['errorUrl'] .= Url::getCommon(['db' => $GLOBALS['db']], '&');
if (! $this->hasDatabase()) {
return;
}
} else {
$url_params['goto'] = Util::getScriptNameForOption($cfg['DefaultTabServer'], 'server');
$url_params['goto'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabServer'], 'server');
$url_params['back'] = Url::getFromRoute('/sql');
$errorUrl = Url::getFromRoute('/');
$GLOBALS['errorUrl'] = Url::getFromRoute('/');
if ($this->dbi->isSuperUser()) {
$this->dbi->selectDb('mysql');
}
}
$result = $this->dbi->tryQuery($sql_query);
$result = $this->dbi->tryQuery($GLOBALS['sql_query']);
$fields_meta = $row = [];
if ($result !== false) {
$fields_meta = $this->dbi->getFieldsMeta($result);
@ -147,10 +145,10 @@ class ChartController extends AbstractController
return;
}
$url_params['db'] = $db;
$url_params['db'] = $GLOBALS['db'];
$url_params['reload'] = 1;
$startAndNumberOfRowsFieldset = Generator::getStartAndNumberOfRowsFieldsetData($sql_query);
$startAndNumberOfRowsFieldset = Generator::getStartAndNumberOfRowsFieldsetData($GLOBALS['sql_query']);
/**
* Displays the page
@ -169,19 +167,17 @@ class ChartController extends AbstractController
*/
public function ajax(): void
{
global $db, $table, $sql_query, $urlParams, $errorUrl, $cfg;
if (strlen($table) > 0 && strlen($db) > 0) {
if (strlen($GLOBALS['table']) > 0 && strlen($GLOBALS['db']) > 0) {
Util::checkParameters(['db', 'table']);
$urlParams = ['db' => $db, 'table' => $table];
$errorUrl = Util::getScriptNameForOption($cfg['DefaultTabTable'], 'table');
$errorUrl .= Url::getCommon($urlParams, '&');
$GLOBALS['urlParams'] = ['db' => $GLOBALS['db'], 'table' => $GLOBALS['table']];
$GLOBALS['errorUrl'] = Util::getScriptNameForOption($GLOBALS['cfg']['DefaultTabTable'], 'table');
$GLOBALS['errorUrl'] .= Url::getCommon($GLOBALS['urlParams'], '&');
DbTableExists::check($db, $table);
DbTableExists::check($GLOBALS['db'], $GLOBALS['table']);
}
$parser = new Parser($sql_query);
$parser = new Parser($GLOBALS['sql_query']);
/**
* @var SelectStatement $statement
*/

View File

@ -58,14 +58,12 @@ class CreateController extends AbstractController
public function __invoke(): void
{
global $num_fields, $sql_query, $result, $db, $table;
Util::checkParameters(['db']);
$cfg = $this->config->settings;
/* Check if database name is empty */
if (strlen($db) === 0) {
if (strlen($GLOBALS['db']) === 0) {
Generator::mysqlDie(
__('The database name is empty!'),
'',
@ -77,28 +75,28 @@ class CreateController extends AbstractController
/**
* Selects the database to work with
*/
if (! $this->dbi->selectDb($db)) {
if (! $this->dbi->selectDb($GLOBALS['db'])) {
Generator::mysqlDie(
sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($db)),
sprintf(__('\'%s\' database does not exist.'), htmlspecialchars($GLOBALS['db'])),
'',
false,
'index.php'
);
}
if ($this->dbi->getColumns($db, $table)) {
if ($this->dbi->getColumns($GLOBALS['db'], $GLOBALS['table'])) {
// table exists already
Generator::mysqlDie(
sprintf(__('Table %s already exists!'), htmlspecialchars($table)),
sprintf(__('Table %s already exists!'), htmlspecialchars($GLOBALS['table'])),
'',
false,
Url::getFromRoute('/database/structure', ['db' => $db])
Url::getFromRoute('/database/structure', ['db' => $GLOBALS['db']])
);
}
$createAddField = new CreateAddField($this->dbi);
$num_fields = $createAddField->getNumberOfFieldsFromRequest();
$GLOBALS['num_fields'] = $createAddField->getNumberOfFieldsFromRequest();
/**
* The form used to define the structure of the table has been submitted
@ -106,23 +104,23 @@ class CreateController extends AbstractController
if (isset($_POST['do_save_data'])) {
// lower_case_table_names=1 `DB` becomes `db`
if ($this->dbi->getLowerCaseNames() === '1') {
$db = mb_strtolower($db);
$table = mb_strtolower($table);
$GLOBALS['db'] = mb_strtolower($GLOBALS['db']);
$GLOBALS['table'] = mb_strtolower($GLOBALS['table']);
}
$sql_query = $createAddField->getTableCreationQuery($db, $table);
$GLOBALS['sql_query'] = $createAddField->getTableCreationQuery($GLOBALS['db'], $GLOBALS['table']);
// If there is a request for SQL previewing.
if (isset($_POST['preview_sql'])) {
Core::previewSQL($sql_query);
Core::previewSQL($GLOBALS['sql_query']);
return;
}
// Executes the query
$result = $this->dbi->tryQuery($sql_query);
$GLOBALS['result'] = $this->dbi->tryQuery($GLOBALS['sql_query']);
if ($result) {
if ($GLOBALS['result']) {
// Update comment table for mime types [MIME]
if (isset($_POST['field_mimetype']) && is_array($_POST['field_mimetype']) && $cfg['BrowseMIME']) {
foreach ($_POST['field_mimetype'] as $fieldindex => $mimetype) {
@ -134,8 +132,8 @@ class CreateController extends AbstractController
}
$this->transformations->setMime(
$db,
$table,
$GLOBALS['db'],
$GLOBALS['table'],
$_POST['field_name'][$fieldindex],
$mimetype,
$_POST['field_transformation'][$fieldindex],
@ -158,7 +156,7 @@ class CreateController extends AbstractController
$this->addScriptFiles(['vendor/jquery/jquery.uitablefilter.js', 'indexes.js']);
$templateData = $this->columnsDefinition->displayForm('/table/create', $num_fields);
$templateData = $this->columnsDefinition->displayForm('/table/create', $GLOBALS['num_fields']);
$this->render('columns_definitions/column_definitions_form', $templateData);
}

Some files were not shown because too many files have changed in this diff Show More