MediaWiki:Gadget-Section creator.js

From TermiKnowledge
Revision as of 16:55, 2 December 2021 by Niik (talk | contribs)
Jump to navigation Jump to search

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
function makeMyTool() {
	var template = [
	{
		type: 'mwTransclusionBlock',
		attributes: { mw: { parts: [
			{
				template: {
					target: { href: 'Template:SectionBlock', wt: 'SectionBlock'},
					params: { 1: { wt: 'name' }, 2: { wt: 'category' } }
				}
			}
		] } }
	},{ type: '/mwTransclusionBlock' } ];
	
	var commandName = 'termi_section_creator';
	
	ve.ui.commandRegistry.register(
		new ve.ui.Command(commandName, 'content', 'insert', {args: [ template, false, true], supportedSelections: ['linear'] } )
	);
	
	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 = commandName;
	ve.ui.toolFactory.register( MyTool );
	
	console.log('Section creator installed');
}

mw.hook( 've.loadModules' ).add( function( addPlugin ) {
	addPlugin( function() {
		return mw.loader.using( [ 'ext.visualEditor.core', 'ext.visualEditor.mwtransclusion' ] )
			.then( function() {
				makeMyTool();
			} );
	} );
} );