Merge #20165 - Improve the way phpMyAdmin uses the user-agent

Pull-request: #20165
Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2026-02-24 09:30:26 +01:00
commit 4bbcd9249b
No known key found for this signature in database
GPG Key ID: 70684F4717D49A31
3 changed files with 22 additions and 7 deletions

View File

@ -103,6 +103,20 @@ $.ajaxPrefilter(function (options, originalOptions) {
}
});
/**
* Get an empty string for user-agent, if undefined
*
* @return {string}
*/
Functions.userAgent = function () {
try {
return navigator.userAgent;
} catch (e) {
console.error(e);
return '';
}
};
/**
* Adds a date/time picker to an element
*
@ -1095,7 +1109,7 @@ AJAX.registerOnload('functions.js', function () {
/**
* Add attribute to text boxes for iOS devices (based on bugID: 3508912)
*/
if (navigator.userAgent.match(/(iphone|ipod|ipad)/i)) {
if (Functions.userAgent().match(/(iphone|ipod|ipad)/i)) {
$('input[type=text]').attr('autocapitalize', 'off').attr('autocorrect', 'off');
}
});

View File

@ -260,7 +260,7 @@ var makeGrid = function (t, enableResize, enableReorder, enableVisib, enableGrid
for (var n = 0, l = $firstRowCols.length; n < l; n++) {
var $col = $($firstRowCols[n]);
var colWidth;
if (navigator.userAgent.toLowerCase().indexOf('safari') !== -1) {
if (Functions.userAgent().toLowerCase().indexOf('safari') !== -1) {
colWidth = $col.outerWidth();
} else {
colWidth = $col.outerWidth(true);
@ -2317,10 +2317,10 @@ var makeGrid = function (t, enableResize, enableReorder, enableVisib, enableGrid
$.fn.noSelect = function (p) { // no select plugin by Paulo P.Marinas
var prevent = (p === null) ? true : p;
/* eslint-disable compat/compat */
var isMsie = navigator.userAgent.indexOf('MSIE') > -1 || !!window.navigator.userAgent.match(/Trident.*rv:11\./);
var isFirefox = navigator.userAgent.indexOf('Firefox') > -1;
var isSafari = navigator.userAgent.indexOf('Safari') > -1;
var isOpera = navigator.userAgent.indexOf('Presto') > -1;
var isMsie = Functions.userAgent().indexOf('MSIE') > -1 || !!Functions.userAgent().match(/Trident.*rv:11\./);
var isFirefox = Functions.userAgent().indexOf('Firefox') > -1;
var isSafari = Functions.userAgent().indexOf('Safari') > -1;
var isOpera = Functions.userAgent().indexOf('Presto') > -1;
/* eslint-enable compat/compat */
if (prevent) {
return this.each(function () {

View File

@ -334,7 +334,8 @@ class Header
// The user preferences have been merged at this point
// so we can conditionally add CodeMirror, other scripts and settings
if ($GLOBALS['cfg']['CodemirrorEnable']) {
// See #20159, why we need to check for HTTP_USER_AGENT here
if ($GLOBALS['cfg']['CodemirrorEnable'] && isset($_SERVER['HTTP_USER_AGENT'])) {
$this->scripts->addFile('vendor/codemirror/lib/codemirror.js');
$this->scripts->addFile('vendor/codemirror/mode/sql/sql.js');
$this->scripts->addFile('vendor/codemirror/addon/runmode/runmode.js');