Remove VE user-agent based browser compatibility checks

Bug: T367735
Change-Id: I07fb1bbbd2f907672400cb9bc74fd40dea973da9
This commit is contained in:
Ed Sanders 2024-06-16 23:37:19 +01:00
parent dc3128fe4e
commit 8cb070f4d7
7 changed files with 7 additions and 278 deletions

View file

@ -47,28 +47,6 @@
},
"merge_strategy": "array_plus"
},
"VisualEditorBrowserUnsupportedList": {
"value": {
"firefox": [
[
"<=",
11
]
],
"safari": [
[
"<=",
6
]
],
"opera": [
[
"<",
12
]
]
}
},
"VisualEditorDisableForAnons": {
"description": "Do not change the edit tabs/links for anon users, regardless of other settings. Does not affect temporary users. Note that this does not actually disable the visual editor, contrary to the name, and you should probably set the user preferences so that wikitext editor is the default. (T253941)",
"value": false
@ -355,7 +333,6 @@
]
},
"dependencies": [
"jquery.client",
"jquery.textSelection",
"mediawiki.page.ready",
"mediawiki.storage",
@ -700,6 +677,7 @@
"oojs",
"oojs-ui",
"unicodejs",
"jquery.client",
"ext.visualEditor.core.utils",
"ext.visualEditor.core.utils.parsing"
]
@ -832,7 +810,6 @@
"savechanges",
"savechanges-start",
"showpreview",
"visualeditor-browserwarning",
"visualeditor-loaderror-revidconflict",
"visualeditor-loaderror-wrongmode",
"visualeditor-mweditmodesource-progress",

View file

@ -50,7 +50,6 @@
"visualeditor-autosave-recovered-text": "Your unsaved changes have been automatically recovered.",
"visualeditor-autosave-recovered-title": "Changes recovered",
"visualeditor-backbutton-tooltip": "Go back",
"visualeditor-browserwarning": "You are using a browser which is not officially supported by this editor.",
"visualeditor-ca-createlocaldescriptionsource": "Add local description source",
"visualeditor-ca-createsource": "Create source",
"visualeditor-ca-editlocaldescriptionsource": "Edit local description source",

View file

@ -72,7 +72,6 @@
"visualeditor-autosave-recovered-text": "Text shown when document recovery is successful",
"visualeditor-autosave-recovered-title": "Title shown when document recovery is successful",
"visualeditor-backbutton-tooltip": "Tooltip text for back button taking user to reading mode and closing the editor.\n{{Identical|Go back}}",
"visualeditor-browserwarning": "Edit notice shown when VisualEditor loads, warning users that their browser is not officially supported.",
"visualeditor-ca-createlocaldescriptionsource": "Text for the \"Create local description source\" tab, shown if the local description page of a file in a foreign repository (e.g. Wikimedia Commons) does not yet exist. The tab allows the user to edit the local description page in the wikitext source code editor.\n\nCf. {{msg-mw|Create-local}}",
"visualeditor-ca-createsource": "Text for the create source link in the tab dropdown, if the page doesn't exist. It's shown next to the message {{msg-mw|vector-view-create}}, so they should be similar (for example, use a similar translation for \"Create\").\n\nThe difference between \"Create source\" and \"Create\" is that when \"Create source\" is for editing the page or the section in wikitext markup language, and \"Create\" is for editing the page in VisualEditor.\n\nIf the page exists, the following link text is used: {{msg-mw|Visualeditor-ca-editsource}}",
"visualeditor-ca-editlocaldescriptionsource": "Text for the \"Edit local description source\" tab, if the page exists and the page is the local description of a file in a foreign repository (e.g. Wikimedia Commons). The tab allows the user to edit the local description page in the wikitext source code editor.\n\nCf. {{msg-mw|Edit-local}}",

View file

@ -267,49 +267,6 @@ class Hooks implements
$this->loadDiffModules( $output );
}
/**
* Detect incompatible browsers which we can't expect to load VE
*
* @param WebRequest $req The web request to check the details of
* @param Config $config VE config object
* @return bool The User Agent is unsupported
*/
private static function isUAUnsupported( WebRequest $req, Config $config ): bool {
if ( $req->getVal( 'vesupported' ) ) {
return false;
}
$unsupportedList = $config->get( 'VisualEditorBrowserUnsupportedList' );
$ua = strtolower( $req->getHeader( 'User-Agent' ) );
foreach ( $unsupportedList as $uaSubstr => $rules ) {
if ( !strpos( $ua, $uaSubstr . '/' ) ) {
continue;
}
if ( !is_array( $rules ) ) {
return true;
}
$matches = [];
$ret = preg_match( '/' . $uaSubstr . '\/([0-9\.]*) ?/i', $ua, $matches );
if ( $ret !== 1 ) {
continue;
}
$version = $matches[1];
foreach ( $rules as $rule ) {
[ $op, $matchVersion ] = $rule;
if (
( $op === '<' && $version < $matchVersion ) ||
( $op === '>' && $version > $matchVersion ) ||
( $op === '<=' && $version <= $matchVersion ) ||
( $op === '>=' && $version >= $matchVersion )
) {
return true;
}
}
}
return false;
}
/**
* @param Title $title
* @param User $user
@ -430,10 +387,7 @@ class Hooks implements
}
}
if (
!self::enabledForUser( $user ) ||
self::isUAUnsupported( $req, $veConfig )
) {
if ( !self::enabledForUser( $user ) ) {
return true;
}
@ -1182,7 +1136,6 @@ class Hooks implements
),
'thumbLimits' => $coreConfig->get( 'ThumbLimits' ),
'galleryOptions' => $coreConfig->get( 'GalleryOptions' ),
'unsupportedList' => $veConfig->get( 'VisualEditorBrowserUnsupportedList' ),
'tabPosition' => $veConfig->get( 'VisualEditorTabPosition' ),
'tabMessages' => array_filter( $veConfig->get( 'VisualEditorTabMessages' ) ),
'singleEditTab' => $veConfig->get( 'VisualEditorUseSingleEditTab' ),

View file

@ -135,28 +135,6 @@ ve.init.mw.DesktopArticleTarget.static.toolbarGroups.push(
}
);
/**
* Compatibility map used with jQuery.client to decide if a browser should
* receive a compatibility warning. Blacklisting is handled in DesktopArticleTarget.init.
*
* @static
* @property {Object}
*/
ve.init.mw.DesktopArticleTarget.static.compatibility = {
// The key is the browser name returned by jQuery.client
// The value is either null (match all versions) or a list of tuples
// containing an inequality (<,>,<=,>=) and a version number
supportedList: {
chrome: [ [ '>=', 19 ] ],
opera: [ [ '>=', 15 ] ],
// All versions not in unsupportedList are fully supported:
firefox: null,
safari: null,
msie: null,
edge: null
}
};
ve.init.mw.DesktopArticleTarget.static.platformType = 'desktop';
/* Events */
@ -317,21 +295,6 @@ ve.init.mw.DesktopArticleTarget.prototype.setupToolbarSaveButton = function () {
this.toolbarSaveButton = this.toolbar.getToolGroupByName( 'save' ).items[ 0 ];
};
/**
* Set up notices for things like unknown browsers.
* Needs to be done on each activation because localNoticeMessages is cleared in clearState.
*/
ve.init.mw.DesktopArticleTarget.prototype.setupLocalNoticeMessages = function () {
if ( !(
this.currentUrl.searchParams.has( 'vesupported' ) ||
$.client.test( this.constructor.static.compatibility.supportedList, null, true )
) ) {
// Show warning in unknown browsers that pass the support test
// Continue at own risk.
this.localNoticeMessages.push( 'visualeditor-browserwarning' );
}
};
/**
* @inheritdoc
*/
@ -451,7 +414,6 @@ ve.init.mw.DesktopArticleTarget.prototype.activate = function ( dataPromise ) {
// User interface changes
this.changeDocumentTitle();
this.transformPage();
this.setupLocalNoticeMessages();
this.load( dataPromise );
}

View file

@ -883,8 +883,6 @@
}
init = {
unsupportedList: conf.unsupportedList,
/**
* Add a plugin module or function.
*
@ -1330,11 +1328,8 @@
// Whether VisualEditor should be available for the current user, page, wiki, mediawiki skin,
// browser etc.
init.isAvailable = (
VisualEditorSupportCheck() &&
( url.searchParams.has( 'vesupported' ) || !$.client.test( init.unsupportedList, null, true ) )
// Extensions can disable VE in certain circumstances using the VisualEditorBeforeEditor hook (T174180)
);
init.isAvailable = VisualEditorSupportCheck();
// Extensions can disable VE in certain circumstances using the VisualEditorBeforeEditor hook (T174180)
const enabledForUser = (
// User has 'visualeditor-enable' preference enabled (for alpha opt-in)
@ -1387,9 +1382,9 @@
init.updateTabs = updateTabs;
// Note: Though VisualEditor itself only needs this exposure for a very small reason
// (namely to access init.unsupportedList from the unit tests...) this has become one of the nicest
// ways to easily detect whether the VisualEditor initialisation code is present.
// Note: Though VisualEditor itself only needed this exposure for a very small reason
// (namely to access the old init.unsupportedList from the unit tests...) this has become one
// of the nicest ways to easily detect whether the VisualEditor initialisation code is present.
//
// The VE global was once available always, but now that platform integration initialisation
// is properly separated, it doesn't exist until the platform loads VisualEditor core.

View file

@ -153,159 +153,3 @@ QUnit.test( 'init', ( assert ) => {
} );
target.activate( dataPromise );
} );
QUnit.test( 'compatibility', ( assert ) => {
const cases = [
{
msg: 'Unidentified browser',
userAgent: 'FooBar Browser Company Version 3.141',
matches: []
},
{
msg: 'IE11',
userAgent: 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; rv:11.0) like Gecko',
matches: [ 'supportedList' ]
},
{
msg: 'Edge 12',
userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246',
matches: [ 'supportedList' ]
},
{
msg: 'Firefox 10',
userAgent: 'Mozilla/5.0 (X11; Mageia; Linux x86_64; rv:10.0.9) Gecko/20100101 Firefox/10.0.9',
matches: [ 'unsupportedList' ]
},
{
msg: 'Firefox 11',
userAgent: 'Mozilla/5.0 (Windows NT 6.1; U;WOW64; de;rv:11.0) Gecko Firefox/11.0',
matches: [ 'unsupportedList' ]
},
{
msg: 'Firefox 12',
userAgent: 'Mozilla/5.0 (compatible; Windows; U; Windows NT 6.2; WOW64; en-US; rv:12.0) Gecko/20120403211507 Firefox/12.0',
matches: [ 'supportedList' ]
},
{
msg: 'Firefox 13',
userAgent: 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:13.0) Gecko/20100101 Firefox/13.0',
matches: [ 'supportedList' ]
},
{
msg: 'Firefox 14',
userAgent: 'Mozilla/5.0 (Windows NT 6.1; rv:12.0) Gecko/20120403211507 Firefox/14.0.1',
matches: [ 'supportedList' ]
},
{
msg: 'Firefox 15',
userAgent: 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:15.0) Gecko/20100101 Firefox/15.0.1',
matches: [ 'supportedList' ]
},
{
msg: 'Firefox 24',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:24.0) Gecko/20100101 Firefox/24.0',
matches: [ 'supportedList' ]
},
{
msg: 'Safari 4',
userAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/531.21.11 (KHTML, like Gecko) Version/4.0.4 Safari/531.21.10',
matches: [ 'unsupportedList' ]
},
{
msg: 'Safari 5',
userAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/534.1+ (KHTML, like Gecko) Version/5.0 Safari/533.16',
matches: [ 'unsupportedList' ]
},
{
msg: 'Safari 6',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 1084) AppleWebKit/536.30.1 (KHTML like Gecko) Version/6.0.5 Safari/536.30.1',
matches: [ 'unsupportedList' ]
},
{
msg: 'Safari 7',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A',
matches: [ 'supportedList' ]
},
{
msg: 'Safari 8',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/600.3.18 (KHTML, like Gecko) Version/8.0.3 Safari/600.3.18',
matches: [ 'supportedList' ]
},
{
msg: 'Chrome 18',
userAgent: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_5_8) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.151 Safari/535.19',
matches: []
},
{
msg: 'Chrome 19',
userAgent: 'Mozilla/5.0 (Windows NT 6.2) AppleWebKit/536.3 (KHTML, like Gecko) Chrome/19.0.1061.0 Safari/536.3',
matches: [ 'supportedList' ]
},
{
msg: 'Chrome 27',
userAgent: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36',
matches: [ 'supportedList' ]
},
{
msg: 'Android 2.3',
userAgent: 'Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1',
matches: []
},
{
msg: 'Android 3.0',
userAgent: 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13',
matches: []
},
{
msg: 'Android 4.0',
userAgent: 'Mozilla/5.0 (Linux; U; Android 4.0.3; HTC Sensation Build/IML74K) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30',
matches: []
},
{
msg: 'Opera 11',
userAgent: 'Opera/9.80 (Windows NT 5.1) Presto/2.10.229 Version/11.64',
matches: [ 'unsupportedList' ]
},
{
msg: 'Opera 12.16',
userAgent: 'Opera/9.80 (Windows NT 5.1) Presto/2.12.388 Version/12.16',
matches: []
},
{
msg: 'Opera 15.0',
userAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.52 Safari/537.36 OPR/15.0.1147.100',
matches: [ 'supportedList' ]
},
{
msg: 'Amazon Silk desktop',
userAgent: 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.0.13.81_10003810) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true',
matches: []
},
{
msg: 'Amazon Silk mobile',
userAgent: 'Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; KFTT Build/IML74K) AppleWebKit/535.19 (KHTML, like Gecko) Silk/2.1 Mobile Safari/535.19 Silk-Accelerated=true',
matches: []
}
];
const compatibility = {
supportedList: ve.init.mw.DesktopArticleTarget.static.compatibility.supportedList,
// TODO: Fix this mess when we split ve.init from ve.platform
unsupportedList: mw.libs.ve.unsupportedList
};
cases.forEach( ( caseItem ) => {
const profile = $.client.profile( { userAgent: caseItem.userAgent, platform: '' } ),
matches = [];
[ 'unsupportedList', 'supportedList' ].every( ( list ) => {
if ( $.client.test( compatibility[ list ], profile, true ) ) {
matches.push( list );
// Don't check supportedList if on unsupportedList
return false;
}
return true;
} );
assert.deepEqual( matches, caseItem.matches,
caseItem.msg + ': ' + ( caseItem.matches.length ? caseItem.matches.join() : 'greylist (no matches)' ) );
} );
} );