mirror of
https://github.com/vrana/adminer.git
synced 2025-08-05 06:07:57 +02:00
Move $drivers to SqlDriver
This commit is contained in:
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
namespace Adminer;
|
namespace Adminer;
|
||||||
|
|
||||||
$drivers["mssql"] = "MS SQL";
|
add_driver("mssql", "MS SQL");
|
||||||
|
|
||||||
if (isset($_GET["mssql"])) {
|
if (isset($_GET["mssql"])) {
|
||||||
define('Adminer\DRIVER', "mssql");
|
define('Adminer\DRIVER', "mssql");
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Adminer;
|
namespace Adminer;
|
||||||
|
|
||||||
$drivers = array("server" => "MySQL / MariaDB") + $drivers;
|
SqlDriver::$drivers = array("server" => "MySQL / MariaDB") + SqlDriver::$drivers;
|
||||||
|
|
||||||
if (!defined('Adminer\DRIVER')) {
|
if (!defined('Adminer\DRIVER')) {
|
||||||
define('Adminer\DRIVER', "server"); // server - backwards compatibility
|
define('Adminer\DRIVER', "server"); // server - backwards compatibility
|
||||||
@@ -366,7 +366,6 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
* @return string|Db string for error
|
* @return string|Db string for error
|
||||||
*/
|
*/
|
||||||
function connect(array $credentials) {
|
function connect(array $credentials) {
|
||||||
global $drivers;
|
|
||||||
$connection = new Db;
|
$connection = new Db;
|
||||||
$error = $connection->attach($credentials[0], $credentials[1], $credentials[2]);
|
$error = $connection->attach($credentials[0], $credentials[1], $credentials[2]);
|
||||||
if ($error) {
|
if ($error) {
|
||||||
@@ -378,7 +377,7 @@ if (!defined('Adminer\DRIVER')) {
|
|||||||
$connection->set_charset(charset($connection));
|
$connection->set_charset(charset($connection));
|
||||||
$connection->query("SET sql_quote_show_create = 1, autocommit = 1");
|
$connection->query("SET sql_quote_show_create = 1, autocommit = 1");
|
||||||
$connection->flavor = (preg_match('~MariaDB~', $connection->server_info) ? 'maria' : 'mysql');
|
$connection->flavor = (preg_match('~MariaDB~', $connection->server_info) ? 'maria' : 'mysql');
|
||||||
$drivers[DRIVER] = ($connection->flavor == 'maria' ? "MariaDB" : "MySQL");
|
add_driver(DRIVER, ($connection->flavor == 'maria' ? "MariaDB" : "MySQL"));
|
||||||
return $connection;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Adminer;
|
namespace Adminer;
|
||||||
|
|
||||||
$drivers["oracle"] = "Oracle (beta)";
|
add_driver("oracle", "Oracle (beta)");
|
||||||
|
|
||||||
if (isset($_GET["oracle"])) {
|
if (isset($_GET["oracle"])) {
|
||||||
define('Adminer\DRIVER', "oracle");
|
define('Adminer\DRIVER', "oracle");
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Adminer;
|
namespace Adminer;
|
||||||
|
|
||||||
$drivers["pgsql"] = "PostgreSQL";
|
add_driver("pgsql", "PostgreSQL");
|
||||||
|
|
||||||
if (isset($_GET["pgsql"])) {
|
if (isset($_GET["pgsql"])) {
|
||||||
define('Adminer\DRIVER', "pgsql");
|
define('Adminer\DRIVER', "pgsql");
|
||||||
@@ -301,7 +301,6 @@ if (isset($_GET["pgsql"])) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function connect($credentials) {
|
function connect($credentials) {
|
||||||
global $drivers;
|
|
||||||
$connection = new Db;
|
$connection = new Db;
|
||||||
$error = $connection->attach($credentials[0], $credentials[1], $credentials[2]);
|
$error = $connection->attach($credentials[0], $credentials[1], $credentials[2]);
|
||||||
if ($error) {
|
if ($error) {
|
||||||
@@ -314,7 +313,7 @@ if (isset($_GET["pgsql"])) {
|
|||||||
$connection->flavor = (preg_match('~CockroachDB~', $version) ? 'cockroach' : '');
|
$connection->flavor = (preg_match('~CockroachDB~', $version) ? 'cockroach' : '');
|
||||||
$connection->server_info = preg_replace('~^\D*([\d.]+[-\w]*).*~', '\1', $version);
|
$connection->server_info = preg_replace('~^\D*([\d.]+[-\w]*).*~', '\1', $version);
|
||||||
if ($connection->flavor == 'cockroach') { // we don't use "PostgreSQL / CockroachDB" by default because it's too long
|
if ($connection->flavor == 'cockroach') { // we don't use "PostgreSQL / CockroachDB" by default because it's too long
|
||||||
$drivers[DRIVER] = "CockroachDB";
|
add_driver(DRIVER, "CockroachDB");
|
||||||
}
|
}
|
||||||
return $connection;
|
return $connection;
|
||||||
}
|
}
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Adminer;
|
namespace Adminer;
|
||||||
|
|
||||||
$drivers["sqlite"] = "SQLite";
|
add_driver("sqlite", "SQLite");
|
||||||
|
|
||||||
if (isset($_GET["sqlite"])) {
|
if (isset($_GET["sqlite"])) {
|
||||||
define('Adminer\DRIVER', "sqlite");
|
define('Adminer\DRIVER', "sqlite");
|
||||||
|
@@ -16,7 +16,7 @@ if ($_POST && !$error) {
|
|||||||
$is_sql = preg_match('~sql~', $_POST["format"]);
|
$is_sql = preg_match('~sql~', $_POST["format"]);
|
||||||
|
|
||||||
if ($is_sql) {
|
if ($is_sql) {
|
||||||
echo "-- Adminer " . VERSION . " " . $drivers[DRIVER] . " " . str_replace("\n", " ", $connection->server_info) . " dump\n\n";
|
echo "-- Adminer " . VERSION . " " . get_driver(DRIVER) . " " . str_replace("\n", " ", $connection->server_info) . " dump\n\n";
|
||||||
if (JUSH == "sql") {
|
if (JUSH == "sql") {
|
||||||
echo "SET NAMES utf8;
|
echo "SET NAMES utf8;
|
||||||
SET time_zone = '+00:00';
|
SET time_zone = '+00:00';
|
||||||
|
@@ -118,10 +118,10 @@ class Adminer {
|
|||||||
|
|
||||||
/** Print login form */
|
/** Print login form */
|
||||||
function loginForm(): void {
|
function loginForm(): void {
|
||||||
global $drivers, $adminer;
|
global $adminer;
|
||||||
echo "<table class='layout'>\n";
|
echo "<table class='layout'>\n";
|
||||||
// this is matched by compile.php
|
// this is matched by compile.php
|
||||||
echo $adminer->loginFormField('driver', '<tr><th>' . lang('System') . '<td>', html_select("auth[driver]", $drivers, DRIVER, "loginDriver(this);"));
|
echo $adminer->loginFormField('driver', '<tr><th>' . lang('System') . '<td>', html_select("auth[driver]", SqlDriver::$drivers, DRIVER, "loginDriver(this);"));
|
||||||
echo $adminer->loginFormField('server', '<tr><th>' . lang('Server') . '<td>', '<input name="auth[server]" value="' . h(SERVER) . '" title="hostname[:port]" placeholder="localhost" autocapitalize="off">');
|
echo $adminer->loginFormField('server', '<tr><th>' . lang('Server') . '<td>', '<input name="auth[server]" value="' . h(SERVER) . '" title="hostname[:port]" placeholder="localhost" autocapitalize="off">');
|
||||||
// this is matched by compile.php
|
// this is matched by compile.php
|
||||||
echo $adminer->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', '<input name="auth[username]" id="username" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">' . script("qs('#username').form['auth[driver]'].onchange();"));
|
echo $adminer->loginFormField('username', '<tr><th>' . lang('Username') . '<td>', '<input name="auth[username]" id="username" autofocus value="' . h($_GET["username"]) . '" autocomplete="username" autocapitalize="off">' . script("qs('#username').form['auth[driver]'].onchange();"));
|
||||||
@@ -946,7 +946,7 @@ class Adminer {
|
|||||||
* @param string $missing can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
|
* @param string $missing can be "auth" if there is no database connection, "db" if there is no database selected, "ns" with invalid schema
|
||||||
*/
|
*/
|
||||||
function navigation(string $missing): void {
|
function navigation(string $missing): void {
|
||||||
global $drivers, $connection, $adminer;
|
global $connection, $adminer;
|
||||||
echo "<h1>" . $adminer->name() . " <span class='version'>" . VERSION;
|
echo "<h1>" . $adminer->name() . " <span class='version'>" . VERSION;
|
||||||
$new_version = $_COOKIE["adminer_version"];
|
$new_version = $_COOKIE["adminer_version"];
|
||||||
echo " <a href='https://www.adminer.org/#download'" . target_blank() . " id='version'>" . (version_compare(VERSION, $new_version) < 0 ? h($new_version) : "") . "</a>";
|
echo " <a href='https://www.adminer.org/#download'" . target_blank() . " id='version'>" . (version_compare(VERSION, $new_version) < 0 ? h($new_version) : "") . "</a>";
|
||||||
@@ -957,7 +957,7 @@ class Adminer {
|
|||||||
$output = "";
|
$output = "";
|
||||||
foreach ((array) $_SESSION["pwds"] as $vendor => $servers) {
|
foreach ((array) $_SESSION["pwds"] as $vendor => $servers) {
|
||||||
foreach ($servers as $server => $usernames) {
|
foreach ($servers as $server => $usernames) {
|
||||||
$name = h(get_setting("vendor-$vendor-$server") ?: $drivers[$vendor]);
|
$name = h(get_setting("vendor-$vendor-$server") ?: get_driver($vendor));
|
||||||
foreach ($usernames as $username => $password) {
|
foreach ($usernames as $username => $password) {
|
||||||
if ($password !== null) {
|
if ($password !== null) {
|
||||||
$dbs = $_SESSION["db"][$vendor][$server][$username];
|
$dbs = $_SESSION["db"][$vendor][$server][$username];
|
||||||
|
@@ -182,7 +182,7 @@ if (isset($_GET["username"]) && is_string(get_password())) {
|
|||||||
if (is_object($connection)) {
|
if (is_object($connection)) {
|
||||||
$driver = new Driver($connection);
|
$driver = new Driver($connection);
|
||||||
if ($connection->flavor) {
|
if ($connection->flavor) {
|
||||||
save_settings(array("vendor-" . DRIVER . "-" . SERVER => $drivers[DRIVER]));
|
save_settings(array("vendor-" . DRIVER . "-" . SERVER => get_driver(DRIVER)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -39,7 +39,7 @@ if ($_GET["script"] == "version") {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
global $adminer, $connection, $driver, $drivers, $translations; // allows including Adminer inside a function
|
global $adminer, $connection, $driver, $translations; // allows including Adminer inside a function
|
||||||
|
|
||||||
if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility
|
if (!$_SERVER["REQUEST_URI"]) { // IIS 5 compatibility
|
||||||
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"];
|
$_SERVER["REQUEST_URI"] = $_SERVER["ORIG_PATH_INFO"];
|
||||||
|
@@ -42,7 +42,7 @@ if (
|
|||||||
echo "<a href='" . h(ME) . "$key='>$val</a>\n";
|
echo "<a href='" . h(ME) . "$key='>$val</a>\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
echo "<p>" . lang('%s version: %s through PHP extension %s', $drivers[DRIVER], "<b>" . h($connection->server_info) . "</b>", "<b>$connection->extension</b>") . "\n";
|
echo "<p>" . lang('%s version: %s through PHP extension %s', get_driver(DRIVER), "<b>" . h($connection->server_info) . "</b>", "<b>$connection->extension</b>") . "\n";
|
||||||
echo "<p>" . lang('Logged as: %s', "<b>" . h(logged_user()) . "</b>") . "\n";
|
echo "<p>" . lang('Logged as: %s', "<b>" . h(logged_user()) . "</b>") . "\n";
|
||||||
if (isset($adminer->plugins) && is_array($adminer->plugins)) {
|
if (isset($adminer->plugins) && is_array($adminer->plugins)) {
|
||||||
echo "<p>" . lang('Loaded plugins') . ":\n<ul>\n";
|
echo "<p>" . lang('Loaded plugins') . ":\n<ul>\n";
|
||||||
|
@@ -7,7 +7,7 @@ namespace Adminer;
|
|||||||
* @param string $title2 used after colon in title and heading, should be HTML escaped
|
* @param string $title2 used after colon in title and heading, should be HTML escaped
|
||||||
*/
|
*/
|
||||||
function page_header(string $title, string $error = "", $breadcrumb = array(), string $title2 = ""): void {
|
function page_header(string $title, string $error = "", $breadcrumb = array(), string $title2 = ""): void {
|
||||||
global $adminer, $drivers;
|
global $adminer;
|
||||||
page_headers();
|
page_headers();
|
||||||
if (is_ajax() && $error) {
|
if (is_ajax() && $error) {
|
||||||
page_messages($error);
|
page_messages($error);
|
||||||
@@ -88,7 +88,7 @@ const thousandsSeparator = '" . js_escape(lang(',')) . "';")
|
|||||||
echo "<div id='content'>\n";
|
echo "<div id='content'>\n";
|
||||||
if ($breadcrumb !== null) {
|
if ($breadcrumb !== null) {
|
||||||
$link = substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1);
|
$link = substr(preg_replace('~\b(username|db|ns)=[^&]*&~', '', ME), 0, -1);
|
||||||
echo '<p id="breadcrumb"><a href="' . h($link ?: ".") . '">' . $drivers[DRIVER] . '</a> » ';
|
echo '<p id="breadcrumb"><a href="' . h($link ?: ".") . '">' . get_driver(DRIVER) . '</a> » ';
|
||||||
$link = substr(preg_replace('~\b(db|ns)=[^&]*&~', '', ME), 0, -1);
|
$link = substr(preg_replace('~\b(db|ns)=[^&]*&~', '', ME), 0, -1);
|
||||||
$server = $adminer->serverName(SERVER);
|
$server = $adminer->serverName(SERVER);
|
||||||
$server = ($server != "" ? $server : lang('Server'));
|
$server = ($server != "" ? $server : lang('Server'));
|
||||||
|
@@ -1,21 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace Adminer;
|
namespace Adminer;
|
||||||
|
|
||||||
$drivers = array();
|
/** Add or overwrite a driver */
|
||||||
|
|
||||||
/** Add a driver */
|
|
||||||
function add_driver(string $id, string $name): void {
|
function add_driver(string $id, string $name): void {
|
||||||
global $drivers;
|
SqlDriver::$drivers[$id] = $name;
|
||||||
$drivers[$id] = $name;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get driver name */
|
/** Get driver name */
|
||||||
function get_driver(string $id): string {
|
function get_driver(string $id): string {
|
||||||
global $drivers;
|
return SqlDriver::$drivers[$id];
|
||||||
return $drivers[$id];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class SqlDriver {
|
abstract class SqlDriver {
|
||||||
|
/** @var string[] */ static array $drivers = array();
|
||||||
/** @var list<string> */ static array $extensions = array(); // possible extensions
|
/** @var list<string> */ static array $extensions = array(); // possible extensions
|
||||||
static string $jush; // JUSH identifier
|
static string $jush; // JUSH identifier
|
||||||
|
|
||||||
|
@@ -391,8 +391,7 @@ function set_session(string $key, $val) {
|
|||||||
|
|
||||||
/** Get authenticated URL */
|
/** Get authenticated URL */
|
||||||
function auth_url(string $vendor, ?string $server, string $username, string $db = null): string {
|
function auth_url(string $vendor, ?string $server, string $username, string $db = null): string {
|
||||||
global $drivers;
|
$uri = remove_from_uri(implode("|", array_keys(SqlDriver::$drivers))
|
||||||
$uri = remove_from_uri(implode("|", array_keys($drivers))
|
|
||||||
. "|username|ext|"
|
. "|username|ext|"
|
||||||
. ($db !== null ? "db|" : "")
|
. ($db !== null ? "db|" : "")
|
||||||
. ($vendor == 'mssql' || $vendor == 'pgsql' ? "" : "ns|") // we don't have access to support() here
|
. ($vendor == 'mssql' || $vendor == 'pgsql' ? "" : "ns|") // we don't have access to support() here
|
||||||
|
@@ -320,8 +320,8 @@ if ($vendor) {
|
|||||||
$file = preg_replace("((\t*)" . preg_quote('if (support("' . $feature . '")') . ".*?\n\\1\\}( else)?)s", '', $file);
|
$file = preg_replace("((\t*)" . preg_quote('if (support("' . $feature . '")') . ".*?\n\\1\\}( else)?)s", '', $file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($project != "editor" && count($drivers) == 1) {
|
if ($project != "editor" && count(Adminer\SqlDriver::$drivers) == 1) {
|
||||||
$file = str_replace('html_select("auth[driver]", $drivers, DRIVER, "loginDriver(this);")', 'input_hidden("auth[driver]", "' . ($vendor == "mysql" ? "server" : $vendor) . '") . "' . reset($drivers) . '"', $file, $count);
|
$file = str_replace('html_select("auth[driver]", SqlDriver::$drivers, DRIVER, "loginDriver(this);")', 'input_hidden("auth[driver]", "' . ($vendor == "mysql" ? "server" : $vendor) . '") . "' . reset(Adminer\SqlDriver::$drivers) . '"', $file, $count);
|
||||||
if (!$count) {
|
if (!$count) {
|
||||||
echo "auth[driver] form field not found\n";
|
echo "auth[driver] form field not found\n";
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@
|
|||||||
namespace Adminer;
|
namespace Adminer;
|
||||||
|
|
||||||
include "../adminer/include/bootstrap.inc.php";
|
include "../adminer/include/bootstrap.inc.php";
|
||||||
$drivers[DRIVER] = lang('Login');
|
add_driver(DRIVER, lang('Login'));
|
||||||
|
|
||||||
if (isset($_GET["select"]) && ($_POST["edit"] || $_POST["clone"]) && !$_POST["save"]) {
|
if (isset($_GET["select"]) && ($_POST["edit"] || $_POST["clone"]) && !$_POST["save"]) {
|
||||||
$_GET["edit"] = $_GET["select"];
|
$_GET["edit"] = $_GET["select"];
|
||||||
|
@@ -12,7 +12,7 @@ parameters:
|
|||||||
- identifier: includeOnce.fileNotFound # ./adminer-plugins.php
|
- identifier: includeOnce.fileNotFound # ./adminer-plugins.php
|
||||||
- "~^Function (set_magic_quotes_runtime|mysql_)~" # PHP < 7 functions
|
- "~^Function (set_magic_quotes_runtime|mysql_)~" # PHP < 7 functions
|
||||||
- "~an unknown class OCI-?Lob~" # this looks like PHPStan bug
|
- "~an unknown class OCI-?Lob~" # this looks like PHPStan bug
|
||||||
- "~^Variable \\$(adminer|connection|driver|drivers|error|translations) might not be defined~" # declared in bootstrap.inc.php
|
- "~^Variable \\$(adminer|connection|driver|error|translations) might not be defined~" # declared in bootstrap.inc.php
|
||||||
- "~^Constant LANG not found~" # defined in lang.inc.php
|
- "~^Constant LANG not found~" # defined in lang.inc.php
|
||||||
- "~expects int, float given~" # this will work
|
- "~expects int, float given~" # this will work
|
||||||
- "~expects bool~" # truthy values
|
- "~expects bool~" # truthy values
|
||||||
|
Reference in New Issue
Block a user