Skip to content

Commit

Permalink
Merge pull request #19503 from MauricioFauth/globals-removal
Browse files Browse the repository at this point in the history
Remove global variables
  • Loading branch information
MauricioFauth authored Jan 11, 2025
2 parents 17c477b + ed9dc6c commit 605e56b
Show file tree
Hide file tree
Showing 108 changed files with 919 additions and 1,927 deletions.
690 changes: 93 additions & 597 deletions phpstan-baseline.neon

Large diffs are not rendered by default.

495 changes: 88 additions & 407 deletions psalm-baseline.xml

Large diffs are not rendered by default.

32 changes: 0 additions & 32 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,4 @@
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>

<globals>
<var name="GLOBALS" type="array{
asfile: bool,
buffer_needed: bool,
cached_affected_rows: int|numeric-string,
charset: string,
complete_query: string,
compression: 'none'|'zip'|'gzip',
conn_error: string,
display_query: string,
errno: int,
error: bool,
file_handle: resource|null,
from_cookie: bool,
hostname: string,
import_text: string,
knjenc: string,
maxsize: string,
memory_limit: int,
old_tz: string,
onfly_compression: bool,
output_charset_conversion: bool,
output_kanji_conversion: bool,
plugin_scripts: string[],
pma_auth_server: string,
querytime: float|int,
save_on_server: bool,
SESSION_KEY: string,
username: string
}"/>
</globals>
</psalm>
20 changes: 10 additions & 10 deletions resources/templates/server/privileges/login_information_fields.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
<label for="select_pred_username">{{ t('User name:') }}</label>
<span class="options">
<select name="pred_username" id="select_pred_username" title="{{ t('User name') }}">
<option value="any"{{ pred_username == 'any' ? ' selected' }}>{{ t('Any user') }}</option>
<option value="userdefined"{{ pred_username is null or pred_username == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
<option value="any"{{ predefined_username == 'any' ? ' selected' }}>{{ t('Any user') }}</option>
<option value="userdefined"{{ predefined_username == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
</select>
</span>
<input type="text" spellcheck="false" name="username" id="pma_username" class="autofocus" maxlength="{{ username_length }}" title="{{ t('User name') }}"
{%- if username is not empty %} value="{{ new_username is not null ? new_username : username }}"{% endif -%}
{{- pred_username is null or pred_username == 'userdefined' ? ' required' }}>
{%- if username is not empty %} value="{{ username }}"{% endif -%}
{{- predefined_username == 'userdefined' ? ' required' }}>

<div id="user_exists_warning" class="hide">
{{ t('An account already exists with the same username but possibly a different hostname.')|notice }}
Expand All @@ -25,17 +25,17 @@
<span class="options">
<select name="pred_hostname" id="select_pred_hostname" title="{{ t('Host name') }}"
{{- this_host is not null and this_host != 'localhost' and this_host != '127.0.0.1' ? ' data-thishost="' ~ this_host ~ '"' }}>
<option value="any"{{ pred_hostname == 'any' ? ' selected' }}>{{ t('Any host') }}</option>
<option value="localhost"{{ pred_hostname == 'localhost' ? ' selected' }}>{{ t('Local') }}</option>
<option value="any"{{ predefined_hostname == 'any' ? ' selected' }}>{{ t('Any host') }}</option>
<option value="localhost"{{ predefined_hostname == 'localhost' ? ' selected' }}>{{ t('Local') }}</option>
{% if this_host is not empty %}
<option value="thishost"{{ pred_hostname == 'thishost' ? ' selected' }}>{{ t('This host') }}</option>
<option value="thishost"{{ predefined_hostname == 'thishost' ? ' selected' }}>{{ t('This host') }}</option>
{% endif %}
<option value="hosttable"{{ pred_hostname == 'hosttable' ? ' selected' }}>{{ t('Use host table') }}</option>
<option value="userdefined"{{ pred_hostname == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
<option value="hosttable"{{ predefined_hostname == 'hosttable' ? ' selected' }}>{{ t('Use host table') }}</option>
<option value="userdefined"{{ predefined_hostname == 'userdefined' ? ' selected' }}>{{ t('Use text field') }}</option>
</select>
</span>
<input type="text" name="hostname" id="pma_hostname" maxlength="{{ hostname_length }}" value="{{ hostname|default('%') }}" title="
{{- t('Host name') }}"{{ pred_hostname == 'userdefined' ? ' required' }}>
{{- t('Host name') }}"{{ predefined_hostname == 'userdefined' ? ' required' }}>

{{ show_hint(t('When Host table is used, this field is ignored and values stored in Host table are used instead.')) }}
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/ConfigStorage/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -1450,7 +1450,7 @@ public function createPmaDatabase(string $configurationStorageDbName): bool

Current::$message = Message::error($error);

if ($GLOBALS['errno'] === 1044) {
if (DatabaseInterface::$errorNumber === 1044) {
Current::$message = Message::error(sprintf(
__(
'You do not have necessary privileges to create a database named'
Expand Down
35 changes: 13 additions & 22 deletions src/Controllers/Database/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
$GLOBALS['table_select'] ??= null;
$GLOBALS['unlim_num_rows'] ??= null;

$this->pageSettings->init('Export');
$pageSettingsErrorHtml = $this->pageSettings->getErrorHTML();
$pageSettingsHtml = $this->pageSettings->getHTML();
Expand Down Expand Up @@ -68,10 +65,10 @@ public function __invoke(ServerRequest $request): Response
UrlParams::$params['goto'] = Url::getFromRoute('/database/export');

$tableNames = $this->export->getTableNames(Current::$database);
$GLOBALS['num_tables'] = count($tableNames);
Current::$numTables = count($tableNames);

// exit if no tables in db found
if ($GLOBALS['num_tables'] < 1) {
if (Current::$numTables < 1) {
$this->response->addHTML(
Message::error(__('No tables found in database.'))->getDisplay(),
);
Expand All @@ -80,30 +77,26 @@ public function __invoke(ServerRequest $request): Response
}

$selectedTable = $request->getParsedBodyParam('selected_tbl');
if (! empty($selectedTable) && empty($GLOBALS['table_select'])) {
$GLOBALS['table_select'] = $selectedTable;
}

$tableSelect = $request->getParsedBodyParam('table_select');
$tableStructure = $request->getParsedBodyParam('table_structure');
$tableData = $request->getParsedBodyParam('table_data');
$tablesForMultiValues = [];

foreach ($tableNames as $tableName) {
$tableSelect = $request->getParsedBodyParam('table_select');
if (is_array($tableSelect)) {
$isChecked = $this->export->getCheckedClause($tableName, $tableSelect);
} elseif (isset($GLOBALS['table_select'])) {
$isChecked = $this->export->getCheckedClause($tableName, $GLOBALS['table_select']);
} elseif (is_array($selectedTable)) {
$isChecked = $this->export->getCheckedClause($tableName, $selectedTable);
} else {
$isChecked = true;
}

$tableStructure = $request->getParsedBodyParam('table_structure');
if (is_array($tableStructure)) {
$structureChecked = $this->export->getCheckedClause($tableName, $tableStructure);
} else {
$structureChecked = $isChecked;
}

$tableData = $request->getParsedBodyParam('table_data');
if (is_array($tableData)) {
$dataChecked = $this->export->getCheckedClause($tableName, $tableData);
} else {
Expand All @@ -118,20 +111,18 @@ public function __invoke(ServerRequest $request): Response
];
}

if (! isset($GLOBALS['unlim_num_rows'])) {
$GLOBALS['unlim_num_rows'] = 0;
}

$isReturnBackFromRawExport = $request->getParsedBodyParam('export_type') === 'raw';
if ($request->hasBodyParam('raw_query') || $isReturnBackFromRawExport) {
$exportType = ExportType::Raw;
} else {
$exportType = ExportType::Database;
}

$GLOBALS['single_table'] = $request->getParam('single_table') ?? $GLOBALS['single_table'] ?? null;
if ($request->has('single_table')) {
Export::$singleTable = (bool) $request->getParam('single_table');
}

$exportList = Plugins::getExport($exportType, isset($GLOBALS['single_table']));
$exportList = Plugins::getExport($exportType, Export::$singleTable);

if ($exportList === []) {
$this->response->addHTML(Message::error(
Expand All @@ -146,8 +137,8 @@ public function __invoke(ServerRequest $request): Response
Current::$database,
Current::$table,
Current::$sqlQuery,
$GLOBALS['num_tables'],
$GLOBALS['unlim_num_rows'],
Current::$numTables,
0,
$exportList,
);

Expand Down
8 changes: 3 additions & 5 deletions src/Controllers/Database/ImportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
$GLOBALS['SESSION_KEY'] ??= null;

$this->pageSettings->init('Import');
$pageSettingsErrorHtml = $this->pageSettings->getErrorHTML();
$pageSettingsHtml = $this->pageSettings->getHTML();
Expand All @@ -67,7 +65,7 @@ public function __invoke(ServerRequest $request): Response
return $this->response->response();
}

[$GLOBALS['SESSION_KEY'], $uploadId] = Ajax::uploadProgressSetup();
[$uploadId] = Ajax::uploadProgressSetup();

ImportSettings::$importType = 'database';
$importList = Plugins::getImport();
Expand All @@ -91,7 +89,7 @@ public function __invoke(ServerRequest $request): Response

$charsets = Charsets::getCharsets($this->dbi, $config->selectedServer['DisableIS']);

$idKey = $_SESSION[$GLOBALS['SESSION_KEY']]['handler']::getIdKey();
$idKey = $_SESSION[Ajax::SESSION_KEY]['handler']::getIdKey();
$hiddenInputs = [$idKey => $uploadId, 'import_type' => 'database', 'db' => Current::$database];

$default = $request->hasQueryParam('format')
Expand All @@ -107,7 +105,7 @@ public function __invoke(ServerRequest $request): Response
'page_settings_error_html' => $pageSettingsErrorHtml,
'page_settings_html' => $pageSettingsHtml,
'upload_id' => $uploadId,
'handler' => $_SESSION[$GLOBALS['SESSION_KEY']]['handler'],
'handler' => $_SESSION[Ajax::SESSION_KEY]['handler'],
'hidden_inputs' => $hiddenInputs,
'db' => Current::$database,
'table' => Current::$table,
Expand Down
9 changes: 7 additions & 2 deletions src/Controllers/Database/Structure/DropTableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use PhpMyAdmin\Http\Response;
use PhpMyAdmin\Http\ServerRequest;
use PhpMyAdmin\Message;
use PhpMyAdmin\ResponseRenderer;
use PhpMyAdmin\Util;
use PhpMyAdmin\Utils\ForeignKey;

Expand All @@ -28,7 +29,11 @@ public function __construct(

public function __invoke(ServerRequest $request): Response
{
$GLOBALS['reload'] = $_POST['reload'] ?? $GLOBALS['reload'] ?? null;
if ($request->hasBodyParam('reload')) {
$reload = $request->getParsedBodyParamAsString('reload');
ResponseRenderer::$reload = $reload === '1' || $reload === 'true';
}

$multBtn = $_POST['mult_btn'] ?? '';
/** @var string[] $selected */
$selected = $_POST['selected'] ?? [];
Expand All @@ -55,7 +60,7 @@ public function __invoke(ServerRequest $request): Response
. Util::backquote($selectedValue);
}

$GLOBALS['reload'] = 1;
ResponseRenderer::$reload = true;
}

if (Current::$sqlQuery !== '') {
Expand Down
Loading

0 comments on commit 605e56b

Please sign in to comment.