Merge "mw.ViewPageTarget.init: Move conditionals client-side"

This commit is contained in:
jenkins-bot 2013-07-23 19:49:15 +00:00 committed by Gerrit Code Review
commit c6331c84d3
3 changed files with 45 additions and 32 deletions

View file

@ -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;

View file

@ -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',
),

View file

@ -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;
}