MediaWiki:Gadget-Wiktoolbar.js

Remarque: après avoir sauvegardé, vous devez vider le cache de votre navigateur pour que les changements prennent effet. Mozilla, cliquez sur Actualiser (ou ctrl-r). Internet Explorer / Opera: ctrl-f5. Safari: cmd-r. Konqueror ctrl-r.

// AJOUT D'UNE BARRE "WIKTIONNAIRE"
// <nowiki>

var wiktoolpars = {
	langue: "fr",
	nom_page: mw.config.get( 'wgPageName' ).replace(/_/g, ' ')
};

function set_wiktool_pars(parname, parval) {
	if (wiktoolpars[ parname ]) {
		wiktoolpars[ parname ] = parval;
	}
}

function get_wiktool_pars( parname ) {
	return wiktoolpars[ parname ];
}

var barre_wiktionnaire = function() {
	// Section "Wiktionnaire"
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		'sections': {
			'wiktionnaire': {
				'type': 'toolbar',
				'label': 'W'
			}
		}
	} );

	// Groupe de boutons
	$('#wpTextbox1').wikiEditor('addToToolbar', {
		section: 'wiktionnaire',
		groups: {
			'sections': {
				label: '',
			},
			'maintenance': {
				label: '',
			}
		}
	});

	// Menu déroulant pour les modèles de section
	$('#wpTextbox1').wikiEditor('addToToolbar', {
		section: 'wiktionnaire',
		group: 'sections',
		tools: {
			'langue': {
				label: 'Sections de langues',
				type: 'select',
				list: {
					'fr'   : {  label: 'Français', action: { type: 'encapsulate', options: {  pre: "== {{langue|fr}} ==\n" } } },
					'en'   : {  label: 'Anglais', action: { type: 'encapsulate', options: {  pre: "== {{langue|en}} ==\n" } } },
					'de'   : {  label: 'Allemand', action: { type: 'encapsulate', options: {  pre: "== {{langue|de}} ==\n" } } },
					'es'   : {  label: 'Espagnol', action: { type: 'encapsulate', options: {  pre: "== {{langue|es}} ==\n" } } },
					'it'   : {  label: 'Italien', action: { type: 'encapsulate', options: {  pre: "== {{langue|it}} ==\n" } } },
					'ja'   : {  label: 'Japonais', action: { type: 'encapsulate', options: {  pre: "== {{langue|ja}} ==\n" } } },
					'la'   : {  label: 'Latin', action: { type: 'encapsulate', options: {  pre: "== {{langue|la}} ==\n" } } },
					'nl'   : {  label: 'Néerlandais', action: { type: 'encapsulate', options: {  pre: "== {{langue|nl}} ==\n" } } },
					'autre'   : {  label: 'Autre (à remplir)', action: { type: 'encapsulate', options: {  pre: "== {{langue|", post: "}} ==\n" } } },
				}
			},
			'niveau3': {
				label: 'Sections principales',
				type: 'select',
				list: {
					'etym'   : {  label: 'Étymologie', action: { type: 'encapsulate', options: {  pre: "=== {{S|étymologie}} ===\n: " } } },
					'etymeb' : {  label: 'Étymologie (ébauche)', action: { type: 'encapsulate', options: {  pre: "=== {{S|étymologie}} ===\n: {{ébauche-étym|" + get_wiktool_pars( "langue" ) + "}}\n\n" } } },
					'pron'   : {  label: 'Prononciation', action: { type: 'encapsulate', options: {  pre: "=== {{S|prononciation}} ===\n* " } } },
					'homo'   : {  label: 'Homophones (sous Prononciation)', action: { type: 'encapsulate', options: {  pre: "==== {{S|homophones}} ====\n* [[", post: "]]" } } },
					'paro'   : {  label: 'Paronymes (sous Prononciation)',  action: { type: 'encapsulate', options: {  pre: "==== {{S|paronymes}} ====\n* [[", post: "]]" } } },
					'anagr'  : {  label: 'Anagrammes', action: { type: 'encapsulate', options: {  pre: "=== {{S|anagrammes}} ===\n* [[", post: "]]" } } },
					'voir'   : {  label: 'Voir aussi', action: { type: 'encapsulate', options: {  pre: "=== {{S|voir aussi}} ===\n" } } },
					'ref'	: {  label: 'Références', action: { type: 'encapsulate', options: {  pre: "=== {{S|références}} ===\n" } } },
					'refb'   : {  label: 'Références (+<references>)', action: { type: 'encapsulate', options: {  pre: "=== {{S|références}} ===\n<references>\n{{R|", post: "}}\n</references>\n" } } },
				}
			},
			'mots': {
				label: 'Sections de mots (fr)',
				type: 'select',
				list: {
					'nom'	  : {  label: 'Nom commun', action: { type: 'encapsulate', options: {  pre: "=== {{S|nom|" + get_wiktool_pars( "langue" ) + "}} ===\n'''" + get_wiktool_pars( "nom_page" ) + "'''\n# " } } },
					'nompr'	: {  label: 'Nom propre', action: { type: 'encapsulate', options: {  pre: "=== {{S|nom propre|" + get_wiktool_pars( "langue" ) + "}} ===\n'''" + get_wiktool_pars( "nom_page" ) + "'''\n# " } } },
					'verb'	 : {  label: 'Verbe', action: { type: 'encapsulate', options: {  pre: "=== {{S|verbe|" + get_wiktool_pars( "langue" ) + "}} ===\n'''" + get_wiktool_pars( "nom_page" ) + "'''\n# " } } },
					'adj'	  : {  label: 'Adjectif', action: { type: 'encapsulate', options: {  pre: "=== {{S|adjectif|" + get_wiktool_pars( "langue" ) + "}} ===\n'''" + get_wiktool_pars( "nom_page" ) + "'''\n# " } } },
					'adv'	  : {  label: 'Adverbe', action: { type: 'encapsulate', options: {  pre: "=== {{S|adverbe|" + get_wiktool_pars( "langue" ) + "}} ===\n'''" + get_wiktool_pars( "nom_page" ) + "'''\n# " } } },
					'autre'	  : {  label: 'Autre (à remplir)', action: { type: 'encapsulate', options: {  pre: "=== {{S|", post: "|" + get_wiktool_pars( "langue" ) + "}} ===\n" } } },
				}
			},

			'sous-mots': {
				label: 'Sous-sections de mots',
				type: 'select',
				list: {
					'var-ortho' : {  label: 'Variantes', action: { type: 'encapsulate', options: {  pre: "==== {{S|variantes orthographiques}} ====\n* [[", post: "]]" } } },
					'syn'	   : {  label: 'Synonymes', action: { type: 'encapsulate', options: {  pre: "==== {{S|synonymes}} ====\n* [[", post: "]]" } } },
					'anto'	  : {  label: 'Antonymes', action: { type: 'encapsulate', options: {  pre: "==== {{S|antonymes}} ====\n* [[", post: "]]" } } },
					'voc'	   : {  label: 'Vocabulaire proche', action: { type: 'encapsulate', options: {  pre: "==== {{S|vocabulaire}} ====\n* [[", post: "]]" } } },
					'apr'	   : {  label: 'Apparentés', action: { type: 'encapsulate', options: {  pre: "==== {{S|apparentés}} ====\n* [[", post: "]]" } } },
					'drv'	   : {  label: 'Dérivés', action: { type: 'encapsulate', options: {  pre: "==== {{S|dérivés}} ====\n* [[", post: "]]" } } },
					'trad'	  : {  label: 'Traductions', action: { type: 'encapsulate', options: {  pre: "==== {{S|traductions}} ====\n*"  } } },
					'autre'	  : {  label: 'Autre (à remplir)', action: { type: 'encapsulate', options: {  pre: "==== {{S|", post: "}} ====\n" } } },
				}
			},

			'externes': {
				label: 'Liens section voir',
				type: 'select',
				list: {
					'catlangue' : {  label: 'Catégorie langue', action: { type: 'encapsulate', options: {  pre: "* {{Catégorie langue}}\n" } } },
					'cat' : {  label: 'Catégorie du Wiktionnaire', action: { type: 'encapsulate', options: {  pre: "* {{Catégorie|", post: "}}\n" } } },
					'thesaurus' : {  label: 'Page de thésaurus', action: { type: 'encapsulate', options: {  pre: "* {{Thésaurus|", post: "}}\n" } } },
					'annexe' : {  label: 'Page d\'annexe', action: { type: 'encapsulate', options: {  pre: "* {{Annexe|", post: "}}\n" } } },
					'w' : {  label: 'Wikipédia', action: { type: 'encapsulate', options: {  pre: "* {{Wikipédia}}\n" } } },
					'b' : {  label: 'Wikilivres', action: { type: 'encapsulate', options: {  pre: "* {{Wikilivres|", post: "}}\n" } } },
					'v' : {  label: 'Wikiversité', action: { type: 'encapsulate', options: {  pre: "* {{Wikiversité|", post: "}}\n" } } },
				}
			},
		}
	});

	// Menu déroulant pour les bandeaux
	$('#wpTextbox1').wikiEditor('addToToolbar', {
		section: 'wiktionnaire',
		group: 'maintenance',
		tools: {
			'bandeaux': {
				label: 'Bandeaux',
				type: 'select',
				list: {
					'pagesup' : {  label: 'Proposer à la suppression', action: { type: 'encapsulate', options: {  pre: "{{" + "supprimer ?}}\n\n" } } },
					'supp'	: {  label: 'Suppression immédiate', action: { type: 'encapsulate', options: {  pre: "{{" + "supp}}\n\n" } } },
					'format'  : {  label: 'Mise en page à revoir', action: { type: 'encapsulate', options: {  pre: "{{" + "formater}}\n\n" } } },
					'stub'	: {  label: 'Ébauche à compléter', action: { type: 'encapsulate', options: {  pre: "{{ébauche|" + get_wiktool_pars( "langue" ) + "}}\n\n" } } },
					'verif'   : {  label: 'Page à vérifier', action: { type: 'encapsulate', options: {  pre: "{{vérifier|", post: "}}\n\n" } } },
				}
			},
		}
	});
	
	// Ajoute un champs pour changer la langue
	/*
	var $langinput = $('<input />').attr('id', 'wiktool_lang').val( get_wiktool_pars( "langue" ) );
	var $group = $( "<div />" ).addClass('group').append( $langinput );
	$('#wikiEditor-section-wiktionnaire').prepend( $group );
	
	$langinput.keydown(function(event) {
		if( (event.keyCode == 13) ) {
			event.preventDefault();
		}
	}).change(function(event) {
		event.preventDefault();
		set_wiktool_pars("langue", $(this).val());
	});
	*/
};

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar . . . */
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
	mw.loader.using( 'user.options', function () {
		if ( mw.user.options.get('usebetatoolbar') ) {
			mw.loader.using( 'ext.wikiEditor', function () {
			   if ( mw.config.get('wgNamespaceNumber') === 0 ) {
				   $(document).ready( barre_wiktionnaire );
			   }
			} );
		}
	} );
}
// </nowiki>