From 517f63835dba91106f4eab5814e92fc63b91c8a0 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Sun, 16 Mar 2025 13:52:04 +0100 Subject: [PATCH] Plugins: add syntaxHighlighting() and CodeMirror --- adminer/include/adminer.inc.php | 54 ++++++++++--------- changes.txt | 1 + editor/include/adminer.inc.php | 3 ++ plugins/codemirror.php | 92 +++++++++++++++++++++++++++++++++ plugins/plugin.php | 5 ++ 5 files changed, 130 insertions(+), 25 deletions(-) create mode 100644 plugins/codemirror.php diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 197bb2e5..24d1b09a 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -1018,31 +1018,7 @@ class Adminer { $connection->select_db(DB); $tables = table_status('', true); } - // this is matched by compile.php - echo script_src("../externals/jush/modules/jush.js"); - echo script_src("../externals/jush/modules/jush-textarea.js"); - echo script_src("../externals/jush/modules/jush-txt.js"); - echo script_src("../externals/jush/modules/jush-js.js"); - if (support("sql")) { - echo script_src("../externals/jush/modules/jush-" . JUSH . ".js"); - ?> -> - $type) { - $links[] = preg_quote($table, '/'); - } - echo "var jushLinks = { " . JUSH . ": [ '" . js_escape(ME) . (support("table") ? "table=" : "select=") . "\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n"; - foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) { - echo "jushLinks.$val = jushLinks." . JUSH . ";\n"; - } - } - ?> -bodyLoad('server_info) : ""); ?>'maria ? ", true" : ""); ?>); - -syntaxHighlighting($tables); $this->databasesPrint($missing); $actions = array(); if (DB == "" || !$missing) { @@ -1067,6 +1043,34 @@ bodyLoad(' + * @param array result of table_status() + */ + function syntaxHighlighting($tables) { + global $connection; + // this is matched by compile.php + echo script_src("../externals/jush/modules/jush.js"); + echo script_src("../externals/jush/modules/jush-textarea.js"); + echo script_src("../externals/jush/modules/jush-txt.js"); + echo script_src("../externals/jush/modules/jush-js.js"); + if (support("sql")) { + echo script_src("../externals/jush/modules/jush-" . JUSH . ".js"); + echo "\n"; + if ($tables) { + $links = array(); + foreach ($tables as $table => $type) { + $links[] = preg_quote($table, '/'); + } + echo "var jushLinks = { " . JUSH . ": [ '" . js_escape(ME) . (support("table") ? "table=" : "select=") . "\$&', /\\b(" . implode("|", $links) . ")\\b/g ] };\n"; + foreach (array("bac", "bra", "sqlite_quo", "mssql_bra") as $val) { + echo "jushLinks.$val = jushLinks." . JUSH . ";\n"; + } + } + echo "\n"; + } + echo script("bodyLoad('" . (is_object($connection) ? preg_replace('~^(\d\.?\d).*~s', '\1', $connection->server_info) : "") . "'" . ($connection->maria ? ", true" : "") . ");"); + } + /** Prints databases list in menu * @param string * @return null diff --git a/changes.txt b/changes.txt index a53e2dfd..1d813728 100644 --- a/changes.txt +++ b/changes.txt @@ -3,6 +3,7 @@ Align numbers right (bug #912) CSS: Dark mode syntax highlighting SQL textarea: Open help on Ctrl+click Designs named adminer-dark.css use dark basic style +Plugins: add method syntaxHighlighting() Adminer 5.0.5 (released 2025-03-13): MySQL: Display converting function for binary, bit or geometry fields diff --git a/editor/include/adminer.inc.php b/editor/include/adminer.inc.php index 6ab6da82..508c7dae 100644 --- a/editor/include/adminer.inc.php +++ b/editor/include/adminer.inc.php @@ -627,6 +627,9 @@ qsl('div').onclick = whisperClick;", "") } } + function syntaxHighlighting($tables) { + } + function databasesPrint($missing) { } diff --git a/plugins/codemirror.php b/plugins/codemirror.php new file mode 100644 index 00000000..8d55988c --- /dev/null +++ b/plugins/codemirror.php @@ -0,0 +1,92 @@ + including type-ahead of keywords and tables +* @link https://codemirror.net/5/ +* @link https://www.adminer.org/plugins/#use +* @author Jakub Vrana, https://www.vrana.cz/ +* @license https://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0 +* @license https://www.gnu.org/licenses/gpl-2.0.html GNU General Public License, version 2 (one or other) +*/ +class AdminerCodemirror { + private $root; + + function __construct($root = "codemirror5") { + $this->root = $root; + } + + function syntaxHighlighting($tableStatuses) { + $connection = Adminer\connection(); + ?> + +root/lib/codemirror.js"); + echo Adminer\script_src("$this->root/addon/runmode/runmode.js"); + echo Adminer\script_src("$this->root/addon/hint/show-hint.js"); + echo Adminer\script_src("$this->root/mode/javascript/javascript.js"); + if (Adminer\support("sql")) { + echo Adminer\script_src("$this->root/mode/sql/sql.js"); + echo Adminer\script_src("$this->root/addon/hint/sql-hint.js"); + } + $tables = array(); + foreach ($tableStatuses as $status) { + foreach (Adminer\fields($status["Name"]) as $name => $field) { + $tables[$status["Name"]][] = $name; + } + } + ?> + +applyPlugin(__FUNCTION__, $args); } + function syntaxHighlighting($tables) { + $args = func_get_args(); + return $this->applyPlugin(__FUNCTION__, $args); + } + function databasesPrint($missing) { $args = func_get_args(); return $this->applyPlugin(__FUNCTION__, $args);