2013-07-03 22:14:52 +00:00
|
|
|
|
/*!
|
2015-07-29 13:41:30 +00:00
|
|
|
|
* VisualEditor MediaWiki DesktopArticleTarget init.
|
2013-07-03 22:14:52 +00:00
|
|
|
|
*
|
|
|
|
|
* This file must remain as widely compatible as the base compatibility
|
|
|
|
|
* for MediaWiki itself (see mediawiki/core:/resources/startup.js).
|
|
|
|
|
* Avoid use of: ES5, SVG, HTML5 DOM, ContentEditable etc.
|
|
|
|
|
*
|
2016-01-03 22:56:59 +00:00
|
|
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
2013-07-03 22:14:52 +00:00
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-08 03:37:51 +00:00
|
|
|
|
/* jshint esversion: 3 */
|
|
|
|
|
|
2013-07-03 22:14:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* Platform preparation for the MediaWiki view page. This loads (when user needs it) the
|
|
|
|
|
* actual MediaWiki integration and VisualEditor library.
|
|
|
|
|
*
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
|
* @class mw.libs.ve
|
2015-07-29 13:41:30 +00:00
|
|
|
|
* @alternateClassName ve.init.mw.DesktopArticleTarget.init
|
2013-07-03 22:14:52 +00:00
|
|
|
|
* @singleton
|
|
|
|
|
*/
|
|
|
|
|
( function () {
|
2015-10-23 16:29:56 +00:00
|
|
|
|
var conf, tabMessages, uri, pageExists, viewUri, veEditUri, isViewPage, isEditPage,
|
2016-02-16 19:20:04 +00:00
|
|
|
|
pageCanLoadVE, init, targetPromise, enable, tempdisable, autodisable,
|
2016-04-15 02:05:27 +00:00
|
|
|
|
tabPreference, userPrefEnabled, userPrefPreferShow, initialWikitext, oldid,
|
|
|
|
|
onlyTabIsVE,
|
2015-05-09 13:47:10 +00:00
|
|
|
|
active = false,
|
|
|
|
|
progressStep = 0,
|
|
|
|
|
progressSteps = [
|
2015-07-22 22:13:09 +00:00
|
|
|
|
[ 30, 3000 ],
|
|
|
|
|
[ 70, 2000 ],
|
|
|
|
|
[ 100, 1000 ]
|
2015-05-09 13:47:10 +00:00
|
|
|
|
],
|
Infrastructure for loading plugins in the MW integration
Server-side, plugins can register themselves by adding to
$wgVisualEditorPluginModules. This is the recommended way for
MW extensions to extend VE. Client-side, plugins can register
themselves through mw.libs.ve.addPlugin(), which takes a string
(RL module name) or a callback.
When VisualEditor loads, we load the registered plugin modules in
parallel with ext.visualEditor.core. Note that they're loaded in
parallel, not after, and so the plugins should explicitly depend
on ext.visualEditor.core if they use or extend classes in VE core.
Once the modules finish loading and user and site scripts have run,
we execute the registered plugin callbacks. These callbacks can
optionally return a promise. We gather these promises and wait for
all of them to be resolved, then initialize the editor.
This allows Gadgets to extend VE by top-loading a small module that
depends on ext.visualEditor.viewPageTarget.init and calls
mw.libs.ve.addPlugin( 'ext.gadget.bottomHalfGadget' ); , the bottom
half being a hidden Gadget that depends on ext.visualEditor.core and
contains the actual code. The addPlugin() call needs to be in a
top-loading module because otherwise there's no guarantee that the
plugin will be registered before the user clicks edit and VE loads.
User and site scripts can extend VE by simply calling addPlugin()
directly, as mw.libs.ve is already present when user scripts run (since
it's top-loaded) and VE waits for 'user' and 'site' to run before
executing plugins.
If user/site scripts need to load additional JS files, they can load
these with $.getScript() and return the corresponding promise:
mw.libs.ve.addPlugin( function() { return $.getScript( 'URL' ); } );
For a diagram of all this, see
https://www.mediawiki.org/wiki/File:VE-plugin-infrastructure.jpg :)
VisualEditor.php:
* Add $wgVisualEditorPluginModules
VisualEditor.hooks.php:
* Expose $wgVisualEditorPluginModules in JS
ve.init.mw.ViewPageTarget.init.js:
* Add mw.libs.ve.addPlugin function that just stores the registered
values in an array and passes them into the mw.Target when it's
being initialized
ve.init.mw.Target.js:
* Add $wgVisualEditorPluginModules to the set of modules to load when
initializing VE
* Add a Deferred (this.modulesReady) to track module loading
* Add addPlugin() and addPlugins() methods that add to either
this.modules or this.pluginCallbacks
* In load(), instead of mw.loader.load()ing this.modules, use using()
to load this.modules plus user and site, and fire onModulesReady()
when they're loaded
* In onModulesReady(), execute the registered callbacks, gather the
returned promises, wait for all of them to be resolved, then resolve
this.modulesReady
* Fire onReady based on this.modulesReady being resolved, rather than
using a second using() call
Bug: 50514
Change-Id: Ib7d87a17eaac6ecdb8b0803b13840d7ee58902df
2013-07-22 20:34:28 +00:00
|
|
|
|
plugins = [];
|
2013-07-03 22:14:52 +00:00
|
|
|
|
|
2015-02-21 05:09:50 +00:00
|
|
|
|
function showLoading() {
|
2015-08-19 18:05:01 +00:00
|
|
|
|
var $content, contentRect, offsetTop, windowHeight, top, bottom, middle;
|
|
|
|
|
|
2016-02-10 02:27:50 +00:00
|
|
|
|
$( 'html' ).addClass( 've-activated ve-loading' );
|
2015-02-21 05:09:50 +00:00
|
|
|
|
if ( !init.$loading ) {
|
2015-02-15 11:42:21 +00:00
|
|
|
|
init.$loading = $(
|
2015-07-29 13:41:30 +00:00
|
|
|
|
'<div class="ve-init-mw-desktopArticleTarget-loading-overlay">' +
|
|
|
|
|
'<div class="ve-init-mw-desktopArticleTarget-progress">' +
|
2015-04-21 10:32:29 +00:00
|
|
|
|
// Stylesheets might not have processed yet, so manually set starting width to 0
|
2015-07-29 13:41:30 +00:00
|
|
|
|
'<div class="ve-init-mw-desktopArticleTarget-progress-bar" style="width: 0;"></div>' +
|
2015-02-15 11:42:21 +00:00
|
|
|
|
'</div>' +
|
|
|
|
|
'</div>'
|
|
|
|
|
);
|
|
|
|
|
}
|
2015-08-19 18:05:01 +00:00
|
|
|
|
|
|
|
|
|
$content = $( '#content' );
|
|
|
|
|
contentRect = $content[ 0 ].getBoundingClientRect();
|
|
|
|
|
offsetTop = $content.offset().top;
|
|
|
|
|
windowHeight = $( window ).height();
|
|
|
|
|
top = Math.max( contentRect.top, 0 );
|
|
|
|
|
bottom = Math.min( contentRect.bottom, windowHeight );
|
|
|
|
|
middle = ( top + bottom ) / 2;
|
2015-02-15 11:42:21 +00:00
|
|
|
|
|
2015-03-23 02:32:00 +00:00
|
|
|
|
init.$loading.css( 'top', middle - offsetTop );
|
2015-02-15 11:42:21 +00:00
|
|
|
|
|
|
|
|
|
$content.prepend( init.$loading );
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-09 13:47:10 +00:00
|
|
|
|
function incrementLoadingProgress() {
|
2015-08-19 17:33:02 +00:00
|
|
|
|
var step = progressSteps[ progressStep ];
|
|
|
|
|
setLoadingProgress( step[ 0 ], step[ 1 ] );
|
2015-05-09 13:47:10 +00:00
|
|
|
|
progressStep++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resetLoadingProgress() {
|
|
|
|
|
progressStep = 0;
|
|
|
|
|
setLoadingProgress( 0, 0 );
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-15 11:42:21 +00:00
|
|
|
|
function setLoadingProgress( target, duration ) {
|
2015-07-29 13:41:30 +00:00
|
|
|
|
var $bar = init.$loading.find( '.ve-init-mw-desktopArticleTarget-progress-bar' ).stop();
|
2015-07-17 21:31:56 +00:00
|
|
|
|
$bar.css( 'transition', 'width ' + duration + 'ms ease-in' );
|
2015-05-09 13:47:10 +00:00
|
|
|
|
setTimeout( function () {
|
2015-02-15 11:42:21 +00:00
|
|
|
|
$bar.css( 'width', target + '%' );
|
2015-05-09 13:47:10 +00:00
|
|
|
|
} );
|
2015-02-21 05:09:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function hideLoading() {
|
2016-02-17 15:35:16 +00:00
|
|
|
|
$( 'html' ).removeClass( 've-loading' );
|
2015-02-21 05:09:50 +00:00
|
|
|
|
if ( init.$loading ) {
|
|
|
|
|
init.$loading.detach();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-12 23:28:49 +00:00
|
|
|
|
function handleLoadFailure() {
|
|
|
|
|
resetLoadingProgress();
|
|
|
|
|
if ( $( '#wpTextbox1' ).length || mw.config.get( 'wgAction' ) !== 'edit' ) {
|
2016-02-17 15:35:16 +00:00
|
|
|
|
$( 'html' ).removeClass( 've-activated' );
|
2016-02-12 23:28:49 +00:00
|
|
|
|
hideLoading();
|
|
|
|
|
} else {
|
|
|
|
|
location.href = viewUri.clone().extend( { action: 'edit', veswitched: 1 } );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-03 22:14:52 +00:00
|
|
|
|
/**
|
|
|
|
|
* Use deferreds to avoid loading and instantiating Target multiple times.
|
2015-08-19 18:21:01 +00:00
|
|
|
|
*
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
|
* @private
|
|
|
|
|
* @return {jQuery.Promise}
|
2013-07-03 22:14:52 +00:00
|
|
|
|
*/
|
|
|
|
|
function getTarget() {
|
2014-09-07 22:47:58 +00:00
|
|
|
|
if ( !targetPromise ) {
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
|
// The TargetLoader module is loaded in the bottom queue, so it should have been
|
|
|
|
|
// requested already but it might not have finished loading yet
|
|
|
|
|
targetPromise = mw.loader.using( 'ext.visualEditor.targetLoader' )
|
|
|
|
|
.then( function () {
|
2015-04-03 20:38:39 +00:00
|
|
|
|
mw.libs.ve.targetLoader.addPlugin( function () {
|
|
|
|
|
// If the user and site modules fail, we still want to continue
|
|
|
|
|
// loading, so convert failure to success
|
|
|
|
|
|
|
|
|
|
return mw.loader.using( [ 'user', 'site' ] ).then(
|
|
|
|
|
null,
|
|
|
|
|
function () {
|
|
|
|
|
return $.Deferred().resolve();
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
} );
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
|
// Add modules specific to desktop (modules shared between desktop
|
|
|
|
|
// and mobile are already added by TargetLoader)
|
|
|
|
|
// Note: it's safe to use .forEach() (ES5) here, because this code will
|
|
|
|
|
// never be called if the browser doesn't support ES5
|
|
|
|
|
[
|
2015-07-29 13:41:30 +00:00
|
|
|
|
'ext.visualEditor.desktopArticleTarget',
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
|
'ext.visualEditor.mwimage',
|
|
|
|
|
'ext.visualEditor.mwmeta'
|
|
|
|
|
].forEach( mw.libs.ve.targetLoader.addPlugin );
|
|
|
|
|
// Add requested plugins
|
|
|
|
|
plugins.forEach( mw.libs.ve.targetLoader.addPlugin );
|
|
|
|
|
plugins = [];
|
|
|
|
|
return mw.libs.ve.targetLoader.loadModules();
|
|
|
|
|
} )
|
2014-09-07 22:47:58 +00:00
|
|
|
|
.then( function () {
|
2015-08-19 18:05:01 +00:00
|
|
|
|
var target;
|
|
|
|
|
|
2016-04-21 11:28:00 +00:00
|
|
|
|
target = ve.init.mw.targetFactory.create( 'article' );
|
2016-04-15 02:05:27 +00:00
|
|
|
|
target.connect( this, {
|
|
|
|
|
transformPage: function () {
|
|
|
|
|
if ( onlyTabIsVE ) {
|
|
|
|
|
$( '#ca-edit' ).addClass( 'selected' );
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
restorePage: function () {
|
|
|
|
|
if ( onlyTabIsVE ) {
|
|
|
|
|
$( '#ca-edit' ).removeClass( 'selected' );
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
deactivate: function () {
|
|
|
|
|
if (
|
|
|
|
|
userPrefPreferShow &&
|
|
|
|
|
( !conf.singleEditTab || tabPreference === 'multi-tab' )
|
|
|
|
|
) {
|
|
|
|
|
init.setupSectionLinks();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} );
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
|
$( '#content' ).append( target.$element );
|
2014-09-07 22:47:58 +00:00
|
|
|
|
return target;
|
2014-08-20 01:53:01 +00:00
|
|
|
|
}, function ( e ) {
|
2014-12-03 23:35:48 +00:00
|
|
|
|
mw.log.warn( 'VisualEditor failed to load: ' + e );
|
2014-09-07 22:47:58 +00:00
|
|
|
|
} );
|
2013-07-03 22:14:52 +00:00
|
|
|
|
}
|
2015-03-31 19:52:14 +00:00
|
|
|
|
|
|
|
|
|
targetPromise.then( function () {
|
|
|
|
|
// Enqueue the loading of deferred modules (that is, modules which provide
|
|
|
|
|
// functionality that is not needed for loading the editor).
|
|
|
|
|
setTimeout( function () {
|
|
|
|
|
mw.loader.load( 'easy-deflate.deflate' );
|
|
|
|
|
}, 500 );
|
|
|
|
|
} );
|
|
|
|
|
|
2014-09-07 22:47:58 +00:00
|
|
|
|
return targetPromise;
|
2013-07-03 22:14:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-11-10 17:50:19 +00:00
|
|
|
|
function activatePageTarget( modified ) {
|
2015-12-10 20:30:01 +00:00
|
|
|
|
var key;
|
2015-10-14 23:34:34 +00:00
|
|
|
|
trackActivateStart( { type: 'page', mechanism: 'click' } );
|
|
|
|
|
|
|
|
|
|
if ( !active ) {
|
2015-12-10 20:30:01 +00:00
|
|
|
|
if (
|
|
|
|
|
mw.config.get( 'wgVisualEditorConfig' ).singleEditTab &&
|
2016-01-18 03:39:01 +00:00
|
|
|
|
tabPreference === 'remember-last'
|
2015-12-10 20:30:01 +00:00
|
|
|
|
) {
|
|
|
|
|
key = pageExists ? 'edit' : 'create';
|
|
|
|
|
if ( $( '#ca-view-foreign' ).length ) {
|
|
|
|
|
key += '-local';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$( '#ca-edit a' ).text( mw.msg( key ) );
|
2015-10-14 23:34:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 01:44:51 +00:00
|
|
|
|
if ( uri.query.action !== 'edit' && uri.query.veaction !== 'edit' ) {
|
2015-10-23 16:29:56 +00:00
|
|
|
|
if ( history.pushState ) {
|
|
|
|
|
// Replace the current state with one that is tagged as ours, to prevent the
|
|
|
|
|
// back button from breaking when used to exit VE. FIXME: there should be a better
|
|
|
|
|
// way to do this. See also similar code in the DesktopArticleTarget constructor.
|
|
|
|
|
history.replaceState( { tag: 'visualeditor' }, document.title, uri );
|
|
|
|
|
// Set veaction to edit
|
|
|
|
|
history.pushState( { tag: 'visualeditor' }, document.title, veEditUri );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update mw.Uri instance
|
|
|
|
|
uri = veEditUri;
|
|
|
|
|
}
|
2015-10-14 23:34:34 +00:00
|
|
|
|
|
2015-11-10 17:50:19 +00:00
|
|
|
|
activateTarget( null, modified );
|
2015-10-14 23:34:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-12 00:51:32 +00:00
|
|
|
|
|
2015-02-21 05:09:50 +00:00
|
|
|
|
/**
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
|
* Load and activate the target.
|
|
|
|
|
*
|
|
|
|
|
* If you need to call methods on the target before activate is called, call getTarget()
|
|
|
|
|
* yourself, chain your work onto that promise, and pass that chained promise in as targetPromise.
|
|
|
|
|
* E.g. `activateTarget( getTarget().then( function( target ) { target.doAThing(); } ) );`
|
2015-02-21 05:09:50 +00:00
|
|
|
|
*
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
|
* @private
|
2015-12-10 16:07:50 +00:00
|
|
|
|
* @param {jQuery.Promise} [targetPromise] Promise that will be resolved with a ve.init.mw.DesktopArticleTarget
|
2015-11-10 17:50:19 +00:00
|
|
|
|
* @param {boolean} [modified] The page was been modified before loading (e.g. in source mode)
|
2015-02-21 05:09:50 +00:00
|
|
|
|
*/
|
2015-11-10 17:50:19 +00:00
|
|
|
|
function activateTarget( targetPromise, modified ) {
|
2015-03-13 15:50:23 +00:00
|
|
|
|
// The TargetLoader module is loaded in the bottom queue, so it should have been
|
|
|
|
|
// requested already but it might not have finished loading yet
|
|
|
|
|
var dataPromise = mw.loader.using( 'ext.visualEditor.targetLoader' )
|
|
|
|
|
.then( function () {
|
|
|
|
|
return mw.libs.ve.targetLoader.requestPageData(
|
|
|
|
|
mw.config.get( 'wgRelevantPageName' ),
|
2015-12-18 00:58:23 +00:00
|
|
|
|
oldid,
|
2015-11-10 17:50:19 +00:00
|
|
|
|
'mwTarget', // ve.init.mw.DesktopArticleTarget.static.name
|
|
|
|
|
modified
|
2015-03-13 15:50:23 +00:00
|
|
|
|
);
|
2015-05-09 13:47:10 +00:00
|
|
|
|
} )
|
2016-02-12 23:28:49 +00:00
|
|
|
|
.done( incrementLoadingProgress )
|
|
|
|
|
.fail( handleLoadFailure );
|
2015-03-16 16:07:14 +00:00
|
|
|
|
|
2015-12-12 00:51:32 +00:00
|
|
|
|
setEditorPreference( 'visualeditor' );
|
2015-10-23 16:29:56 +00:00
|
|
|
|
|
2015-02-15 11:42:21 +00:00
|
|
|
|
showLoading();
|
2015-05-09 13:47:10 +00:00
|
|
|
|
incrementLoadingProgress();
|
|
|
|
|
active = true;
|
2015-03-16 16:07:14 +00:00
|
|
|
|
|
2015-03-13 15:50:23 +00:00
|
|
|
|
targetPromise = targetPromise || getTarget();
|
|
|
|
|
targetPromise
|
2015-02-21 05:09:50 +00:00
|
|
|
|
.then( function ( target ) {
|
2015-05-09 13:47:10 +00:00
|
|
|
|
incrementLoadingProgress();
|
|
|
|
|
target.on( 'deactivate', function () {
|
|
|
|
|
active = false;
|
|
|
|
|
} );
|
2016-02-12 23:28:49 +00:00
|
|
|
|
target.on( 'loadError', handleLoadFailure );
|
2015-03-13 15:50:23 +00:00
|
|
|
|
return target.activate( dataPromise );
|
2015-02-21 05:09:50 +00:00
|
|
|
|
} )
|
|
|
|
|
.then( function () {
|
|
|
|
|
ve.track( 'mwedit.ready' );
|
|
|
|
|
} )
|
2015-12-23 12:13:50 +00:00
|
|
|
|
.always( function () {
|
|
|
|
|
hideLoading();
|
|
|
|
|
resetLoadingProgress();
|
|
|
|
|
} );
|
2015-02-21 05:09:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 03:48:46 +00:00
|
|
|
|
function trackActivateStart( initData ) {
|
|
|
|
|
ve.track( 'trace.activate.enter' );
|
|
|
|
|
ve.track( 'mwedit.init', initData );
|
|
|
|
|
mw.libs.ve.activationStart = ve.now();
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-12 00:51:32 +00:00
|
|
|
|
function setEditorPreference( editor ) {
|
|
|
|
|
if ( editor !== 'visualeditor' && editor !== 'wikitext' ) {
|
|
|
|
|
throw new Error( 'setEditorPreference called with invalid option: ', editor );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$.cookie( 'VEE', editor, { path: '/', expires: 30 } );
|
2015-12-15 01:38:05 +00:00
|
|
|
|
if ( mw.user.isAnon() ) {
|
|
|
|
|
return $.Deferred().resolve();
|
|
|
|
|
}
|
2016-03-08 23:12:39 +00:00
|
|
|
|
if ( mw.user.options.get( 'visualeditor-editor' ) === editor ) {
|
|
|
|
|
return $.Deferred().resolve();
|
|
|
|
|
}
|
|
|
|
|
return new mw.Api().saveOption( 'visualeditor-editor', editor ).then( function () {
|
|
|
|
|
mw.user.options.set( 'visualeditor-editor', editor );
|
|
|
|
|
} );
|
2015-12-12 00:51:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 16:29:56 +00:00
|
|
|
|
function getLastEditor() {
|
|
|
|
|
var editor = $.cookie( 'VEE' );
|
2016-03-07 19:27:23 +00:00
|
|
|
|
// Set editor to user's preference or site's default if …
|
|
|
|
|
if (
|
|
|
|
|
// … user is logged in,
|
|
|
|
|
!mw.user.isAnon() ||
|
|
|
|
|
// … no cookie is set, or
|
|
|
|
|
!editor ||
|
|
|
|
|
// value is invalid.
|
|
|
|
|
!( editor === 'visualeditor' || editor === 'wikitext' )
|
|
|
|
|
) {
|
2015-10-23 16:29:56 +00:00
|
|
|
|
editor = mw.user.options.get( 'visualeditor-editor' );
|
|
|
|
|
}
|
|
|
|
|
return editor;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-03 22:14:52 +00:00
|
|
|
|
conf = mw.config.get( 'wgVisualEditorConfig' );
|
2013-08-02 20:25:44 +00:00
|
|
|
|
tabMessages = conf.tabMessages;
|
2013-07-03 22:14:52 +00:00
|
|
|
|
uri = new mw.Uri();
|
2015-12-18 00:58:23 +00:00
|
|
|
|
oldid = uri.query.oldid || $( 'input[name=parentRevId]' ).val();
|
2014-11-19 22:40:41 +00:00
|
|
|
|
pageExists = !!mw.config.get( 'wgRelevantArticleId' );
|
2013-11-07 22:21:08 +00:00
|
|
|
|
viewUri = new mw.Uri( mw.util.getUrl( mw.config.get( 'wgRelevantPageName' ) ) );
|
2015-11-20 01:47:22 +00:00
|
|
|
|
isViewPage = mw.config.get( 'wgIsArticle' ) && !( 'diff' in uri.query );
|
2015-10-14 23:34:34 +00:00
|
|
|
|
pageCanLoadVE = (
|
2015-11-20 01:47:22 +00:00
|
|
|
|
isViewPage ||
|
2015-10-08 22:16:56 +00:00
|
|
|
|
mw.config.get( 'wgAction' ) === 'edit' ||
|
|
|
|
|
mw.config.get( 'wgAction' ) === 'submit'
|
2013-07-03 22:14:52 +00:00
|
|
|
|
);
|
2015-10-23 16:29:56 +00:00
|
|
|
|
isEditPage = conf.singleEditTab && (
|
|
|
|
|
uri.query.action === 'edit' ||
|
|
|
|
|
uri.query.action === 'submit'
|
|
|
|
|
);
|
2013-07-03 22:14:52 +00:00
|
|
|
|
|
|
|
|
|
init = {
|
2013-10-10 12:33:49 +00:00
|
|
|
|
blacklist: conf.blacklist,
|
2013-07-03 22:14:52 +00:00
|
|
|
|
|
Infrastructure for loading plugins in the MW integration
Server-side, plugins can register themselves by adding to
$wgVisualEditorPluginModules. This is the recommended way for
MW extensions to extend VE. Client-side, plugins can register
themselves through mw.libs.ve.addPlugin(), which takes a string
(RL module name) or a callback.
When VisualEditor loads, we load the registered plugin modules in
parallel with ext.visualEditor.core. Note that they're loaded in
parallel, not after, and so the plugins should explicitly depend
on ext.visualEditor.core if they use or extend classes in VE core.
Once the modules finish loading and user and site scripts have run,
we execute the registered plugin callbacks. These callbacks can
optionally return a promise. We gather these promises and wait for
all of them to be resolved, then initialize the editor.
This allows Gadgets to extend VE by top-loading a small module that
depends on ext.visualEditor.viewPageTarget.init and calls
mw.libs.ve.addPlugin( 'ext.gadget.bottomHalfGadget' ); , the bottom
half being a hidden Gadget that depends on ext.visualEditor.core and
contains the actual code. The addPlugin() call needs to be in a
top-loading module because otherwise there's no guarantee that the
plugin will be registered before the user clicks edit and VE loads.
User and site scripts can extend VE by simply calling addPlugin()
directly, as mw.libs.ve is already present when user scripts run (since
it's top-loaded) and VE waits for 'user' and 'site' to run before
executing plugins.
If user/site scripts need to load additional JS files, they can load
these with $.getScript() and return the corresponding promise:
mw.libs.ve.addPlugin( function() { return $.getScript( 'URL' ); } );
For a diagram of all this, see
https://www.mediawiki.org/wiki/File:VE-plugin-infrastructure.jpg :)
VisualEditor.php:
* Add $wgVisualEditorPluginModules
VisualEditor.hooks.php:
* Expose $wgVisualEditorPluginModules in JS
ve.init.mw.ViewPageTarget.init.js:
* Add mw.libs.ve.addPlugin function that just stores the registered
values in an array and passes them into the mw.Target when it's
being initialized
ve.init.mw.Target.js:
* Add $wgVisualEditorPluginModules to the set of modules to load when
initializing VE
* Add a Deferred (this.modulesReady) to track module loading
* Add addPlugin() and addPlugins() methods that add to either
this.modules or this.pluginCallbacks
* In load(), instead of mw.loader.load()ing this.modules, use using()
to load this.modules plus user and site, and fire onModulesReady()
when they're loaded
* In onModulesReady(), execute the registered callbacks, gather the
returned promises, wait for all of them to be resolved, then resolve
this.modulesReady
* Fire onReady based on this.modulesReady being resolved, rather than
using a second using() call
Bug: 50514
Change-Id: Ib7d87a17eaac6ecdb8b0803b13840d7ee58902df
2013-07-22 20:34:28 +00:00
|
|
|
|
/**
|
|
|
|
|
* Add a plugin module or function.
|
|
|
|
|
*
|
|
|
|
|
* Plugins are run after VisualEditor is loaded, but before it is initialized. This allows
|
|
|
|
|
* plugins to add classes and register them with the factories and registries.
|
|
|
|
|
*
|
|
|
|
|
* The parameter to this function can be a ResourceLoader module name or a function.
|
|
|
|
|
*
|
|
|
|
|
* If it's a module name, it will be loaded together with the VisualEditor core modules when
|
|
|
|
|
* VE is loaded. No special care is taken to ensure that the module runs after the VE
|
|
|
|
|
* classes are loaded, so if this is desired, the module should depend on
|
|
|
|
|
* ext.visualEditor.core .
|
|
|
|
|
*
|
|
|
|
|
* If it's a function, it will be invoked once the VisualEditor core modules and any
|
|
|
|
|
* plugin modules registered through this function have been loaded, but before the editor
|
Load RL modules in one load.php request, rather than in two stages
This introduces TargetLoader, which manages plugins and RL modules
in a slightly more generic fashion so that Targets themselves don't
have to. This allows us to load all RL modules in one load.php
request, rather than first loading ViewPageTarget which then
loads the other modules.
TargetLoader loads in the bottom queue, so it will be loaded
as part of the main load.php request, but in VPT.init.js we
still have to wait for it with using() because it might not
have arrived yet. This also degrades gracefully on cached pages
where TargetLoader isn't in the bottom queue: it'll be loaded
as a separate request instead, which is suboptimal but no
worse that what we were doing before.
Right now TargetLoader is small enough that it could also be in
the top queue, but in the future we want to add things like
the action=visualeditor API request to it, and mw.Api is
relatively big.
Note: this also makes a breaking change to the plugin API:
plugin callbacks no longer receive the target instance
as a parameter, as they're now executed before the target
has been constructed rather than after. In the long term,
if we want to give plugins access to the target instance,
we could give them the target promise somehow. For now,
I've killed this feature because nothing used it and
the change from a direct object reference to a promise
would have been a breaking change anyway.
Also fixed incorrect documentation index for ve.init.mw.ViewPageTarget.init.
Bug: T53569
Change-Id: Ibfa6abbeaf872ae2aadc6ed9d5beba7473ea441a
2015-02-26 01:22:44 +00:00
|
|
|
|
* is intialized. The function can optionally return a jQuery.Promise . VisualEditor will
|
Infrastructure for loading plugins in the MW integration
Server-side, plugins can register themselves by adding to
$wgVisualEditorPluginModules. This is the recommended way for
MW extensions to extend VE. Client-side, plugins can register
themselves through mw.libs.ve.addPlugin(), which takes a string
(RL module name) or a callback.
When VisualEditor loads, we load the registered plugin modules in
parallel with ext.visualEditor.core. Note that they're loaded in
parallel, not after, and so the plugins should explicitly depend
on ext.visualEditor.core if they use or extend classes in VE core.
Once the modules finish loading and user and site scripts have run,
we execute the registered plugin callbacks. These callbacks can
optionally return a promise. We gather these promises and wait for
all of them to be resolved, then initialize the editor.
This allows Gadgets to extend VE by top-loading a small module that
depends on ext.visualEditor.viewPageTarget.init and calls
mw.libs.ve.addPlugin( 'ext.gadget.bottomHalfGadget' ); , the bottom
half being a hidden Gadget that depends on ext.visualEditor.core and
contains the actual code. The addPlugin() call needs to be in a
top-loading module because otherwise there's no guarantee that the
plugin will be registered before the user clicks edit and VE loads.
User and site scripts can extend VE by simply calling addPlugin()
directly, as mw.libs.ve is already present when user scripts run (since
it's top-loaded) and VE waits for 'user' and 'site' to run before
executing plugins.
If user/site scripts need to load additional JS files, they can load
these with $.getScript() and return the corresponding promise:
mw.libs.ve.addPlugin( function() { return $.getScript( 'URL' ); } );
For a diagram of all this, see
https://www.mediawiki.org/wiki/File:VE-plugin-infrastructure.jpg :)
VisualEditor.php:
* Add $wgVisualEditorPluginModules
VisualEditor.hooks.php:
* Expose $wgVisualEditorPluginModules in JS
ve.init.mw.ViewPageTarget.init.js:
* Add mw.libs.ve.addPlugin function that just stores the registered
values in an array and passes them into the mw.Target when it's
being initialized
ve.init.mw.Target.js:
* Add $wgVisualEditorPluginModules to the set of modules to load when
initializing VE
* Add a Deferred (this.modulesReady) to track module loading
* Add addPlugin() and addPlugins() methods that add to either
this.modules or this.pluginCallbacks
* In load(), instead of mw.loader.load()ing this.modules, use using()
to load this.modules plus user and site, and fire onModulesReady()
when they're loaded
* In onModulesReady(), execute the registered callbacks, gather the
returned promises, wait for all of them to be resolved, then resolve
this.modulesReady
* Fire onReady based on this.modulesReady being resolved, rather than
using a second using() call
Bug: 50514
Change-Id: Ib7d87a17eaac6ecdb8b0803b13840d7ee58902df
2013-07-22 20:34:28 +00:00
|
|
|
|
* only be initialized once all promises returned by plugin functions have been resolved.
|
|
|
|
|
*
|
|
|
|
|
* // Register ResourceLoader module
|
2014-12-01 19:59:53 +00:00
|
|
|
|
* mw.libs.ve.addPlugin( 'ext.gadget.foobar' );
|
Infrastructure for loading plugins in the MW integration
Server-side, plugins can register themselves by adding to
$wgVisualEditorPluginModules. This is the recommended way for
MW extensions to extend VE. Client-side, plugins can register
themselves through mw.libs.ve.addPlugin(), which takes a string
(RL module name) or a callback.
When VisualEditor loads, we load the registered plugin modules in
parallel with ext.visualEditor.core. Note that they're loaded in
parallel, not after, and so the plugins should explicitly depend
on ext.visualEditor.core if they use or extend classes in VE core.
Once the modules finish loading and user and site scripts have run,
we execute the registered plugin callbacks. These callbacks can
optionally return a promise. We gather these promises and wait for
all of them to be resolved, then initialize the editor.
This allows Gadgets to extend VE by top-loading a small module that
depends on ext.visualEditor.viewPageTarget.init and calls
mw.libs.ve.addPlugin( 'ext.gadget.bottomHalfGadget' ); , the bottom
half being a hidden Gadget that depends on ext.visualEditor.core and
contains the actual code. The addPlugin() call needs to be in a
top-loading module because otherwise there's no guarantee that the
plugin will be registered before the user clicks edit and VE loads.
User and site scripts can extend VE by simply calling addPlugin()
directly, as mw.libs.ve is already present when user scripts run (since
it's top-loaded) and VE waits for 'user' and 'site' to run before
executing plugins.
If user/site scripts need to load additional JS files, they can load
these with $.getScript() and return the corresponding promise:
mw.libs.ve.addPlugin( function() { return $.getScript( 'URL' ); } );
For a diagram of all this, see
https://www.mediawiki.org/wiki/File:VE-plugin-infrastructure.jpg :)
VisualEditor.php:
* Add $wgVisualEditorPluginModules
VisualEditor.hooks.php:
* Expose $wgVisualEditorPluginModules in JS
ve.init.mw.ViewPageTarget.init.js:
* Add mw.libs.ve.addPlugin function that just stores the registered
values in an array and passes them into the mw.Target when it's
being initialized
ve.init.mw.Target.js:
* Add $wgVisualEditorPluginModules to the set of modules to load when
initializing VE
* Add a Deferred (this.modulesReady) to track module loading
* Add addPlugin() and addPlugins() methods that add to either
this.modules or this.pluginCallbacks
* In load(), instead of mw.loader.load()ing this.modules, use using()
to load this.modules plus user and site, and fire onModulesReady()
when they're loaded
* In onModulesReady(), execute the registered callbacks, gather the
returned promises, wait for all of them to be resolved, then resolve
this.modulesReady
* Fire onReady based on this.modulesReady being resolved, rather than
using a second using() call
Bug: 50514
Change-Id: Ib7d87a17eaac6ecdb8b0803b13840d7ee58902df
2013-07-22 20:34:28 +00:00
|
|
|
|
*
|
|
|
|
|
* // Register a callback
|
2014-12-01 19:59:53 +00:00
|
|
|
|
* mw.libs.ve.addPlugin( function ( target ) {
|
Infrastructure for loading plugins in the MW integration
Server-side, plugins can register themselves by adding to
$wgVisualEditorPluginModules. This is the recommended way for
MW extensions to extend VE. Client-side, plugins can register
themselves through mw.libs.ve.addPlugin(), which takes a string
(RL module name) or a callback.
When VisualEditor loads, we load the registered plugin modules in
parallel with ext.visualEditor.core. Note that they're loaded in
parallel, not after, and so the plugins should explicitly depend
on ext.visualEditor.core if they use or extend classes in VE core.
Once the modules finish loading and user and site scripts have run,
we execute the registered plugin callbacks. These callbacks can
optionally return a promise. We gather these promises and wait for
all of them to be resolved, then initialize the editor.
This allows Gadgets to extend VE by top-loading a small module that
depends on ext.visualEditor.viewPageTarget.init and calls
mw.libs.ve.addPlugin( 'ext.gadget.bottomHalfGadget' ); , the bottom
half being a hidden Gadget that depends on ext.visualEditor.core and
contains the actual code. The addPlugin() call needs to be in a
top-loading module because otherwise there's no guarantee that the
plugin will be registered before the user clicks edit and VE loads.
User and site scripts can extend VE by simply calling addPlugin()
directly, as mw.libs.ve is already present when user scripts run (since
it's top-loaded) and VE waits for 'user' and 'site' to run before
executing plugins.
If user/site scripts need to load additional JS files, they can load
these with $.getScript() and return the corresponding promise:
mw.libs.ve.addPlugin( function() { return $.getScript( 'URL' ); } );
For a diagram of all this, see
https://www.mediawiki.org/wiki/File:VE-plugin-infrastructure.jpg :)
VisualEditor.php:
* Add $wgVisualEditorPluginModules
VisualEditor.hooks.php:
* Expose $wgVisualEditorPluginModules in JS
ve.init.mw.ViewPageTarget.init.js:
* Add mw.libs.ve.addPlugin function that just stores the registered
values in an array and passes them into the mw.Target when it's
being initialized
ve.init.mw.Target.js:
* Add $wgVisualEditorPluginModules to the set of modules to load when
initializing VE
* Add a Deferred (this.modulesReady) to track module loading
* Add addPlugin() and addPlugins() methods that add to either
this.modules or this.pluginCallbacks
* In load(), instead of mw.loader.load()ing this.modules, use using()
to load this.modules plus user and site, and fire onModulesReady()
when they're loaded
* In onModulesReady(), execute the registered callbacks, gather the
returned promises, wait for all of them to be resolved, then resolve
this.modulesReady
* Fire onReady based on this.modulesReady being resolved, rather than
using a second using() call
Bug: 50514
Change-Id: Ib7d87a17eaac6ecdb8b0803b13840d7ee58902df
2013-07-22 20:34:28 +00:00
|
|
|
|
* ve.dm.Foobar = .....
|
|
|
|
|
* } );
|
|
|
|
|
*
|
|
|
|
|
* // Register a callback that loads another script
|
2014-12-01 19:59:53 +00:00
|
|
|
|
* mw.libs.ve.addPlugin( function () {
|
Infrastructure for loading plugins in the MW integration
Server-side, plugins can register themselves by adding to
$wgVisualEditorPluginModules. This is the recommended way for
MW extensions to extend VE. Client-side, plugins can register
themselves through mw.libs.ve.addPlugin(), which takes a string
(RL module name) or a callback.
When VisualEditor loads, we load the registered plugin modules in
parallel with ext.visualEditor.core. Note that they're loaded in
parallel, not after, and so the plugins should explicitly depend
on ext.visualEditor.core if they use or extend classes in VE core.
Once the modules finish loading and user and site scripts have run,
we execute the registered plugin callbacks. These callbacks can
optionally return a promise. We gather these promises and wait for
all of them to be resolved, then initialize the editor.
This allows Gadgets to extend VE by top-loading a small module that
depends on ext.visualEditor.viewPageTarget.init and calls
mw.libs.ve.addPlugin( 'ext.gadget.bottomHalfGadget' ); , the bottom
half being a hidden Gadget that depends on ext.visualEditor.core and
contains the actual code. The addPlugin() call needs to be in a
top-loading module because otherwise there's no guarantee that the
plugin will be registered before the user clicks edit and VE loads.
User and site scripts can extend VE by simply calling addPlugin()
directly, as mw.libs.ve is already present when user scripts run (since
it's top-loaded) and VE waits for 'user' and 'site' to run before
executing plugins.
If user/site scripts need to load additional JS files, they can load
these with $.getScript() and return the corresponding promise:
mw.libs.ve.addPlugin( function() { return $.getScript( 'URL' ); } );
For a diagram of all this, see
https://www.mediawiki.org/wiki/File:VE-plugin-infrastructure.jpg :)
VisualEditor.php:
* Add $wgVisualEditorPluginModules
VisualEditor.hooks.php:
* Expose $wgVisualEditorPluginModules in JS
ve.init.mw.ViewPageTarget.init.js:
* Add mw.libs.ve.addPlugin function that just stores the registered
values in an array and passes them into the mw.Target when it's
being initialized
ve.init.mw.Target.js:
* Add $wgVisualEditorPluginModules to the set of modules to load when
initializing VE
* Add a Deferred (this.modulesReady) to track module loading
* Add addPlugin() and addPlugins() methods that add to either
this.modules or this.pluginCallbacks
* In load(), instead of mw.loader.load()ing this.modules, use using()
to load this.modules plus user and site, and fire onModulesReady()
when they're loaded
* In onModulesReady(), execute the registered callbacks, gather the
returned promises, wait for all of them to be resolved, then resolve
this.modulesReady
* Fire onReady based on this.modulesReady being resolved, rather than
using a second using() call
Bug: 50514
Change-Id: Ib7d87a17eaac6ecdb8b0803b13840d7ee58902df
2013-07-22 20:34:28 +00:00
|
|
|
|
* return $.getScript( 'http://example.com/foobar.js' );
|
|
|
|
|
* } );
|
|
|
|
|
*
|
|
|
|
|
* @param {string|Function} plugin Module name or callback that optionally returns a promise
|
|
|
|
|
*/
|
2013-12-06 02:34:44 +00:00
|
|
|
|
addPlugin: function ( plugin ) {
|
Infrastructure for loading plugins in the MW integration
Server-side, plugins can register themselves by adding to
$wgVisualEditorPluginModules. This is the recommended way for
MW extensions to extend VE. Client-side, plugins can register
themselves through mw.libs.ve.addPlugin(), which takes a string
(RL module name) or a callback.
When VisualEditor loads, we load the registered plugin modules in
parallel with ext.visualEditor.core. Note that they're loaded in
parallel, not after, and so the plugins should explicitly depend
on ext.visualEditor.core if they use or extend classes in VE core.
Once the modules finish loading and user and site scripts have run,
we execute the registered plugin callbacks. These callbacks can
optionally return a promise. We gather these promises and wait for
all of them to be resolved, then initialize the editor.
This allows Gadgets to extend VE by top-loading a small module that
depends on ext.visualEditor.viewPageTarget.init and calls
mw.libs.ve.addPlugin( 'ext.gadget.bottomHalfGadget' ); , the bottom
half being a hidden Gadget that depends on ext.visualEditor.core and
contains the actual code. The addPlugin() call needs to be in a
top-loading module because otherwise there's no guarantee that the
plugin will be registered before the user clicks edit and VE loads.
User and site scripts can extend VE by simply calling addPlugin()
directly, as mw.libs.ve is already present when user scripts run (since
it's top-loaded) and VE waits for 'user' and 'site' to run before
executing plugins.
If user/site scripts need to load additional JS files, they can load
these with $.getScript() and return the corresponding promise:
mw.libs.ve.addPlugin( function() { return $.getScript( 'URL' ); } );
For a diagram of all this, see
https://www.mediawiki.org/wiki/File:VE-plugin-infrastructure.jpg :)
VisualEditor.php:
* Add $wgVisualEditorPluginModules
VisualEditor.hooks.php:
* Expose $wgVisualEditorPluginModules in JS
ve.init.mw.ViewPageTarget.init.js:
* Add mw.libs.ve.addPlugin function that just stores the registered
values in an array and passes them into the mw.Target when it's
being initialized
ve.init.mw.Target.js:
* Add $wgVisualEditorPluginModules to the set of modules to load when
initializing VE
* Add a Deferred (this.modulesReady) to track module loading
* Add addPlugin() and addPlugins() methods that add to either
this.modules or this.pluginCallbacks
* In load(), instead of mw.loader.load()ing this.modules, use using()
to load this.modules plus user and site, and fire onModulesReady()
when they're loaded
* In onModulesReady(), execute the registered callbacks, gather the
returned promises, wait for all of them to be resolved, then resolve
this.modulesReady
* Fire onReady based on this.modulesReady being resolved, rather than
using a second using() call
Bug: 50514
Change-Id: Ib7d87a17eaac6ecdb8b0803b13840d7ee58902df
2013-07-22 20:34:28 +00:00
|
|
|
|
plugins.push( plugin );
|
|
|
|
|
},
|
|
|
|
|
|
2013-08-02 20:25:44 +00:00
|
|
|
|
setupSkin: function () {
|
|
|
|
|
init.setupTabs();
|
|
|
|
|
init.setupSectionLinks();
|
2013-07-05 06:01:31 +00:00
|
|
|
|
},
|
|
|
|
|
|
2013-08-02 20:25:44 +00:00
|
|
|
|
setupTabs: function () {
|
2013-08-01 19:14:41 +00:00
|
|
|
|
var caVeEdit,
|
2013-07-03 22:14:52 +00:00
|
|
|
|
action = pageExists ? 'edit' : 'create',
|
|
|
|
|
pTabsId = $( '#p-views' ).length ? 'p-views' : 'p-cactions',
|
|
|
|
|
$caSource = $( '#ca-viewsource' ),
|
|
|
|
|
$caEdit = $( '#ca-edit' ),
|
2013-08-01 19:14:41 +00:00
|
|
|
|
$caVeEdit = $( '#ca-ve-edit' ),
|
2013-07-03 22:14:52 +00:00
|
|
|
|
$caEditLink = $caEdit.find( 'a' ),
|
2013-08-01 19:14:41 +00:00
|
|
|
|
$caVeEditLink = $caVeEdit.find( 'a' ),
|
2013-07-03 22:14:52 +00:00
|
|
|
|
reverseTabOrder = $( 'body' ).hasClass( 'rtl' ) && pTabsId === 'p-views',
|
2013-08-01 19:14:41 +00:00
|
|
|
|
/*jshint bitwise:false */
|
2015-08-19 18:05:01 +00:00
|
|
|
|
caVeEditNextnode =
|
|
|
|
|
( reverseTabOrder ^ conf.tabPosition === 'before' ) ?
|
|
|
|
|
/*jshint bitwise:true */
|
|
|
|
|
$caEdit.get( 0 ) :
|
|
|
|
|
$caEdit.next().get( 0 );
|
|
|
|
|
|
|
|
|
|
// HACK: Remove this when the Education Program offers a proper way to detect and disable.
|
|
|
|
|
if (
|
|
|
|
|
// HACK: Work around jscs.requireCamelCaseOrUpperCaseIdentifiers
|
|
|
|
|
mw.config.get( 'wgNamespaceIds' )[ true && 'education_program' ] === mw.config.get( 'wgNamespaceNumber' )
|
|
|
|
|
) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-08-01 19:14:41 +00:00
|
|
|
|
|
|
|
|
|
if ( !$caVeEdit.length ) {
|
|
|
|
|
// The below duplicates the functionality of VisualEditorHooks::onSkinTemplateNavigation()
|
|
|
|
|
// in case we're running on a cached page that doesn't have these tabs yet.
|
2013-07-03 22:14:52 +00:00
|
|
|
|
|
|
|
|
|
// If there is no edit tab or a view-source tab,
|
|
|
|
|
// the user doesn't have permission to edit.
|
2013-08-01 19:14:41 +00:00
|
|
|
|
if ( $caEdit.length && !$caSource.length ) {
|
|
|
|
|
// Add the VisualEditor tab (#ca-ve-edit)
|
|
|
|
|
caVeEdit = mw.util.addPortletLink(
|
|
|
|
|
pTabsId,
|
|
|
|
|
// Use url instead of '#'.
|
|
|
|
|
// So that 1) one can always open it in a new tab, even when
|
|
|
|
|
// onEditTabClick is bound.
|
2015-10-14 23:34:34 +00:00
|
|
|
|
// 2) when onEditTabClick is not bound (!pageCanLoadVE) it will
|
2013-08-01 19:14:41 +00:00
|
|
|
|
// just work.
|
|
|
|
|
veEditUri,
|
2015-08-19 17:33:02 +00:00
|
|
|
|
tabMessages[ action ] !== null ? mw.msg( tabMessages[ action ] ) : $caEditLink.text(),
|
2013-08-01 19:14:41 +00:00
|
|
|
|
'ca-ve-edit',
|
|
|
|
|
mw.msg( 'tooltip-ca-ve-edit' ),
|
|
|
|
|
mw.msg( 'accesskey-ca-ve-edit' ),
|
|
|
|
|
caVeEditNextnode
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$caVeEdit = $( caVeEdit );
|
|
|
|
|
$caVeEditLink = $caVeEdit.find( 'a' );
|
|
|
|
|
}
|
2014-03-18 05:25:08 +00:00
|
|
|
|
} else if ( $caEdit.length && $caVeEdit.length ) {
|
2013-08-01 19:14:41 +00:00
|
|
|
|
// Make the state of the page consistent with the config if needed
|
|
|
|
|
/*jshint bitwise:false */
|
|
|
|
|
if ( reverseTabOrder ^ conf.tabPosition === 'before' ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
|
if ( $caEdit[ 0 ].nextSibling === $caVeEdit[ 0 ] ) {
|
2013-08-01 19:14:41 +00:00
|
|
|
|
$caVeEdit.after( $caEdit );
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-08-19 17:33:02 +00:00
|
|
|
|
if ( $caVeEdit[ 0 ].nextSibling === $caEdit[ 0 ] ) {
|
2013-08-01 19:14:41 +00:00
|
|
|
|
$caEdit.after( $caVeEdit );
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-08-19 17:33:02 +00:00
|
|
|
|
if ( tabMessages[ action ] !== null ) {
|
|
|
|
|
$caVeEditLink.text( mw.msg( tabMessages[ action ] ) );
|
2013-08-01 19:14:41 +00:00
|
|
|
|
}
|
2013-07-03 22:14:52 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-05-16 21:51:12 +00:00
|
|
|
|
// If the edit tab is hidden, remove it.
|
2016-04-15 02:05:27 +00:00
|
|
|
|
if ( !( init.isAvailable && userPrefPreferShow ) ) {
|
2014-05-16 21:51:12 +00:00
|
|
|
|
$caVeEdit.remove();
|
2015-11-06 18:23:44 +00:00
|
|
|
|
} else if ( pageCanLoadVE ) {
|
|
|
|
|
// Allow instant switching to edit mode, without refresh
|
2015-12-09 17:34:00 +00:00
|
|
|
|
$caVeEdit.on( 'click', init.onEditTabClick );
|
2014-05-16 21:51:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-08-01 19:14:41 +00:00
|
|
|
|
// Alter the edit tab (#ca-edit)
|
2014-04-08 23:07:33 +00:00
|
|
|
|
if ( $( '#ca-view-foreign' ).length ) {
|
2015-08-19 17:33:02 +00:00
|
|
|
|
if ( tabMessages[ action + 'localdescriptionsource' ] !== null ) {
|
|
|
|
|
$caEditLink.text( mw.msg( tabMessages[ action + 'localdescriptionsource' ] ) );
|
2014-04-08 23:07:33 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2015-08-19 17:33:02 +00:00
|
|
|
|
if ( tabMessages[ action + 'source' ] !== null ) {
|
|
|
|
|
$caEditLink.text( mw.msg( tabMessages[ action + 'source' ] ) );
|
2014-04-08 23:07:33 +00:00
|
|
|
|
}
|
2013-08-01 19:14:41 +00:00
|
|
|
|
}
|
2014-04-03 01:14:54 +00:00
|
|
|
|
|
2015-08-25 03:49:27 +00:00
|
|
|
|
if ( init.isAvailable ) {
|
|
|
|
|
if ( conf.tabPosition === 'before' ) {
|
|
|
|
|
$caEdit.addClass( 'collapsible' );
|
|
|
|
|
} else {
|
|
|
|
|
$caVeEdit.addClass( 'collapsible' );
|
|
|
|
|
}
|
2014-04-03 01:14:54 +00:00
|
|
|
|
}
|
2013-07-05 06:01:31 +00:00
|
|
|
|
},
|
|
|
|
|
|
2013-08-02 20:25:44 +00:00
|
|
|
|
setupSectionLinks: function () {
|
mw.ViewPageTarget: Get rid of FOUC on edit section brackets
We don't have a FOUC on the appearing of the 'edit' link. That
one is handled quite intelligently:
* Via the stylesheet that is also loaded in noscript mode, its
(hidden) appearance is already predetermined. So as soon as
those elements are seen by the browser they style correctly
for users without JavaScript (display: none).
* This same stylesheet also hides it for users with JavaScript
but where VE is not available (e.g. due to browser support).
While ve-not-available is added very early on (before
document ready), it could in theory cause a short FOUC, but
that's okay. We simply don't know that VE isn't supported
until then. We optimise for the common case (JavaScript
enabled, VE available), while still ensuring that it is
always hidden in noscript, and is hidden as soon as possible
when VE turns out not to be available.
For some reason, one small detail (the little bit of whitespace
added inside the brackets), was left out of this and was
implemented by adding the class 'mw-editsection-expanded' to them
from a document ready handler.
* First step, get rid of the script that adds this class and
use ve-available instead. That means they're styled
correctly much earlier (we add the class to <html> before
document ready). This can still cause a brief FOUC, though
in most cases they're correct from the start.
* Step two, make brackets expand by default for script users,
and let ve-not-available reset it. This way, like with edit tabs,
a FOUC will never happen for ve-available. And even for
ve-not-available, a FOUC is rare since we add it before
document ready via <html> look-ahead styling.
There was still a brief reflow jump because of negative margins
between two paint events. One was undoing the other at a later
time. These negative margins are a remnant of when we were doing
animations (follows-up I4b9c47fd65a70). They were added to reduce
reflows and content shift, but were now actually causing them.
Removed "padding-right" from mw-editsection, and negative margin
from the brackets.
Also:
* Don't add inline 'style="direction: ltr;"' on every single
editsection throughout the DOM. This was the only operation we
were doing unconditionally. While I doubt the need of it in
general, we can at least allow MediaWiki to do it right, and
only add the override if needed. This saves quite a few DOM
operations.
Change-Id: I7a729edc2cd4a66ebc0ad6935ffd02cb9b948bff
2014-05-07 00:08:53 +00:00
|
|
|
|
var $editsections = $( '#mw-content-text .mw-editsection' ),
|
|
|
|
|
bodyDir = $( 'body' ).css( 'direction' );
|
|
|
|
|
|
|
|
|
|
// Match direction of the user interface
|
|
|
|
|
// TODO: Why is this needed? It seems to work fine without.
|
|
|
|
|
if ( $editsections.css( 'direction' ) !== bodyDir ) {
|
|
|
|
|
// Avoid creating inline style attributes if the inherited value is already correct
|
|
|
|
|
$editsections.css( 'direction', bodyDir );
|
|
|
|
|
}
|
2013-07-05 06:01:31 +00:00
|
|
|
|
|
|
|
|
|
// The "visibility" css construct ensures we always occupy the same space in the layout.
|
|
|
|
|
// This prevents the heading from changing its wrap when the user toggles editSourceLink.
|
2013-08-01 19:14:41 +00:00
|
|
|
|
if ( $editsections.find( '.mw-editsection-visualeditor' ).length === 0 ) {
|
|
|
|
|
// If PHP didn't build the section edit links (because of caching), build them
|
|
|
|
|
$editsections.each( function () {
|
|
|
|
|
var $editsection = $( this ),
|
|
|
|
|
$editSourceLink = $editsection.find( 'a' ).eq( 0 ),
|
|
|
|
|
$editLink = $editSourceLink.clone(),
|
|
|
|
|
$divider = $( '<span>' ),
|
|
|
|
|
dividerText = mw.msg( 'pipe-separator' );
|
|
|
|
|
|
|
|
|
|
if ( tabMessages.editsectionsource !== null ) {
|
|
|
|
|
$editSourceLink.text( mw.msg( tabMessages.editsectionsource ) );
|
2013-07-03 22:14:52 +00:00
|
|
|
|
}
|
2013-08-01 19:14:41 +00:00
|
|
|
|
if ( tabMessages.editsection !== null ) {
|
|
|
|
|
$editLink.text( mw.msg( tabMessages.editsection ) );
|
|
|
|
|
}
|
|
|
|
|
$divider
|
|
|
|
|
.addClass( 'mw-editsection-divider' )
|
|
|
|
|
.text( dividerText );
|
2014-04-28 15:07:03 +00:00
|
|
|
|
// Don't mess with section edit links on foreign file description pages
|
|
|
|
|
// (bug 54259)
|
|
|
|
|
if ( !$( '#ca-view-foreign' ).length ) {
|
|
|
|
|
$editLink
|
|
|
|
|
.attr( 'href', function ( i, val ) {
|
|
|
|
|
return new mw.Uri( veEditUri ).extend( {
|
2014-08-22 20:50:48 +00:00
|
|
|
|
vesection: new mw.Uri( val ).query.section
|
2014-04-28 15:07:03 +00:00
|
|
|
|
} );
|
|
|
|
|
} )
|
|
|
|
|
.addClass( 'mw-editsection-visualeditor' );
|
|
|
|
|
if ( conf.tabPosition === 'before' ) {
|
|
|
|
|
$editSourceLink.before( $editLink, $divider );
|
|
|
|
|
} else {
|
|
|
|
|
$editSourceLink.after( $divider, $editLink );
|
|
|
|
|
}
|
2013-08-01 19:14:41 +00:00
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
}
|
2013-07-05 06:01:31 +00:00
|
|
|
|
|
2015-10-14 23:34:34 +00:00
|
|
|
|
if ( pageCanLoadVE ) {
|
2013-08-01 19:14:41 +00:00
|
|
|
|
// Only init without refresh if we're on a view page. Though section edit links
|
|
|
|
|
// are rarely shown on non-view pages, they appear in one other case, namely
|
|
|
|
|
// when on a diff against the latest version of a page. In that case we mustn't
|
|
|
|
|
// init without refresh as that'd initialise for the wrong rev id (bug 50925)
|
|
|
|
|
// and would preserve the wrong DOM with a diff on top.
|
|
|
|
|
$editsections
|
|
|
|
|
.find( '.mw-editsection-visualeditor' )
|
2015-12-09 17:34:00 +00:00
|
|
|
|
.on( 'click', init.onEditSectionLinkClick )
|
2013-08-01 19:14:41 +00:00
|
|
|
|
;
|
|
|
|
|
}
|
2013-07-05 06:01:31 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onEditTabClick: function ( e ) {
|
|
|
|
|
// Default mouse button is normalised by jQuery to key code 1.
|
|
|
|
|
// Only do our handling if no keys are pressed, mouse button is 1
|
|
|
|
|
// (e.g. not middle click or right click) and no modifier keys
|
|
|
|
|
// (e.g. cmd-click to open in new tab).
|
|
|
|
|
if ( ( e.which && e.which !== 1 ) || e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ) {
|
|
|
|
|
return;
|
2013-07-03 22:14:52 +00:00
|
|
|
|
}
|
2015-11-04 10:10:28 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
init.activateVe();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
activateVe: function () {
|
2015-11-18 01:26:01 +00:00
|
|
|
|
var wikitext = $( '#wpTextbox1' ).val(),
|
2015-11-09 17:55:21 +00:00
|
|
|
|
wikitextModified = wikitext !== initialWikitext;
|
2013-07-05 06:01:31 +00:00
|
|
|
|
|
2015-11-18 01:26:01 +00:00
|
|
|
|
// Close any open jQuery.UI dialogs (e.g. WikiEditor's find and replace)
|
|
|
|
|
if ( $.fn.dialog ) {
|
|
|
|
|
$( '.ui-dialog-content' ).dialog( 'close' );
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-03 18:32:13 +00:00
|
|
|
|
if (
|
|
|
|
|
mw.config.get( 'wgAction' ) === 'submit' ||
|
2015-11-20 00:10:38 +00:00
|
|
|
|
( mw.config.get( 'wgAction' ) === 'edit' && wikitextModified ) ||
|
|
|
|
|
// switching from section editing must prompt because we can't
|
|
|
|
|
// keep changes from that (yet?)
|
|
|
|
|
$( 'input[name=wpSection]' ).val()
|
2015-11-03 18:32:13 +00:00
|
|
|
|
) {
|
2015-12-11 23:39:34 +00:00
|
|
|
|
mw.loader.using( 'ext.visualEditor.switching' ).done( function () {
|
|
|
|
|
var windowManager = new OO.ui.WindowManager(),
|
|
|
|
|
switchWindow = new mw.libs.ve.SwitchConfirmDialog();
|
|
|
|
|
// Prompt if either we're on action=submit (the user has previewed) or
|
|
|
|
|
// the wikitext hash is different to the value observed upon page load.
|
|
|
|
|
|
|
|
|
|
$( 'body' ).append( windowManager.$element );
|
|
|
|
|
windowManager.addWindows( [ switchWindow ] );
|
|
|
|
|
windowManager.openWindow( switchWindow )
|
|
|
|
|
.then( function ( opened ) { return opened; } )
|
|
|
|
|
.then( function ( closing ) { return closing; } )
|
|
|
|
|
.then( function ( data ) {
|
2016-04-05 00:25:33 +00:00
|
|
|
|
var oldUri;
|
2016-04-28 21:08:26 +00:00
|
|
|
|
// TODO: windowManager.destroy()?
|
2015-12-11 23:39:34 +00:00
|
|
|
|
if ( data && data.action === 'keep' ) {
|
|
|
|
|
activatePageTarget( true );
|
|
|
|
|
} else if ( data && data.action === 'discard' ) {
|
2015-12-12 00:51:32 +00:00
|
|
|
|
setEditorPreference( 'visualeditor' );
|
2016-04-05 00:25:33 +00:00
|
|
|
|
oldUri = veEditUri.clone();
|
|
|
|
|
delete oldUri.query.veswitched;
|
|
|
|
|
location.href = oldUri.extend( { wteswitched: 1 } );
|
2015-12-11 23:39:34 +00:00
|
|
|
|
}
|
2015-10-14 23:34:34 +00:00
|
|
|
|
} );
|
2015-12-11 23:39:34 +00:00
|
|
|
|
} );
|
2015-11-09 17:55:21 +00:00
|
|
|
|
} else {
|
2016-03-04 02:05:41 +00:00
|
|
|
|
activatePageTarget( false );
|
2014-10-21 01:10:41 +00:00
|
|
|
|
}
|
2013-07-05 06:01:31 +00:00
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onEditSectionLinkClick: function ( e ) {
|
2015-02-21 05:09:50 +00:00
|
|
|
|
var targetPromise;
|
2013-07-05 06:01:31 +00:00
|
|
|
|
if ( ( e.which && e.which !== 1 ) || e.shiftKey || e.altKey || e.ctrlKey || e.metaKey ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-09 03:48:46 +00:00
|
|
|
|
trackActivateStart( { type: 'section', mechanism: 'click' } );
|
2014-11-18 20:47:11 +00:00
|
|
|
|
|
2014-11-19 01:10:52 +00:00
|
|
|
|
if ( history.pushState && uri.query.veaction !== 'edit' ) {
|
2014-11-18 20:47:11 +00:00
|
|
|
|
// Replace the current state with one that is tagged as ours, to prevent the
|
|
|
|
|
// back button from breaking when used to exit VE. FIXME: there should be a better
|
2015-07-29 13:41:30 +00:00
|
|
|
|
// way to do this. See also similar code in the DesktopArticleTarget constructor.
|
2014-11-18 20:47:11 +00:00
|
|
|
|
history.replaceState( { tag: 'visualeditor' }, document.title, uri );
|
|
|
|
|
// Change the state to the href of the section link that was clicked. This saves
|
|
|
|
|
// us from having to figure out the section number again.
|
2014-11-19 01:10:52 +00:00
|
|
|
|
history.pushState( { tag: 'visualeditor' }, document.title, this.href );
|
2014-10-21 01:10:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-05 06:01:31 +00:00
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
2015-02-21 05:09:50 +00:00
|
|
|
|
targetPromise = getTarget().then( function ( target ) {
|
2013-07-05 06:01:31 +00:00
|
|
|
|
target.saveEditSection( $( e.target ).closest( 'h1, h2, h3, h4, h5, h6' ).get( 0 ) );
|
2015-02-23 08:51:20 +00:00
|
|
|
|
return target;
|
2014-11-05 20:50:40 +00:00
|
|
|
|
} );
|
2015-02-21 05:09:50 +00:00
|
|
|
|
activateTarget( targetPromise );
|
2013-07-03 22:14:52 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2015-02-14 01:44:59 +00:00
|
|
|
|
// Cast "0" (T89513)
|
|
|
|
|
enable = Number( mw.user.options.get( 'visualeditor-enable' ) );
|
|
|
|
|
tempdisable = Number( mw.user.options.get( 'visualeditor-betatempdisable' ) );
|
2015-08-11 22:31:43 +00:00
|
|
|
|
autodisable = Number( mw.user.options.get( 'visualeditor-autodisable' ) );
|
2016-01-18 03:39:01 +00:00
|
|
|
|
tabPreference = mw.user.options.get( 'visualeditor-tabs' );
|
2016-04-15 02:05:27 +00:00
|
|
|
|
onlyTabIsVE = mw.config.get( 'wgVisualEditorConfig' ).singleEditTab && (
|
|
|
|
|
tabPreference === 'prefer-ve' || (
|
|
|
|
|
tabPreference === 'remember-last' &&
|
|
|
|
|
getLastEditor() !== 'wikitext'
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// On a view page, extend the current URI so parameters like oldid are carried over
|
|
|
|
|
// On a non-view page, use viewUri
|
|
|
|
|
if ( onlyTabIsVE ) {
|
|
|
|
|
veEditUri = viewUri.clone().extend( { action: 'edit' } );
|
|
|
|
|
delete veEditUri.query.veaction;
|
|
|
|
|
} else {
|
|
|
|
|
veEditUri = ( pageCanLoadVE ? uri : viewUri ).clone().extend( { veaction: 'edit' } );
|
|
|
|
|
delete veEditUri.query.action;
|
|
|
|
|
}
|
|
|
|
|
if ( oldid ) {
|
|
|
|
|
veEditUri.extend( { oldid: oldid } );
|
|
|
|
|
}
|
2013-09-30 16:18:46 +00:00
|
|
|
|
|
2013-08-02 20:25:44 +00:00
|
|
|
|
userPrefEnabled = (
|
2013-07-19 02:44:22 +00:00
|
|
|
|
// Allow disabling for anonymous users separately from changing the
|
|
|
|
|
// default preference (bug 50000)
|
2013-08-01 01:43:16 +00:00
|
|
|
|
!( conf.disableForAnons && mw.config.get( 'wgUserName' ) === null ) &&
|
2013-07-19 02:44:22 +00:00
|
|
|
|
|
2013-07-24 01:11:56 +00:00
|
|
|
|
// User has 'visualeditor-enable' preference enabled (for alpha opt-in)
|
|
|
|
|
// User has 'visualeditor-betatempdisable' preference disabled
|
2015-08-11 22:31:43 +00:00
|
|
|
|
// User has 'visualeditor-autodisable' preference disabled
|
2016-04-15 02:05:27 +00:00
|
|
|
|
enable && !tempdisable && !autodisable
|
|
|
|
|
);
|
|
|
|
|
userPrefPreferShow = (
|
|
|
|
|
userPrefEnabled &&
|
2016-01-18 03:39:01 +00:00
|
|
|
|
|
|
|
|
|
// If in two-edit-tab mode, or the user doesn't prefer wikitext always
|
|
|
|
|
( !conf.singleEditTab || tabPreference !== 'prefer-wt' )
|
2013-08-02 20:25:44 +00:00
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Whether VisualEditor should be available for the current user, page, wiki, mediawiki skin,
|
|
|
|
|
// browser etc.
|
|
|
|
|
init.isAvailable = (
|
2016-04-21 11:29:20 +00:00
|
|
|
|
// Support check asserts that Array.prototype.indexOf is available so we can use it below
|
2016-02-26 20:16:25 +00:00
|
|
|
|
VisualEditorSupportCheck() &&
|
2016-02-16 19:20:04 +00:00
|
|
|
|
|
|
|
|
|
( ( 'vewhitelist' in uri.query ) || !$.client.test( init.blacklist, null, true ) ) &&
|
2013-08-02 20:25:44 +00:00
|
|
|
|
|
2013-07-19 02:44:22 +00:00
|
|
|
|
// Only in supported skins
|
2016-04-21 11:29:20 +00:00
|
|
|
|
conf.skins.indexOf( mw.config.get( 'skin' ) ) !== -1 &&
|
2013-07-19 02:44:22 +00:00
|
|
|
|
|
|
|
|
|
// Only in enabled namespaces
|
2016-04-21 11:29:20 +00:00
|
|
|
|
conf.namespaces.indexOf( new mw.Title( mw.config.get( 'wgRelevantPageName' ) ).getNamespaceId() ) !== -1 &&
|
2013-07-19 02:44:22 +00:00
|
|
|
|
|
2015-10-23 16:29:56 +00:00
|
|
|
|
// Not on pages like Special:RevisionDelete
|
|
|
|
|
mw.config.get( 'wgNamespaceNumber' ) !== -1 &&
|
|
|
|
|
|
2014-03-19 00:26:54 +00:00
|
|
|
|
// Not on pages which are outputs of the Page Translation feature
|
|
|
|
|
mw.config.get( 'wgTranslatePageTranslation' ) !== 'translation' &&
|
|
|
|
|
|
2013-07-19 02:44:22 +00:00
|
|
|
|
// Only for pages with a wikitext content model
|
|
|
|
|
mw.config.get( 'wgPageContentModel' ) === 'wikitext'
|
|
|
|
|
);
|
|
|
|
|
|
2015-12-12 00:51:32 +00:00
|
|
|
|
// FIXME: We should do this more elegantly
|
|
|
|
|
init.setEditorPreference = setEditorPreference;
|
|
|
|
|
|
2013-07-10 13:55:17 +00:00
|
|
|
|
// 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
|
2013-08-03 04:33:03 +00:00
|
|
|
|
// ways to easily detect whether the VisualEditor initialisation code is present.
|
|
|
|
|
//
|
|
|
|
|
// The VE global was once available always, but now that platform integration initialisation
|
|
|
|
|
// is properly separated, it doesn't exist until the platform loads VisualEditor core.
|
|
|
|
|
//
|
|
|
|
|
// Most of mw.libs.ve is considered subject to change and private. The exception is that
|
|
|
|
|
// mw.libs.ve.isAvailable is public, and indicates whether the VE editor itself can be loaded
|
|
|
|
|
// on this page. See above for why it may be false.
|
2015-08-05 19:20:31 +00:00
|
|
|
|
mw.libs.ve = $.extend( mw.libs.ve || {}, init );
|
2013-07-03 22:14:52 +00:00
|
|
|
|
|
2016-04-15 02:05:27 +00:00
|
|
|
|
if ( init.isAvailable && userPrefPreferShow ) {
|
2013-09-04 17:57:29 +00:00
|
|
|
|
$( 'html' ).addClass( 've-available' );
|
|
|
|
|
} else {
|
2013-08-01 19:14:41 +00:00
|
|
|
|
$( 'html' ).addClass( 've-not-available' );
|
2013-09-04 17:57:29 +00:00
|
|
|
|
// Don't return here because we do want the skin setup to consistently happen
|
|
|
|
|
// for e.g. "Edit" > "Edit source" even when VE is not available.
|
2013-08-02 20:25:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-07-03 22:14:52 +00:00
|
|
|
|
$( function () {
|
2016-04-28 21:08:26 +00:00
|
|
|
|
var showWikitextWelcome = true,
|
|
|
|
|
isLoggedIn = !mw.user.isAnon(),
|
|
|
|
|
prefSaysShowWelcome = isLoggedIn && !mw.user.options.get( 'visualeditor-hidebetawelcome' ),
|
|
|
|
|
urlSaysHideWelcome = 'hidewelcomedialog' in new mw.Uri( location.href ).query;
|
|
|
|
|
|
2015-10-23 16:29:56 +00:00
|
|
|
|
if ( uri.query.action === 'edit' && $( '#wpTextbox1' ).length ) {
|
2015-10-14 23:34:34 +00:00
|
|
|
|
initialWikitext = $( '#wpTextbox1' ).val();
|
|
|
|
|
}
|
|
|
|
|
|
2013-11-26 09:46:42 +00:00
|
|
|
|
if ( init.isAvailable ) {
|
2016-01-18 03:39:01 +00:00
|
|
|
|
// Load the editor …
|
2015-10-23 16:29:56 +00:00
|
|
|
|
if (
|
2016-04-15 02:05:27 +00:00
|
|
|
|
uri.query.undo === undefined &&
|
|
|
|
|
uri.query.undoafter === undefined &&
|
|
|
|
|
uri.query.editintro === undefined &&
|
|
|
|
|
uri.query.preload === undefined &&
|
|
|
|
|
uri.query.preloadtitle === undefined &&
|
|
|
|
|
uri.query.preloadparams === undefined &&
|
|
|
|
|
uri.query.veswitched === undefined
|
|
|
|
|
// Known-good parameters: edit, veaction, section, vesection
|
|
|
|
|
// TODO: other params too? See identical list in VisualEditor.hooks.php)
|
|
|
|
|
) {
|
|
|
|
|
if (
|
2016-01-18 03:39:01 +00:00
|
|
|
|
// … if on a ?veaction=edit page
|
2015-10-23 16:29:56 +00:00
|
|
|
|
( isViewPage && uri.query.veaction === 'edit' ) ||
|
2016-01-18 03:39:01 +00:00
|
|
|
|
// … or if on ?action=edit in single edit mode and the user wants it
|
2015-10-23 16:29:56 +00:00
|
|
|
|
(
|
|
|
|
|
isEditPage &&
|
2015-12-09 23:04:02 +00:00
|
|
|
|
(
|
2016-02-29 23:44:13 +00:00
|
|
|
|
uri.query.wteswitched === '1' ||
|
2015-12-09 23:04:02 +00:00
|
|
|
|
(
|
2016-02-29 23:44:13 +00:00
|
|
|
|
tabPreference !== 'multi-tab' &&
|
2016-04-15 02:05:27 +00:00
|
|
|
|
userPrefPreferShow &&
|
2016-02-29 23:44:13 +00:00
|
|
|
|
// If it's a view-source situation, we don't want to show VE on-load
|
|
|
|
|
!$( '#ca-viewsource' ).length &&
|
|
|
|
|
(
|
|
|
|
|
(
|
|
|
|
|
tabPreference === 'prefer-ve' &&
|
|
|
|
|
mw.config.get( 'wgAction' ) !== 'submit'
|
|
|
|
|
) ||
|
|
|
|
|
(
|
|
|
|
|
tabPreference === 'remember-last' &&
|
|
|
|
|
getLastEditor() !== 'wikitext'
|
|
|
|
|
)
|
|
|
|
|
)
|
2016-01-18 03:39:01 +00:00
|
|
|
|
)
|
2015-12-09 23:04:02 +00:00
|
|
|
|
)
|
2015-10-23 16:29:56 +00:00
|
|
|
|
)
|
2016-04-15 02:05:27 +00:00
|
|
|
|
) {
|
2016-04-28 21:08:26 +00:00
|
|
|
|
showWikitextWelcome = false;
|
2016-04-15 02:05:27 +00:00
|
|
|
|
trackActivateStart( {
|
|
|
|
|
type: uri.query.vesection === undefined ? 'page' : 'section',
|
|
|
|
|
mechanism: 'url'
|
|
|
|
|
} );
|
|
|
|
|
activateTarget();
|
|
|
|
|
} else if ( pageCanLoadVE && userPrefEnabled ) {
|
|
|
|
|
// Page can be edited in VE, parameters are good, user prefs are mostly good
|
|
|
|
|
// but have visualeditor-tabs=prefer-wt? Add a keyboard shortcut to go to
|
|
|
|
|
// VE.
|
|
|
|
|
$( 'body' ).append(
|
|
|
|
|
$( '<a>' ).attr( { accesskey: 'v', href: veEditUri } ).hide()
|
|
|
|
|
);
|
|
|
|
|
}
|
2013-07-03 22:14:52 +00:00
|
|
|
|
}
|
2015-10-23 16:29:56 +00:00
|
|
|
|
|
2016-01-18 03:39:01 +00:00
|
|
|
|
// Add the switch button to wikitext ?action=edit or ?action=submit pages
|
2015-10-23 16:29:56 +00:00
|
|
|
|
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
|
|
|
|
|
mw.loader.load( 'ext.visualEditor.switching' );
|
|
|
|
|
$( '#wpTextbox1' ).on( 'wikiEditor-toolbar-doneInitialSections', function () {
|
|
|
|
|
mw.loader.using( 'ext.visualEditor.switching' ).done( function () {
|
2015-11-10 23:01:49 +00:00
|
|
|
|
var $content, windowManager, editingTabDialog, showAgainCheckbox, showAgainLayout, switchButton,
|
|
|
|
|
showPopup = uri.query.veswitched && !mw.user.options.get( 'visualeditor-hidesourceswitchpopup' );
|
|
|
|
|
|
|
|
|
|
if ( showPopup ) {
|
|
|
|
|
$content = $( '<p>' ).text( mw.msg( 'visualeditor-mweditmodeve-popup-body' ) );
|
|
|
|
|
|
|
|
|
|
if ( !mw.user.isAnon() ) {
|
|
|
|
|
showAgainCheckbox = new OO.ui.CheckboxInputWidget()
|
|
|
|
|
.on( 'change', function ( value ) {
|
|
|
|
|
var configValue = value ? '1' : '';
|
|
|
|
|
new mw.Api().saveOption( 'visualeditor-hidesourceswitchpopup', configValue );
|
|
|
|
|
mw.user.options.set( 'visualeditor-hidesourceswitchpopup', configValue );
|
|
|
|
|
} );
|
|
|
|
|
|
2016-04-04 16:31:39 +00:00
|
|
|
|
showAgainLayout = new OO.ui.FieldLayout( showAgainCheckbox, {
|
|
|
|
|
align: 'inline',
|
|
|
|
|
label: mw.msg( 'visualeditor-mweditmodeve-showagain' )
|
|
|
|
|
} );
|
2015-11-10 23:01:49 +00:00
|
|
|
|
$content = $content.add( showAgainLayout.$element );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switchButton = new OO.ui.PopupButtonWidget( {
|
|
|
|
|
framed: false,
|
|
|
|
|
icon: 'edit',
|
|
|
|
|
title: mw.msg( 'visualeditor-mweditmodeve-tool' ),
|
2016-04-04 16:31:39 +00:00
|
|
|
|
classes: [ 've-init-mw-editSwitch' ],
|
2015-11-10 23:01:49 +00:00
|
|
|
|
popup: {
|
|
|
|
|
label: mw.msg( 'visualeditor-mweditmodeve-popup-title' ),
|
|
|
|
|
$content: $content,
|
|
|
|
|
padded: true,
|
|
|
|
|
head: true
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
// HACK: Disable the toggle behaviour
|
|
|
|
|
switchButton.disconnect( switchButton, { click: 'onAction' } );
|
|
|
|
|
} else {
|
|
|
|
|
switchButton = new OO.ui.ButtonWidget( {
|
2015-10-23 16:29:56 +00:00
|
|
|
|
framed: false,
|
|
|
|
|
icon: 'edit',
|
|
|
|
|
title: mw.msg( 'visualeditor-mweditmodeve-tool' ),
|
2016-04-04 16:31:39 +00:00
|
|
|
|
classes: [ 've-init-mw-editSwitch' ]
|
2015-11-10 23:01:49 +00:00
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switchButton.on( 'click', init.activateVe );
|
|
|
|
|
|
|
|
|
|
$( '.wikiEditor-ui-toolbar' ).prepend( switchButton.$element );
|
|
|
|
|
|
|
|
|
|
if ( showPopup ) {
|
|
|
|
|
// Show the popup after appending
|
|
|
|
|
switchButton.getPopup().toggle( true );
|
|
|
|
|
}
|
2015-10-23 16:29:56 +00:00
|
|
|
|
|
|
|
|
|
// Duplicate of this code in ve.init.mw.DesktopArticleTarget.js
|
|
|
|
|
if ( $( '#ca-edit' ).hasClass( 'visualeditor-showtabdialog' ) ) {
|
|
|
|
|
// Set up a temporary window manager
|
|
|
|
|
windowManager = new OO.ui.WindowManager();
|
|
|
|
|
$( 'body' ).append( windowManager.$element );
|
|
|
|
|
editingTabDialog = new mw.libs.ve.EditingTabDialog();
|
|
|
|
|
windowManager.addWindows( [ editingTabDialog ] );
|
2016-04-13 21:46:14 +00:00
|
|
|
|
windowManager.openWindow( editingTabDialog )
|
2015-10-23 16:29:56 +00:00
|
|
|
|
.then( function ( opened ) { return opened; } )
|
|
|
|
|
.then( function ( closing ) { return closing; } )
|
|
|
|
|
.then( function ( data ) {
|
|
|
|
|
// Detach the temporary window manager
|
|
|
|
|
windowManager.destroy();
|
|
|
|
|
|
|
|
|
|
if ( data && data.action === 'prefer-ve' ) {
|
|
|
|
|
location.href = veEditUri;
|
2016-03-11 05:36:15 +00:00
|
|
|
|
} else if ( data && data.action === 'multi-tab' ) {
|
|
|
|
|
location.reload();
|
2015-10-23 16:29:56 +00:00
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
} );
|
2016-03-07 20:55:07 +00:00
|
|
|
|
|
|
|
|
|
// Remember that the user wanted wikitext, at least this time
|
|
|
|
|
mw.libs.ve.setEditorPreference( 'wikitext' );
|
2015-10-23 16:29:56 +00:00
|
|
|
|
}
|
2015-12-14 20:52:26 +00:00
|
|
|
|
|
2016-01-18 03:39:01 +00:00
|
|
|
|
// Set up the tabs appropriately if the user has VE on
|
2016-04-15 02:05:27 +00:00
|
|
|
|
if ( userPrefPreferShow ) {
|
2016-01-18 03:39:01 +00:00
|
|
|
|
// … on two-edit-tab wikis, or single-edit-tab wikis, where the user wants both …
|
|
|
|
|
if ( !conf.singleEditTab || tabPreference === 'multi-tab' ) {
|
|
|
|
|
// … set the skin up with both tabs and both section edit links.
|
|
|
|
|
init.setupSkin();
|
2016-04-15 02:05:27 +00:00
|
|
|
|
} else if ( pageCanLoadVE && onlyTabIsVE ) {
|
2016-01-18 03:39:01 +00:00
|
|
|
|
// … on single-edit-tab wikis, where VE is the user's preferred editor
|
2016-04-15 02:05:27 +00:00
|
|
|
|
// Handle section edit link clicks
|
|
|
|
|
$( '.mw-editsection a' ).on( 'click', function ( e ) {
|
|
|
|
|
init.onEditSectionLinkClick( e );
|
|
|
|
|
} );
|
|
|
|
|
// Allow instant switching to edit mode, without refresh
|
|
|
|
|
$( '#ca-edit' ).on( 'click', function ( e ) {
|
|
|
|
|
trackActivateStart( { type: 'page', mechanism: 'click' } );
|
|
|
|
|
activateTarget();
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
} );
|
2015-12-15 02:44:10 +00:00
|
|
|
|
}
|
2015-10-23 16:29:56 +00:00
|
|
|
|
}
|
2013-07-03 22:14:52 +00:00
|
|
|
|
}
|
2013-11-26 09:46:42 +00:00
|
|
|
|
|
2016-04-28 21:08:26 +00:00
|
|
|
|
if (
|
|
|
|
|
showWikitextWelcome &&
|
|
|
|
|
mw.config.get( 'wgVisualEditorConfig' ).showBetaWelcome &&
|
|
|
|
|
[ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 &&
|
|
|
|
|
!urlSaysHideWelcome &&
|
|
|
|
|
(
|
|
|
|
|
prefSaysShowWelcome ||
|
|
|
|
|
(
|
|
|
|
|
!isLoggedIn &&
|
|
|
|
|
localStorage.getItem( 've-beta-welcome-dialog' ) === null &&
|
|
|
|
|
$.cookie( 've-beta-welcome-dialog' ) === null
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
) {
|
|
|
|
|
mw.loader.using( 'ext.visualEditor.welcome' ).done( function () {
|
|
|
|
|
var windowManager = new OO.ui.WindowManager(),
|
|
|
|
|
welcomeDialog = new mw.libs.ve.WelcomeDialog();
|
|
|
|
|
$( 'body' ).append( windowManager.$element );
|
|
|
|
|
windowManager.addWindows( [ welcomeDialog ] );
|
|
|
|
|
windowManager.openWindow(
|
|
|
|
|
welcomeDialog,
|
|
|
|
|
{
|
|
|
|
|
switchable: init.isAvailable,
|
|
|
|
|
editor: 'wte'
|
|
|
|
|
}
|
|
|
|
|
)
|
|
|
|
|
.then( function ( opened ) { return opened; } )
|
|
|
|
|
.then( function ( closing ) { return closing; } )
|
|
|
|
|
.then( function ( data ) {
|
|
|
|
|
windowManager.destroy();
|
|
|
|
|
if ( data && data.action === 'switch-ve' ) {
|
|
|
|
|
init.activateVe();
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
|
|
|
|
|
if ( prefSaysShowWelcome ) {
|
|
|
|
|
new mw.Api().saveOption( 'visualeditor-hidebetawelcome', '1' );
|
|
|
|
|
mw.user.options.set( 'visualeditor-hidebetawelcome', '1' );
|
|
|
|
|
} else if ( !isLoggedIn && !urlSaysHideWelcome ) {
|
|
|
|
|
try {
|
|
|
|
|
localStorage.setItem( 've-beta-welcome-dialog', 1 );
|
|
|
|
|
} catch ( e ) {
|
|
|
|
|
$.cookie( 've-beta-welcome-dialog', 1, { path: '/', expires: 30 } );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} );
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-23 16:29:56 +00:00
|
|
|
|
if ( uri.query.venotify ) {
|
2015-01-22 23:41:10 +00:00
|
|
|
|
// The following messages can be used here:
|
|
|
|
|
// postedit-confirmation-saved
|
|
|
|
|
// postedit-confirmation-created
|
|
|
|
|
// postedit-confirmation-restored
|
|
|
|
|
mw.hook( 'postEdit' ).fire( {
|
2015-10-23 16:29:56 +00:00
|
|
|
|
message: mw.msg( 'postedit-confirmation-' + uri.query.venotify, mw.user )
|
2015-01-22 23:41:10 +00:00
|
|
|
|
} );
|
|
|
|
|
|
2015-10-23 16:29:56 +00:00
|
|
|
|
delete uri.query.venotify;
|
2015-01-22 23:41:10 +00:00
|
|
|
|
}
|
2013-07-03 22:14:52 +00:00
|
|
|
|
} );
|
|
|
|
|
}() );
|