User:Manuelt15/FastButtons/Main.js

Note: After saving, you have to bypass your browser's cache to see the changes. Internet Explorer: press Ctrl-F5, Mozilla: hold down Shift while clicking Reload (or press Ctrl-Shift-R), Opera/Konqueror: press F5, Safari: hold down Shift + Alt while clicking Reload, Chrome: hold down Shift while clicking Reload.
//<pre>
 
//By es:Usuario:Racso
//*********************************************************************
//Load functions [by default] of the buttons.
//*********************************************************************
 
//Buttons for non-sysops
function loadNoSysop()
{
	var tmp='';
 
	tmp += addFastButton('Test edits', "FBdest");
	tmp += addFastButton('Out of scope', "FBdest");
	tmp += addFastButton('Vandalism', "FBdest");
	tmp += addFastButton('Nosense', "FBdest");
	tmp+=addActionFastButton("Copyvio","readInputButton('URL','FBplagio');");
	tmp+=addActionFastButton("Otro","readInputButton('Motivo','FBdest');");
 
	return tmp;
}
 
//Buttons for sysops
function loadSysop()
{
	var tmp='';
 
	tmp+= addFastButton('Speedy delete','FBdelete','default','delete');
	tmp+= addActionFastButton("Speedy","readInputButton('Motivo','FBdelete','delete');");
 
	return tmp;
}
 
 
//*********************************************************************
//Funciones generales
//*********************************************************************
 
//addTemplate: añade una plantilla al inicio de la página, y guarda.
function addTemplate(plantilla,resumen)
{
	document.getElementById("wpTextbox1").value = plantilla + '\n' + document.getElementById("wpTextbox1").value;
	document.editform.wpSummary.value = resumen + ufb;
	document.editform.submit();
}

//addTemplateEnd: añade una plantilla al final de la página, y guarda.
function addTemplateEnd(plantilla,resumen)
{
	document.getElementById("wpTextbox1").value = document.getElementById("wpTextbox1").value + '\n' + plantilla;
	document.editform.wpSummary.value = resumen + ufb;
	document.editform.submit();
}

 
//addFastButton: genera la cadena para añadir un botón, tomando ciertos parámetros.
function addFastButton(buttonLabel, buttonType, typeParam, wikiAction )
{
	if (!typeParam) var typeParam = buttonLabel;
	if (!wikiAction) var wikiAction = 'edit';
	return '[<a href='+wikiURL+ wikiAction + '&' + buttonType + '='+encodeURI(typeParam)+'>'+buttonLabel+'</a>] ';
}
 
//addActionFastButton: genera la cadena para añadir un botón de acción.
function addActionFastButton(buttonLabel, accion)
{
	return '[<a onclick='+accion+'>'+buttonLabel+'</a>] ';
}
 
//readInputButton: ejecuta el código de un botón de acción que lee datos. Lee un dato del usuario.
function readInputButton(mensaje, buttonType, wikiAction)
{
	if (!wikiAction) var wikiAction='edit';
	var input = prompt(decodeURI(mensaje));
	if (input!=null) location.href=wikiURL+wikiAction+'&'+buttonType+'='+encodeURI(input);
}
 
//*********************************************************************
//Añadir los botones
//*********************************************************************
var PAGENAME='';
var USERNAME='';
var FBList=''; 
var isSysop=false;
var ufb = ', using [[es:Wikipedia:Fastbuttons|Fastbuttons]]';
var wikiURL="http://commons.wikimedia.org/w/index.php?title=";
 
 
//Extraer datos de la página
for (i=0; i<wgUserGroups.length; i++)
   {  if (wgUserGroups[i] == "sysop") isSysop=true; }
 
PAGENAME=encodeURI(wgPageName);
if (PAGENAME.match("&"))
{
PAGENAME=PAGENAME.replace("&","%26");
}
wikiURL=wikiURL+PAGENAME+"&action=";
USERNAME=PAGENAME.split(":")[1];
 
 
 
//Botones de destruir. Sólo aparecen a no-bibliotecarios.
if (isSysop==false)
{
	if (typeof botonesNoSysop=='function') tmp = botonesNoSysop(); else tmp = loadNoSysop();
	if (tmp!='') FBList = FBList + 'Speedy: ' + tmp + '<br>';
}
 
//Botones para bibliotecarios.
if (isSysop==true)
{
	if (typeof botonesSysop=='function') tmp = botonesSysop(); else tmp = loadSysop();
	if (tmp!='') FBList = FBList + 'Sysop: ' +tmp+'<br>';
}
 
 
/* Mostrar los botones en la página */
 
$(function ()
{
 
	if (document.getElementById('contentSub').innerHTML!='') document.getElementById('contentSub').innerHTML += '<br>';
	document.getElementById('contentSub').innerHTML += FBList;
 
	if (location.href.match("FBdest=")) 
	{
		var plantilla = decodeURI(location.href.substring(location.href.indexOf("FBdest=")+7));
		addTemplate("{{speedy|"+plantilla+"}}" , "Speedy: "+plantilla);
	}
 
	if (location.href.match("FBplant=")) 
	{
		var plantilla = decodeURI(location.href.substring(location.href.indexOf("FBplant=")+8));
		addTemplate(plantilla , "Plantilla: "+plantilla);
	}
 
	if (location.href.match("FBplagio=")) 
	{
		var url = decodeURI(location.href.substring(location.href.indexOf("FBplagio=")+9));
		addTemplate('{{copyvio|1='+url+'}}', "Copyright violation from "+url);
	}
 
	else if (location.href.match("FBdelete=")) 
	{
		var motivo = decodeURI(location.href.substring(location.href.indexOf("FBdelete=")+9));
			if (motivo!='default')document.getElementById ("wpReason").value=reason;
		document.getElementById ("wpConfirmB").click();
	}
 
});
 
//</pre>