diff options
author | Jo Michael <me@mynetx.net> | 2012-04-13 03:43:32 +0400 |
---|---|---|
committer | Jo Michael <me@mynetx.net> | 2012-04-13 03:43:32 +0400 |
commit | 8744f8cf66e57963c74bfc7bca800667ba793554 (patch) | |
tree | cb742feb6be3101a2b8a6b42e8b6364875dceac4 | |
parent | 6557b71b88fe19997844169854d34af73a02c70f (diff) |
+ rfe #3517354 [interface] Allow disabling CodeMirror with $cfg['CodemirrorEnable'] = false
-rw-r--r-- | ChangeLog | 1 | ||||
-rw-r--r-- | Documentation.html | 6 | ||||
-rw-r--r-- | db_events.php | 7 | ||||
-rw-r--r-- | db_routines.php | 7 | ||||
-rw-r--r-- | db_sql.php | 7 | ||||
-rw-r--r-- | db_triggers.php | 7 | ||||
-rw-r--r-- | js/functions.js | 26 | ||||
-rw-r--r-- | js/rte/common.js | 15 | ||||
-rw-r--r-- | js/server_privileges.js | 43 | ||||
-rw-r--r-- | js/server_status.js | 13 | ||||
-rw-r--r-- | js/server_status_monitor.js | 26 | ||||
-rw-r--r-- | libraries/Theme.class.php | 4 | ||||
-rw-r--r-- | libraries/config.default.php | 7 | ||||
-rw-r--r-- | libraries/config/messages.inc.php | 2 | ||||
-rw-r--r-- | libraries/config/setup.forms.php | 3 | ||||
-rw-r--r-- | libraries/config/user_preferences.forms.php | 3 | ||||
-rw-r--r-- | querywindow.php | 7 | ||||
-rw-r--r-- | server_privileges.php | 7 | ||||
-rw-r--r-- | server_sql.php | 7 | ||||
-rw-r--r-- | server_status.php | 3 | ||||
-rw-r--r-- | sql.php | 7 | ||||
-rw-r--r-- | tbl_export.php | 7 | ||||
-rw-r--r-- | tbl_sql.php | 7 |
23 files changed, 156 insertions, 66 deletions
@@ -27,6 +27,7 @@ phpMyAdmin - ChangeLog - bug [export] Texy! Text: Columns containing Pipe Character don't export properly + [export] Show triggers in Open Document Text, Word and Texy! Text - Patch #3415061 [auth] Login screen appears under the page ++ rfe #3517354 [interface] Allow disabling CodeMirror with $cfg['CodemirrorEnable'] = false 3.5.1.0 (not yet released) - bug #3510784 [edit] Limit clause ignored when sort order is remembered diff --git a/Documentation.html b/Documentation.html index 0dbafe4895..05f1e93f9c 100644 --- a/Documentation.html +++ b/Documentation.html @@ -1453,6 +1453,12 @@ CREATE DATABASE,ALTER DATABASE,DROP DATABASE</pre> <dd>Defines whether the <abbr title="structured query language">SQL</abbr> query box should be kept displayed after its submission.</dd> + <dt id="cfg_CodemirrorEnable">$cfg['CodemirrorEnable'] boolean</dt> + <dd>Defines whether to use a Javascript code editor for SQL query boxes. + CodeMirror provides syntax highlighting and line numbers. <br /> + However, middle-clicking for pasting the clipboard contents in some Linux + distributions (such as Ubuntu) is not supported by all browsers.</dd> + <dt id="cfg_AllowUserDropDatabase">$cfg['AllowUserDropDatabase'] boolean</dt> <dd>Defines whether normal users (non-administrator) are allowed to delete their own database or not. If set as FALSE, the link "Drop diff --git a/db_events.php b/db_events.php index aecda1aad1..35702ee547 100644 --- a/db_events.php +++ b/db_events.php @@ -18,8 +18,11 @@ require_once 'libraries/common.lib.php'; $GLOBALS['js_include'][] = 'jquery/timepicker.js'; $GLOBALS['js_include'][] = 'rte/common.js'; $GLOBALS['js_include'][] = 'rte/events.js'; -$GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; -$GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; + +if ($GLOBALS['cfg']['CodemirrorEnable']) { + $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; + $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; +} /** * Include all other files diff --git a/db_routines.php b/db_routines.php index dd55c72a8c..13f33f1561 100644 --- a/db_routines.php +++ b/db_routines.php @@ -24,8 +24,11 @@ if (PMA_DRIZZLE) { $GLOBALS['js_include'][] = 'jquery/timepicker.js'; $GLOBALS['js_include'][] = 'rte/common.js'; $GLOBALS['js_include'][] = 'rte/routines.js'; -$GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; -$GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; + +if ($GLOBALS['cfg']['CodemirrorEnable']) { + $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; + $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; +} /** * Include all other files diff --git a/db_sql.php b/db_sql.php index 23c1c64162..ed4c47b19b 100644 --- a/db_sql.php +++ b/db_sql.php @@ -16,8 +16,11 @@ require_once 'libraries/common.inc.php'; $GLOBALS['js_include'][] = 'functions.js'; $GLOBALS['js_include'][] = 'makegrid.js'; $GLOBALS['js_include'][] = 'sql.js'; -$GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; -$GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; + +if ($GLOBALS['cfg']['CodemirrorEnable']) { + $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; + $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; +} require 'libraries/db_common.inc.php'; require_once 'libraries/sql_query_form.lib.php'; diff --git a/db_triggers.php b/db_triggers.php index 4fa8592fc5..ec29205833 100644 --- a/db_triggers.php +++ b/db_triggers.php @@ -17,8 +17,11 @@ require_once 'libraries/common.lib.php'; */ $GLOBALS['js_include'][] = 'rte/common.js'; $GLOBALS['js_include'][] = 'rte/triggers.js'; -$GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; -$GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; + +if ($GLOBALS['cfg']['CodemirrorEnable']) { + $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; + $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; +} /** * Include all other files diff --git a/js/functions.js b/js/functions.js index 94792eb40e..088cc457d8 100644 --- a/js/functions.js +++ b/js/functions.js @@ -1069,18 +1069,20 @@ $(document).ready(function() { // These settings are duplicated from the .ready()function in functions.js var height = $('#sql_query_edit').css('height'); - codemirror_editor = CodeMirror.fromTextArea($('textarea[name="sql_query_edit"]')[0], { - lineNumbers: true, - matchBrackets: true, - indentUnit: 4, - mode: "text/x-mysql", - lineWrapping: true - }); - codemirror_editor.getScrollerElement().style.height = height; - codemirror_editor.refresh(); + if (typeof CodeMirror !== 'undefined') { + codemirror_editor = CodeMirror.fromTextArea($('textarea[name="sql_query_edit"]')[0], { + lineNumbers: true, + matchBrackets: true, + indentUnit: 4, + mode: "text/x-mysql", + lineWrapping: true + }); + codemirror_editor.getScrollerElement().style.height = height; + codemirror_editor.refresh(); + } $("input.btnSave").click(function() { - if (codemirror_editor !== undefined) { + if (codemirror_editor) { var sql_query = codemirror_editor.getValue(); } else { var sql_query = $(this).prev().val(); @@ -1673,6 +1675,10 @@ function PMA_prettyProfilingNum(num, acc) */ function PMA_SQLPrettyPrint(string) { + if (typeof CodeMirror == 'undefined') { + return string; + } + var mode = CodeMirror.getMode({},"text/x-mysql"); var stream = new CodeMirror.StringStream(string); var state = mode.startState(); diff --git a/js/rte/common.js b/js/rte/common.js index 8804f23765..121d0039a8 100644 --- a/js/rte/common.js +++ b/js/rte/common.js @@ -42,7 +42,12 @@ var RTE = { } $elm = $('table.rte_table').find('textarea[name=item_definition]'); if ($elm.val() === '') { - this.syntaxHiglighter.focus(); + if (this.syntaxHiglighter !== null) { + this.syntaxHiglighter.focus(); + } + else { + $('textarea[name=item_definition]').last().focus(); + } alert(PMA_messages['strFormEmpty']); return false; } @@ -106,7 +111,9 @@ $(document).ready(function () { RTE.buttonOptions[PMA_messages['strGo']] = function () { // Move the data from the codemirror editor back to the // textarea, where it can be used in the form submission. - RTE.syntaxHiglighter.save(); + if (typeof CodeMirror != 'undefined') { + RTE.syntaxHiglighter.save(); + } // Validate editor and submit request, if passed. if (RTE.validate()) { /** @@ -241,7 +248,9 @@ $(document).ready(function () { * @var opts Options to pass to the codemirror editor. */ var opts = {lineNumbers: true, matchBrackets: true, indentUnit: 4, mode: "text/x-mysql"}; - RTE.syntaxHiglighter = CodeMirror.fromTextArea($elm[0], opts); + if (typeof CodeMirror != 'undefined') { + RTE.syntaxHiglighter = CodeMirror.fromTextArea($elm[0], opts); + } // Execute item-specific code RTE.postDialogShow(data); } else { diff --git a/js/server_privileges.js b/js/server_privileges.js index 7d9ee25626..9e8593a0af 100644 --- a/js/server_privileges.js +++ b/js/server_privileges.js @@ -507,19 +507,22 @@ $(document).ready(function() { }); PMA_ajaxRemoveMessage($msgbox); // Attach syntax highlited editor to export dialog - CodeMirror.fromTextArea( - $ajaxDialog.find('textarea')[0], - { - lineNumbers: true, - matchBrackets: true, - indentUnit: 4, - mode: "text/x-mysql" - } - ); + if (typeof CodeMirror != 'undefined') { + CodeMirror.fromTextArea( + $ajaxDialog.find('textarea')[0], + { + lineNumbers: true, + matchBrackets: true, + indentUnit: 4, + mode: "text/x-mysql" + } + ); + } }); //end $.post }); // if exporting non-ajax, highlight anyways - if ($("textarea.export").length > 0) + if ($("textarea.export").length > 0 + && typeof CodeMirror != 'undefined') { CodeMirror.fromTextArea( $('textarea.export')[0], @@ -555,15 +558,17 @@ $(document).ready(function() { }); PMA_ajaxRemoveMessage($msgbox); // Attach syntax highlited editor to export dialog - CodeMirror.fromTextArea( - $ajaxDialog.find('textarea')[0], - { - lineNumbers: true, - matchBrackets: true, - indentUnit: 4, - mode: "text/x-mysql" - } - ); + if (typeof CodeMirror != 'undefined') { + CodeMirror.fromTextArea( + $ajaxDialog.find('textarea')[0], + { + lineNumbers: true, + matchBrackets: true, + indentUnit: 4, + mode: "text/x-mysql" + } + ); + } }); //end $.get }); //end export privileges diff --git a/js/server_status.js b/js/server_status.js index 71f0e9b2f6..3b3f11d846 100644 --- a/js/server_status.js +++ b/js/server_status.js @@ -155,10 +155,15 @@ $(function() { ); // Delay loading a bit so the tab loads and the user gets to see a ajax loading icon setTimeout(function() { - loadJavascript(['js/jquery/timepicker.js', 'js/jquery/jquery.json-2.2.js', - 'js/jquery/jquery.sortableTable.js', - 'js/codemirror/lib/codemirror.js', 'js/codemirror/mode/mysql/mysql.js', - 'js/server_status_monitor.js']); + var scripts = [ + 'js/jquery/timepicker.js', + 'js/jquery/jquery.json-2.2.js', + 'js/jquery/jquery.sortableTable.js']; + if (cfg_CodemirrorEnable) { + scripts.push('js/codemirror/lib/codemirror.js', 'js/codemirror/mode/mysql/mysql.js'); + } + scripts.push('js/server_status_monitor.js'); + loadJavascript(scripts); }, 50); monitorLoaded = true; diff --git a/js/server_status_monitor.js b/js/server_status_monitor.js index b9c686217e..bc36225fe9 100644 --- a/js/server_status_monitor.js +++ b/js/server_status_monitor.js @@ -1710,12 +1710,17 @@ $(function() { var rowData = $(this).parent().data('query'); var query = rowData.argument || rowData.sql_text; - query = PMA_SQLPrettyPrint(query); - codemirror_editor.setValue(query); - // Codemirror is bugged, it doesn't refresh properly sometimes. Following lines seem to fix that - setTimeout(function() { - codemirror_editor.refresh(); - },50); + if (codemirror_editor) { + query = PMA_SQLPrettyPrint(query); + codemirror_editor.setValue(query); + // Codemirror is bugged, it doesn't refresh properly sometimes. Following lines seem to fix that + setTimeout(function() { + codemirror_editor.refresh(); + },50); + } + else { + $('#sqlquery').val(query); + } var profilingChart = null; var dlgBtns = {}; @@ -1728,7 +1733,12 @@ $(function() { profilingChart.destroy(); } $('div#queryAnalyzerDialog div.placeHolder').html(''); - codemirror_editor.setValue(''); + if (codemirror_editor) { + codemirror_editor.setValue(''); + } + else { + $('#sqlquery').val(''); + } $(this).dialog("close"); }; @@ -1751,7 +1761,7 @@ $(function() { $.post('server_status.php?' + url_query, { ajax_request: true, query_analyzer: true, - query: codemirror_editor.getValue(), + query: codemirror_editor ? codemirror_editor.getValue() : $('#sqlquery').val(), database: db }, function(data) { data = $.parseJSON(data); diff --git a/libraries/Theme.class.php b/libraries/Theme.class.php index 11ebb0d333..776a81f1a3 100644 --- a/libraries/Theme.class.php +++ b/libraries/Theme.class.php @@ -406,6 +406,10 @@ class PMA_Theme */ function getCssCodeMirror() { + if (! $GLOBALS['cfg']['CodemirrorEnable']) { + return ''; + } + $result[] = 'span.cm-keyword, span.cm-statement-verb {'; $result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_reservedWord'] . ';'; $result[] = '}'; diff --git a/libraries/config.default.php b/libraries/config.default.php index 874a5ed87d..fcf7d406cb 100644 --- a/libraries/config.default.php +++ b/libraries/config.default.php @@ -646,6 +646,13 @@ $cfg['ShowSQL'] = true; $cfg['RetainQueryBox'] = false; /** + * use CodeMirror syntax highlighting for editing SQL + * + * @global boolean $cfg['CodemirrorEnable'] + */ +$cfg['CodemirrorEnable'] = true; + +/** * show a 'Drop database' link to normal users * * @global boolean $cfg['AllowUserDropDatabase'] diff --git a/libraries/config/messages.inc.php b/libraries/config/messages.inc.php index 416ed28674..ed36b8775e 100644 --- a/libraries/config/messages.inc.php +++ b/libraries/config/messages.inc.php @@ -31,6 +31,8 @@ $strConfigBZipDump_desc = __('Enable [a@http://en.wikipedia.org/wiki/Bzip2]bzip2 $strConfigBZipDump_name = __('Bzip2'); $strConfigCharEditing_desc = __('Defines which type of editing controls should be used for CHAR and VARCHAR columns; [kbd]input[/kbd] - allows limiting of input length, [kbd]textarea[/kbd] - allows newlines in columns'); $strConfigCharEditing_name = __('CHAR columns editing'); +$strConfigCodemirrorEnable_desc = __('Use user-friendly editor for editing SQL queries ([a@http://codemirror.net/]CodeMirror[/a]) with syntax highlighting and line numbers'); +$strConfigCodemirrorEnable_name = __('Enable CodeMirror'); $strConfigMinSizeForInputField_desc = __('Defines the minimum size for input fields generated for CHAR and VARCHAR columns'); $strConfigMinSizeForInputField_name = __('Minimum size for input field'); $strConfigMaxSizeForInputField_desc = __('Defines the maximum size for input fields generated for CHAR and VARCHAR columns'); diff --git a/libraries/config/setup.forms.php b/libraries/config/setup.forms.php index 70fd17e750..94912567fd 100644 --- a/libraries/config/setup.forms.php +++ b/libraries/config/setup.forms.php @@ -152,7 +152,8 @@ $forms['Sql_queries']['Sql_queries'] = array( //'QueryWindowWidth', // overridden in theme //'QueryWindowHeight', 'QueryWindowDefTab', - 'RetainQueryBox'); + 'RetainQueryBox', + 'CodemirrorEnable'); $forms['Sql_queries']['Sql_box'] = array('SQLQuery' => array( 'Edit', 'Explain', diff --git a/libraries/config/user_preferences.forms.php b/libraries/config/user_preferences.forms.php index a8a0f7a46d..788ea9999b 100644 --- a/libraries/config/user_preferences.forms.php +++ b/libraries/config/user_preferences.forms.php @@ -69,7 +69,8 @@ $forms['Sql_queries']['Sql_queries'] = array( //'QueryWindowWidth', // overridden in theme //'QueryWindowHeight', 'QueryWindowDefTab', - 'RetainQueryBox'); + 'RetainQueryBox', + 'CodemirrorEnable'); $forms['Sql_queries']['Sql_box'] = array( 'SQLQuery/Edit', 'SQLQuery/Explain', diff --git a/querywindow.php b/querywindow.php index 22df73bbf7..fc8afea804 100644 --- a/querywindow.php +++ b/querywindow.php @@ -119,8 +119,11 @@ $sql_query = ''; */ $js_include[] = 'common.js'; $js_include[] = 'querywindow.js'; -$js_include[] = 'codemirror/lib/codemirror.js'; -$js_include[] = 'codemirror/mode/mysql/mysql.js'; + +if ($GLOBALS['cfg']['CodemirrorEnable']) { + $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; + $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; +} if (PMA_isValid($_REQUEST['auto_commit'], 'identical', 'true')) { $js_events[] = array( diff --git a/server_privileges.php b/server_privileges.php index a96eef03c2..79f3b2a169 100644 --- a/server_privileges.php +++ b/server_privileges.php @@ -15,8 +15,11 @@ require_once 'libraries/common.inc.php'; */ $GLOBALS['js_include'][] = 'server_privileges.js'; $GLOBALS['js_include'][] = 'functions.js'; -$GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; -$GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; + +if ($GLOBALS['cfg']['CodemirrorEnable']) { + $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; + $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; +} $_add_user_error = false; require 'libraries/server_common.inc.php'; diff --git a/server_sql.php b/server_sql.php index bf5d7aa4db..c3842c3fec 100644 --- a/server_sql.php +++ b/server_sql.php @@ -16,8 +16,11 @@ require_once 'libraries/common.inc.php'; $GLOBALS['js_include'][] = 'functions.js'; $GLOBALS['js_include'][] = 'makegrid.js'; $GLOBALS['js_include'][] = 'sql.js'; -$GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; -$GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; + +if ($GLOBALS['cfg']['CodemirrorEnable']) { + $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; + $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; +} require_once 'libraries/server_common.inc.php'; require_once 'libraries/sql_query_form.lib.php'; diff --git a/server_status.php b/server_status.php index be4f8ac748..09822b5e5d 100644 --- a/server_status.php +++ b/server_status.php @@ -432,7 +432,10 @@ if (PMA_DRIZZLE) { * JS Includes */ +// needed to decide whether to load codemirror.js in server_status.js +PMA_AddJSVar('cfg_CodemirrorEnable', $GLOBALS['cfg']['CodemirrorEnable'] ? 1 : 0); $GLOBALS['js_include'][] = 'server_status.js'; + $GLOBALS['js_include'][] = 'jquery/jquery.tablesorter.js'; $GLOBALS['js_include'][] = 'jquery/jquery.cookie.js'; // For tab persistence // Charting @@ -19,8 +19,11 @@ $GLOBALS['js_include'][] = 'tbl_change.js'; // the next one needed because sql.php may do a "goto" to tbl_structure.php $GLOBALS['js_include'][] = 'tbl_structure.js'; $GLOBALS['js_include'][] = 'gis_data_editor.js'; -$GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; -$GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; + +if ($GLOBALS['cfg']['CodemirrorEnable']) { + $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; + $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; +} /** diff --git a/tbl_export.php b/tbl_export.php index a22fd023ac..f9722c4fc2 100644 --- a/tbl_export.php +++ b/tbl_export.php @@ -11,8 +11,11 @@ require_once 'libraries/common.inc.php'; $GLOBALS['js_include'][] = 'export.js'; -$GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; -$GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; + +if ($GLOBALS['cfg']['CodemirrorEnable']) { + $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; + $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; +} /** * Gets tables informations and displays top links diff --git a/tbl_sql.php b/tbl_sql.php index d8a8fb6695..a4a595a33d 100644 --- a/tbl_sql.php +++ b/tbl_sql.php @@ -16,8 +16,11 @@ require_once 'libraries/common.inc.php'; $GLOBALS['js_include'][] = 'functions.js'; $GLOBALS['js_include'][] = 'makegrid.js'; $GLOBALS['js_include'][] = 'sql.js'; -$GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; -$GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; + +if ($GLOBALS['cfg']['CodemirrorEnable']) { + $GLOBALS['js_include'][] = 'codemirror/lib/codemirror.js'; + $GLOBALS['js_include'][] = 'codemirror/mode/mysql/mysql.js'; +} require 'libraries/tbl_common.php'; $url_query .= '&goto=tbl_sql.php&back=tbl_sql.php'; |