2016-10-25 20:44:26 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki Initialization CollabTarget class.
|
|
|
|
*
|
|
|
|
* @copyright 2011-2016 VisualEditor Team and others; see AUTHORS.txt
|
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MediaWiki mobile article target.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.init.mw.Target
|
|
|
|
*
|
|
|
|
* @constructor
|
2017-05-20 21:26:42 +00:00
|
|
|
* @param {mw.Title} title Page sub-title
|
|
|
|
* @param {rebaserUrl} string Rebaser server URL
|
2016-10-25 20:44:26 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2017-05-20 21:26:42 +00:00
|
|
|
ve.init.mw.CollabTarget = function VeInitMwCollabTarget( title, rebaserUrl, config ) {
|
2016-10-25 20:44:26 +00:00
|
|
|
config = config || {};
|
|
|
|
config.toolbarConfig = $.extend( {
|
|
|
|
shadow: true,
|
|
|
|
actions: true,
|
|
|
|
floatable: true
|
|
|
|
}, config.toolbarConfig );
|
|
|
|
|
2017-05-20 21:26:42 +00:00
|
|
|
this.title = title;
|
|
|
|
this.rebaserUrl = rebaserUrl;
|
|
|
|
|
2016-10-25 20:44:26 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.init.mw.CollabTarget.super.call( this, config );
|
|
|
|
|
2018-01-25 18:16:58 +00:00
|
|
|
// HACK: Disable history commands until supported (T185706)
|
|
|
|
ve.ui.commandRegistry.unregister( 'undo' );
|
|
|
|
ve.ui.commandRegistry.unregister( 'redo' );
|
|
|
|
|
2016-10-25 20:44:26 +00:00
|
|
|
this.$originalContent = $( '<div>' ).addClass( 've-init-mw-desktopArticleTarget-originalContent' );
|
|
|
|
this.$editableContent = $( '#mw-content-text' );
|
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-init-mw-articleTarget ve-init-mw-desktopArticleTarget ve-init-mw-collabTarget' ).append( this.$originalContent );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.init.mw.CollabTarget, ve.init.mw.Target );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
|
|
|
ve.init.mw.CollabTarget.static.name = 'collab';
|
|
|
|
|
|
|
|
ve.init.mw.CollabTarget.static.trackingName = 'collab';
|
|
|
|
|
2018-05-18 17:36:00 +00:00
|
|
|
ve.init.mw.CollabTarget.static.toolbarGroups = ve.copy( ve.init.mw.CollabTarget.static.toolbarGroups );
|
|
|
|
ve.init.mw.CollabTarget.static.toolbarGroups.splice( 4, 0, {
|
|
|
|
name: 'commentAnnotation',
|
|
|
|
include: [ 'commentAnnotation' ]
|
|
|
|
} );
|
2018-05-20 10:18:32 +00:00
|
|
|
// Temporarily disable references until they are properly supported (T194838)
|
|
|
|
ve.init.mw.CollabTarget.static.toolbarGroups = ve.init.mw.CollabTarget.static.toolbarGroups.filter( function ( group ) {
|
|
|
|
return group.name !== 'reference';
|
|
|
|
} );
|
2018-05-18 17:36:00 +00:00
|
|
|
|
2017-05-23 16:21:16 +00:00
|
|
|
ve.init.mw.CollabTarget.static.actionGroups = [
|
2017-09-07 21:32:16 +00:00
|
|
|
{
|
2018-05-12 15:18:07 +00:00
|
|
|
name: 'help',
|
|
|
|
include: [ 'help' ]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'pageMenu',
|
2017-09-07 21:32:16 +00:00
|
|
|
type: 'list',
|
|
|
|
icon: 'menu',
|
|
|
|
indicator: null,
|
|
|
|
title: ve.msg( 'visualeditor-pagemenu-tooltip' ),
|
|
|
|
include: [ 'changeDirectionality', 'findAndReplace' ]
|
|
|
|
},
|
2018-05-12 15:18:07 +00:00
|
|
|
{
|
|
|
|
name: 'authorList',
|
|
|
|
include: [ 'authorList' ]
|
|
|
|
}
|
2017-05-23 16:21:16 +00:00
|
|
|
];
|
|
|
|
|
2016-10-25 20:44:26 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Page modifications after editor load.
|
|
|
|
*/
|
|
|
|
ve.init.mw.CollabTarget.prototype.transformPage = function () {
|
|
|
|
this.$originalContent.append( this.$element.siblings() );
|
|
|
|
};
|
|
|
|
|
2017-05-20 19:22:44 +00:00
|
|
|
/**
|
|
|
|
* Page modifications after editor teardown.
|
|
|
|
*/
|
|
|
|
ve.init.mw.CollabTarget.prototype.restorePage = function () {
|
|
|
|
this.$element.parent().append( this.$originalContent.children() );
|
|
|
|
};
|
|
|
|
|
2017-05-20 21:26:42 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.CollabTarget.prototype.surfaceReady = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.init.mw.CollabTarget.super.prototype.surfaceReady.apply( this, arguments );
|
|
|
|
|
2017-05-23 16:21:16 +00:00
|
|
|
this.getSurface().getView().focus();
|
2017-05-20 21:26:42 +00:00
|
|
|
};
|
|
|
|
|
2016-10-25 20:44:26 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.CollabTarget.prototype.attachToolbar = function () {
|
2017-07-21 18:30:00 +00:00
|
|
|
this.toolbar.$element.addClass(
|
|
|
|
've-init-mw-desktopArticleTarget-toolbar ve-init-mw-desktopArticleTarget-toolbar-open ve-init-mw-desktopArticleTarget-toolbar-opened'
|
|
|
|
);
|
2016-10-25 20:44:26 +00:00
|
|
|
this.$element.prepend( this.toolbar.$element );
|
2017-09-07 21:32:16 +00:00
|
|
|
this.toolbar.initialize();
|
2016-10-25 20:44:26 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.CollabTarget.prototype.setSurface = function ( surface ) {
|
2018-05-18 09:43:29 +00:00
|
|
|
var synchronizer, surfaceView, defaultName,
|
2018-05-20 09:58:50 +00:00
|
|
|
importDeferred = $.Deferred(),
|
2018-05-18 09:43:29 +00:00
|
|
|
target = this;
|
2017-05-23 16:21:16 +00:00
|
|
|
|
2016-10-25 20:44:26 +00:00
|
|
|
if ( surface !== this.surface ) {
|
|
|
|
this.$editableContent.after( surface.$element );
|
2017-05-23 16:21:16 +00:00
|
|
|
|
|
|
|
surfaceView = surface.getView();
|
|
|
|
|
|
|
|
synchronizer = new ve.dm.SurfaceSynchronizer(
|
|
|
|
surface.getModel(),
|
|
|
|
this.title.toString(),
|
|
|
|
{ server: this.rebaserUrl }
|
|
|
|
);
|
2018-05-16 15:59:27 +00:00
|
|
|
synchronizer.on( 'authorNameChange', function ( authorId ) {
|
2018-05-17 11:17:11 +00:00
|
|
|
var newName = synchronizer.getAuthorName( authorId );
|
2018-05-16 15:59:27 +00:00
|
|
|
if ( authorId === synchronizer.getAuthorId() ) {
|
|
|
|
mw.storage.session.set( 've-collab-username', newName );
|
|
|
|
}
|
|
|
|
} );
|
2017-05-23 16:21:16 +00:00
|
|
|
|
2018-05-18 09:43:29 +00:00
|
|
|
synchronizer.once( 'initDoc', function () {
|
|
|
|
var initPromise,
|
|
|
|
importTitle = new mw.Uri( location.href ).query.import;
|
|
|
|
if ( importTitle && !surface.getModel().getDocument().getCompleteHistoryLength() ) {
|
|
|
|
initPromise = mw.libs.ve.targetLoader.requestParsoidData( importTitle, { targetName: 'collabpad' } ).then( function ( response ) {
|
|
|
|
var doc, dmDoc,
|
|
|
|
content = ve.getProp( response, 'visualeditor', 'content' );
|
|
|
|
|
|
|
|
if ( content ) {
|
|
|
|
doc = target.constructor.static.parseDocument( content );
|
|
|
|
dmDoc = target.constructor.static.createModelFromDom( doc );
|
|
|
|
surface.getModel().getLinearFragment( new ve.Range( 0, 2 ) ).insertDocument( dmDoc );
|
|
|
|
surface.getModel().selectFirstContentOffset();
|
|
|
|
} else {
|
|
|
|
// Import failed
|
|
|
|
return $.Deferred().reject( 'No content for ' + importTitle ).promise();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
} else {
|
|
|
|
// No import, or history already exists
|
|
|
|
initPromise = $.Deferred().resolve().promise();
|
|
|
|
}
|
|
|
|
initPromise.fail( function ( err ) {
|
|
|
|
setTimeout( function () {
|
|
|
|
throw new Error( err );
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
initPromise.always( function () {
|
|
|
|
surface.getModel().selectFirstContentOffset();
|
2018-05-20 09:58:50 +00:00
|
|
|
// Resolve progress bar
|
|
|
|
importDeferred.resolve();
|
|
|
|
} );
|
2018-05-18 09:43:29 +00:00
|
|
|
} );
|
|
|
|
|
2018-05-16 10:48:34 +00:00
|
|
|
// TODO: server could communicate with MW (via oauth?) to know the
|
|
|
|
// current-user's name. Disable changing name if logged in?
|
|
|
|
// Communicate an I-am-a-valid-user flag to other clients?
|
2018-05-16 15:59:27 +00:00
|
|
|
defaultName = mw.storage.session.get( 've-collab-username' );
|
|
|
|
if ( !defaultName && !mw.user.isAnon() ) {
|
|
|
|
defaultName = mw.user.getName();
|
|
|
|
}
|
|
|
|
if ( defaultName ) {
|
|
|
|
synchronizer.changeName( defaultName );
|
2018-05-16 10:48:34 +00:00
|
|
|
}
|
|
|
|
|
2018-05-20 09:58:50 +00:00
|
|
|
surfaceView.setSynchronizer( synchronizer, importDeferred.promise() );
|
2016-10-25 20:44:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Parent method
|
|
|
|
ve.init.mw.CollabTarget.super.prototype.setSurface.apply( this, arguments );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.init.mw.targetFactory.register( ve.init.mw.CollabTarget );
|