1
0
mirror of https://github.com/vrana/adminer.git synced 2025-08-06 22:56:46 +02:00

Use adminer() instead of $adminer

This commit is contained in:
Jakub Vrana
2025-03-29 20:56:19 +01:00
parent 87f149ce1d
commit 845445baad
29 changed files with 184 additions and 218 deletions

View File

@@ -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 "<table class='layout'>\n";
// this is matched by compile.php
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('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">');
// 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('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">');
echo $adminer->loginFormField('db', '<tr><th>' . lang('Database') . '<td>', '<input name="auth[db]" value="' . h($_GET["db"]) . '" autocapitalize="off">');
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('password', '<tr><th>' . lang('Password') . '<td>', '<input type="password" name="auth[password]" autocomplete="current-password">');
echo adminer()->loginFormField('db', '<tr><th>' . lang('Database') . '<td>', '<input name="auth[db]" value="' . h($_GET["db"]) . '" autocapitalize="off">');
echo "</table>\n";
echo "<p><input type='submit' value='" . lang('Login') . "'>\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 "<div>" . select_input(
" name='where[$i][col]'",
$columns,
@@ -405,7 +404,7 @@ class Adminer {
($val ? "selectFieldChange" : "selectAddRow"),
"(" . lang('anywhere') . ")"
);
echo html_select("where[$i][op]", $adminer->operators(), $val["op"], $change_next);
echo html_select("where[$i][op]", adminer()->operators(), $val["op"], $change_next);
echo "<input type='search' name='where[$i][val]' value='" . h($val["val"]) . "'>";
echo script("mixin(qsl('input'), {oninput: function () { $change_next }, onkeydown: selectSearchKeydown, onsearch: selectSearchSearch});", "");
echo "</div>\n";
@@ -528,7 +527,7 @@ class Adminer {
* @return list<string> expressions to join by AND
*/
function selectSearchProcess(array $fields, array $indexes): array {
global $connection, $driver, $adminer;
global $connection, $driver;
$return = array();
foreach ($indexes as $i => $index) {
if ($index["type"] == "FULLTEXT" && $_GET["fulltext"][$i] != "") {
@@ -536,7 +535,7 @@ class Adminer {
}
}
foreach ((array) $_GET["where"] as $key => $val) {
if ("$val[col]$val[val]" != "" && in_array($val["op"], $adminer->operators())) {
if ("$val[col]$val[val]" != "" && in_array($val["op"], adminer()->operators())) {
$prefix = "";
$cond = " $val[op]";
if (preg_match('~IN$~', $val["op"])) {
@@ -545,14 +544,14 @@ class Adminer {
} elseif ($val["op"] == "SQL") {
$cond = " $val[val]"; // SQL injection
} elseif ($val["op"] == "LIKE %%") {
$cond = " LIKE " . $adminer->processInput($fields[$val["col"]], "%$val[val]%");
$cond = " LIKE " . adminer()->processInput($fields[$val["col"]], "%$val[val]%");
} elseif ($val["op"] == "ILIKE %%") {
$cond = " ILIKE " . $adminer->processInput($fields[$val["col"]], "%$val[val]%");
$cond = " ILIKE " . adminer()->processInput($fields[$val["col"]], "%$val[val]%");
} elseif ($val["op"] == "FIND_IN_SET") {
$prefix = "$val[op](" . q($val["val"]) . ", ";
$cond = ")";
} elseif (!preg_match('~NULL$~', $val["op"])) {
$cond .= " " . $adminer->processInput($fields[$val["col"]], $val["val"]);
$cond .= " " . adminer()->processInput($fields[$val["col"]], $val["val"]);
}
if ($val["col"] != "") {
$return[] = $prefix . $driver->convertSearch(idf_escape($val["col"]), $val, $fields[$val["col"]]) . $cond;
@@ -947,8 +946,8 @@ 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
*/
function navigation(string $missing): void {
global $connection, $adminer;
echo "<h1>" . $adminer->name() . " <span class='version'>" . VERSION;
global $connection;
echo "<h1>" . adminer()->name() . " <span class='version'>" . 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 "</span></h1>\n";
@@ -963,7 +962,7 @@ class Adminer {
if ($password !== null) {
$dbs = $_SESSION["db"][$vendor][$server][$username];
foreach (($dbs ? array_keys($dbs) : array("")) as $db) {
$output .= "<li><a href='" . h(auth_url($vendor, $server, $username, $db)) . "'>($name) " . h($username . ($server != "" ? "@" . $adminer->serverName($server) : "") . ($db != "" ? " - $db" : "")) . "</a>\n";
$output .= "<li><a href='" . h(auth_url($vendor, $server, $username, $db)) . "'>($name) " . h($username . ($server != "" ? "@" . adminer()->serverName($server) : "") . ($db != "" ? " - $db" : "")) . "</a>\n";
}
}
}
@@ -978,8 +977,8 @@ class Adminer {
$connection->select_db(DB);
$tables = table_status('', true);
}
$adminer->syntaxHighlighting($tables);
$adminer->databasesPrint($missing);
adminer()->syntaxHighlighting($tables);
adminer()->databasesPrint($missing);
$actions = array();
if (DB == "" || !$missing) {
if (support("sql")) {
@@ -995,7 +994,7 @@ class Adminer {
echo ($actions ? "<p class='links'>\n" . implode("\n", $actions) . "\n" : "");
if ($in_db) {
if ($tables) {
$adminer->tablesPrint($tables);
adminer()->tablesPrint($tables);
} else {
echo "<p class='message'>" . lang('No tables.') . "</p>\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 "<input type='submit' value='" . lang('Use') . "'" . ($databases ? " class='hidden'" : "") . ">\n";
if (support("scheme")) {
if ($missing != "db" && DB != "" && $connection->select_db(DB)) {
echo "<br><span>" . lang('Schema') . ":</span> " . html_select("ns", array("" => "") + $adminer->schemas(), $_GET["ns"]) . $db_events;
echo "<br><span>" . lang('Schema') . ":</span> " . html_select("ns", array("" => "") + adminer()->schemas(), $_GET["ns"]) . $db_events;
if ($_GET["ns"] != "") {
set_schema($_GET["ns"]);
}
@@ -1069,10 +1068,9 @@ class Adminer {
* @param TableStatus[] $tables
*/
function tablesPrint(array $tables): void {
global $adminer;
echo "<ul id='tables'>" . script("mixin(qs('#tables'), {onmouseover: menuOver, onmouseout: menuOut});");
foreach ($tables as $table => $status) {
$name = $adminer->tableName($status);
$name = adminer()->tableName($status);
if ($name != "") {
echo '<li><a href="' . h(ME) . 'select=' . urlencode($table) . '"'
. bold($_GET["select"] == $table || $_GET["edit"] == $table, "select")