Utente:Sanjilops/monobook.js: differenze tra le versioni

Vai alla navigazione Vai alla ricerca
Contenuto aggiunto Contenuto cancellato
mNessun oggetto della modifica
Nessun oggetto della modifica
Riga 90: Riga 90:
form.appendChild(p);
form.appendChild(p);
}
}

function timestamp () {
var d = new Date();
return d.getUTCFullYear().toString() + addzero(d.getUTCMonth()) + addzero(d.getUTCDate()) + addzero(d.getUTCHours()) + addzero(d.getUTCMinutes())+ addzero(d.getUTCSeconds());
}





Riga 149: Riga 155:
httpRequest.setRequestHeader('Content-Length', param.length);
httpRequest.setRequestHeader('Content-Length', param.length);
document.getElementsByTagName('body')[0].style.cursor = 'progress';
document.getElementsByTagName('body')[0].style.cursor = 'progress';
var edit_timestamp = timestamp();
httpRequest.send(param);
httpRequest.send(param);
return;
return;
Riga 227: Riga 234:
if (success) {
if (success) {
msg_box.innerHTML = "Salvataggio riuscito";
msg_box.innerHTML = "Salvataggio riuscito";
document.getElementsByName("wpEdittime")[0].value = edit_timestamp;
var d = new Date();
document.getElementsByName("wpStarttime")[0].value = timestamp();
var timestamp = d.getUTCFullYear().toString() + addzero(d.getUTCMonth()) + addzero(d.getUTCDate()) + addzero(d.getUTCHours()) + addzero(d.getUTCMinutes());
document.getElementsByName("wpEdittime")[0].value = timestamp + addzero(d.getUTCSeconds());
document.getElementsByName("wpStarttime")[0].value = timestamp + addzero(d.getUTCSeconds() + 1);
quicksave_checktext = textbox.value;
quicksave_checktext = textbox.value;



Versione delle 03:38, 21 ago 2009

//disablehideEdit=1;
disablealertLoad=1;
disableaprilfish = 1;




function Main() {
  FastOpen();
  if (document.getElementById('alert-load')) alert("alert onload presenti");
  if (document.getElementById('alert-unload')) alert("alert onunload presenti");

 /* Funzioni dell'editor */
 if ((wgAction == "edit" || wgAction == "submit") && document.getElementById("toolbar")) {

Quick_Editor();

if (mwCustomEditButtons) {
   mwCustomEditButtons[0] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png",
     "speedTip": "A capo",
     "tagOpen": "<br />\n",
     "tagClose": "",
     "sampleText": ""};

   mwCustomEditButtons[1] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/commons/0/05/Button_Anf%C3%BChrung.png",
     "speedTip": "Citazione",
     "tagOpen": "{" + "{Cit|",
     "tagClose": "}" + "}",
     "sampleText": "..."};

   mwCustomEditButtons[2] = {
     "imageFile": "http://upload.wikimedia.org/wikipedia/commons/0/0c/Button_P_template.png",
     "speedTip": "Template",
     "tagOpen": "{{",
     "tagClose": "}" + "}",
     "sampleText": "Template"};

   mwCustomEditButtons[3] = {
     "imageFile": "http://images.wikia.com/nonciclopedia/images/f/f9/Button_box.png",
     "speedTip": "Box",
     "tagOpen": '{|width="100%" align="center" style="background: #FFFFFF; color: #000000; border: 1px solid #000000; text-align: left; margin-bottom: 0px; margin-top: 0px; padding-right: 4px; padding-left: 4px;"\n|',
     "tagClose": "\n|}\n",
     "sampleText": ""};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://images.wikia.com/nonciclopedia/images/0/0c/Button_Chuck.png",
     "speedTip": "tag generico",
     "tagOpen": "{{",
     "tagClose": "||firma=~~" + "~~{{VF|" + wgCurRevisionId + "}" + "}" + "}" + "}\n\n",
     "sampleText": ""};
   mwCustomEditButtons[mwCustomEditButtons.length] = {
     "imageFile": "http://images2.wikia.nocookie.net/nonciclopedia/images/a/a5/Button_Samara.png",
     "speedTip": "scadenza",
     "tagOpen": "{" + "{scadenza|{" + "{subst:7g}" + "}|note=",
     "tagClose": "|firma=~~" + "~~{{VF|" + wgCurRevisionId + "}" + "}" + "}" + "}\n\n",
     "sampleText": ""};
}

  if(wgCurRevisionId)
    mwEditButtons[9].tagOpen = '--~~' + '~~{{VF|' + wgCurRevisionId + '}' + '}';
   else
    mwEditButtons[9].tagOpen = '--~~' + '~~{{VF|}' + '}';

  }
}
addOnloadHook(Main);

function FastOpen() {
 var Box = document.getElementById("searchBody");
 if (!Box) return;
 var form = document.createElement("form");
  Box.appendChild(form);
 form.action = "/index.php";
 form.target = "_blank";
 var c = document.createElement("input");
 form.appendChild(c);
 c.type = "text";
 c.setAttribute('name', "title");
 c.size = "20";
 var menu = document.createElement("select");
 form.appendChild(menu);
 menu.setAttribute('name', "action");
 menu.options[menu.length] = new Option("Modifica", "edit", true);
 menu.options[menu.length] = new Option("Cronol", "history");
 menu.options[menu.length] = new Option("Elimina", "delete");
 var p = document.createElement("input");
 p.type = "submit";
 p.value = "vai"; 
 form.appendChild(p);
}

function timestamp () {
 var d = new Date();
 return d.getUTCFullYear().toString() + addzero(d.getUTCMonth()) + addzero(d.getUTCDate()) + addzero(d.getUTCHours()) + addzero(d.getUTCMinutes())+ addzero(d.getUTCSeconds());
 }



var isScript = false;
function Quick_Editor() {
 isScript = /\.(j|cs)s$/.test(wgTitle) && wgNamespaceNumber % 2 == 0;
 if (!/&?undo=\d+/.test(location.search)) quicksave_load();
 // if (!isScript) quickpreview_load();
 return;
 }

var quicksave_checktext = '';
function quicksave_load() {
 var buttons = getElementsByClass(document, "editButtons", 'div')[0];
 var b = document.createElement('input');
 b.type = 'button';
 b.value = "Salva";
 b.id = "quicksaveButton";
 b.marginRight = "4px";
 if (b.addEventListener) b.addEventListener('click', quicksave, false);
  else if (b.attachEvent) b.attachEvent('onclick', quicksave);
 buttons.insertBefore(b, document.getElementById("wpPreview"));
 quicksave_checktext = document.getElementById("wpTextbox1").value;
 return;
 }

var quicksave_firstload = true;
function quicksave () {
	var textbox = document.getElementById("wpTextbox1");
	if (textbox.value == quicksave_checktext) return;
	document.getElementById("quicksaveButton").disabled = true;
	var Source = textbox.value.replace(/&/g, "%26");
	Source = Source.replace(/\+/g, "%2B");
	var msg_box = document.getElementById("contentSub");
	msg_box.innerHTML = '';
	if (!hasClass(msg_box, "quicksave_msgbox")) msg_box.className += " quicksave_msgbox";
	var temp = null;
	var httpRequest = createRequest();
	var id = setTimeout(function() { httpRequest.abort(); alert("Errore: il server non risponde"); Finish(false); }, 30000);
	httpRequest.onreadystatechange = function () { Response(httpRequest, id); return;};
	var url = wgServer + wgScriptPath + "/api.php";
	var param = "action=edit&format=xml&title=" + encodeURI(wgPageName).replace(/&/g, "%26").replace(/\+/g, "%2B");
	param += "&token=" + document.getElementsByName("wpEditToken")[0].value.replace(/\+\\/, '%2B%5C');
	temp = document.getElementById("wpSummary").value;
	if (temp) param += "&summary=" + encodeURI(temp).replace(/&/g, "%26").replace(/\+/g, "%2B");
	temp = document.getElementById("wpCaptchaId");
	if (temp) param += "&captchaid=" + temp.value + "&captchaword=" + encodeURI(document.getElementById("wpCaptchaWord").value);
	if (document.getElementById("wpMinoredit").checked) param += "&minor";
	param += "&basetimestamp=" + document.getElementsByName("wpEdittime")[0].value;
	param += "&starttimestamp=" + document.getElementsByName("wpStarttime")[0].value;
	temp = document.getElementsByName("wpSection")[0].value;
	if (temp) {
		if (temp == 'new' && !quicksave_firstload) param += "&appendtext=";
		 else param += "&section=" + temp + "&text=";
	 } else param += "&text=";
	param += Source;
	httpRequest.open('POST', url, true);
	httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
	httpRequest.setRequestHeader('Content-Length', param.length);
	document.getElementsByTagName('body')[0].style.cursor = 'progress';
	var edit_timestamp = timestamp();
	httpRequest.send(param);
	return;
	
 function Response (o, id) {
	if (o.readyState != 4) return;
	clearTimeout(id);
	if (o.status != 200) {
		if (o.status && (o.status < 199 || o.status > 300)) {
			alert("Salvataggio non riuscito. Risposta del server: " + o.status);
			Finish(false);
		 }
		return;
	 }
	if (o.responseXML == null)  {
		alert("Errore nella risposta del server. Controlla nella cronologia se il salvataggio è avvenuto");
		Finish(false);
		return;
	 }
	if (o.responseXML.normalize) o.responseXML.normalize();
	var result = o.responseXML.getElementsByTagName('edit');
	if (result && result[0] != undefined) {
		if (result[0].getAttribute('result') == "Success") {
			wgCurRevisionId = result[0].getAttribute('newrevid');
			Finish(true);
			return;
	 	 }
		if (result[0].getAttribute('result') == "Failure") {
			var captcha = result[0].getElementsByTagName('captcha')[0];
			if (captcha == null) {
				msg_box.innerHTML = "Salvataggio fallito: errore ignoto";
				Finish(false);
				return;
			 }
			var captcha_id = document.createElement('input');
			captcha_id.type = 'hidden';
			captcha_id.id = "wpCaptchaId";
			captcha_id.value = captcha.getAttribute('id');
			var captcha_word = document.createElement('input');
			captcha_word.id = "wpCaptchaWord";
			var captcha_img = document.createElement('img');
			captcha_img.src = "/index.php?title=Speciale:Captcha/image&wpCaptchaId=" + captcha.getAttribute('id');
			var captcha_msg = document.createElement('p');
			captcha_msg.innerHTML = 'La modifica richiesta aggiunge dei collegamenti esterni alla pagina; come misura precauzionale contro l\'inserimento automatico di spam, si prega di inserire nella casella sottostante la parola che compare distorta in questa immagine (<a href="/wiki/Speciale:Captcha/help" title="Speciale:Captcha/help">come funziona?';
			var toolbar = document.getElementById('toolbar');
			document.insertBefore(captcha_msg, toolbar);
			document.insertBefore(captcha_img, toolbar);
			document.insertBefore(captcha_word, toolbar);
			Finish(false);
			return;
		 }
	 }
	var error = o.responseXML.getElementsByTagName('error');
	if (error == null)  {
		alert("Errore nella risposta del server. Controlla nella cronologia se il salvataggio è avvenuto");
		Finish(false);
		return;
	 }
	switch (error[0].getAttribute('code')) {
		case 'editconflict':
		 document.getElementById('wpSave').click();
		 return;

		case 'noedit':
		case 'noedit-anon':
		 textbox.disabled = true;
		
		default:
		 msg_box.innerHTML = "Salvataggio fallito: " + error.getAttribute('info');
		 Finish(false);
		 return;
	 }

 }

 function Finish(success) {
	document.getElementById("quicksaveButton").disabled = false;
	if (success) {
		msg_box.innerHTML = "Salvataggio riuscito";
		document.getElementsByName("wpEdittime")[0].value = edit_timestamp;
		document.getElementsByName("wpStarttime")[0].value = timestamp();
		quicksave_checktext = textbox.value;

		if (quicksave_firstload) quicksave_firstload = false;
		if (!isScript) {
			textbox.selectionStart = 0;
			textbox.selectionEnd = 0;
			quickpreview();
		 }
		if (document.getElementsByName("wpSection")[0].value == 'new' && quicksave_firstload) document.getElementById("wpSummary").value = '';
	 }
	 else {
		document.getElementById("wikiPreview").innerHTML = '';
		document.getElementsByTagName('body')[0].style.cursor = 'auto';
	 }
	return;
 }
}