Replace $GLOBALS with global in common.inc.php

- Replaces $GLOBALS['var'] with global $var in the
libraries/common.inc.php file.
- Replaces qualifier with imports.

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2019-12-11 19:40:13 -03:00
parent 301835e9a6
commit 7eace56891

View File

@ -39,8 +39,11 @@ use PhpMyAdmin\ErrorHandler;
use PhpMyAdmin\LanguageManager;
use PhpMyAdmin\Logging;
use PhpMyAdmin\Message;
use PhpMyAdmin\MoTranslator\Loader;
use PhpMyAdmin\Response;
use PhpMyAdmin\Sanitize;
use PhpMyAdmin\Session;
use PhpMyAdmin\SqlParser\Lexer;
use PhpMyAdmin\ThemeManager;
use PhpMyAdmin\Tracker;
use PhpMyAdmin\Util;
@ -48,6 +51,8 @@ use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
global $containerBuilder, $error_handler, $PMA_Config, $server, $dbi, $lang, $cfg;
/**
* block attempts to directly run this script
*/
@ -99,10 +104,10 @@ $diMigration = $containerBuilder->get('di_migration');
/**
* Load gettext functions.
*/
PhpMyAdmin\MoTranslator\Loader::loadFunctions();
Loader::loadFunctions();
/** @var ErrorHandler $GLOBALS['error_handler'] */
$GLOBALS['error_handler'] = $containerBuilder->get('error_handler');
/** @var ErrorHandler $error_handler */
$error_handler = $containerBuilder->get('error_handler');
/**
* Warning about missing PHP extensions.
@ -123,18 +128,17 @@ Core::cleanupPathInfo();
/* parsing configuration file LABEL_parsing_config_file */
/**
* @global Config $GLOBALS['PMA_Config']
* force reading of config file, because we removed sensitive values
* in the previous iteration
* Force reading of config file, because we removed sensitive values
* in the previous iteration.
* @var Config $PMA_Config
*/
$GLOBALS['PMA_Config'] = $containerBuilder->get('config');
//$containerBuilder->set('config', $GLOBALS['PMA_Config']);
$PMA_Config = $containerBuilder->get('config');
/**
* include session handling after the globals, to prevent overwriting
*/
if (! defined('PMA_NO_SESSION')) {
Session::setUp($GLOBALS['PMA_Config'], $GLOBALS['error_handler']);
Session::setUp($PMA_Config, $error_handler);
}
/**
@ -143,13 +147,13 @@ if (! defined('PMA_NO_SESSION')) {
/**
* holds parameters to be passed to next page
* @global array $GLOBALS['url_params']
* @global array $url_params
*/
$diMigration->setGlobal('url_params', []);
/**
* holds page that should be displayed
* @global string $GLOBALS['goto']
* @global string $goto
*/
$diMigration->setGlobal('goto', '');
// Security fix: disallow accessing serious server files via "?goto="
@ -157,18 +161,18 @@ if (isset($_REQUEST['goto']) && Core::checkPageValidity($_REQUEST['goto'])) {
$diMigration->setGlobal('goto', $_REQUEST['goto']);
$diMigration->setGlobal('url_params', ['goto' => $_REQUEST['goto']]);
} else {
$GLOBALS['PMA_Config']->removeCookie('goto');
$PMA_Config->removeCookie('goto');
unset($_REQUEST['goto'], $_GET['goto'], $_POST['goto']);
}
/**
* returning page
* @global string $GLOBALS['back']
* @global string $back
*/
if (isset($_REQUEST['back']) && Core::checkPageValidity($_REQUEST['back'])) {
$diMigration->setGlobal('back', $_REQUEST['back']);
} else {
$GLOBALS['PMA_Config']->removeCookie('back');
$PMA_Config->removeCookie('back');
unset($_REQUEST['back'], $_GET['back'], $_POST['back']);
}
@ -213,26 +217,26 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') {
* or is not provided
*/
$whitelist = ['ajax_request'];
PhpMyAdmin\Sanitize::removeRequestVars($whitelist);
Sanitize::removeRequestVars($whitelist);
}
}
/**
* current selected database
* @global string $GLOBALS['db']
* @global string $db
*/
Core::setGlobalDbOrTable('db');
/**
* current selected table
* @global string $GLOBALS['table']
* @global string $table
*/
Core::setGlobalDbOrTable('table');
/**
* Store currently selected recent table.
* Affect $GLOBALS['db'] and $GLOBALS['table']
* Affect $db and $table globals
*/
if (isset($_REQUEST['selected_recent_table']) && Core::isValid($_REQUEST['selected_recent_table'])) {
$recent_table = json_decode($_REQUEST['selected_recent_table'], true);
@ -258,7 +262,7 @@ if (isset($_REQUEST['selected_recent_table']) && Core::isValid($_REQUEST['select
/**
* SQL query to be executed
* @global string $GLOBALS['sql_query']
* @global string $sql_query
*/
$diMigration->setGlobal('sql_query', '');
if (Core::isValid($_POST['sql_query'])) {
@ -282,8 +286,8 @@ $language->activate();
* check for errors occurred while loading configuration
* this check is done here after loading language files to present errors in locale
*/
$GLOBALS['PMA_Config']->checkPermissions();
$GLOBALS['PMA_Config']->checkErrors();
$PMA_Config->checkPermissions();
$PMA_Config->checkErrors();
/* Check server configuration */
Core::checkConfiguration();
@ -294,34 +298,35 @@ Core::checkRequest();
/******************************************************************************/
/* setup servers LABEL_setup_servers */
$GLOBALS['PMA_Config']->checkServers();
$PMA_Config->checkServers();
/**
* current server
* @global integer $GLOBALS['server']
* @global integer $server
*/
$diMigration->setGlobal('server', $GLOBALS['PMA_Config']->selectServer());
$diMigration->setGlobal('server', $PMA_Config->selectServer());
$diMigration->setGlobal('url_params', ['server' => $containerBuilder->getParameter('server')] + $containerBuilder->getParameter('url_params'));
/**
* BC - enable backward compatibility
* exports all configuration settings into $GLOBALS ($GLOBALS['cfg'])
* exports all configuration settings into globals ($cfg global)
*/
$GLOBALS['PMA_Config']->enableBc();
$PMA_Config->enableBc();
/******************************************************************************/
/* setup themes LABEL_theme_setup */
ThemeManager::initializeTheme();
$GLOBALS['dbi'] = null;
/** @var DatabaseInterface $dbi */
$dbi = null;
if (! defined('PMA_MINIMUM_COMMON')) {
/**
* save some settings in cookies
* @todo should be done in PhpMyAdmin\Config
*/
$GLOBALS['PMA_Config']->setCookie('pma_lang', $GLOBALS['lang']);
$PMA_Config->setCookie('pma_lang', $lang);
ThemeManager::getInstance()->setThemeCookie();
@ -336,13 +341,13 @@ if (! defined('PMA_MINIMUM_COMMON')) {
// no generic solution for loading preferences from cache as some settings
// need to be kept for processing in
// PhpMyAdmin\Config::loadUserPreferences()
$cache_key = 'server_' . $GLOBALS['server'];
$cache_key = 'server_' . $server;
if (isset($_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'])
) {
$value
= $_SESSION['cache'][$cache_key]['userprefs']['LoginCookieValidity'];
$GLOBALS['PMA_Config']->set('LoginCookieValidity', $value);
$GLOBALS['cfg']['LoginCookieValidity'] = $value;
$PMA_Config->set('LoginCookieValidity', $value);
$cfg['LoginCookieValidity'] = $value;
unset($value);
}
unset($cache_key);
@ -373,14 +378,14 @@ if (! defined('PMA_MINIMUM_COMMON')) {
// scripts)
$controllink = false;
if ($cfg['Server']['controluser'] != '') {
$controllink = $GLOBALS['dbi']->connect(
$controllink = $dbi->connect(
DatabaseInterface::CONNECT_CONTROL
);
}
// Connects to the server (validates user's login)
/** @var DatabaseInterface $userlink */
$userlink = $GLOBALS['dbi']->connect(DatabaseInterface::CONNECT_USER);
$userlink = $dbi->connect(DatabaseInterface::CONNECT_USER);
if ($userlink === false) {
$auth_plugin->showFailure('mysql-denied');
@ -393,7 +398,7 @@ if (! defined('PMA_MINIMUM_COMMON')) {
* and phpMyAdmin issuing queries to configuration storage, which
* is not locked by that time.
*/
$controllink = $GLOBALS['dbi']->connect(
$controllink = $dbi->connect(
DatabaseInterface::CONNECT_USER,
null,
DatabaseInterface::CONNECT_CONTROL
@ -407,7 +412,7 @@ if (! defined('PMA_MINIMUM_COMMON')) {
/* Log success */
Logging::logUser($cfg['Server']['user']);
if ($GLOBALS['dbi']->getVersion() < $cfg['MysqlMinVersion']['internal']) {
if ($dbi->getVersion() < $cfg['MysqlMinVersion']['internal']) {
Core::fatalError(
__('You should upgrade to %s %s or later.'),
[
@ -419,7 +424,7 @@ if (! defined('PMA_MINIMUM_COMMON')) {
// Sets the default delimiter (if specified).
if (! empty($_REQUEST['sql_delimiter'])) {
PhpMyAdmin\SqlParser\Lexer::$DEFAULT_DELIMITER = $_REQUEST['sql_delimiter'];
Lexer::$DEFAULT_DELIMITER = $_REQUEST['sql_delimiter'];
}
// TODO: Set SQL modes too.
@ -473,7 +478,7 @@ if (! defined('PMA_MINIMUM_COMMON')) {
}
// load user preferences
$GLOBALS['PMA_Config']->loadUserPreferences();
$PMA_Config->loadUserPreferences();
$containerBuilder->set('theme_manager', ThemeManager::getInstance());