]> git.joonet.de Git - adminer.git/commitdiff
Rename highlight plugins
authorJakub Vrana <jakub@vrana.cz>
Thu, 19 Jun 2025 07:12:04 +0000 (09:12 +0200)
committerJakub Vrana <jakub@vrana.cz>
Thu, 19 Jun 2025 07:12:48 +0000 (09:12 +0200)
plugins/codemirror.php [deleted file]
plugins/highlight-codemirror.php [new file with mode: 0644]
plugins/highlight-monaco.php [new file with mode: 0644]
plugins/highlight-prism.php [new file with mode: 0644]
plugins/monaco.php [deleted file]
plugins/prism.php [deleted file]

diff --git a/plugins/codemirror.php b/plugins/codemirror.php
deleted file mode 100644 (file)
index 7735da1..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-
-/** Use CodeMirror 5 for syntax highlighting and <textarea> 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 extends Adminer\Plugin {
-       private $root;
-       private $minified;
-
-       function __construct($root = "https://cdn.jsdelivr.net/npm/codemirror@5", $minified = ".min") {
-               $this->root = $root;
-               $this->minified = $minified;
-       }
-
-       function syntaxHighlighting($tableStatuses) {
-               ?>
-<style>
-@import url(<?php echo $this->root; ?>/lib/codemirror<?php echo $this->minified; ?>.css);
-@import url(<?php echo $this->root; ?>/addon/hint/show-hint<?php echo $this->minified; ?>.css);
-.CodeMirror { border: 1px inset #ccc; resize: both; }
-</style>
-<?php
-               echo Adminer\script_src("$this->root/lib/codemirror$this->minified.js", true);
-               echo Adminer\script_src("$this->root/addon/runmode/runmode$this->minified.js", true);
-               echo Adminer\script_src("$this->root/addon/hint/show-hint$this->minified.js", true);
-               echo Adminer\script_src("$this->root/mode/javascript/javascript$this->minified.js", true);
-               $tables = array_fill_keys(array_keys($tableStatuses), array());
-               if (Adminer\support("sql")) {
-                       echo Adminer\script_src("$this->root/mode/sql/sql$this->minified.js", true);
-                       echo Adminer\script_src("$this->root/addon/hint/sql-hint$this->minified.js", true);
-                       if (isset($_GET["sql"]) || isset($_GET["trigger"]) || isset($_GET["check"])) {
-                               foreach (Adminer\driver()->allFields() as $table => $fields) {
-                                       foreach ($fields as $field) {
-                                               $tables[$table][] = $field["field"];
-                                       }
-                               }
-                       }
-               }
-               ?>
-<script <?php echo Adminer\nonce(); ?>>
-addEventListener('DOMContentLoaded', () => {
-       function getCmMode(el) {
-               const match = el.className.match(/(^|\s)jush-([^ ]+)/);
-               if (match) {
-                       const modes = {
-                               js: 'application/json',
-                               sql: 'text/x-<?php echo (Adminer\connection()->flavor == "maria" ? "mariadb" : "mysql"); ?>',
-                               oracle: 'text/x-sql',
-                               clickhouse: 'text/x-sql',
-                               firebird: 'text/x-sql'
-                       };
-                       return modes[match[2]] || 'text/x-' + match[2];
-               }
-       }
-
-       adminerHighlighter = els => els.forEach(el => {
-               const mode = getCmMode(el);
-               if (mode) {
-                       el.classList.add('cm-s-default');
-                       CodeMirror.runMode(el.textContent, mode, el);
-               }
-       });
-
-       adminerHighlighter(qsa('code'));
-
-       for (const el of qsa('textarea')) {
-               const mode = getCmMode(el);
-               if (mode) {
-                       const width = el.clientWidth;
-                       const height = el.clientHeight;
-                       const cm = CodeMirror.fromTextArea(el, {
-                               mode: mode,
-                               extraKeys: { 'Ctrl-Space': 'autocomplete' },
-                               hintOptions: {
-                                       completeSingle: false,
-                                       tables: <?php echo json_encode($tables); ?>,
-                                       defaultTable: <?php echo json_encode($_GET["trigger"] ?: ($_GET["check"] ?: null)); ?>
-                               }
-                       });
-                       cm.setSize(width, height);
-                       cm.on('inputRead', () => {
-                               const token = cm.getTokenAt(cm.getCursor());
-                               if (/^[.`"\w]\w*$/.test(token.string)) {
-                                       CodeMirror.commands.autocomplete(cm);
-                               }
-                       });
-                       setupSubmitHighlightInput(cm.getWrapperElement());
-                       el.onchange = () => cm.setValue(el.value);
-               }
-       }
-});
-</script>
-<?php
-               return true;
-       }
-
-       function screenshot() {
-               return "https://www.adminer.org/static/plugins/codemirror.gif";
-       }
-
-       protected $translations = array(
-               'cs' => array('' => 'Použít CodeMirror 5 pro zvýrazňování syntaxe a <textarea> včetně našeptávání klíčových slov a tabulek'),
-               'de' => array('' => 'CodeMirror 5 verwenden für die Syntaxhervorhebung und <textarea> einschließlich der Überschrift von Schlüsselwörtern und Tabellen'),
-               'ja' => array('' => 'CodeMirror 5 を用い、キーワードやテーブルを含む構文や <textarea> を強調表示'),
-               'pl' => array('' => 'Użyj CodeMirror 5 do podświetlania składni i <textarea>, uwzględniając wcześniejsze wpisywanie słów kluczowych i tabel'),
-       );
-}
diff --git a/plugins/highlight-codemirror.php b/plugins/highlight-codemirror.php
new file mode 100644 (file)
index 0000000..58d23d9
--- /dev/null
@@ -0,0 +1,111 @@
+<?php
+
+/** Use CodeMirror 5 for syntax highlighting and <textarea> 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 AdminerHighlightCodemirror extends Adminer\Plugin {
+       private $root;
+       private $minified;
+
+       function __construct($root = "https://cdn.jsdelivr.net/npm/codemirror@5", $minified = ".min") {
+               $this->root = $root;
+               $this->minified = $minified;
+       }
+
+       function syntaxHighlighting($tableStatuses) {
+               ?>
+<style>
+@import url(<?php echo $this->root; ?>/lib/codemirror<?php echo $this->minified; ?>.css);
+@import url(<?php echo $this->root; ?>/addon/hint/show-hint<?php echo $this->minified; ?>.css);
+.CodeMirror { border: 1px inset #ccc; resize: both; }
+</style>
+<?php
+               echo Adminer\script_src("$this->root/lib/codemirror$this->minified.js", true);
+               echo Adminer\script_src("$this->root/addon/runmode/runmode$this->minified.js", true);
+               echo Adminer\script_src("$this->root/addon/hint/show-hint$this->minified.js", true);
+               echo Adminer\script_src("$this->root/mode/javascript/javascript$this->minified.js", true);
+               $tables = array_fill_keys(array_keys($tableStatuses), array());
+               if (Adminer\support("sql")) {
+                       echo Adminer\script_src("$this->root/mode/sql/sql$this->minified.js", true);
+                       echo Adminer\script_src("$this->root/addon/hint/sql-hint$this->minified.js", true);
+                       if (isset($_GET["sql"]) || isset($_GET["trigger"]) || isset($_GET["check"])) {
+                               foreach (Adminer\driver()->allFields() as $table => $fields) {
+                                       foreach ($fields as $field) {
+                                               $tables[$table][] = $field["field"];
+                                       }
+                               }
+                       }
+               }
+               ?>
+<script <?php echo Adminer\nonce(); ?>>
+addEventListener('DOMContentLoaded', () => {
+       function getCmMode(el) {
+               const match = el.className.match(/(^|\s)jush-([^ ]+)/);
+               if (match) {
+                       const modes = {
+                               js: 'application/json',
+                               sql: 'text/x-<?php echo (Adminer\connection()->flavor == "maria" ? "mariadb" : "mysql"); ?>',
+                               oracle: 'text/x-sql',
+                               clickhouse: 'text/x-sql',
+                               firebird: 'text/x-sql'
+                       };
+                       return modes[match[2]] || 'text/x-' + match[2];
+               }
+       }
+
+       adminerHighlighter = els => els.forEach(el => {
+               const mode = getCmMode(el);
+               if (mode) {
+                       el.classList.add('cm-s-default');
+                       CodeMirror.runMode(el.textContent, mode, el);
+               }
+       });
+
+       adminerHighlighter(qsa('code'));
+
+       for (const el of qsa('textarea')) {
+               const mode = getCmMode(el);
+               if (mode) {
+                       const width = el.clientWidth;
+                       const height = el.clientHeight;
+                       const cm = CodeMirror.fromTextArea(el, {
+                               mode: mode,
+                               extraKeys: { 'Ctrl-Space': 'autocomplete' },
+                               hintOptions: {
+                                       completeSingle: false,
+                                       tables: <?php echo json_encode($tables); ?>,
+                                       defaultTable: <?php echo json_encode($_GET["trigger"] ?: ($_GET["check"] ?: null)); ?>
+                               }
+                       });
+                       cm.setSize(width, height);
+                       cm.on('inputRead', () => {
+                               const token = cm.getTokenAt(cm.getCursor());
+                               if (/^[.`"\w]\w*$/.test(token.string)) {
+                                       CodeMirror.commands.autocomplete(cm);
+                               }
+                       });
+                       setupSubmitHighlightInput(cm.getWrapperElement());
+                       el.onchange = () => cm.setValue(el.value);
+               }
+       }
+});
+</script>
+<?php
+               return true;
+       }
+
+       function screenshot() {
+               return "https://www.adminer.org/static/plugins/codemirror.gif";
+       }
+
+       protected $translations = array(
+               'cs' => array('' => 'Použít CodeMirror 5 pro zvýrazňování syntaxe a <textarea> včetně našeptávání klíčových slov a tabulek'),
+               'de' => array('' => 'CodeMirror 5 verwenden für die Syntaxhervorhebung und <textarea> einschließlich der Überschrift von Schlüsselwörtern und Tabellen'),
+               'ja' => array('' => 'CodeMirror 5 を用い、キーワードやテーブルを含む構文や <textarea> を強調表示'),
+               'pl' => array('' => 'Użyj CodeMirror 5 do podświetlania składni i <textarea>, uwzględniając wcześniejsze wpisywanie słów kluczowych i tabel'),
+       );
+}
diff --git a/plugins/highlight-monaco.php b/plugins/highlight-monaco.php
new file mode 100644 (file)
index 0000000..1c0cd71
--- /dev/null
@@ -0,0 +1,81 @@
+<?php
+
+/** Use VS Code's Monaco Editor for syntax highlighting and SQL <textarea>
+* @link https://microsoft.github.io/monaco-editor/
+* @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 AdminerHighlightMonaco extends Adminer\Plugin {
+       private $root;
+
+       function __construct($root = "https://cdn.jsdelivr.net/npm/monaco-editor@0.52/min/vs") {
+               $this->root = $root;
+       }
+
+       function syntaxHighlighting($tableStatuses) {
+               echo Adminer\script_src("$this->root/loader.js", true);
+               ?>
+<script <?php echo Adminer\nonce(); ?>>
+addEventListener('DOMContentLoaded', () => {
+       require.config({ paths: { vs: '<?php echo $this->root; ?>' } });
+       require(['vs/editor/editor.main'], function (monaco) {
+               adminerHighlighter = els => els.forEach(el => {
+                       const lang = getMonacoLang(el);
+                       if (lang) {
+                               monaco.editor.colorize(el.textContent, lang).then(html => el.innerHTML = html);
+                       }
+               });
+               adminerHighlighter(qsa('code'));
+
+               for (const el of qsa('textarea')) {
+                       const lang = getMonacoLang(el);
+                       if (lang) {
+                               const container = document.createElement('div');
+                               container.style.border = '1px inset #ccc';
+                               container.style.width = el.clientWidth + 'px';
+                               container.style.height = el.clientHeight + 'px';
+                               el.before(container);
+                               el.style.display = 'none';
+                               var editor = monaco.editor.create(container, {
+                                       value: el.value,
+                                       lineNumbers: 'off',
+                                       glyphMargin: false,
+                                       folding: false,
+                                       lineDecorationsWidth: 1,
+                                       minimap: {enabled: false},
+                                       language: lang
+                               });
+                               editor.onDidChangeModelContent(() => el.value = editor.getValue());
+                               el.onchange = () => editor.setValue(el.value);
+                               monaco.editor.addKeybindingRules([
+                                       {keybinding: monaco.KeyCode.Tab, command: null}
+                                       //! Ctrl+Enter
+                               ]);
+                       }
+               }
+       });
+
+       function getMonacoLang(el) {
+               return (
+                       /jush-js/.test(el.className) ? 'javascript' : (
+                       /jush-sql/.test(el.className) ? 'mysql' : (
+                       /jush-pgsql/.test(el.className) ? 'pgsql' : (
+                       /jush-(sqlite|mssql|oracle|clickhouse|firebird)/.test(el.className) ? 'sql' : (
+                       ''
+               )))));
+       }
+});
+</script>
+<?php
+               return true;
+       }
+
+       protected $translations = array(
+               'cs' => array('' => 'Použije Monaco Editor z VS Code pro zvýrazňování syntaxe a <textarea>'),
+               'de' => array('' => 'Monaco-Editor von VS Code verwenden, für die Syntaxhervorhebung und SQL <textarea>'),
+               'ja' => array('' => '構文や <textarea> の強調表示に VS Code の Monaco Editor を使用'),
+               'pl' => array('' => 'Użyj Monaco Editora programu VS Code do podświetlania składni i <textarea> SQL'),
+       );
+}
diff --git a/plugins/highlight-prism.php b/plugins/highlight-prism.php
new file mode 100644 (file)
index 0000000..70f505f
--- /dev/null
@@ -0,0 +1,69 @@
+<?php
+
+/** Use Prism Code Editor for syntax highlighting and <textarea>
+* @link https://prism-code-editor.netlify.app/
+* @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 AdminerHighlightPrism extends Adminer\Plugin {
+       private $editorRoot;
+       private $minified;
+       private $theme;
+
+       function __construct($editorRoot = "https://cdn.jsdelivr.net/npm/prism-code-editor@3/dist", $minified = ".min", $theme = "prism") {
+               $this->editorRoot = $editorRoot;
+               $this->minified = $minified;
+               $this->theme = $theme;
+       }
+
+       function syntaxHighlighting($tableStatuses) {
+               ?>
+<style>
+@import url(<?php echo "$this->editorRoot/layout$this->minified.css"; ?>);
+@import url(<?php echo "$this->editorRoot/themes/$this->theme$this->minified.css"; ?>);
+.prism-code-editor { border: 1px inset #ccc; resize: both; }
+</style>
+<script type="module"<?php echo Adminer\nonce(); ?>>
+import { editorFromPlaceholder } from '<?php echo $this->editorRoot; ?>/index.js';
+import { highlightText } from '<?php echo $this->editorRoot; ?>/prism/index.js';
+import '<?php echo $this->editorRoot; ?>/prism/languages/json.js';
+import '<?php echo $this->editorRoot; ?>/prism/languages/sql.js';
+
+adminerHighlighter = els => els.forEach(el => {
+       const mode = (
+               /jush-js/.test(el.className) ? 'json' : (
+               /jush-(\w*sql|oracle|clickhouse|firebird)/.test(el.className) ? 'sql' : (
+               ''
+       )));
+       if (mode) {
+               el.innerHTML = highlightText(el.textContent, mode);
+       }
+});
+adminerHighlighter(qsa('code'));
+
+const el = document.querySelector('.sqlarea');
+if (el) {
+       const name = el.name;
+       const width = el.clientWidth;
+       const height = el.clientHeight;
+       const editor = editorFromPlaceholder('.sqlarea', { language: 'sql', lineNumbers: false });
+       editor.wrapper.parentElement.style.width = width + 'px';
+       editor.wrapper.style.height = height + 'px';
+       editor.textarea.name = name;
+       editor.textarea.className = 'sqlarea';
+       editor.textarea.onchange = editor.update;
+}
+</script>
+<?php
+               return true;
+       }
+
+       protected $translations = array(
+               'cs' => array('' => 'Použije Prism Code Editor pro zvýrazňování syntaxe a <textarea>'),
+               'de' => array('' => 'Prism Code Editor verwenden, für die Syntaxhervorhebung und <textarea>'),
+               'ja' => array('' => '構文や <textarea> の強調表示に Prism Code Editor を使用'),
+               'pl' => array('' => 'Użyj Prism Code Editora do podświetlania składni i <textarea>'),
+       );
+}
diff --git a/plugins/monaco.php b/plugins/monaco.php
deleted file mode 100644 (file)
index 570e40d..0000000
+++ /dev/null
@@ -1,81 +0,0 @@
-<?php
-
-/** Use VS Code's Monaco Editor for syntax highlighting and SQL <textarea>
-* @link https://microsoft.github.io/monaco-editor/
-* @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 AdminerMonaco extends Adminer\Plugin {
-       private $root;
-
-       function __construct($root = "https://cdn.jsdelivr.net/npm/monaco-editor@0.52/min/vs") {
-               $this->root = $root;
-       }
-
-       function syntaxHighlighting($tableStatuses) {
-               echo Adminer\script_src("$this->root/loader.js", true);
-               ?>
-<script <?php echo Adminer\nonce(); ?>>
-addEventListener('DOMContentLoaded', () => {
-       require.config({ paths: { vs: '<?php echo $this->root; ?>' } });
-       require(['vs/editor/editor.main'], function (monaco) {
-               adminerHighlighter = els => els.forEach(el => {
-                       const lang = getMonacoLang(el);
-                       if (lang) {
-                               monaco.editor.colorize(el.textContent, lang).then(html => el.innerHTML = html);
-                       }
-               });
-               adminerHighlighter(qsa('code'));
-
-               for (const el of qsa('textarea')) {
-                       const lang = getMonacoLang(el);
-                       if (lang) {
-                               const container = document.createElement('div');
-                               container.style.border = '1px inset #ccc';
-                               container.style.width = el.clientWidth + 'px';
-                               container.style.height = el.clientHeight + 'px';
-                               el.before(container);
-                               el.style.display = 'none';
-                               var editor = monaco.editor.create(container, {
-                                       value: el.value,
-                                       lineNumbers: 'off',
-                                       glyphMargin: false,
-                                       folding: false,
-                                       lineDecorationsWidth: 1,
-                                       minimap: {enabled: false},
-                                       language: lang
-                               });
-                               editor.onDidChangeModelContent(() => el.value = editor.getValue());
-                               el.onchange = () => editor.setValue(el.value);
-                               monaco.editor.addKeybindingRules([
-                                       {keybinding: monaco.KeyCode.Tab, command: null}
-                                       //! Ctrl+Enter
-                               ]);
-                       }
-               }
-       });
-
-       function getMonacoLang(el) {
-               return (
-                       /jush-js/.test(el.className) ? 'javascript' : (
-                       /jush-sql/.test(el.className) ? 'mysql' : (
-                       /jush-pgsql/.test(el.className) ? 'pgsql' : (
-                       /jush-(sqlite|mssql|oracle|clickhouse|firebird)/.test(el.className) ? 'sql' : (
-                       ''
-               )))));
-       }
-});
-</script>
-<?php
-               return true;
-       }
-
-       protected $translations = array(
-               'cs' => array('' => 'Použije Monaco Editor z VS Code pro zvýrazňování syntaxe a <textarea>'),
-               'de' => array('' => 'Monaco-Editor von VS Code verwenden, für die Syntaxhervorhebung und SQL <textarea>'),
-               'ja' => array('' => '構文や <textarea> の強調表示に VS Code の Monaco Editor を使用'),
-               'pl' => array('' => 'Użyj Monaco Editora programu VS Code do podświetlania składni i <textarea> SQL'),
-       );
-}
diff --git a/plugins/prism.php b/plugins/prism.php
deleted file mode 100644 (file)
index 186f838..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-<?php
-
-/** Use Prism Code Editor for syntax highlighting and <textarea>
-* @link https://prism-code-editor.netlify.app/
-* @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 AdminerPrism extends Adminer\Plugin {
-       private $editorRoot;
-       private $minified;
-       private $theme;
-
-       function __construct($editorRoot = "https://cdn.jsdelivr.net/npm/prism-code-editor@3/dist", $minified = ".min", $theme = "prism") {
-               $this->editorRoot = $editorRoot;
-               $this->minified = $minified;
-               $this->theme = $theme;
-       }
-
-       function syntaxHighlighting($tableStatuses) {
-               ?>
-<style>
-@import url(<?php echo "$this->editorRoot/layout$this->minified.css"; ?>);
-@import url(<?php echo "$this->editorRoot/themes/$this->theme$this->minified.css"; ?>);
-.prism-code-editor { border: 1px inset #ccc; resize: both; }
-</style>
-<script type="module"<?php echo Adminer\nonce(); ?>>
-import { editorFromPlaceholder } from '<?php echo $this->editorRoot; ?>/index.js';
-import { highlightText } from '<?php echo $this->editorRoot; ?>/prism/index.js';
-import '<?php echo $this->editorRoot; ?>/prism/languages/json.js';
-import '<?php echo $this->editorRoot; ?>/prism/languages/sql.js';
-
-adminerHighlighter = els => els.forEach(el => {
-       const mode = (
-               /jush-js/.test(el.className) ? 'json' : (
-               /jush-(\w*sql|oracle|clickhouse|firebird)/.test(el.className) ? 'sql' : (
-               ''
-       )));
-       if (mode) {
-               el.innerHTML = highlightText(el.textContent, mode);
-       }
-});
-adminerHighlighter(qsa('code'));
-
-const el = document.querySelector('.sqlarea');
-if (el) {
-       const name = el.name;
-       const width = el.clientWidth;
-       const height = el.clientHeight;
-       const editor = editorFromPlaceholder('.sqlarea', { language: 'sql', lineNumbers: false });
-       editor.wrapper.parentElement.style.width = width + 'px';
-       editor.wrapper.style.height = height + 'px';
-       editor.textarea.name = name;
-       editor.textarea.className = 'sqlarea';
-       editor.textarea.onchange = editor.update;
-}
-</script>
-<?php
-               return true;
-       }
-
-       protected $translations = array(
-               'cs' => array('' => 'Použije Prism Code Editor pro zvýrazňování syntaxe a <textarea>'),
-               'de' => array('' => 'Prism Code Editor verwenden, für die Syntaxhervorhebung und <textarea>'),
-               'ja' => array('' => '構文や <textarea> の強調表示に Prism Code Editor を使用'),
-               'pl' => array('' => 'Użyj Prism Code Editora do podświetlania składni i <textarea>'),
-       );
-}