mediawiki-extensions-Visual.../modules/ve-mw/preinit/ve.init.MWWelcomeDialog.js
Bartosz Dziewoński 3f0f302577 Enforce that some files must not use the ve global
Previously, the ve-mw/init/ directory contained two kinds of files:
those that were used when initializing VE, and those that may be
loaded even if VE is not going to be initialized at all. The latter
kind must not use the `ve` global variable.

After moving those files to ve-mw/preinit/ we can enforce this with
.eslintrc.json in that directory. This would have prevented T228684.

(Technically they merely must not use `ve.init`, and may use `ve`,
but that's harder to enforce. We should instead move the few non-init
methods out of `ve`: now, track, trackSubscribe, trackSubscribeAll).

Also, group some files under ve-mw/init/: targets/ now (only)
contains ve.init.mw.Target and its subclasses, apiresponsecache/
now contains ve.init.mw.ApiResponseCache and its subclasses.

Bug: T228684
Change-Id: I945249a27f6a0fa10a432d5c5dc57bc7e0461fd8
2019-10-10 15:15:40 +00:00

93 lines
2.3 KiB
JavaScript

/*!
* VisualEditor user interface MWWelcomeDialog class.
*
* @copyright 2011-2019 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
mw.libs.ve = mw.libs.ve || {};
/**
* Dialog for welcoming new users.
*
* @class
* @extends OO.ui.MessageDialog
*
* @constructor
* @param {Object} [config] Configuration options
*/
mw.libs.ve.WelcomeDialog = function VeInitWelcomeDialog( config ) {
// Parent constructor
mw.libs.ve.WelcomeDialog.super.call( this, config );
this.$element
.addClass( 've-init-mw-welcomeDialog' );
};
/* Inheritance */
OO.inheritClass( mw.libs.ve.WelcomeDialog, OO.ui.MessageDialog );
/* Static Properties */
mw.libs.ve.WelcomeDialog.static.name = 'welcome';
mw.libs.ve.WelcomeDialog.static.size = 'medium';
mw.libs.ve.WelcomeDialog.static.actions = [
{
action: 'switch-wte',
label: OO.ui.deferMsg( 'visualeditor-welcomedialog-switch' ),
modes: [ 'visual' ]
},
{
action: 'switch-ve',
label: OO.ui.deferMsg( 'visualeditor-welcomedialog-switch-ve' ),
modes: [ 'source' ]
},
{
action: 'accept',
label: OO.ui.deferMsg( 'visualeditor-welcomedialog-action' ),
flags: [ 'progressive', 'primary' ],
modes: [ 'visual', 'source', 'noswitch' ]
}
];
/**
* @inheritdoc
*/
mw.libs.ve.WelcomeDialog.prototype.getSetupProcess = function ( data ) {
// Provide default title and message
data = $.extend( {
title: mw.msg( 'visualeditor-welcomedialog-title', mw.user, mw.config.get( 'wgSiteName' ) ),
message: $( '<span>' )
.addClass( 've-init-mw-welcomeDialog-content' )
.append(
document.createTextNode( mw.msg( 'visualeditor-welcomedialog-content' ) ),
$( '<br>' ),
document.createTextNode( mw.msg( 'visualeditor-welcomedialog-content-thanks' ) )
)
}, data );
return mw.libs.ve.WelcomeDialog.super.prototype.getSetupProcess.call( this, data )
.next( function () {
this.switchable = data.switchable;
this.editor = data.editor;
this.actions.setMode( this.switchable ? this.editor : 'noswitch' );
}, this );
};
/**
* @inheritdoc
*/
mw.libs.ve.WelcomeDialog.prototype.getActionProcess = function ( action ) {
if ( action === 'switch-wte' ) {
return new OO.ui.Process( function () {
this.close( { action: 'switch-wte' } );
}, this );
}
// Parent method
return mw.libs.ve.WelcomeDialog.super.prototype.getActionProcess.call( this, action );
};