mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-24 02:38:40 +00:00
Allow for citation tools to work under the reference dialog
Set up the surface widget as inside the reference dialog, and let the citation action notify the template dialog the name of the dialog it is in. If the tool was executed from within the reference dialog, skip over creating a reference and instead insert the citation as a template. * Depends on ve-core fix I709eeb0de475 * Bug: T94621 Change-Id: I4871f8c0afe190117cc90e88227b37f292a71e20
This commit is contained in:
parent
0d78c3225f
commit
7c0b307d8a
|
@ -1314,6 +1314,7 @@ $wgResourceModules += array(
|
|||
'modules/ve-mw/ui/contextitems/ve.ui.MWReferenceContextItem.js',
|
||||
'modules/ve-mw/ui/contextitems/ve.ui.MWReferencesListContextItem.js',
|
||||
'modules/ve-mw/ui/contextitems/ve.ui.MWCitationContextItem.js',
|
||||
'modules/ve-mw/ui/actions/ve.ui.MWCitationAction.js',
|
||||
),
|
||||
'styles' => array(
|
||||
'modules/ve-mw/ui/styles/widgets/ve.ui.MWReferenceGroupInputWidget.css',
|
||||
|
|
|
@ -1331,7 +1331,8 @@
|
|||
"modules/ve-mw/ui/tools/ve.ui.MWCitationDialogTool.js",
|
||||
"modules/ve-mw/ui/contextitems/ve.ui.MWReferenceContextItem.js",
|
||||
"modules/ve-mw/ui/contextitems/ve.ui.MWReferencesListContextItem.js",
|
||||
"modules/ve-mw/ui/contextitems/ve.ui.MWCitationContextItem.js"
|
||||
"modules/ve-mw/ui/contextitems/ve.ui.MWCitationContextItem.js",
|
||||
"modules/ve-mw/ui/actions/ve.ui.MWCitationAction.js"
|
||||
],
|
||||
"styles": [
|
||||
"modules/ve-mw/ui/styles/widgets/ve.ui.MWReferenceGroupInputWidget.css",
|
||||
|
|
|
@ -768,44 +768,6 @@ ve.init.mw.Target.prototype.generateCitationFeatures = function () {
|
|||
item = tools[i];
|
||||
data = { template: item.template };
|
||||
|
||||
// Generate transclusion tool
|
||||
name = 'cite-transclusion-' + item.name;
|
||||
if ( !ve.ui.toolFactory.lookup( name ) ) {
|
||||
tool = function GeneratedMWTransclusionDialogTool( toolbar, config ) {
|
||||
ve.ui.MWTransclusionDialogTool.call( this, toolbar, config );
|
||||
};
|
||||
OO.inheritClass( tool, ve.ui.MWTransclusionDialogTool );
|
||||
tool.static.group = 'cite-transclusion';
|
||||
tool.static.name = name;
|
||||
tool.static.icon = item.icon;
|
||||
tool.static.title = item.title;
|
||||
tool.static.commandName = name;
|
||||
tool.static.template = item.template;
|
||||
tool.static.autoAddToCatchall = false;
|
||||
tool.static.autoAddToGroup = true;
|
||||
ve.ui.toolFactory.register( tool );
|
||||
ve.ui.commandRegistry.register(
|
||||
new ve.ui.Command(
|
||||
name, 'window', 'open',
|
||||
{ args: ['transclusion', data], supportedSelections: ['linear'] }
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Generate transclusion context item
|
||||
if ( !ve.ui.contextItemFactory.lookup( name ) ) {
|
||||
contextItem = function GeneratedMWTransclusionContextItem( toolbar, config ) {
|
||||
ve.ui.MWTransclusionContextItem.call( this, toolbar, config );
|
||||
};
|
||||
OO.inheritClass( contextItem, ve.ui.MWTransclusionContextItem );
|
||||
contextItem.static.name = name;
|
||||
contextItem.static.icon = item.icon;
|
||||
contextItem.static.label = item.title;
|
||||
contextItem.static.commandName = name;
|
||||
contextItem.static.template = item.template;
|
||||
ve.ui.contextItemFactory.register( contextItem );
|
||||
}
|
||||
|
||||
// Generate citation tool
|
||||
name = 'cite-' + item.name;
|
||||
if ( !ve.ui.toolFactory.lookup( name ) ) {
|
||||
|
@ -824,8 +786,7 @@ ve.init.mw.Target.prototype.generateCitationFeatures = function () {
|
|||
ve.ui.toolFactory.register( tool );
|
||||
ve.ui.commandRegistry.register(
|
||||
new ve.ui.Command(
|
||||
name, 'window', 'open',
|
||||
{ args: [name, data], supportedSelections: ['linear'] }
|
||||
name, 'mwcite', 'open', { args: [name, data], supportedSelections: ['linear'] }
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
57
modules/ve-mw/ui/actions/ve.ui.MWCitationAction.js
Normal file
57
modules/ve-mw/ui/actions/ve.ui.MWCitationAction.js
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWCitationAction class.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see http://ve.mit-license.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* Link action.
|
||||
*
|
||||
* Opens either MWLinkAnnotationInspector or MWLinkNodeInspector depending on what is selected.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.Action
|
||||
* @constructor
|
||||
* @param {ve.ui.Surface} surface Surface to act on
|
||||
*/
|
||||
ve.ui.MWCitationAction = function VeUiMWCitationAction( surface ) {
|
||||
// Parent constructor
|
||||
ve.ui.Action.call( this, surface );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWCitationAction, ve.ui.Action );
|
||||
|
||||
/* Static Properties */
|
||||
|
||||
ve.ui.MWCitationAction.static.name = 'mwcite';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWCitationAction.static.methods = [ 'open' ];
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* When opening a citation, send the dialog a property of the surface
|
||||
* dialog name.
|
||||
*
|
||||
* @method
|
||||
* @param {string} windowName Dialog name to open
|
||||
* @param {Object} windowData Data to send to the dialog
|
||||
* @return {boolean} Action was executed
|
||||
*/
|
||||
ve.ui.MWCitationAction.prototype.open = function ( windowName, windowData ) {
|
||||
windowData = $.extend( {
|
||||
inDialog: this.surface.getInDialog()
|
||||
}, windowData );
|
||||
|
||||
this.surface.execute( 'window', 'open', windowName, windowData );
|
||||
return true;
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ui.actionFactory.register( ve.ui.MWCitationAction );
|
|
@ -21,6 +21,7 @@ ve.ui.MWCitationDialog = function VeUiMWCitationDialog( config ) {
|
|||
// Properties
|
||||
this.referenceModel = null;
|
||||
this.referenceNode = null;
|
||||
this.inDialog = '';
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
@ -89,6 +90,9 @@ ve.ui.MWCitationDialog.prototype.initialize = function ( data ) {
|
|||
ve.ui.MWCitationDialog.prototype.getSetupProcess = function ( data ) {
|
||||
return ve.ui.MWCitationDialog.super.prototype.getSetupProcess.call( this, data )
|
||||
.next( function () {
|
||||
data = data || {};
|
||||
this.inDialog = data.inDialog;
|
||||
|
||||
// Initialization
|
||||
if ( this.selectedNode ) {
|
||||
this.referenceNode = this.getReferenceNode();
|
||||
|
@ -161,7 +165,10 @@ ve.ui.MWCitationDialog.prototype.hasUsefulParameter = function () {
|
|||
*/
|
||||
ve.ui.MWCitationDialog.prototype.getActionProcess = function ( action ) {
|
||||
var dialog = this;
|
||||
if ( action === 'apply' || action === 'insert' ) {
|
||||
if (
|
||||
this.inDialog !== 'reference' &&
|
||||
( action === 'apply' || action === 'insert' )
|
||||
) {
|
||||
return new OO.ui.Process( function () {
|
||||
var deferred = $.Deferred();
|
||||
dialog.checkRequiredParameters().done( function () {
|
||||
|
|
|
@ -97,13 +97,6 @@ ve.ui.MWReferenceDialog.static.excludeCommands = [
|
|||
'referencesList'
|
||||
];
|
||||
|
||||
// HACK: change group: 'cite' to group: 'cite-transclusion'
|
||||
ve.ui.MWReferenceDialog.static.toolbarGroups = ( function () {
|
||||
var toolbarGroups = ve.copy( ve.init.mw.Target.static.toolbarGroups );
|
||||
toolbarGroups[4].include[0].group = 'cite-transclusion';
|
||||
return toolbarGroups;
|
||||
}() );
|
||||
|
||||
/**
|
||||
* Get the import rules for the surface widget in the dialog
|
||||
*
|
||||
|
@ -247,9 +240,10 @@ ve.ui.MWReferenceDialog.prototype.useReference = function ( ref ) {
|
|||
this.referenceModel.getDocument(),
|
||||
{
|
||||
$: this.$,
|
||||
tools: this.constructor.static.toolbarGroups,
|
||||
tools: ve.copy( ve.init.mw.Target.static.toolbarGroups ),
|
||||
excludeCommands: this.constructor.static.excludeCommands,
|
||||
importRules: this.constructor.static.getImportRules()
|
||||
importRules: this.constructor.static.getImportRules(),
|
||||
inDialog: this.constructor.static.name
|
||||
}
|
||||
);
|
||||
|
||||
|
|
Loading…
Reference in a new issue