diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index e39fb9184f..e0192e4a24 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -53,35 +53,12 @@ class VisualEditorHooks { global $wgVisualEditorNamespaces, $wgVisualEditorEnableEventLogging, $wgVisualEditorDisableForAnons; - if ( - // Bug 50000: Allow disabling for anonymous users separately from changing - // the default preference - !( $wgVisualEditorDisableForAnons && $skin->getUser()->isAnon() ) && - - // Bug 47328: Disable on redirect pages until redirects are editable - !$skin->getTitle()->isRedirect() && - - // User has the 'visualeditor-enable' preference set - $skin->getUser()->getOption( 'visualeditor-enable' ) && - - // The user's current skin is supported - in_array( $skin->getSkinName(), self::$supportedSkins ) && - - // The current page is in a VisualEditor-enabled namespace - in_array( $skin->getRelevantTitle()->getNamespace(), $wgVisualEditorNamespaces ) && - - // Only use VisualEditor if the page is wikitext, not CSS/JS - $skin->getTitle()->getContentModel() === CONTENT_MODEL_WIKITEXT - ) { - if ( $wgVisualEditorEnableEventLogging ) { - $output->addModules( array( 'schema.Edit' ) ); - } - $output->addModules( array( 'ext.visualEditor.viewPageTarget.init' ) ); - } else { - if ( $wgVisualEditorEnableEventLogging ) { - $output->addModules( array( 'schema.Edit', 'ext.visualEditor.splitTest' ) ); - } + if ( $wgVisualEditorEnableEventLogging ) { + $output->addModules( array( 'schema.Edit' ) ); } + + $output->addModules( array( 'ext.visualEditor.viewPageTarget.init' ) ); + return true; } @@ -139,13 +116,16 @@ class VisualEditorHooks { * Adds extra variables to the global config */ public static function onResourceLoaderGetConfigVars( array &$vars ) { - global $wgVisualEditorEnableEventLogging, - $wgVisualEditorEnableExperimentalCode, $wgVisualEditorTabLayout; + global $wgVisualEditorEnableExperimentalCode, $wgVisualEditorEnableEventLogging, + $wgVisualEditorTabLayout, $wgVisualEditorDisableForAnons, $wgVisualEditorNamespaces; $vars['wgVisualEditorConfig'] = array( 'enableExperimentalCode' => $wgVisualEditorEnableExperimentalCode, 'enableEventLogging' => $wgVisualEditorEnableEventLogging, 'tabLayout' => $wgVisualEditorTabLayout, + 'disableForAnons' => $wgVisualEditorDisableForAnons, + 'namespaces' => $wgVisualEditorNamespaces, + 'skins' => self::$supportedSkins, ); return true; diff --git a/VisualEditor.php b/VisualEditor.php index 1ea12f7499..97e605337c 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -157,6 +157,7 @@ $wgResourceModules += array( 'styles' => 've-mw/init/styles/ve.init.mw.ViewPageTarget.init.css', 'dependencies' => array( 'jquery.client', + 'mediawiki.Title', 'mediawiki.Uri', 'mediawiki.util', ), diff --git a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js index e736e6f065..6faae63728 100644 --- a/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js +++ b/modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js @@ -313,6 +313,39 @@ support.contentEditable && ( ( 'vewhitelist' in uri.query ) || !$.client.test( init.blacklist, null, true ) ); + // Whether VisualEditor should be available for the current user, page, wiki, mediawiki skin, + // browser etc. + init.isAvailable = ( + support.visualEditor && + + // Allow disabling for anonymous users separately from changing the + // default preference (bug 50000) + !( conf.disableForAnons && mw.user.isAnon() ) && + + // Disable on redirect pages until redirects are editable (bug 47328) + // Property wgIsRedirect is relatively new in core, many cached pages + // don't have it yet. We do a best-effort approach using the url query + // which will cover all working redirect (the only case where one can + // read a redirect page without ?redirect=no is in case of broken or + // double redirects). + !mw.config.get( 'wgIsRedirect', !!uri.query.redirect ) && + + // User has 'visualeditor-enable' preference enabled + mw.user.options.get( 'visualeditor-enable' ) && + + // Only in supported skins + $.inArray( mw.config.get( 'skin' ), conf.skins ) !== -1 && + + // Only in enabled namespaces + $.inArray( + new mw.Title( mw.config.get( 'wgRelevantPageName' ) ).getNamespaceId(), + conf.namespaces + ) !== -1 && + + // Only for pages with a wikitext content model + mw.config.get( 'wgPageContentModel' ) === 'wikitext' + ); + // Note: Though VisualEditor itself only needs this exposure for a very small reason // (namely to access init.blacklist from the unit tests...) this has become one of the nicest // ways to easily detect whether VisualEditor is present on this page. The VE global was once @@ -322,8 +355,7 @@ // of this property should be reliable. mw.libs.ve = init; - if ( !support.visualEditor ) { - mw.log( 'Browser does not support VisualEditor' ); + if ( !init.isAvailable ) { return; }