jenkins-bot has submitted this change and it was merged. Change subject: mw.ViewPageTarget.init: Move conditionals client-side ......................................................................
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 --- M VisualEditor.hooks.php M VisualEditor.php M modules/ve-mw/init/targets/ve.init.mw.ViewPageTarget.init.js 3 files changed, 45 insertions(+), 32 deletions(-) Approvals: Catrope: Looks good to me, approved jenkins-bot: Verified diff --git a/VisualEditor.hooks.php b/VisualEditor.hooks.php index e39fb91..e0192e4 100644 --- a/VisualEditor.hooks.php +++ b/VisualEditor.hooks.php @@ -53,35 +53,12 @@ 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 @@ * 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 1ea12f7..97e6053 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -157,6 +157,7 @@ '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 e736e6f..6faae63 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; } -- To view, visit https://gerrit.wikimedia.org/r/74824 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: I21114960a88d224747447f2dc83d17d160f5f066 Gerrit-PatchSet: 5 Gerrit-Project: mediawiki/extensions/VisualEditor Gerrit-Branch: master Gerrit-Owner: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Catrope <roan.katt...@gmail.com> Gerrit-Reviewer: Krinkle <krinklem...@gmail.com> Gerrit-Reviewer: Trevor Parscal <tpars...@wikimedia.org> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits