MediaWiki:Gadget-EditFormAutor.js

Ocio: Daspò ver salvà, podaria esare neçesario snetare ła cache dal propio navegadore web par vedare i canbiamenti.

  • Firefox / Safari: tegner strucà el boton de łe letare grande Shift e schiciare sora Ricarga, o se nò struca Ctrl-F5 o Ctrl-R (⌘-R so Mac)
  • Google Chrome: strucare Ctrl-Shift-R (⌘-Shift-R so on Mac)
  • Internet Explorer / Edge: tegner strucà el boton Ctrl e schiciare so Ajorna, o sinò Ctrl-F5
  • Opera: Va in tel Menu → Inpostasion (Opera → Prefarense so on Mac) e pò in Privacy & sicuresa → Sneta dati del navegadore → Imajini e file in te ła cache.
/* 
 * Custom edit form for author pages (namespace Autor).
 *
 * Modulo de modifica par le pagine dei autori, adatà par vec.source
 *
 * based on proofread_index.js written by ThomasV
 * http://wikisource.org/w/extensions/ProofreadPage/proofread_index.js
 */


// the parameters of Template:Autor, in the form: "name|label|dimension or type" 
// (2 = textarea of 2 rows, R = radio button, D = drop-down list)
var campiAutor = new Array("nome|Nome", "secondo nome|Secondo nome", "cognome|Cognome", 
"nato a|Nato a", "morto a|Morto a", "ano de nassita|Nato nel", "ano de morte|Morto nel", 
"descrizion|Descrission|2", "italian|Pagina sul Wikisource italian", 
"Wikipedia|Pagina su Wikipedia", "Wikiquote|Pagina su Wikiquote", "Wikicommons|Pagina su Commons", 
"imagine|Imagine", "secolo|Secolo de atività|D", "secolo2|Eventuale 2° secolo|D");


// parameters with multiple values, to use in drop-down lists
var campiAutorD = [];
campiAutorD.secolo = new Array("", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI");
campiAutorD.secolo2 = new Array("", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI");


/*
 * Called on load.
 * Builds the edit form.
 */
function startEditAutor() {

	if (mw.config.get('wgNamespaceNumber') != 100) { return; }

	var text = document.getElementById("wpTextbox1");
	if (!text) { return; }
	var testo = text.value;

	// exit if the page does not contain Template:Autor
	params = '';
	if (testo) {
		var re = /\{\{[Aa]utor([\s\S]*)\n\}\}/m;
		var mm = testo.match(re);
		if (!mm) return;
		params = mm[1] + '\n\|END=';
	}

	// take the text after Template:Autor
	// this should work also when Autor contains other templates
	begin = testo.search(/\{\{[Aa]utor/);
	testo = testo.substring(begin+2);
	var i = 1;
	while (i > 0) {
		var open = testo.search("{{");
		var close = testo.search("}}");
		if (open != -1 && open < close) {
			i++;
			testo = testo.substring(open+2);
		}
		else {
			i--;
			testo = testo.substring(close+2);
		}
	}

	//the remaining text (trimming initial newlines)
	$('#wpTextbox1').val(testo.replace(/^\s*/, ''));

	var str = '<table id="formNovo" width="100%">';

	//loop on every field
	for (i = 0; i < campiAutor.length; i++) {
		var m = campiAutor[i].split('|');
		param_name = m[0];
 
		// use the label if there is one
		if (m[1]) param_label = m[1]; 
		else param_label = param_name;
		str += '<tr><td>' + param_label + ': </td><td width="50%">';
 
		// default size 1
		if (m[2]) size = m[2];
		else size="1";

		// get the value
		value = findparam(params, param_name);
		value = value.replace(/\{\{!\}\}/g,'|');

		// show as a drop-down list
		if (size == "D") {
			str += '<select name="' + param_name + '">';

			for (j = 0; j < campiAutorD[param_name].length; j++) {
				str += '<option value="' + campiAutorD[param_name][j] + '"';
				if (value.toLowerCase() == campiAutorD[param_name][j].toLowerCase() ) str += ' selected';
				str += '>' + campiAutorD[param_name][j] + '</option>';
			}

			str += '</select>';
		}
		// show as a radiobutton
		else if (size == "R") {
			str += '<input type="radio" name="' + param_name + '" value="sì"';
			if (value == "sì") str += ' checked';
			str +='/>Sì&nbsp;&nbsp;<input type="radio" name="' + param_name + '" value="no"';
			if (value == "no") str += ' checked';
			str += '/>No'; 
		}
		// show as a simple text field
		else if (size == "1") {
			str += '<input name="' + param_name + '" value="'+value+'"/>'; 
		}
		// show as a textarea
		else {
			str += '<textarea name="' + param_name + '" rows='+size+'>'+value+'</textarea>';
		}
	}

	str += '</td></tr></table>';
	$('.wikiEditor-ui').after('<div id="editFormAutoreContainer"><div id="editFormAutoreLeft" style="float:left;width:50%"></div><div style="float:right;width:50%"><div id="editFormAutoreRight" style="margin-left:10px"></div></div></div>');
	$('#editFormAutoreLeft').append($('.wikiEditor-ui'));
	$('#editFormAutoreRight').append(str);
 
	// change the 3 buttons so that they call endEditAutor() before submit
	impostaBottoni(endEditAutor);
}


/*
 * Called before page submit.
 * Takes field values and builds the text to be saved
 */
function endEditAutor() {

	var form = document.getElementById("editform");
	var template = "{{Autor";
	var textdata = '<div id="areaDati" style="display:none">';

	for (i = 0; i < campiAutor.length; i++) {
		m = campiAutor[i].split('|');
		var param_name = m[0];
		var param_type = m[2];
		var value = "";

		if (!form.elements[param_name]) continue;

		if (param_type == "R") {
			value = getRadioValue(form.elements[param_name]);
		}
		else {
			value = form.elements[param_name].value;
		}

		// remove trailing \n
		value = value.replace(/\n$/,'');

		// replace pipe symbol everywhere...
		value = value.replace(/\|/g,'{{!}}');

		// ...except in links...
		do { 
			prev = value;
			value = value.replace(/\[\[(.*?)\{\{!\}\}(.*?)\]\]/g,'[[$1|$2]]');
		}
		while (value != prev);
 
		// ..and in templates
		do { 
			prev = value;
			value = value.replace(/\{\{(.*?)\{\{!\}\}(.*?)\}\}/g,'{{$1|$2}}');
		}
		while (value != prev);

		if (value !== "") {
			template = template + '\n|' + param_name + '=' + value;
			textdata = textdata + '\n<section begin="' + param_name + '"/>' + value.replace(/<ref>(.*?)<\/ref>/g, "") + '<section end="' + param_name + '"/>';
		}
	}

	template = template + "\n}}\n";
	textdata = textdata + "</div>";

	form.elements.wpTextbox1.value = textdata + template + form.elements.wpTextbox1.value;
}


//carica EditFormAutor
$(document).ready(function() {
	$.when(mw.loader.using('ext.wikiEditor'), $.ready).then(function() {
		startEditAutor();
	});
});
Traesto fora da Wikipèdia - L'ençiclopedia łìbara e cołaboradiva in łéngua Vèneta "https://vec.wikisource.org/w/index.php?title=MediaWiki:Gadget-EditFormAutor.js&oldid=66099"