Utente:Elcairo/Monobook.js

Da Wikiversità, l'apprendimento libero.

Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
/* <pre> */


/** 
 * Extra tabs for monobook skin
 * Forked from [[User:ABCD/monobook.js]] around April 2005
 * Dual licensed under the GFDL and GPL
 * See also: [[User:JesseW/monobook.js]]
 * For italian translation [[it:Utente:Helios89/monobook.js]]
 * Additional programming: [[it:Utente:Paulatz/monobook.js]]
 * Mi perdoni Jacopo86
 */

/**** Initialise on window load ****/

if (window.addEventListener) window.addEventListener("load",myLoadFuncs,false);
else if (window.attachEvent) window.attachEvent("onload",myLoadFuncs);
else
{
    window.previousLoadFunction = window.onload;
    window.onload = function()
    {
        window.previousLoadFunction();
        myLoadFuncs();
    }
}

// [[User:Lupin/popups.js]] - please include this line 

document.write('<script type="text/javascript" src="' 
    + 'http://it.wikipedia.org/w/index.php?title=User:Emc2/strings-it.js' 
    + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');
mw.loader.load(
             'https://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js'
             + '&action=raw&ctype=text/javascript&dontcountme=s');
             simplePopups=true;
             popupAdminLinks=true;
             popupWatchRedirredPages=true;
             popupFixRedirs=true;
             popupFixDabs=true;
             popupWatchRedirredPages=true;
             popupHistoricalLinks=true;

/****  Load custom functions ****/

function myLoadFuncs()
{
    // &action=purge
    addPurge();
    // &section=0
    addEditSection0();
    // cause the personal menu looks bad
    changeLinks();
    // because edit summaries are good
    addForceSummary();
    // if this is VFD, add the show/hide thingies
    if(document.title.indexOf("Wikipedia:Pagine da cancellare") != -1 && document.title.indexOf("Editing ") != 0) vfdlinks();
    // now add a million extra tabs
    morelinks();
    // and some stuff for the sidebar
    addToolBoxLinks();
    // for admins only...
    // if(document.title.indexOf("Confirm delete - Delete") == 0) addVfdLink();
    // change the title of the edit link
    ta['ca-edit'] = ['e', 'Modifica questa pagina'];
    // re-render the title and accesskeys for stuff
    akeytt();
}


// Functions auxFicus and Ficus
function auxFicus(extra){
    Template = windowArgument.name
    if (Template == "ABORT") return '';

    Argument = windowArgument.document.formArgument.Argument.value
    wpTextbox1 = document.getElementById("wpTextbox1");
    if (Template == "W"||Template == "w")
        addString = "{{"+Template+"|"+Argument+"|"+"{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}|~~~~}}"
    else {
            Because = windowArgument.document.formArgument.Because.value
            addString = "{{"+Template+"|"+Because+"|"+Argument+"|"+"{{subst:CURRENTMONTHNAME}} {{subst:CURRENTYEAR}}|~~~~}}"
        }
    wpTextbox1.value=addString+"\n"+wpTextbox1.value;
    summ=document.getElementById("wpSummary");
    summ.value=summ.value+"+[[Template:"+Template+"]]";
}

function Ficus(Template){

    arrayArgument = new Array("antropologia", "archeologia", "architettura", "biografie", "biologia", "calcio", "chimica", "cinema", "diritto", "economia", "filosofia", "fisica", "fumetti", "geografia", "giochi", "informatica", "ingegneria", "letteratura", "matematica", "meccanica", "medicina", "musei", "musica", "politica", "religione", "scienza", "sociologia", "sport", "storia", "teatro")

    switch(Template){
    case "A":
    case "a":
        Greeter = "Hai richiesto di inserire questa pagina nella Categoria <b>\"Da aiutare\"</b>\n. Per favore scrivi una motivazione e scegli un argomento dalla lista";
        break;
    case "C":
    case "c":
        Greeter = "Hai richiesto di inserire questa pagina nella Categoria <b>\"Da controllare\"</b>\n. Per favore scrivi una motivazione e scegli un argomento dalla lista";
        break;
    case "P":
    case "p":
        Greeter = "Hai richiesto di inserire questa pagina nella Categoria <b>\"Segnalazioni NPOV\"</b>\n. Per favore scrivi una motivazione e scegli un argomento dalla lista";
        break;
    case "W":
    case "w":
        Greeter = "Hai richiesto di inserire questa pagina nella Categoria <b>\"Da wikificare\"</b>\n. Per favore scegli un argomento dalla lista.";
        break;
    default: Greeter = "Qualcosa è andato storto, fai pure quello che vuoi: non ho idea di cosa succederà"
    }

    windowArgument = window.open("", Template, "width=320, height=240, toolbar=0 location=0 directories=0 status=0 menubar=0 scrollbars=0");
    windowArgument.document.write("<html>\n");
    windowArgument.document.write("<head>\n");
    windowArgument.document.write("<title>Selezionare l'argomento</title>\n");
    windowArgument.document.write("</head>\n");
    windowArgument.document.write("<body>\n");
    windowArgument.document.write("<p>"+Greeter+"</p>");
    windowArgument.document.write("<form name=\"formArgument\">\n");
    if (Template == "W"||Template == "w")
        true;
    else {
        //windowArgument.document.write("<b>Motivazione:&nbsp;</b>");
        DS="<!--Inserire una motivazione-->"
        windowArgument.document.write('<input size="60" type="text" name="Because" value="'+DS+'" onFocus="javascript:if(value==\''+DS+'\') value=\'\';"');
    }
    windowArgument.document.write("<br/>");
    windowArgument.document.write("<select name=\"Argument\">\n");
    windowArgument.document.write("<option selected value=''>Scegli un argomento</option>\n");
    for (i=0; i<arrayArgument.length; i++) {
        windowArgument.document.write("<option value='"+arrayArgument[i]+"'>"+arrayArgument[i]+"</option>\n");
    }
    windowArgument.document.write("</select>\n");
    windowArgument.document.write("<input type=\"button\" value=\"Invia\" onClick=\"window.close()\">\n");
    windowArgument.document.write("&nbsp;<input type=\"button\" value=\"Annulla\" onClick=\"window.name='ABORT';window.close()\">\n");
    windowArgument.document.write("</form>\n");
    windowArgument.document.write("</body>\n");

    //windowArgument.captureEvents(Event.CLICK)
    windowArgument.onunload = auxFicus;
}

/**** Extra tab adding ****/

function addEditSection0()
{
    ta['ca-edit-0'] = ['', 'Modifica la sezione 0'];
    if(!document.getElementById) return;
    var x = document.getElementById('ca-edit');
    if(!x) return;
    var y = document.createElement('LI');
    y.id = 'ca-edit-0';
    if(x.className == 'selected'){
      if(/&action=edit&section=0$/.test(window.location.href)){
        x.className = 'istalk';
        y.className = 'selected';
      } else {
        x.className = 'selected istalk';
      }
    } else if(x.className == 'selected istalk'){
      if(/&action=edit&section=0$/.test(window.location.href)){
        x.className = 'istalk';
        y.className = 'selected istalk';
      } else {
        y.className = 'istalk';
      }
    } else {
      y.className = x.className;
      x.className = 'istalk';
    }
    var z = document.createElement('A');
    if(x.children){
        z.href = x.children[0].href + '&section=0';
        z.appendChild(document.createTextNode('0'));
        y.appendChild(z);
        document.getElementById('p-cactions').children[1].insertBefore(y,x.nextSibling);
    }else{
        z.href = x.childNodes[0].href + '&section=0';
        z.appendChild(document.createTextNode('0'));
        y.appendChild(z);
        document.getElementById('p-cactions').childNodes[3].insertBefore(y,x.nextSibling);
    }
}

function addlilink(tabs, url, name, id){
    var na = document.createElement('a');
    na.href = url;
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.appendChild(na);
    tabs.appendChild(li);
    return li;
}

function addlimenu(tabs, name, id)
{
    var na = document.createElement('a');
    na.href = '';
    var mn = document.createElement('ul');
    na.appendChild(document.createTextNode(name));
    var li = document.createElement('li');
    li.id = id;
    li.className = 'tabmenu';
    li.appendChild(na);
    li.appendChild(mn);
    tabs.appendChild(li);
    return li;
}

function addPurge()
{
    ta['ca-purge'] = ['g', 'Purge the internal cache for this page'];
    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];
    addlilink(tabs, x.href.replace(/=history/, "=purge"), 'purge', 'ca-purge');
}

function closevfd(bold, notbold)
{
  var txt = document.editform.wpTextbox1;
  txt.value = "{{subst:vt}} '''" + bold + "'''" + notbold + ". &ndash; ~~~~\n" + txt.value + "\n{{subst:vb}}\n";
  txt = document.editform.wpSummary;
  txt.value = "close discussion: " + bold + notbold;
  document.editform.wpWatchthis.checked = false;
}

function editSummary()
{
    var txt = document.editform.wpTextbox1;
    document.editform.wpSummary.value = 'Edit summary';
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '{{subst:edit summary}} ~~~~';
    txt.focus();
}

function welcomeMessage()
{
    document.editform.wpSummary.value = 'Benvenuto nella Wikipedia';
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '{{subst:User:Alphax/Welcome}} ~~~~';
    txt.focus();
}

function anonWelcome()
{
    document.editform.wpSummary.value = 'Create an account!';
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '{{subst:anon}} Thanks, ~~~~';
    txt.focus();
}

function replace()
{
    var s = prompt("Search regexp?");
    if(s){
        var r = prompt("Replace regexp?");
        var txt = document.editform.wpTextbox1;
        txt.value = txt.value.replace(new RegExp(s, "g"), r);
    }
}

function vfdresult()
{
    var res = prompt("Result?");
    var vfddate = prompt("Nomination date?");
    if(!res) return;
    document.editform.wpSummary.value = 'VFD result - ' + res.replace(/'/g, '');
    var txt = document.editform.wpTextbox1;
    if(txt.value.length > 0) txt.value += '\n';
    txt.value += '==VFD==\nOn [[' + vfddate + ']] [[{{subst:CURRENTYEAR}}]], this article was nominated for deletion. The result was ' + res + '. See [[Wikipedia:Votes for deletion/{{subst:PAGENAME}}]] for a record of the discussion. &ndash; ~~~~';
    txt.focus();
}

function hidevfd()
{
    var divs = document.getElementsByTagName("div");
    for(var x = 0; x < divs.length; ++x)
        if(divs[x].className.indexOf("vfd") != -1)
            divs[x].style.display = "none";
    document.getElementById('footer').style.display = 'none';
}

function showvfd()
{
    var divs = document.getElementsByTagName("div");
    for(var x = 0; x < divs.length; ++x)
        if(divs[x].className.indexOf("vfd") != -1)
            divs[x].style.display = "";
    document.getElementById('footer').style.display = '';
}

function vfdlinks()
{
    if(!document.getElementById) return;
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    addlilink(tabs, 'javascript:hidevfd()', 'hide closed', 'ca-hide');
    ta['ca-hide'] = ['', 'Hide closed VFDs'];
    addlilink(tabs, 'javascript:showvfd()', 'show closed', 'ca-show');
    ta['ca-show'] = ['', 'Show closed VFDs'];
}

function addForceSummary(){
    if(!/&action=edit/.test(window.location.href)) return;
    if(/&section=new/.test(window.location.href)) return;
    if(!document.forms.editform) return;
    document.forms.editform.wpSave.onclick = forceSummary;
}

function forceSummary(){
    if(!document.forms.editform.wpSummary.value.replace(/^(?:\/\\*.*\\*\/)? *(.*) *$/,'$1')){
      var r = prompt('Are you sure you want to submit without adding a summary?\nTo add a summary, type it in the box below:',document.forms.editform.wpSummary.value);
      if(r == null) return false;
      document.forms.editform.wpSummary.value = r;
    }
    return true;
}

function vfddelete(){
    var form = document.forms.deleteconfirm;
    form.wpReason.value = '[[Wikipedia:Votes for deletion/' + unescape(window.location.href.replace(/^.*\?title=([^&]+)&action=delete.*$/, '$1').replace(/_/g, ' ')) + ']]';
    form.wpConfirm.checked = true;
}

function morelinks(){
    var tabs = document.getElementById('p-cactions').getElementsByTagName('ul')[0];
    if(document.title.indexOf("Editing Wikipedia:Votes for deletion") == 0)
    {
        addlimenu(tabs, 'vfd actions', 'vfda');
        var vfda = document.getElementById('vfda').getElementsByTagName('ul')[0];
        addlilink(vfda, 'javascript:closevfd("keep", "")', 'keep', '');
        addlilink(vfda, 'javascript:closevfd("merge and redirect", " to [[" + prompt("Merge and redirect to?") + "]]")', 'merge', '');
        addlilink(vfda, 'javascript:closevfd("redirect", " to [[" + prompt("Redirect to?") + "]]")', 'redir', '');
        addlilink(vfda, 'javascript:closevfd("transwiki", " to " + prompt("Transwiki to?"))', 'trans', '');
        addlilink(vfda, 'javascript:closevfd("transwiki", " to Wiktionary")', 'wikt', '');
        addlilink(vfda, 'javascript:closevfd("speedy delete", "")', 'speedy', '');
        addlilink(vfda, 'javascript:closevfd("delete", "")', 'del', '');
        addlilink(vfda, 'javascript:closevfd(prompt("Result?"), "")', 'other', '');
        addlilink(tabs, 'javascript:replace()', 'replace', '');
    }
    else if(document.title.indexOf("Confirm delete - Delete") == 0)
    {
        addlilink(tabs, 'javascript:vfddelete()', 'vfd', '');
    }
    else if(document.title.indexOf("Editing User talk:") == 0)
    {
        addlilink(tabs, 'javascript:replace()', 'replace', '');
        addlimenu(tabs, 'talk messages', 'talkm');
        var talkm = document.getElementById('talkm').getElementsByTagName('ul')[0];
        addlilink(talkm, 'javascript:welcomeMessage()', 'welcome', '');
        addlilink(talkm, 'javascript:anonWelcome()', 'anon', '');
        addlilink(talkm, 'javascript:startThread()', 'thread', '');
        addlilink(talkm, 'javascript:editSummary()', 'summary', '');
    }
    else if(document.title.indexOf("Editing ") == 0)
    {
        addlilink(tabs, 'javascript:replace()', 'replace', '');
        addlilink(tabs, 'javascript:vfdresult()', 'vfd result', '');
    }


}

function addToolBoxLinks()
{
    var tb = document.getElementById('p-tb').getElementsByTagName('ul')[0];
    addlilink(tb, '/wiki/Speciale:Newpages', 'New pages', '');
    addlilink(tb, '/wiki/Speciale:Shortpages', 'Short pages', '');
    addlilink(tb, '/wiki/Speciale:Log', 'Logs', '');
    addlilink(tb, '/wiki/Template:Deletiontools', 'Deletion tools', '');
    addlilink(tb, '/wiki/Wikipedia:Disambiguation_pages_with_links', 'Dab list', '');
    addlilink(tb, '/wiki/Wikipedia:Template_messages/User_talk_namespace', 'Talk messages', '');
    addlilink(tb, '/wiki/User_talk:Alphax/special', 'Special characters', '');
    addlilink(tb, '/wiki/WP:ICT', 'Image Copyright tags', '');
}

// Returns <li><a href="url">name</a></li>
function addlilink(url, name)
{
  var na = document.createElement('a');
  na.setAttribute('href', url);

  var txt = document.createTextNode(name);
  na.appendChild(txt);

  var li = document.createElement('li');
  li.appendChild(na);
  return li;
}

// Adds a "blocklog" tab and fills in the username field on Speciale:Blockip, if a "&faketarget=username" is present.
function do_blockip_stuff()
{
  // focus on Reason field
  document.getElementsByName('wpBlockReason')[0].focus();

  // Look for a &faketarget= for the username/ip
  var l = location.search.substring(1).split('&');
  var target = '';
  for (var i = 0; i < l.length; ++i)
    {
      var n = l[i].indexOf('=');
      if (l[i].substring(0, n) == 'faketarget')
	{
	  target = l[i].substring(n + 1);
	  break;
	}
    }

  if (target == '')
    return;

  // put account name in "IP Address/username" field
  var addr = document.getElementsByName('wpBlockAddress')[0];
  addr.value = unescape(target);

  // add "blocklog" tab
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];
  tabs.appendChild(addlilink('/w/index.php?title=Special%3ALog&type=block&user=&page=Utente%3A' + target, 'blocklog'));
}

// Opens the block log in the current window, and Speciale:Blockip in a popup.
// Width, height, top, and left are chosen for a 1600x1200 display.
//function blockpage_and_log(target)
//{
//  window.open('Special_Blockip.html?foo=blarg&faketarget=' + target, 'Block', 'width=1600,height=600,top=600,left=0');
//  document.location.href = 'http://it.wikipedia.org/w/index.php?title=Speciale%3ALog&type=block&user=&page=Utente%3A' + target;
//}

// Adds "block" and "blocklog" tabs to User: and User talk: pages.
function add_block_tab()
{
  var c1 = document.getElementById('column-one');
  var tabs = c1.getElementsByTagName('div')[0].getElementsByTagName('ul')[0];

  // use the "edit this page" tab to get already-tidied url
  var editlk = document.getElementById('ca-edit').getElementsByTagName('a')[0].href;
  // cut everything up to "title=" from the start and everything past "&action=edit" from the end
  editlk = editlk.substring(editlk.indexOf('title=') + 6, editlk.lastIndexOf('&action=edit'));
  editlk = editlk.substring(editlk.indexOf(':') + 1);
  var slloc = editlk.indexOf('/');
  if (slloc > 0)
    editlk = editlk.substring(0, slloc);

  // add "block" tab
  tabs.appendChild(addlilink('/w/index.php?title=Special%3ABlockip&faketarget=' + editlk, 'block'));

  // To open the block page and block log simultaneously, replace the above line with:
  // tabs.appendChild(addlilink('javascript:blockpage_and_log("' + editlk + '")', 'Block'));
  // and uncomment the blockpage_and_log() function above.

  // add "blocklog" tab
  tabs.appendChild(addlilink('/w/index.php?title=Speciale%3ALog&type=block&user=&page=Utente%3A' + editlk, 'blocklog'));

  //add "contributions" tab
  tabs.appendChild(addlilink('/w/wiki.phtml?title=Speciale:Contributions&target=Utente:%3A' + editlk, 'contributions'));

}

function do_onload()
{
  if (document.title.indexOf('User:') == 0
      || document.title.indexOf('User talk:') == 0)
    add_block_tab();
  else if (document.title.indexOf('Block user') == 0) // could stand to be more robust
    do_blockip_stuff();
}

if (window.addEventListener) 
  window.addEventListener("load", do_onload, false);
else if (window.attachEvent) 
  window.attachEvent("onload", do_onload);

if ( document.createElement && window.addEventListener )
{
	function SoFixItInit() // pre-load, (don't want to slow down loading of article's content, though)
	{

	}

	function SoFixItLoad() // post-load
	{
		UserMenu = new PortletMenu( 'p-personal'   );
		PageMenu = new PortletMenu( 'p-cactions'   );
		 NavMenu = new PortletMenu( 'p-navigation' );
		//ToolMenu = new PortletMenu( 'p-tb'         );

			//	This is inefficient and not particularly robust.
			//	This comes first, I want this link to come up as
			//	fast as possible.
			//
		function GetByClass( sElem, sClass )
		{	var i, a2 = [], a = document.getElementsByTagName( sElem );
			for ( i = 0; i < a.length; i++ )
				if ( a[ i ].className == sClass )
					a2.push( a[ i ] );
			return a2;
		}
		var a, td = GetByClass( 'td', 'diff-otitle' );
		if ( ( td = td[ 0 ] ) && ( a = td.getElementsByTagName( 'a' )[ 0 ] ) )
			a.href = a.href + '&action=edit'; // need to change text, later

		var userName = UserMenu.getText( 'pt-userpage' );

			// personal (top-most) menu
			//
			//		Func  Talk  Prefs  Watch  List  Edits  Kate  Logs  #IRC  Out
			//
		UserMenu.setText( 'pt-mytalk'     , 'le mie discussioni'  );
		UserMenu.setText( 'pt-preferences', 'preferenze' );
		UserMenu.setText( 'pt-watchlist'  , 'osservati speciali' );
		UserMenu.setText( 'pt-mycontris'  , 'miei contributi' );
		UserMenu.setText( 'pt-logout'     , 'esci'   );
			//
		UserMenu.setHref( 'pt-mycontris',
			'http://it.wikinews.org/w/index.php?title=Speciale:Contributions&target=' +
			userName + '&offset=0&limit=500' );
			//
			//
			//	it seems there is a stylesheet that makes them lowercase
			//
			//		ok, the lowercased menu items are starting to really bug me:
			//
		document.getElementById( 'p-personal' ).getElementsByTagName( 'ul' )[0].style.textTransform = 'none';
			//
		UserMenu.insertBefore( 'pt-mycontris', 'pt-list', 'Google', 'http://google.com/' );
		UserMenu.insertBefore( 'pt-logout'   , 'pt-logs', 'log',
			'/w/index.php?title=Special%3ALog&user=' + userName );
		UserMenu.insertBefore( 'pt-logout'   , 'pt-irc' , '#irc', 'irc://irc.freenode.net/wikinews-it' );
		UserMenu.insertBefore( 'pt-mycontris', 'pt-list', 'n°edit', 'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?hash=fa5da33d50ea3c4cb81efd75d62a9bd89a7f5ad2&user=Tooby&dbname=itwikinews_p' );

			//	article-actions menu, (the "tabs")
			//
		if ( PageMenu[ 'ca-history' ] ) // theory: if it has a history tab, then it's purgable
		{
			PageMenu.insertBefore( 'ca-history', 'ca-lastdiff', 'Ultima modifica',
				PageMenu.getHref( 'ca-history' ).replace( /action=history/, 'diff=0' ) );

			PageMenu.append( 'ca-purge', 'Purga',
				PageMenu.getHref( 'ca-history' ).replace( /action=history/, 'action=purge' ) );
		}

		var x = 1;
                NavMenu.append( 'n-' + x++, 'Amministratori', '/wiki/Wikinotizie:Amministratori' );
		NavMenu.append( 'n-' + x++, 'Log', '/wiki/Speciale:Log' );
		NavMenu.append( 'n-' + x++, 'Pagine da cancellare', '/wiki/Wikinotizie:Richieste di cancellazione' );
		NavMenu.append( 'n-' + x++, 'Cancellazioni veloci', '/wiki/Categoria:Cancellazioni veloci' );
                NavMenu.append( 'n-' + x++, 'Sondaggi', '/wiki/Wikinotizie:Sondaggi' );
		NavMenu.append( 'n-' + x++, 'Stub', '/wiki/Categoria:Stub' );
		NavMenu.append( 'n-' + x++, 'Template', '/wiki/Wikinotizie:Messaggi template' );
                NavMenu.append( 'n-' + x++, 'Vetrina', '/wiki/Wikinotizie:Vetrina' );
                NavMenu.append( 'n-' + x++, 'Blocconote', '/wiki/Utente:Tooby/Blocconote' );
                NavMenu.append( 'n-' + x++, 'Archivio', '/wiki/Utente:Tooby/Archivio' );

	}

	function PortletMenu( id ) // constructor
	{
		this.menu = document.getElementById( id );
		this.list = this.menu.getElementsByTagName( 'ul' )[ 0 ]; // bypass "<h5>Views</h5>", etc.

			//	sigh...as far as I can figure, there is empty whitespace being treated
			//	as TextNodes....
			//
		var LIs = this.list.getElementsByTagName( 'li' );

		for ( var i = 0; i < LIs.length; i++ )
		{
			this[ LIs[ i ].id ] = LIs[ i ];
		}

		this.newItem = function( id, txt, url )
		{	var li = document.createElement( 'li' ); li.id   = id;
			var  a = document.createElement( 'a'  );  a.href = url;

			 a.appendChild( document.createTextNode( txt ) );
			li.appendChild( a );

			this[ id ] = li; // watch this!!!

			return li;
		}

		this.append = function( id, txt, url )
		{	this.list.appendChild( this.newItem( id, txt, url ) );
		}
		
		this.insertBefore = function( old, id, txt, url )
		{	this.list.insertBefore( this.newItem( id, txt, url ), this[ old ] );
		}

			//	the ByTagName here is a bit annoying, but in Safari, I was picking
			//	up TextNodes by using this[ id ].firstChild.firstChild
			//
		this.getText = function( id      ) { return this[ id ].getElementsByTagName( 'a' )[ 0 ].firstChild.data }
		this.setText = function( id, txt ) {        this[ id ].getElementsByTagName( 'a' )[ 0 ].firstChild.data = txt }

		this.getHref = function( id      ) { return this[ id ].getElementsByTagName( 'a' )[ 0 ].href       }
		this.setHref = function( id, url ) {        this[ id ].getElementsByTagName( 'a' )[ 0 ].href = url }
		
		//	I add em as I need em....
	}

	function InlineKate( user )
	{
		var kate =
			'http://tools.wikimedia.de/~interiot/cgi-bin/count_edits?dbname=itwiki_p&user=' + user;

		var div = document.createElement( 'div' );
			div.id = 'inlineKateDiv';
			div.style.position = 'absolute';
			div.style.zIndex   = 1000;
			div.style.left     =  '5px';
			div.style.top      =  '5px';
			div.style.backgroundColor = '#FFFFFF';
			div.style.borderStyle     = 'solid';
			div.style.borderWidth     = ' medium';
			div.style.borderColor     = '#000000';

			var top = document.createElement( 'div' );
				top.id = 'inlineKateTop';
				top.style.textAlign = 'right';
				top.style.margin = '8px';
				top.style.backgroundColor = '#DDDDDD';

				var a = document.createElement( 'a' );
					a.appendChild( document.createTextNode( "Go to Kate's" ) );
					a.href    = kate;
					a.target  = '_parent';
					a.style.margin = '8px';

				top.appendChild( a );

					a = document.createElement( 'a' );
					a.appendChild( document.createTextNode( 'Close' ) );
					a.href    = "javascript:void RemoveNode('inlineKateDiv')";
					a.style.margin = '8px';

				top.appendChild( a );

			div.appendChild( top );

			var iframe = document.createElement( 'iframe' );
				iframe.id   = 'inlineKateBot';
				iframe.style.width  = '400px';
				iframe.style.height = '600px';
				iframe.style.margin =   '8px';
				iframe.style.borderStyle = 'solid';
				iframe.style.borderWidth = 'thin';
				iframe.style.borderColor = '#000000';
				iframe.src = kate;

			div.appendChild( iframe );

		document.body.appendChild( div );
	}

	
	function RemoveNode( id )
	{	var node = document.getElementById( id )
		node.parentNode.removeChild( node );
	}

	SoFixItInit();
	window.addEventListener( 'load', SoFixItLoad, false );
}
// Trigger generale: addLoadEvent();

// WikiSign
function WikiSign() {
  arra = document.getElementsByTagName("a");
  for ( i=0; i < arra.length;i++ ) {
    if ( arra[i].getAttribute("href") == "javascript:insertTags('--~~~~','','');" ) {
      arra[i].setAttribute("href", "javascript:insertTags('~~~~ ','','');");
      break;
    }
  }
}
addLoadEvent(WikiSign);

//ToolbarButton
function ToolbarButton() {
  var toolbar = null;
  toolbar = document.getElementById("toolbar");
  if (toolbar == null)
    return;
  
  var today = new Date();
  var anno= today.getYear()+1900;
  var tmp= today.getMonth()+1;
  switch (tmp)
  {
     case 1:
        var mese="gennaio"
        break;
     case 2:
        var mese="febbraio"
        break;
     case 3:
        var mese="marzo"
        break;
     case 4:
        var mese="aprile"
        break;
     case 5:
        var mese="maggio"
        break;
     case 6:
        var mese="giugno"
        break;
     case 7:
        var mese="luglio"
        break;
     case 8:
        var mese="agosto"
        break;
     case 9:
        var mese="settembre"
        break;
     case 10:
        var mese="ottobre"
        break;
     case 11:
        var mese="novembre"
        break;
     case 12:
        var mese="dicembre"
        break;
  }
  
// pulsante STUB
  tmp = document.createElement("a");
  tmp.id = 'tb-stb';
  tmp.href = 'javascript:(function() {wpTextbox1=document.getElementById("wpTextbox1");wpTextbox1.value="{{stub}}\\n"+wpTextbox1.value;summ=document.getElementById("wpSummary");summ.value=summ.value+"+{{stub}}";})();';
  var imag = document.createElement("img");
  imag.setAttribute('src','http://upload.wikimedia.org/wikipedia/it/1/11/Stubber.png');
  imag.setAttribute('alt','[Stub]');
  imag.setAttribute('title','{{stub}}');
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);
  
// pulsante FICUS-AIUTARE
  tmp = document.createElement("a");
  tmp.id = 'tb-fic';
  tmp.href = "javascript:Ficus('A');";
  //tmp.href = "javascript:void auxFicus('TestCase')";
  var imag = document.createElement("img");
  imag.setAttribute('src','http://upload.wikimedia.org/wikipedia/it/c/c4/Pulsante-aiutare.gif');
  imag.setAttribute('alt','[ficus]');
  imag.setAttribute('title','{{A}}iutare');
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);

// pulsante FICUS-CONTROLLARE
  tmp = document.createElement("a");
  tmp.id = 'tb-fic';
  tmp.href = "javascript:Ficus('C');";
  //tmp.href = "javascript:void auxFicus('TestCase')";
  var imag = document.createElement("img");
  imag.setAttribute('src','http://upload.wikimedia.org/wikipedia/it/e/e2/Pulsante-controllare.gif');
  imag.setAttribute('alt','[ficus]');
  imag.setAttribute('title','{{C}}ontrollare');
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);

// pulsante FICUS-POV
  tmp = document.createElement("a");
  tmp.id = 'tb-fic';
  tmp.href = "javascript:Ficus('P');";
  //tmp.href = "javascript:void auxFicus('TestCase')";
  var imag = document.createElement("img");
  imag.setAttribute('src','http://upload.wikimedia.org/wikipedia/it/a/ab/Pulsante-pov.gif');
  imag.setAttribute('alt','[ficus]');
  imag.setAttribute('title','{{P}}OV');
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);

// pulsante FICUS-WIKIFICARE
  tmp = document.createElement("a");
  tmp.id = 'tb-fic';
  tmp.href = "javascript:Ficus('W');";
  //tmp.href = "javascript:void auxFicus('TestCase')";
  var imag = document.createElement("img");
  imag.setAttribute('src','http://upload.wikimedia.org/wikipedia/it/2/24/Pulsante-wikificare.gif');
  imag.setAttribute('alt','[ficus]');
  imag.setAttribute('title','{{W}}ikificare');
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);
  
// pulsante VOTO FAVOREVOLE +1
  tmp = document.createElement("a");
  tmp.id = 'tb-piu';
  tmp.href = 'javascript:(function() {wpTextbox1=document.getElementById("wpTextbox1");wpTextbox1.value=wpTextbox1.value+"*{{+1}} ~~~ ~~~~~";summ=document.getElementById("wpSummary");summ.value=summ.value+"+{{+1}}";document.getElementById("wpMinoredit").checked=1;})();';
  var imag = document.createElement("img");
  imag.setAttribute('src','http://upload.wikimedia.org/wikipedia/it/f/f8/Favorevole.png');
  imag.setAttribute('alt','[+1]');
  imag.setAttribute('title','voto +1');
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);

// pulsante VOTO ASTENUTO =0
  tmp = document.createElement("a");
  tmp.id = 'tb-uguale';
  tmp.href = 'javascript:(function() {wpTextbox1=document.getElementById("wpTextbox1");wpTextbox1.value=wpTextbox1.value+"*{{0}} ~~~ ~~~~~";summ=document.getElementById("wpSummary");summ.value=summ.value+"+{{0}}";document.getElementById("wpMinoredit").checked=1;})();';
  var imag = document.createElement("img");
  imag.setAttribute('src','http://upload.wikimedia.org/wikipedia/it/a/aa/Astenuto.png');
  imag.setAttribute('alt','[=0]');
  imag.setAttribute('title','voto =0');
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);

// pulsante VOTO CONTRARIO -1
  tmp = document.createElement("a");
  tmp.id = 'tb-meno';
  tmp.href = 'javascript:(function() {wpTextbox1=document.getElementById("wpTextbox1");wpTextbox1.value=wpTextbox1.value+"*{{-1}} ~~~ ~~~~~";summ=document.getElementById("wpSummary");summ.value=summ.value+"+{{-1}}";document.getElementById("wpMinoredit").checked=1;})();';
  var imag = document.createElement("img");
  imag.setAttribute('src','http://upload.wikimedia.org/wikipedia/it/4/43/Contrario.png');
  imag.setAttribute('alt','[-1]');
  imag.setAttribute('title','voto -1');
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);

// pulsante UNVERIFIED
  tmp = document.createElement("a");
  tmp.id = 'tb-fic';
  tmp.href = 'javascript:(function() {wpTextbox1=document.getElementById("wpTextbox1");wpTextbox1.value=wpTextbox1.value+"{{unverified}}";summ=document.getElementById("wpSummary");summ.value=summ.value+"unverified";document.getElementById("wpMinoredit").checked=1;})();';
  var imag = document.createElement("img");
imag.setAttribute('src','http://upload.wikimedia.org/wikipedia/it/5/52/Pulsante_copyviol.png');
  imag.setAttribute('alt','[Unverified]');
  imag.setAttribute('title','unverified');
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);

// pulsante AVVISO VANDALISMO
  addToolbarButton('tb-vnd', 'javascript:addText("{{Vandalismo}}", "+Avviso vandalismo", 1)','http://commons.wikimedia.org/wiki/Image:Wiki_vand.gif','[Avv]','{{Vandalismo}}');

// pulsante ORFANA
  tmp = document.createElement("a");
  tmp.id = 'tb-fic';
  tmp.href = 'javascript:(function() {wpTextbox1=document.getElementById("wpTextbox1");wpTextbox1.value=wpTextbox1.value+"{{OrfanaLicenzaLibera}}";summ=document.getElementById("wpSummary");summ.value=summ.value+"orfanaLicenzaLibera";document.getElementById("wpMinoredit").checked=1;})();';
  var imag = document.createElement("img");
imag.setAttribute('src','');
  imag.setAttribute('alt','[OrfanaLicenzaLibera]');
  imag.setAttribute('title','Orfana licenza libera');
  tmp.appendChild(imag);
  toolbar.appendChild(tmp);
}

addLoadEvent(ToolbarButton);

function InsertButtonsToToolBar()
{
//Strike-Out Button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/c/c9/Button_strike.png",
    "speedTip": "Strike",
    "tagOpen": "<s>",
    "tagClose": "</s>",
    "sampleText": "Strike-through text"}
//Left-Text Button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/e/ea/Button_align_left.png",
    "speedTip": "Left-Align",
    "tagOpen": "<div style='text-align: left; direction: ltr; margin-left: 1em;'>\n",
    "tagClose": "\n</div>",
    "sampleText": "Left-aligned text"}
//Center-Text Button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/5/5f/Button_center.png",
    "speedTip": "Center",
    "tagOpen": "<div style='text-align: center;'>\n",
    "tagClose": "\n</div>",
    "sampleText": "Centered text"}
//Table button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/6/60/Button_insert_table.png",
    "speedTip": "Table",
    "tagOpen": "\n{| border='1' \n|- \n| 1 || 2\n|- \n| 3 || 4",
    "tagClose": "\n|}\n",
    "sampleText": ""}
//Line break button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/13/Button_enter.png",
    "speedTip": "Line break",
    "tagOpen": "<br />",
    "tagClose": "",
    "sampleText": ""}
//Superscript
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/8/80/Button_upper_letter.png",
    "speedTip": "Superscript",
    "tagOpen": "<sup>",
    "tagClose": "</sup>",
    "sampleText": "Superscript text"}
//Subscript
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/7/70/Button_lower_letter.png",
    "speedTip": "Subscript",
    "tagOpen": "<sub>",
    "tagClose": "</sub>",
    "sampleText": "Subscript text"}
//Small Text
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/5/58/Button_small.png",
    "speedTip": "Small",
    "tagOpen": "<small>",
    "tagClose": "</small>",
    "sampleText": "Small Text"}
//Comment
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/3/34/Button_hide_comment.png",
    "speedTip": "Insert hidden Comment",
    "tagOpen": "<!-- ",
    "tagClose": " -->",
    "sampleText": "Comment"}
//Gallery
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/12/Button_gallery.png",
    "speedTip": "Insert a picture gallery",
    "tagOpen": "\n<gallery>\n",
    "tagClose": "\n</gallery>",
    "sampleText": "Image:FileName.jpg|Caption1\\Image:FileName2.jpg|Caption2"}
//Secondary Headline
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/e/e9/Button_headline2.png",
    "speedTip": "Secondary headline",
    "tagOpen": "\n===",
    "tagClose": "===",
    "sampleText": "Secondary headline"}
//Tabs
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/8/8e/Button_shifting.png",
    "speedTip": "Insert tab(s)",
    "tagOpen": ":",
    "tagClose": "",
    "sampleText": ":"}
//Block Quote
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png",
    "speedTip": "Insert block of quoted text",
    "tagOpen": "<blockquote style='border: 1px solid blue; padding: 2em;'>\n",
    "tagClose": "\n</blockquote>",
    "sampleText": "Block quote"}
//Colour
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/1/1e/Button_font_color.png",
    "speedTip": "Insert colored text",
    "tagOpen": "<span style='color: ColorName'>",
    "tagClose": "</span>",
    "sampleText": "Span of text"}
//Code
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/2/23/Button_code.png",
    "speedTip": "Insert code",
    "tagOpen": "<code>",
    "tagClose": "</code>",
    "sampleText": "Code"}
//Sub-Link
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/9/93/Button_sub_link.png",
    "speedTip": "Insert link to sub-page",
    "tagOpen": "[[Page#",
    "tagClose": "]]",
    "sampleText": "Sub_page"}
//Definition List
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/d/d3/Button_definition_list.png",
    "speedTip": "Insert definition list",
    "tagOpen": "\n; ",
    "tagClose": " : ",
    "sampleText": "Insert text"}
//Template button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/3/3b/Button_template_alt.png",
    "speedTip": "Template",
    "tagOpen": "{{",
    "tagClose": "}}",
    "sampleText": "Template name"}
//Category button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/5/5a/Button_category_alt.png",
    "speedTip": "Categoria",
    "tagOpen": "[[Categoria:",
    "tagClose": "]]",
    "sampleText": "Category title"}
//Reference link button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/7/79/Button_reflink.png",
    "speedTip": "<ref>",
    "tagOpen": "<ref>",
    "tagClose": "</ref>",
    "sampleText": "Insert reference material"}
//Reference button
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/a/a0/Button_references_alt.png",
    "speedTip": "Reference footer",
    "tagOpen": "<references/>",
    "tagClose": "",
    "sampleText": ""}

//Link a Wikipedia
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/7/7f/Button_link_to_Wikipedia.png",
    "speedTip": "Wikipedia link",
    "tagOpen": "[[w:",
    "tagClose": "|]]",
    "sampleText": "wikipedialink"}

//Link a Wikipedia
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/8/83/Button_encrypted.png",
    "speedTip": "Archiviato",
    "tagOpen": "{{archiviato",
    "tagClose": "}}",
    "sampleText": ""}
}
$( InsertButtonsToToolBar );

//Add an "invert" button in Undeletion page (source: http://en.wikipedia.org/wiki/User:Cryptic/toggleundelete.js)

function toggle_undelete()
{
  var f = document.getElementById("undelete");
  if (f)
    {
      var inputs = f.getElementsByTagName("input");
      var i;
      for (i = 0; i < inputs.length; ++i)
        if (inputs[i].type == "checkbox")
          inputs[i].checked = !inputs[i].checked;
    }
}

function setup_toggle_undelete()
{
  if (document.title.indexOf("Vedi e recupera pagine cancellate") == 0)
    {
      var f = document.getElementById("undelete");
      if (f)
        {
          var h2 = f.getElementsByTagName("h2")[0];
          if (h2)
            {
              var button = document.createElement('input');
              button.type = "button";
              button.value = "Inverti";
              button.setAttribute('onClick', 'toggle_undelete()');
              f.insertBefore(button, h2);
            }
        }
    }
}

$(setup_toggle_undelete);

//============================================================
// Table generator
//============================================================

/**
 *
 * English: Generate an array using Mediawiki syntax
 *
 * @author: fr:user:dake (language conversion and  new options added by en:user:Voice of All)
 * @version: 0.1
 */
 
function generateTable(nbCol, nbRow, exfield)
{
        code = '\n{| class="wikitable"\n';
        code += "|+ TABLE CAPTION <!-- if required -->\n";
        if (exfield==true) code += '!\n';
        
        for (var i=1;i<nbCol+1;i++) code += '! FIELD ' + i + '\n';

        var items = 0;
        for (var j=0;j<nbRow;j++) 
        {
                   if (exfield==true) { 
                        items++;        
                        code += '|-\n'
                        code += '! ITEM ' + items + '\n';
                   }  else if (exfield==false) {                
                        code += '|-\n'
                   }    
                for (var i=0;i<nbCol;i++) code += '| element\n';
        }
        code += '|}\n';
        insertTags('','', code); 
}

/**
 *
 * English: Open a popup with parameters to generate an array. 
 * The number of rows/columns can be modified. Some additional
 * parameters are related to templates available on :fr
 *
 * @author: fr:user:dake
 * @version: 0.1
 */
 
function popupTable()
{
  var popup = window.open('about:blank','WPtable','height=350,width=400,scrollbars=yes');
  
  javaCode = '<script type="text\/javascript">function insertCode(){';
  javaCode += 'var row = parseInt(document.paramForm.inputRow.value); ';
  javaCode += 'var col = parseInt(document.paramForm.inputCol.value); ';
  javaCode += 'var exfield = document.paramForm.inputItems.checked; ';
  javaCode += 'window.opener.generateTable(col,row,exfield);';
  javaCode += 'window.close(); '
  javaCode += '}<\/script>';
  
  popup.document.write('<html><head><title>Make table</title>');
  popup.document.write('<script type="text\/javascript" src="\/skins-1.5\/common\/wikibits.js"><!-- wikibits js --><\/script>');
  popup.document.write('<style type="text\/css" media="screen,projection">/*<![CDATA[*/ @import "\/skins-1.5\/monobook\/main.css?5"; /*]]>*/<\/style>');
  popup.document.write(javaCode); 
  popup.document.write('</head><body>');
  popup.document.write('<p>Enter the table parameters below: </p>');
  popup.document.write('<form name="paramForm">');
  popup.document.write('Number of rows: <input type="text" name="inputRow" value="3" ><p>');
  popup.document.write('Number of columns: <input type="text" name="inputCol" value="3" ><p>');
  popup.document.write('Item column: <input type="checkbox" name="inputItems" ><p>');
  popup.document.write('</form">');
  popup.document.write('<i>The default table contains one row of fields.</i><p>');
  popup.document.write('Check "Item column" to give the table a field row <i>and</i> an item column.</i><p>');
  popup.document.write('<p><a href="javascript:insertCode()"> Insert table</a>     |');
  popup.document.write('    <a href="javascript:self.close()">Cancel</a></p>');
  popup.document.write('</body></html>');
  popup.document.close();
}

//Ressemble à la fonction de /skins-1.5/commons/wikibits.js pour insérer un autre lien que insertTags
function table_button()
{
 var toolbar = document.getElementById('toolbar');
 if (!toolbar) return false;
 
 var textbox = document.getElementById('wpTextbox1');
 if (!textbox) return false;
 
 if (!document.selection && textbox.selectionStart == null)
 return false;
 
 var image = document.createElement("img");
 image.width = 23;
 image.height = 22;
 image.src = 'http://upload.wikimedia.org/wikipedia/commons/0/04/Button_array.png';
 image.border = 0;
 image.alt = 'Table';
 image.title = 'Make table';
 image.style.cursor = "pointer";
 image.onclick = function() {
   popupTable();
   return false;
 }
 toolbar.appendChild(image);
}

// Changes made on Sat, 30 Sep 2006 20:28 UTC, seems to work on IE
$(table_button);
/* </pre> */