diff --git a/VisualEditor.php b/VisualEditor.php index 94128e83bd..86a536cee7 100644 --- a/VisualEditor.php +++ b/VisualEditor.php @@ -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', diff --git a/extension.json b/extension.json index 1c3d7dfbf8..531a1b7352 100644 --- a/extension.json +++ b/extension.json @@ -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", diff --git a/modules/ve-mw/init/ve.init.mw.Target.js b/modules/ve-mw/init/ve.init.mw.Target.js index 933ccef5a9..5a7d1a5191 100644 --- a/modules/ve-mw/init/ve.init.mw.Target.js +++ b/modules/ve-mw/init/ve.init.mw.Target.js @@ -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'] } ) ); } diff --git a/modules/ve-mw/ui/actions/ve.ui.MWCitationAction.js b/modules/ve-mw/ui/actions/ve.ui.MWCitationAction.js new file mode 100644 index 0000000000..2285c9e4ac --- /dev/null +++ b/modules/ve-mw/ui/actions/ve.ui.MWCitationAction.js @@ -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 ); diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWCitationDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWCitationDialog.js index b3c850a358..b6caaa9de2 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWCitationDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWCitationDialog.js @@ -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 () { diff --git a/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js b/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js index 81e8f38a59..1d0ccd2f05 100644 --- a/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js +++ b/modules/ve-mw/ui/dialogs/ve.ui.MWReferenceDialog.js @@ -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 } );