Wikibooks:Monobook.js/commandline.js
/*
*/ /**** Command Line Start ****/ /* Commandline versione 0.9 Scritto da [[w:Utente:Salvatore Ingala]]; contiene alcuni spezzoni di codice di [[w:Utente:Timendum]]. Rilasciato ai sensi delle license GFDL e GPL. */ arrayArgument = new Array("aeronautica", "agricoltura", "allevamento", "alpinismo", "animali", "animanga", "antropologia", "antroponimi", "archeologia", "architettura", "arte", "arti divinatorie", "arti marziali", "astronomia", "atletica", "automobilismo", "aziende", "baseball", "biografie", "biologia", "blues", "botanica", "buddismo", "calcio", "canottaggio", "cattolicesimo", "chimica", "ciclismo", "cinema", "classica", "cristianesimo", "cucina", "curling", "danza", "diritto", "ebraismo", "ecologia", "economia", "editoria", "educazione", "F1", "filosofia", "fisica", "fotografia", "fumetti", "funghi", "gastronomia", "GDR", "geografia", "giochi", "golf", "guerra", "hockey", "informatica", "ingegneria", "hip hop", "jazz", "letteratura", "LGBT", "lingue", "linguistica", "matematica", "meccanica", "medicina", "metal", "mitologia", "motociclismo", "musei", "musica", "nautica", "neopaganesimo", "numismatica", "nuoto", "paleontologia", "pallacanestro", "pallamano", "pallanuoto", "pallavolo", "pattinaggio", "pesca sportiva", "piante", "politica", "Pokémon", "psicologia", "pugilato", "punk", "radio", "religione", "rock", "rugby", "scacchi", "scienza", "scherma", "sci", "skeleton", "sociologia", "sport", "stadi", "storia", "subacquea", "teatro", "telecomunicazioni", "televisione", "tennis", "tiro con l'arco", "trasporti", "turismo", "vela", "videogiochi", "vini","voci comuni", "wrestling", "zoologia"); arrayLingue = new Array("bulgara", "catalana", "cinese", "danese", "esperanto", "finlandese", "francese", "giapponese", "greca", "inglese", "islandese", "italiana", "latina", "lettone", "maltese", "moldava", "norvegese", "olandese", "polacca", "portoghese", "rumena", "russa", "slovena", "spagnola", "svedese", "tedesca", "ucraina", "ungherese"); if (typeof(fixformat_list) == 'undefined'){ //nessuna sostituzione impostata, usa quelle standard fixformat_list = new Array( [/\’/g, "'"], [/ '([\w\ ]+)' /g, ' "$1" '], [/“/g,'"'], [/”/g,'"'], [/–/g, '-'], [/,,/g, ','], [/ m2 /g, ' m² '], [/a' /g, "à "], [/([^p])o' /g, "$1ò "], [/u' /g, "ù "], [/i' /g, "ì "], [/ anzich(è|e')/g, "anziché"], [/ affinch(è|e')/g, "affinché"], [/ bench(è|e')/g, " benché"], [/ cioé/g, " cioè"], [/ Dè /g, " De' "], [/ dè /g, " de' "], [/ dò/g, " do"], [/E' /g, "È "], [/É /g, "È "], [/ e' /g, " è "], [/ é/g, " è"], [/ fà /g, " fa "], [/ fè /g, " fe' "], [/ Frà /g, " Fra' "], [/ fù /g, " fu "], [/ mò /g, " mo' "], [/ nè /g, " né "], [/ ne' /g, " né "], [/ nonch(è|e')/g, " nonché"], [/ pè /g, " pe' "], [/ perch(è|e')/g, " perché"], [/ per(ó|o') /g,' però '], [/ piu' /g, " più "], [/ pò/g, " po'"], [/ poich(è|e') /g, " poiché "], [/ propio/g, " proprio"], [/ (puo|puo') /gi,' può '], [/ quì /gi, " qui "], [/ quà /gi, " qua "], [/ qual'è /gi, " qual è"], [/ sà /gi, " sa "], [/ sè /gi, " sé "], [/si' /g, "sì"], [/ sò /g, " so "], [/ sù /g, " su "], [/ tr(è|e'|é) /g, " tre "], [/ sucessivo /gi, " successivo "], [/</g,'<'], [/>/g,'>'], [/&/g,'&'], [/"/g,'"'], [/à/g,'à'], [/è/g,'è'], [/é/g,'é'], [/ì/g,'ì'], [/¡/g,'¡'], [/¢/g,'¢'], [/£/g,'£'], [/¥/g,'¥'], [/´/g,"'"], [/±/g,'±'], [/×/g,'×'], [/÷/g,'÷'], [/µ/g,'µ'], [/°/g,'°'], [/¼/g,'¼'], [/½/g,'½'], [/¾/g,'¾'], [/¹/g,'¹'], [/²/g,'²'], [/³/g,'³'], [/§/g,'§'], [/<\/?(b|strong)>/gi, "'''"], [/<\/?(i|em|var)>/gi, "''"], [/<br>\n\n/g,'\n\n'], [/<br>/gi,'<br />'], [/\n<hr[ \/]*>\n/gi, '\n----\n'], [/ +<hr[ \/]*> +/gi, '\n----\n'], [/<hr ([^>\/]+?)>/gi,'<hr $1 />'], [/\n *<h1> *([^<]+?) *<\/h1> *\n/gi, "\n= $1 =\n"], [/\n *<h2> *([^<]+?) *<\/h1> *\n/gi, "\n== $1 ==\n"], [/\n *<h3> *([^<]+?) *<\/h1> *\n/gi, "\n=== $1 ===\n"], [/\n *<h4> *([^<]+?) *<\/h1> *\n/gi, "\n==== $1 ====\n"], [/\n *<h5> *([^<]+?) *<\/h1> *\n/gi, "\n===== $1 =====\n"], [/\n *<h6> *([^<]+?) *<\/h1> *\n/gi, "\n====== $1 =======\n"] ); } if (typeof(fixformat_subject) == 'undefined') fixformat_subject = 'correzioni automatiche; '; //Funzioni di Timendum //Segna "modifica minore" function TimenME() { document.getElementById("wpMinoredit").checked=1; } //Aggiungi all'oggetto function TimenSA(text) { var summ=document.getElementById("wpSummary"); if (summ == null) return; summ.value=summ.value+text; } //Aggiungi testo prima function TimenPr(text) { wpTextbox1=document.getElementById("wpTextbox1"); wpTextbox1.value=text+wpTextbox1.value; } //Aggiungi testo dopo function TimenDp(text) { wpTextbox1=document.getElementById("wpTextbox1"); wpTextbox1.value=wpTextbox1.value+text; } function mese(){ var today = new Date(); return (new Array("gennaio","febbraio","marzo","aprile","maggio","giugno","luglio","agosto", "settembre","ottobre","novembre","dicembre"))[today.getMonth()]; } function anno(){ var today = new Date(); return today.getYear()+1900; } //Prova a completare string usando dict come dizionario. //Restituisce -1 se c'è ambiguità, 0 se non trova nessuna corrispondenza, o la stringa completa se trova una sola occorrenza //Versione per dizionario di tipo object function autoComplete1(dict, string, failIfAmbiguous){ var found = '' if ((string == "")||(string==null)) return string; for (var x in dict) if (x.indexOf(string) == 0){ if (!failIfAmbiguous) return x; if (found == '') found = x; else { return -1; } } if (found != '') return found; return 0; } //Versione per dizionario di tipo array function autoComplete2(dict, string, failIfAmbiguous){ var found = '' var i; if ((string == "")||(string==null)) return ""; for (i = 0; i < dict.length; i++) if (dict[i].indexOf(string) == 0){ if (!failIfAmbiguous) return dict[i]; if (found == '') found = dict[i]; else { return -1; } } if (found != '') return found; return 0; } //Prova ad auto-completare l'argomento usando arrayArgument[] come dizionario; //In caso di fallimento restituisce arg function autoCompleteArgument(arg){ var completed = autoComplete2(arrayArgument, arg, false); if ((completed == -1) || (completed == 0)) return arg; else return completed; } //Comandi //cmd['nome comando'] = [funzione, 'commento']; cmd = new Object(); cmd['a'] = [cmd_a, 'Da aiutare; richiede motivo e argomento']; cmd['c'] = [cmd_c, 'Da aiutare; richiede motivo e argomento']; cmd['e'] = [cmd_e, 'Avviso enciclopedicità dubbia; richiede motivo e argomento']; cmd['p'] = [cmd_p, 'Avviso nNPOV; richiede motivo e argomento']; cmd['w'] = [cmd_w, 'Da wikificare; richiede argomento']; cmd['s'] = [cmd_s, 'Stub; richiede argomento (opzionale)']; cmd['t'] = [cmd_t, 'Da tradurre; richiede lingua e argomento']; cmd['categorizzare'] = [cmd_categorizzare, 'Da categorizzare']; cmd['unire'] = [cmd_unire, 'Da unire; richiede la voce simile']; cmd['purge'] = [cmd_purge, 'Aggiorna la cache']; cmd['fixformat'] = [cmd_fixformat, 'Sostituzioni automatiche']; cmd['replace'] = [cmd_replace, 'Cerca e sostituisci']; cmd['benvenuto'] = [cmd_benvenuto, 'Messaggio di benvenuto']; cmd['save'] = [cmd_save, 'Simula la pressione del tasto di salvataggio']; cmd['preview'] = [cmd_preview, 'Simula la pressione del tasto "Visualizza anteprima"']; cmd['diff'] = [cmd_diff, 'Simula la pressione del tasto "Mostra cambiamenti"']; //Preleva un argomento dalla commandline se possibile, altrimenti preleva tramite prompt() function getArg(text){ if (cmdline_command_array[cmdline_next_argument] != null) return cmdline_command_array[cmdline_next_argument++]; else{ var retval = prompt(text); if (retval == null) return ""; else return retval; } } //Template:A function cmd_a(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; TimenPr('{{A|motivo='+(getArg("Motivo"))+'|argomento='+(autoCompleteArgument(getArg("Argomento"),false))+'|mese='+mese()+' '+anno()+'|firma=~~~~}}\n'); TimenSA('+da aiutare; '); TimenME(); } //Template:W function cmd_w(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; TimenPr('{{W|argomento='+(autoCompleteArgument(getArg("Argomento"),false))+'|mese='+mese()+' '+anno()+'|firma=~~~~}}\n'); TimenSA('+wikificare; '); TimenME(); } //Template:E function cmd_e(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; TimenPr('{{E|'+(getArg("Motivo"))+'|'+(autoCompleteArgument(getArg("Argomento"),false))+'|'+mese()+' '+anno()+'|~~~~}}\n'); TimenSA('+avviso enciclopedicità dubbia; '); TimenME(); } //Template:P function cmd_p(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; TimenPr('{{P|motivo='+(getArg("Motivo"))+'|argomento='+(autoCompleteArgument(getArg("Argomento"),false))+'|mese='+mese()+' '+anno()+'|firma=~~~~}}\n'); TimenSA('+avviso nNPOV; '); TimenME(); } //Template:C function cmd_c(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; TimenPr('{{C|motivo='+(getArg("Motivo"))+'|argomento='+(autoCompleteArgument(getArg("Argomento"),false))+'|mese='+mese()+' '+anno()+'|firma=~~~~}}\n'); TimenSA('+da controllare; '); TimenME(); } //Template {{S}} function cmd_s(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; var arg = getArg("Argomento"); var pipepos = arg.indexOf("|"); if (pipepos == -1) var argomento = autoCompleteArgument(arg, false); else var argomento = autoCompleteArgument(arg.substring(0,pipepos), false) + "|" + autoCompleteArgument(arg.substring(pipepos+1), false); TimenPr('{{S' + (((argomento != null)&&(argomento!='')) ? ('|' + argomento + '}}\n') : '}}\n')); TimenSA('+stub; '); TimenME(); } function cmd_t(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; var lingua = autoComplete2(arrayLingue, getArg("Lingua"), false); var argomento = autoCompleteArgument(getArg("Argomento")); TimenPr('{{T|lingua=' + lingua + '|argomento=' + argomento +'|data='+mese()+' '+anno()+ '}}\n'); TimenSA('+stub; '); TimenME(); } //Template {{categorizzare}} function cmd_categorizzare(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; TimenDp('{{Categorizzare}}\n'); TimenSA('da categorizzare; '); TimenME(); } //Template {{Da unire}} function cmd_unire(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; TimenPr('{{Da unire|' + getArg("Voce:") + '}}\n'); TimenSA('+da unire; '); TimenME(); } //Benvenuto ai nuovi utenti function cmd_benvenuto(){ TimenDp('{{benve|nome={{subst:PAGENAME}}|~~~ ~~~~~}}'); TimenSA('Benvenuto su it.wiki!'); TimenME(); } //Aggiorna cache function cmd_purge(){ if (!document.getElementById) return; var x = document.getElementById('ca-history'); var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0]; if (!x) return; if (x.children) x = x.children[0]; else x = x.childNodes[0]; location.href=x.href.replace(/action=history/g, "action=purge"); } //Sostituzioni automatiche function cmd_fixformat(){ if ((wpTextbox1 = document.getElementById("wpTextbox1")) == null) return; if (typeof(fixformat_list) == 'undefined') return; for (i = 0; i < fixformat_list.length; i++) wpTextbox1.value = wpTextbox1.value.replace(fixformat_list[i][0], fixformat_list[i][1]); TimenSA(fixformat_subject); TimenME(); } //Cerca e sostituisci function cmd_replace(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; var s = getArg("Regexp da cercare?"); if(s){ var r = getArg("Sostituire con?"); if(!r && r != '') return; var txt = wpTextbox1; txt.value = txt.value.replace(new RegExp(s, "g"), r); } } //Premi "Salva" function cmd_save(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; document.getElementById("wpSave").click(); } //Premi "Visualizza anteprima" function cmd_preview(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; document.getElementById("wpPreview").click(); } //Premi "Mostra cambiamenti" function cmd_diff(){ wpTextbox1=document.getElementById("wpTextbox1"); if (wpTextbox1 == null) return; document.getElementById("wpDiff").click(); } function runCommand(command){ if ((command == null)||(command == "")) return; var commandline = command; //WARNING: variabile globale cmdline_command_array = commandline.split('#'); //WARNING: variabile globale: indice del prossimo argomento da leggere cmdline_next_argument = 0; while((command = cmdline_command_array[cmdline_next_argument++]) != null){ wpTextbox1=document.getElementById("wpTextbox1"); if (cmd[command] != null){ cmd[command][0](); continue; } //Cerchiamo se è prefisso univoco di un comando var completed = autoComplete1(cmd, command, true) if ((completed != 0)&&(completed != -1)) cmd[completed][0](); //tutto a posto, eseguiamo } } function showCommandLine(){ runCommand(prompt("Comando:")); } function addCommandLine(){ var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0]; var na = document.createElement('a'); na.href = "javascript:showCommandLine()"; na.appendChild(document.createTextNode('Command line')); var li = document.createElement('li'); li.id = 'tb-cmdline'; li.appendChild(na); tb.appendChild(li); ta['tb-cmdline'] = ['z', 'Command line']; akeytt(); } $(addCommandLine); function fakeActionRunCommands(){ if (getParamValue("fakeaction") == "runcommand"){ var commandline = getParamValue("command"); runCommand(commandline); } } /**** Command Line End ****/ /*
*/