Skip to content
Browse files

+ rfe #3517354 [interface] Allow disabling CodeMirror with $cfg['Code…

…mirrorEnable'] = false
  • Loading branch information...
1 parent 6557b71 commit 8744f8cf66e57963c74bfc7bca800667ba793554 Jo Michael committed Apr 13, 2012
View
1 ChangeLog
@@ -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
View
6 Documentation.html
@@ -1453,6 +1453,12 @@ <h2 id="config">Configuration</h2>
<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 &quot;Drop
View
7 db_events.php
@@ -18,8 +18,11 @@
$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
View
7 db_routines.php
@@ -24,8 +24,11 @@
$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
View
7 db_sql.php
@@ -16,8 +16,11 @@
$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';
View
7 db_triggers.php
@@ -17,8 +17,11 @@
*/
$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
View
26 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();
View
15 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 {
View
43 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
View
13 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;
View
26 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);
View
4 libraries/Theme.class.php
@@ -406,6 +406,10 @@ function getCssGradient($start_color, $end_color)
*/
function getCssCodeMirror()
{
+ if (! $GLOBALS['cfg']['CodemirrorEnable']) {
+ return '';
+ }
+
$result[] = 'span.cm-keyword, span.cm-statement-verb {';
$result[] = ' color: ' . $GLOBALS['cfg']['SQP']['fmtColor']['alpha_reservedWord'] . ';';
$result[] = '}';
View
7 libraries/config.default.php
@@ -646,6 +646,13 @@
$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']
View
2 libraries/config/messages.inc.php
@@ -31,6 +31,8 @@
$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');
View
3 libraries/config/setup.forms.php
@@ -152,7 +152,8 @@
//'QueryWindowWidth', // overridden in theme
//'QueryWindowHeight',
'QueryWindowDefTab',
- 'RetainQueryBox');
+ 'RetainQueryBox',
+ 'CodemirrorEnable');
$forms['Sql_queries']['Sql_box'] = array('SQLQuery' => array(
'Edit',
'Explain',
View
3 libraries/config/user_preferences.forms.php
@@ -69,7 +69,8 @@
//'QueryWindowWidth', // overridden in theme
//'QueryWindowHeight',
'QueryWindowDefTab',
- 'RetainQueryBox');
+ 'RetainQueryBox',
+ 'CodemirrorEnable');
$forms['Sql_queries']['Sql_box'] = array(
'SQLQuery/Edit',
'SQLQuery/Explain',
View
7 querywindow.php
@@ -119,8 +119,11 @@
*/
$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(
View
7 server_privileges.php
@@ -15,8 +15,11 @@
*/
$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';
View
7 server_sql.php
@@ -16,8 +16,11 @@
$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';
View
3 server_status.php
@@ -432,7 +432,10 @@
* 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
View
7 sql.php
@@ -19,8 +19,11 @@
// 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';
+}
/**
View
7 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
View
7 tbl_sql.php
@@ -16,8 +16,11 @@
$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 .= '&amp;goto=tbl_sql.php&amp;back=tbl_sql.php';

0 comments on commit 8744f8c

Please sign in to comment.
Something went wrong with that request. Please try again.