Difference between revisions of "MediaWiki:Gadget-Section creator.js"
Jump to navigation
Jump to search
Line 1: | Line 1: | ||
function makeMyTool() { | function makeMyTool() { | ||
var | //Create and register command | ||
var myTemplate = [ { | |||
type: 'mwTransclusionBlock', | type: 'mwTransclusionBlock', | ||
attributes: { mw: { parts: [ | attributes: { | ||
mw: { | |||
parts: [ { | |||
template: { | |||
target: { | |||
} | href: 'Template:MyTemplate', | ||
wt: 'MyTemplate' | |||
}, | |||
params: { | |||
1: { | |||
wt: 'my parameter' | |||
} | |||
} | |||
} | |||
} ] | |||
} | } | ||
} | |||
},{ type: '/mwTransclusionBlock' } ]; | }, { | ||
type: '/mwTransclusionBlock' | |||
} ]; | |||
ve.ui.commandRegistry.register( | ve.ui.commandRegistry.register( | ||
new ve.ui.Command( | new ve.ui.Command( 'mycommand', 'content', 'insert', { | ||
args: [ myTemplate, false, true ], | |||
supportedSelections: [ 'linear' ] | |||
} ) | |||
); | ); | ||
//Create and register wikitext command | |||
if ( ve.ui.wikitextCommandRegistry ) { | |||
ve.ui.wikitextCommandRegistry.register( | |||
new ve.ui.Command( 'mycommand', 'mwWikitext', 'wrapSelection', { | |||
args: [ '{{MyTemplate|', '}}', 'my parameter' ], | |||
supportedSelections: [ 'linear' ] | |||
} ) | |||
); | |||
} | |||
//Create and register tool | |||
function MyTool() { | function MyTool() { | ||
MyTool.parent.apply( this, arguments ); | MyTool.parent.apply( this, arguments ); | ||
} | } | ||
OO.inheritClass( MyTool, ve.ui.MWTransclusionDialogTool ); | OO.inheritClass( MyTool, ve.ui.MWTransclusionDialogTool ); | ||
Line 28: | Line 50: | ||
MyTool.static.group = 'insert'; | MyTool.static.group = 'insert'; | ||
MyTool.static.title = 'My tool'; | MyTool.static.title = 'My tool'; | ||
MyTool.static.commandName = | MyTool.static.commandName = 'mycommand'; | ||
ve.ui.toolFactory.register( MyTool ); | ve.ui.toolFactory.register( MyTool ); | ||
} | } | ||
//Initialize | |||
mw.hook( 've.loadModules' ).add( function( addPlugin ) { | mw.hook( 've.loadModules' ).add( function( addPlugin ) { | ||
addPlugin( function() { | addPlugin( function() { | ||
return mw.loader.using( [ 'ext.visualEditor.core', 'ext.visualEditor.mwtransclusion' ] ) | return mw.loader.using( [ 'ext.visualEditor.core', 'ext.visualEditor.mwwikitext', 'ext.visualEditor.mwtransclusion' ] ) | ||
.then( function() { | .then( function() { | ||
makeMyTool(); | makeMyTool(); |
Revision as of 16:57, 2 December 2021
function makeMyTool() { //Create and register command var myTemplate = [ { type: 'mwTransclusionBlock', attributes: { mw: { parts: [ { template: { target: { href: 'Template:MyTemplate', wt: 'MyTemplate' }, params: { 1: { wt: 'my parameter' } } } } ] } } }, { type: '/mwTransclusionBlock' } ]; ve.ui.commandRegistry.register( new ve.ui.Command( 'mycommand', 'content', 'insert', { args: [ myTemplate, false, true ], supportedSelections: [ 'linear' ] } ) ); //Create and register wikitext command if ( ve.ui.wikitextCommandRegistry ) { ve.ui.wikitextCommandRegistry.register( new ve.ui.Command( 'mycommand', 'mwWikitext', 'wrapSelection', { args: [ '{{MyTemplate|', '}}', 'my parameter' ], supportedSelections: [ 'linear' ] } ) ); } //Create and register tool function MyTool() { MyTool.parent.apply( this, arguments ); } OO.inheritClass( MyTool, ve.ui.MWTransclusionDialogTool ); MyTool.static.name = 'mytool'; MyTool.static.group = 'insert'; MyTool.static.title = 'My tool'; MyTool.static.commandName = 'mycommand'; ve.ui.toolFactory.register( MyTool ); } //Initialize mw.hook( 've.loadModules' ).add( function( addPlugin ) { addPlugin( function() { return mw.loader.using( [ 'ext.visualEditor.core', 'ext.visualEditor.mwwikitext', 'ext.visualEditor.mwtransclusion' ] ) .then( function() { makeMyTool(); } ); } ); } );