init: Fix checks for required skin elements to avoid false positives

* Do not try to load the editor on protected pages, or if the user
  doesn't have permission to edit pages.
* Move the check for required DOM elements after the check for
  pages without the editor (T162411) and after DOM ready (T163307).

Bug: T162411
Bug: T163307
Change-Id: I8149694ba8155682701f2cda6ca212d60f446caa
This commit is contained in:
Bartosz Dziewoński 2017-04-26 19:20:58 +02:00
parent 99656bae30
commit a02e68374e

View file

@ -19,7 +19,7 @@
*/
( function () {
var conf, tabMessages, uri, pageExists, viewUri, veEditUri, veEditSourceUri, isViewPage, isEditPage,
pageCanLoadEditor, init, targetPromise, enable, tempdisable, autodisable, requiredSkinElements,
pageCanLoadEditor, init, targetPromise, enable, tempdisable, autodisable,
tabPreference, enabledForUser, initialWikitext, oldid,
isLoading,
editModes = {
@ -752,18 +752,6 @@
veEditUri.extend( { oldid: oldid } );
}
requiredSkinElements =
$( '#content' ).length &&
$( '#mw-content-text' ).length &&
$( '#ca-edit' ).length;
if ( pageCanLoadEditor && !requiredSkinElements ) {
mw.log.warn(
'Your skin is incompatible with VisualEditor. ' +
'See <https://www.mediawiki.org/wiki/VisualEditor/Skin_requirements> for the requirements.'
);
}
// Whether VisualEditor should be available for the current user, page, wiki, mediawiki skin,
// browser etc.
init.isAvailable = (
@ -772,8 +760,8 @@
( ( 'vewhitelist' in uri.query ) || !$.client.test( init.blacklist, null, true ) ) &&
// Only in supported skins
requiredSkinElements &&
// Not on protected pages, or if the user doesn't have permission to edit
mw.config.get( 'wgIsProbablyEditable' ) &&
// Not on pages which are outputs of the Translate extensions
// TODO: Allow the Translate extension to do this itself
@ -854,7 +842,7 @@
}
$( function () {
var mode,
var mode, requiredSkinElements,
showWikitextWelcome = true,
section = uri.query.section !== undefined ? parseSection( uri.query.section ) : null,
isLoggedIn = !mw.user.isAnon(),
@ -862,6 +850,11 @@
urlSaysHideWelcome = 'hidewelcomedialog' in new mw.Uri( location.href ).query,
welcomeDialogLocalStorageValue = null;
requiredSkinElements =
$( '#content' ).length &&
$( '#mw-content-text' ).length &&
$( '#ca-edit' ).length;
if ( uri.query.action === 'edit' && $( '#wpTextbox1' ).length ) {
initialWikitext = $( '#wpTextbox1' ).textSelection( 'getContents' );
}
@ -904,7 +897,12 @@
return null;
}
if ( init.isAvailable ) {
if ( init.isAvailable && pageCanLoadEditor && !requiredSkinElements ) {
mw.log.warn(
'Your skin is incompatible with VisualEditor. ' +
'See <https://www.mediawiki.org/wiki/VisualEditor/Skin_requirements> for the requirements.'
);
} else if ( init.isAvailable ) {
mode = getInitialEditMode();
if ( mode ) {
showWikitextWelcome = false;