MediaWiki:Gadget-WikiEditor-TemplateTools.js

/** * WikiEditor tools for Template editing * * The WikiEditor-Tools-loader gadget will only load this when editing a * page in the Template namespace. Users not editing such pages will never have * it loaded. * * Suggest new help items on the talk page. */

( function {

'strict';

var addTemplatesnippets = function ( wikiEditor ) {

var makeSnippetRule = function ( label, pre, post, peri ) { var ret = { label: label, action: { type: 'encapsulate', options: { pre: pre }				}			};

if ( peri ) { ret.action.options.periMsg = peri; }

if ( post ) { ret.action.options.post = post; }			return ret; };

var snips; var title;

if ( mw.config.get( 'wgTitle' ).match( /\/doc$/ ) ) {

title = 'Template doc snippets';

var base = mw.config.get( 'wgTitle' ).replace( /\/doc$/, '' );

snips = { docexample: makeSnippetRule( ,					 ), luatemp: makeSnippetRule( ,					, base ), useststemp: makeSnippetRule( ,					, base ), templatedata: makeSnippetRule( 'TemplateData',					'===Template data===\n\n \n{}\n \n' ) };		} else { title = 'Template snippets';

snips = { incnoinc: makeSnippetRule( 'includeonly/noinclude',					' ', ' \n\n ' ), module: makeSnippetRule( 'Invoke module',					'', mw.config.get( 'wgTitle' ) ), ts: makeSnippetRule( 'TemplateStyles',					'', mw.config.get( 'wgTitle' ) ), ifinline: makeSnippetRule( '#if parameter',					'', 'PARAMETER' ) };		}

wikiEditor( 'addToToolbar', {			section: 'main',			groups: {				list: {					tools: {						props: {							label: title,							icon: 'puzzle',							type: 'select',							list: snips						}					}				}			}		} ); };

window.wsutils.wikiEditorConfigIncantation( addTemplatesnippets );

} ); //