diff --git a/modules/ve-mw/init/ve.init.mw.Target.js b/modules/ve-mw/init/ve.init.mw.Target.js index dac7c3071b..275d867a05 100644 --- a/modules/ve-mw/init/ve.init.mw.Target.js +++ b/modules/ve-mw/init/ve.init.mw.Target.js @@ -804,81 +804,94 @@ ve.init.mw.Target.prototype.generateCitationFeatures = function () { for ( i = 0, len = Math.min( limit, tools.length ); i < len; i++ ) { item = tools[i]; data = { template: item.template }; + // Generate transclusion tool name = 'cite-transclusion-' + item.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'] } - ) - ); + 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; - tool = function GeneratedMWCitationDialogTool( toolbar, config ) { - ve.ui.MWCitationDialogTool.call( this, toolbar, config ); - }; - OO.inheritClass( tool, ve.ui.MWCitationDialogTool ); - tool.static.group = 'cite'; - 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: [name, data], supportedSelections: ['linear'] } - ) - ); - // Generate transclusion context item - name = 'cite-transclusion-' + item.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 ); + if ( !ve.ui.toolFactory.lookup( name ) ) { + tool = function GeneratedMWCitationDialogTool( toolbar, config ) { + ve.ui.MWCitationDialogTool.call( this, toolbar, config ); + }; + OO.inheritClass( tool, ve.ui.MWCitationDialogTool ); + tool.static.group = 'cite'; + 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: [name, data], supportedSelections: ['linear'] } + ) + ); + } + // Generate citation context item - name = 'cite-' + item.name; - contextItem = function GeneratedMWCitationContextItem( toolbar, config ) { - ve.ui.MWCitationContextItem.call( this, toolbar, config ); - }; - OO.inheritClass( contextItem, ve.ui.MWCitationContextItem ); - 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 ); + if ( !ve.ui.contextItemFactory.lookup( name ) ) { + contextItem = function GeneratedMWCitationContextItem( toolbar, config ) { + ve.ui.MWCitationContextItem.call( this, toolbar, config ); + }; + OO.inheritClass( contextItem, ve.ui.MWCitationContextItem ); + 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 dialog - dialog = function GeneratedMWCitationDialog( config ) { - ve.ui.MWCitationDialog.call( this, config ); - }; - OO.inheritClass( dialog, ve.ui.MWCitationDialog ); - dialog.static.name = name; - dialog.static.icon = item.icon; - dialog.static.title = item.title; - ve.ui.windowFactory.register( dialog ); + if ( !ve.ui.windowFactory.lookup( name ) ) { + dialog = function GeneratedMWCitationDialog( config ) { + ve.ui.MWCitationDialog.call( this, config ); + }; + OO.inheritClass( dialog, ve.ui.MWCitationDialog ); + dialog.static.name = name; + dialog.static.icon = item.icon; + dialog.static.title = item.title; + ve.ui.windowFactory.register( dialog ); + } } } };