diff --git a/adminer/call.inc.php b/adminer/call.inc.php index 36c9e333..c409fd7e 100644 --- a/adminer/call.inc.php +++ b/adminer/call.inc.php @@ -36,12 +36,12 @@ if (!$error && $_POST) { $start = microtime(true); $result = $connection->multi_query($query); $affected = $connection->affected_rows; // getting warnings overwrites this - echo $adminer->selectQuery($query, $start, !$result); + echo adminer()->selectQuery($query, $start, !$result); if (!$result) { echo "
" . error() . "\n"; } else { - $connection2 = connect($adminer->credentials()); + $connection2 = connect(adminer()->credentials()); if (is_object($connection2)) { $connection2->select_db(DB); } @@ -71,7 +71,7 @@ if ($in) { foreach ($in as $key) { $field = $routine["fields"][$key]; $name = $field["field"]; - echo "
" . lang('Move to other database') . ": "; diff --git a/adminer/drivers/mssql.inc.php b/adminer/drivers/mssql.inc.php index c83c2ed8..63adc3b6 100644 --- a/adminer/drivers/mssql.inc.php +++ b/adminer/drivers/mssql.inc.php @@ -26,16 +26,15 @@ if (isset($_GET["mssql"])) { } function attach(?string $server, string $username, string $password): string { - global $adminer; $connection_info = array("UID" => $username, "PWD" => $password, "CharacterSet" => "UTF-8"); - $ssl = $adminer->connectSsl(); + $ssl = adminer()->connectSsl(); if (isset($ssl["Encrypt"])) { $connection_info["Encrypt"] = $ssl["Encrypt"]; } if (isset($ssl["TrustServerCertificate"])) { $connection_info["TrustServerCertificate"] = $ssl["TrustServerCertificate"]; } - $db = $adminer->database(); + $db = adminer()->database(); if ($db != "") { $connection_info["Database"] = $db; } diff --git a/adminer/drivers/mysql.inc.php b/adminer/drivers/mysql.inc.php index ea92f131..0b252fdf 100644 --- a/adminer/drivers/mysql.inc.php +++ b/adminer/drivers/mysql.inc.php @@ -15,10 +15,9 @@ if (!defined('Adminer\DRIVER')) { } function attach(?string $server, string $username, string $password): string { - global $adminer; mysqli_report(MYSQLI_REPORT_OFF); // stays between requests, not required since PHP 5.3.4 list($host, $port) = explode(":", $server, 2); // part after : is used for port or socket - $ssl = $adminer->connectSsl(); + $ssl = adminer()->connectSsl(); if ($ssl) { $this->ssl_set($ssl['key'], $ssl['cert'], $ssl['ca'], '', ''); } @@ -158,9 +157,8 @@ if (!defined('Adminer\DRIVER')) { public string $extension = "PDO_MySQL"; function attach(?string $server, string $username, string $password): string { - global $adminer; $options = array(\PDO::MYSQL_ATTR_LOCAL_INFILE => false); - $ssl = $adminer->connectSsl(); + $ssl = adminer()->connectSsl(); if ($ssl) { if ($ssl['key']) { $options[\PDO::MYSQL_ATTR_SSL_KEY] = $ssl['key']; diff --git a/adminer/drivers/pgsql.inc.php b/adminer/drivers/pgsql.inc.php index 5c4e7f82..d4d0ff42 100644 --- a/adminer/drivers/pgsql.inc.php +++ b/adminer/drivers/pgsql.inc.php @@ -20,11 +20,10 @@ if (isset($_GET["pgsql"])) { } function attach(?string $server, string $username, string $password): string { - global $adminer; - $db = $adminer->database(); + $db = adminer()->database(); set_error_handler(array($this, '_error')); $this->string = "host='" . str_replace(":", "' port='", addcslashes($server, "'\\")) . "' user='" . addcslashes($username, "'\\") . "' password='" . addcslashes($password, "'\\") . "'"; - $ssl = $adminer->connectSsl(); + $ssl = adminer()->connectSsl(); if (isset($ssl["mode"])) { $this->string .= " sslmode='" . $ssl["mode"] . "'"; } @@ -53,8 +52,7 @@ if (isset($_GET["pgsql"])) { } function select_db(string $database): bool { - global $adminer; - if ($database == $adminer->database()) { + if ($database == adminer()->database()) { return $this->database; } $return = @pg_connect("$this->string dbname='" . addcslashes($database, "'\\") . "'", PGSQL_CONNECT_FORCE_NEW); @@ -130,11 +128,10 @@ if (isset($_GET["pgsql"])) { public int $timeout; function attach(?string $server, string $username, string $password): string { - global $adminer; - $db = $adminer->database(); + $db = adminer()->database(); //! client_encoding is supported since 9.1, but we can't yet use min_version here $dsn = "pgsql:host='" . str_replace(":", "' port='", addcslashes($server, "'\\")) . "' client_encoding=utf8 dbname='" . ($db != "" ? addcslashes($db, "'\\") : "postgres") . "'"; - $ssl = $adminer->connectSsl(); + $ssl = adminer()->connectSsl(); if (isset($ssl["mode"])) { $dsn .= " sslmode='" . $ssl["mode"] . "'"; } @@ -142,8 +139,7 @@ if (isset($_GET["pgsql"])) { } function select_db(string $database): bool { - global $adminer; - return ($adminer->database() == $database); + return (adminer()->database() == $database); } function query(string $query, bool $unbuffered = false) { diff --git a/adminer/dump.inc.php b/adminer/dump.inc.php index 6d472e64..09a8eea3 100644 --- a/adminer/dump.inc.php +++ b/adminer/dump.inc.php @@ -39,7 +39,7 @@ SET foreign_key_checks = 0; } foreach ((array) $databases as $db) { - $adminer->dumpDatabase($db); + adminer()->dumpDatabase($db); if ($connection->select_db($db)) { if ($is_sql && preg_match('~CREATE~', $style) && ($create = get_val("SHOW CREATE DATABASE " . idf_escape($db), 1))) { set_utf8mb4($create); @@ -99,12 +99,12 @@ SET foreign_key_checks = 0; ob_start(array($tmp_file, 'write'), 1e5); } - $adminer->dumpTable($name, ($table ? $_POST["table_style"] : ""), (is_view($table_status) ? 2 : 0)); + adminer()->dumpTable($name, ($table ? $_POST["table_style"] : ""), (is_view($table_status) ? 2 : 0)); if (is_view($table_status)) { $views[] = $name; } elseif ($data) { $fields = fields($name); - $adminer->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . table($name)); + adminer()->dumpData($name, $_POST["data_style"], "SELECT *" . convert_fields($fields, $fields) . " FROM " . table($name)); } if ($is_sql && $_POST["triggers"] && $table && ($triggers = trigger_sql($name))) { echo "\nDELIMITER ;;\n$triggers\nDELIMITER ;\n"; @@ -130,7 +130,7 @@ SET foreign_key_checks = 0; } foreach ($views as $view) { - $adminer->dumpTable($view, $_POST["table_style"], 1); + adminer()->dumpTable($view, $_POST["table_style"], 1); } if ($ext == "tar") { @@ -140,7 +140,7 @@ SET foreign_key_checks = 0; } } - $adminer->dumpFooter(); + adminer()->dumpFooter(); exit; } @@ -165,9 +165,9 @@ if (!isset($row["events"])) { // backwards compatibility $row["triggers"] = $row["table_style"]; } -echo "
" . lang('Target table') . ": " . html_select("table", $referencable, $row["table"], $onchange) . "\n"; if (support("scheme")) { - $schemas = array_filter($adminer->schemas(), function ($schema) { + $schemas = array_filter(adminer()->schemas(), function ($schema) { return !preg_match('~^information_schema$~i', $schema); }); echo lang('Schema') . ": " . html_select("ns", $schemas, $row["ns"] != "" ? $row["ns"] : $_GET["ns"], $onchange); @@ -78,7 +78,7 @@ if (support("scheme")) { } } elseif (JUSH != "sqlite") { $dbs = array(); - foreach ($adminer->databases() as $db) { + foreach (adminer()->databases() as $db) { if (!information_schema($db)) { $dbs[] = $db; } diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 321be6bf..a87900d8 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -3,8 +3,9 @@ namespace Adminer; // any method change in this file should be transferred to editor/include/adminer.inc.php -/** Default Adminer plugin; it should call methods via $adminer->f() instead of $this->f() to give chance to other plugins */ +/** Default Adminer plugin; it should call methods via adminer()->f() instead of $this->f() to give chance to other plugins */ class Adminer { + /** @var Adminer|Plugins */ static $instance; /** @visibility protected(set) */ public string $error = ''; // HTML /** Name in title and navigation @@ -119,15 +120,14 @@ class Adminer { /** Print login form */ function loginForm(): void { - global $adminer; echo "
| ' . lang('System') . ' | ', html_select("auth[driver]", SqlDriver::$drivers, DRIVER, "loginDriver(this);")); - echo $adminer->loginFormField('server', ' |
|---|---|
| ' . lang('Server') . ' | ', ''); + echo adminer()->loginFormField('driver', ' |
| ' . lang('System') . ' | ', html_select("auth[driver]", SqlDriver::$drivers, DRIVER, "loginDriver(this);")); + echo adminer()->loginFormField('server', ' |
| ' . lang('Server') . ' | ', ''); // this is matched by compile.php - echo $adminer->loginFormField('username', ' |
| ' . lang('Username') . ' | ', '' . script("qs('#username').form['auth[driver]'].onchange();")); - echo $adminer->loginFormField('password', ' |
| ' . lang('Password') . ' | ', ''); - echo $adminer->loginFormField('db', ' |
| ' . lang('Database') . ' | ', ''); + echo adminer()->loginFormField('username', ' |
| ' . lang('Username') . ' | ', '' . script("qs('#username').form['auth[driver]'].onchange();")); + echo adminer()->loginFormField('password', ' |
| ' . lang('Password') . ' | ', ''); + echo adminer()->loginFormField('db', ' |
| ' . lang('Database') . ' | ', ''); echo " |
\n"; echo checkbox("auth[permanent]", 1, $_COOKIE["adminer_permanent"], lang('Permanent login')) . "\n"; @@ -384,7 +384,6 @@ class Adminer { * @param Index[] $indexes */ function selectSearchPrint(array $where, array $columns, array $indexes): void { - global $adminer; print_fieldset("search", lang('Search'), $where); foreach ($indexes as $i => $index) { if ($index["type"] == "FULLTEXT") { @@ -397,7 +396,7 @@ class Adminer { } $change_next = "this.parentNode.firstChild.onchange();"; foreach (array_merge((array) $_GET["where"], array(array())) as $i => $val) { - if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $adminer->operators()))) { + if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], adminer()->operators()))) { echo "
\n" . implode("\n", $actions) . "\n" : ""); if ($in_db) { if ($tables) { - $adminer->tablesPrint($tables); + adminer()->tablesPrint($tables); } else { echo "
\n"; } @@ -1035,8 +1034,8 @@ class Adminer { /** Print databases list in menu */ function databasesPrint(string $missing): void { - global $adminer, $connection; - $databases = $adminer->databases(); + global $connection; + $databases = adminer()->databases(); if (DB && $databases && !in_array(DB, $databases)) { array_unshift($databases, DB); } @@ -1050,7 +1049,7 @@ class Adminer { echo "\n"; if (support("scheme")) { if ($missing != "db" && DB != "" && $connection->select_db(DB)) { - echo "" . lang('%s version: %s through PHP extension %s', get_driver(DRIVER), "" . h($connection->server_info) . "", "$connection->extension") . "\n"; echo "
" . lang('Logged as: %s', "" . h(logged_user()) . "") . "\n"; - if (isset($adminer->plugins) && is_array($adminer->plugins)) { + if (isset(adminer()->plugins) && is_array(adminer()->plugins)) { echo "
" . lang('Loaded plugins') . ":\n
$print: " . error()) . "\n"; @@ -364,15 +363,14 @@ function on_help(string $command, int $side = 0): string { * @param mixed $row */ function edit_form(string $table, array $fields, $row, ?bool $update, string $error = ''): void { - global $adminer; - $table_name = $adminer->tableName(table_status1($table, true)); + $table_name = adminer()->tableName(table_status1($table, true)); page_header( ($update ? lang('Edit') : lang('Insert')), $error, array("select" => array($table, $table_name)), $table_name ); - $adminer->editRowPrint($table, $fields, $row, $update); + adminer()->editRowPrint($table, $fields, $row, $update); if ($row === false) { echo "
" . lang('No rows.') . "\n"; return; @@ -384,7 +382,7 @@ function edit_form(string $table, array $fields, $row, ?bool $update, string $er echo "
| " . $adminer->fieldName($field); + echo " | ||||
|---|---|---|---|---|
| " . adminer()->fieldName($field); $default = idx($_GET["set"], bracket_escape($name)); if ($default === null) { $default = $field["default"]; @@ -406,7 +404,7 @@ function edit_form(string $table, array $fields, $row, ?bool $update, string $er ) ); if (!$_POST["save"] && is_string($value)) { - $value = $adminer->editVal($value, $field); + $value = adminer()->editVal($value, $field); } $function = ($_POST["save"] ? idx($_POST["function"], $name, "") @@ -439,7 +437,7 @@ function edit_form(string $table, array $fields, $row, ?bool $update, string $er echo " | ||||
| " . script("qsl('input').oninput = fieldChange;") - . " | " . html_select("field_funs[]", $adminer->editFunctions(array("null" => isset($_GET["select"])))) + . " | " . html_select("field_funs[]", adminer()->editFunctions(array("null" => isset($_GET["select"])))) . " | "
. "\n"
;
diff --git a/adminer/schema.inc.php b/adminer/schema.inc.php
index b3ab4e41..b677514b 100644
--- a/adminer/schema.inc.php
+++ b/adminer/schema.inc.php
@@ -31,7 +31,7 @@ foreach (table_status('', true) as $table => $table_status) {
$schema[$table]["fields"][$name] = $field;
}
$schema[$table]["pos"] = ($table_pos[$table] ?: array($top, 0));
- foreach ($adminer->foreignKeys($table) as $val) {
+ foreach (adminer()->foreignKeys($table) as $val) {
if (!$val["db"]) {
$left = $base_left;
if (idx($table_pos[$table], 1) || idx($table_pos[$val["table"]], 1)) {
diff --git a/adminer/script.inc.php b/adminer/script.inc.php
index c5fb950f..35b981c6 100644
--- a/adminer/script.inc.php
+++ b/adminer/script.inc.php
@@ -39,7 +39,7 @@ if ($_GET["script"] == "db") {
$connection->query("KILL " . number($_POST["kill"]));
} else { // connect
- foreach (count_tables($adminer->databases()) as $db => $val) {
+ foreach (count_tables(adminer()->databases()) as $db => $val) {
json_row("tables-$db", $val);
json_row("size-$db", db_size($db));
}
diff --git a/adminer/select.inc.php b/adminer/select.inc.php
index b71656aa..b9ce4d8c 100644
--- a/adminer/select.inc.php
+++ b/adminer/select.inc.php
@@ -15,12 +15,12 @@ $search_columns = array(); // searchable columns
$order_columns = array(); // searchable columns
$text_length = "";
foreach ($fields as $key => $field) {
- $name = $adminer->fieldName($field);
+ $name = adminer()->fieldName($field);
$name_plain = html_entity_decode(strip_tags($name), ENT_QUOTES);
if (isset($field["privileges"]["select"]) && $name != "") {
$columns[$key] = $name_plain;
if (is_shortable($field)) {
- $text_length = $adminer->selectLengthProcess();
+ $text_length = adminer()->selectLengthProcess();
}
}
if (isset($field["privileges"]["where"]) && $name != "") {
@@ -32,13 +32,13 @@ foreach ($fields as $key => $field) {
$rights += $field["privileges"];
}
-list($select, $group) = $adminer->selectColumnsProcess($columns, $indexes);
+list($select, $group) = adminer()->selectColumnsProcess($columns, $indexes);
$select = array_unique($select);
$group = array_unique($group);
$is_group = count($group) < count($select);
-$where = $adminer->selectSearchProcess($fields, $indexes);
-$order = $adminer->selectOrderProcess($fields, $indexes);
-$limit = $adminer->selectLimitProcess();
+$where = adminer()->selectSearchProcess($fields, $indexes);
+$order = adminer()->selectOrderProcess($fields, $indexes);
+$limit = adminer()->selectLimitProcess();
if ($_GET["val"] && is_ajax()) {
header("Content-Type: text/plain; charset=utf-8");
@@ -85,7 +85,7 @@ if ($_POST && !$error) {
if ($_POST["export"]) {
save_settings(array("output" => $_POST["output"], "format" => $_POST["format"]), "adminer_import");
dump_headers($TABLE);
- $adminer->dumpTable($TABLE, "");
+ adminer()->dumpTable($TABLE, "");
$from = ($select ? implode(", ", $select) : "*")
. convert_fields($columns, $fields, $select)
. "\nFROM " . table($TABLE);
@@ -99,12 +99,12 @@ if ($_POST && !$error) {
}
$query = implode(" UNION ALL ", $union);
}
- $adminer->dumpData($TABLE, "table", $query);
- $adminer->dumpFooter();
+ adminer()->dumpData($TABLE, "table", $query);
+ adminer()->dumpFooter();
exit;
}
- if (!$adminer->selectEmailProcess($where, $foreign_keys)) {
+ if (!adminer()->selectEmailProcess($where, $foreign_keys)) {
if ($_POST["save"] || $_POST["delete"]) { // edit
$result = true;
$affected = 0;
@@ -174,7 +174,7 @@ if ($_POST && !$error) {
$set = array();
foreach ($row as $key => $val) {
$key = bracket_escape($key, true); // true - back
- $set[idf_escape($key)] = (preg_match('~char|text~', $fields[$key]["type"]) || $val != "" ? $adminer->processInput($fields[$key], $val) : "NULL");
+ $set[idf_escape($key)] = (preg_match('~char|text~', $fields[$key]["type"]) || $val != "" ? adminer()->processInput($fields[$key], $val) : "NULL");
}
$result = $driver->update(
$TABLE,
@@ -229,7 +229,7 @@ if ($_POST && !$error) {
}
}
-$table_name = $adminer->tableName($table_status);
+$table_name = adminer()->tableName($table_status);
if (is_ajax()) {
page_headers();
ob_start();
@@ -251,7 +251,7 @@ if (isset($rights["insert"]) || !support("table")) {
$set = $params ? "&" . http_build_query($params) : "";
}
-$adminer->selectLinks($table_status, $set);
+adminer()->selectLinks($table_status, $set);
if (!$columns && support("table")) {
echo " " . lang('Unable to select the table') . ($fields ? "." : ": " . error()) . "\n"; @@ -262,12 +262,12 @@ if (!$columns && support("table")) { echo (DB != "" ? input_hidden("db", DB) . (isset($_GET["ns"]) ? input_hidden("ns", $_GET["ns"]) : "") : ""); // not used in Editor echo input_hidden("select", $TABLE); echo "\n"; - $adminer->selectColumnsPrint($select, $columns); - $adminer->selectSearchPrint($where, $search_columns, $indexes); - $adminer->selectOrderPrint($order, $order_columns, $indexes); - $adminer->selectLimitPrint($limit); - $adminer->selectLengthPrint($text_length); - $adminer->selectActionPrint($indexes); + adminer()->selectColumnsPrint($select, $columns); + adminer()->selectSearchPrint($where, $search_columns, $indexes); + adminer()->selectOrderPrint($order, $order_columns, $indexes); + adminer()->selectLimitPrint($limit); + adminer()->selectLengthPrint($text_length); + adminer()->selectActionPrint($indexes); echo "\n"; $page = $_GET["page"]; @@ -325,7 +325,7 @@ if (!$columns && support("table")) { if (!$rows) { echo " ";
echo "
|