mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-24 06:24:08 +00:00
mw.ViewPageTarget.init: Move conditionals client-side
Load the module always and have the conditionals on the client-side so that we can change these without running into problems with the new conditions not being rolled-out quickly for anonymous users because the load queue is in the HTML and cached for 30+ days. This also allows us to fix above problem retroactively in wmf production by just adding a mw.loader.load for this module in something like MediaWiki:Common.js or something else that is already in the cached load queue (temporarily, until the cache has rolled over). Removed unreachable code for loading ext.visualEditor.splitTest. Change-Id: I21114960a88d224747447f2dc83d17d160f5f066
This commit is contained in:
parent
bf342d660c
commit
a81beef27a
|
@ -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;
|
||||
|
|
|
@ -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',
|
||||
),
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue