]> git.joonet.de Git - adminer.git/commitdiff
Highlight code in textarea by CodeMirror
authorJakub Vrana <jakub@vrana.cz>
Mon, 16 Apr 2012 04:59:36 +0000 (21:59 -0700)
committerJakub Vrana <jakub@vrana.cz>
Mon, 16 Apr 2012 05:00:33 +0000 (22:00 -0700)
.gitmodules
adminer/include/design.inc.php
adminer/include/editing.inc.php
adminer/sql.inc.php
adminer/static/default.css
changes.txt
compile.php
externals/CodeMirror2 [new submodule]

index 9b4770cbcc16ab507ea2e01649e36d540d4665af..ae3f414d4e3e135a087aa64c49707e3989cde0a5 100644 (file)
@@ -16,3 +16,6 @@
 [submodule "JsShrink"]
        path = externals/JsShrink
        url = git://github.com/vrana/JsShrink.git
+[submodule "CodeMirror2"]
+       path = externals/CodeMirror2
+       url = git://github.com/marijnh/CodeMirror2.git
index f39ea46b97eccc84f9a6f79017f11b694a5c1161..7240bb8c552eae519f4a5b35e81bd723914d5031 100644 (file)
@@ -4,9 +4,10 @@
 * @param string
 * @param mixed array("key" => "link=desc", "key2" => array("link", "desc")), null for nothing, false for driver only, true for driver and server
 * @param string used after colon in title and heading, will be HTML escaped
+* @param string printed in <head>
 * @return null
 */
-function page_header($title, $error = "", $breadcrumb = array(), $title2 = "") {
+function page_header($title, $error = "", $breadcrumb = array(), $title2 = "", $head = "") {
        global $LANG, $adminer, $connection, $drivers;
        header("Content-Type: text/html; charset=utf-8");
        if ($adminer->headers()) {
@@ -38,6 +39,7 @@ var noResponse = '<?php echo lang('No response from server.'); ?>';
 <link rel="stylesheet" type="text/css" href="adminer.css">
 <?php } ?>
 <?php } ?>
+<?php echo $head; ?>
 
 <body class="<?php echo lang('ltr'); ?> nojs"<?php echo ($_POST ? "" : " onclick=\"return bodyClick(event, '" . h(js_escape(DB) . "', '" . js_escape($_GET["ns"])) . "');\""); // avoid re-post confirmation after refreshing the next page in Google Chrome ?> onkeydown="bodyKeydown(event);" onload="bodyLoad('<?php echo (is_object($connection) ? substr($connection->server_info, 0, 3) : ""); ?>');<?php echo (isset($_COOKIE["adminer_version"]) ? "" : " verifyVersion();"); ?>">
 <script type="text/javascript">
index b2b35d1df61af3374448de33c38f0705e2367a55..f245266a725113003b156a148b07eb330462c37b 100644 (file)
@@ -113,10 +113,11 @@ function referencable_primary($self) {
 * @param int
 * @param int
 * @param string
+* @param string
 * @return null
 */
-function textarea($name, $value, $rows = 10, $cols = 80) {
-       echo "<textarea name='$name' rows='$rows' cols='$cols' class='sqlarea' spellcheck='false' wrap='off' onkeydown='return textareaKeydown(this, event);'>"; // spellcheck, wrap - not valid before HTML5
+function textarea($name, $value, $rows = 10, $cols = 80, $id = "") {
+       echo "<textarea name='$name'" . ($id ? " id='$id'" : "") . " rows='$rows' cols='$cols' class='sqlarea' spellcheck='false' wrap='off' onkeydown='return textareaKeydown(this, event);'>"; // spellcheck, wrap - not valid before HTML5
        if (is_array($value)) {
                foreach ($value as $val) { // not implode() to save memory
                        echo h($val[0]) . "\n\n\n"; // $val == array($query, $time)
index fe842863c39e8dc6d847bc60da88004b3b9fbb3e..61acae2f10cb2e570466225c15712a4f44d78c28 100644 (file)
@@ -14,7 +14,10 @@ if (!$error && $_POST["clear"]) {
        redirect(remove_from_uri("history"));
 }
 
-page_header(lang('SQL command'), $error);
+$codemirror_path = "../externals/CodeMirror2";
+$codemirror_mode = ($jush == "sql" ? "mysql" : "plsql");
+
+page_header(lang('SQL command'), $error, array(), "", "<link rel='stylesheet' href='$codemirror_path/lib/codemirror.css'>");
 
 if (!$error && $_POST) {
        $fp = false;
@@ -173,8 +176,8 @@ if ($_POST) {
 } elseif ($_GET["history"] != "") {
        $q = $history[$_GET["history"]][0];
 }
-textarea("query", $q, 20);
-echo ($_POST ? "" : "<script type='text/javascript'>document.getElementsByTagName('textarea')[0].focus();</script>\n");
+textarea("query", $q, 20, 80, "query");
+echo ($_POST ? "" : "<script type='text/javascript'>document.getElementById('query').focus();</script>\n");
 echo "<p>" . (ini_bool("file_uploads")
        ? lang('File upload') . ': <input type="file" name="sql_file"' . ($_FILES && $_FILES["sql_file"]["error"] != 4 ? '' : ' onchange="this.form[\'only_errors\'].checked = true;"') . '> (&lt; ' . ini_get("upload_max_filesize") . 'B)' // ignore post_max_size because it is for all form fields together and bytes computing would be necessary
        : lang('File uploads are disabled.')
@@ -212,3 +215,11 @@ if ($history) {
 ?>
 
 </form>
+
+<script src="<?php echo $codemirror_path; ?>/lib/codemirror.js"></script>
+<script src="<?php echo "$codemirror_path/mode/$codemirror_mode/$codemirror_mode.js"; ?>"></script>
+<script type="text/javascript">
+if (window.CodeMirror) {
+       CodeMirror.fromTextArea(document.getElementById('query'));
+}
+</script>
index 2b9a468bd1b9462017cd84b2e5904df9d8116081..a5c6f6965aad4d765d98ca69af5f2ce1ef2d667d 100644 (file)
@@ -62,6 +62,8 @@ input[type=image] { vertical-align: middle; }
 .rtl #breadcrumb { left: auto; right: 21em; margin: 0 -18px 0 0; }
 .rtl #lang, .rtl #menu { left: auto; right: 0; }
 
+.CodeMirror { border: 1px inset #777; }
+
 @media print {
        #lang, #menu { display: none; }
        #content { margin-left: 1em; }
index 393d079a928021e7f8bd2ee82c573c7ad04a9887..75d81c99538055ae954a0d5f65a5019f0a94bae8 100644 (file)
@@ -1,5 +1,6 @@
 Adminer 3.4.0-dev:
 Print current time next to executed SQL queries
+Highlight code in textarea by CodeMirror
 Link to original table in EXPLAIN of SELECT * FROM table t
 Replace JSMin by better JavaScript minifier
 Ukrainian translation
index 78a7a43074447fa31255cda77352705d5ccd29ea..cc3ccac41618ad3c7d43491986be3489bbdd5aa2 100644 (file)
@@ -265,6 +265,7 @@ foreach (array("adminer", "editor") as $project) {
        $file = preg_replace('~\\.\\./adminer/static/(default\\.css|functions\\.js|favicon\\.ico|loader\\.gif)~', '<?php echo ' . $replace . '"; ?>', $file);
        $file = preg_replace('~\\.\\./adminer/static/([^\'"]*)~', '" . ' . $replace, $file);
        $file = str_replace("'../externals/jush/'", "location.protocol + '//www.adminer.org/static/'", $file);
+       $file = str_replace('"../externals/CodeMirror2"', '($_SERVER["HTTPS"] ? "https" : "http") . "://www.adminer.org/static/CodeMirror2"', $file);
        $file = preg_replace("~<\\?php\\s*\\?>\n?|\\?>\n?<\\?php~", '', $file);
        $file = php_shrink($file);
 
diff --git a/externals/CodeMirror2 b/externals/CodeMirror2
new file mode 160000 (submodule)
index 0000000..8feb48b
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit 8feb48b37c3678a102b2de41e24f0f43bee86f50