Diferencia entre revisiones de «MediaWiki:Gadget-FastButtons.js»
Apariencia
Contenido eliminado Contenido añadido
mSin resumen de edición |
Error de chequeo |
||
Línea 220: | Línea 220: | ||
$('#contentSub').html($('#contentSub').html() + fastButtons.FBList); |
$('#contentSub').html($('#contentSub').html() + fastButtons.FBList); |
||
if (mw.util.getParamValue('FBdest')) { |
if (mw.util.getParamValue('FBdest') !== null) { |
||
var plantilla = mw.util.getParamValue('FBdest'); |
var plantilla = mw.util.getParamValue('FBdest'); |
||
addTemplate("{{destruir|1=" + plantilla + "}}", "Destruir: " + plantilla); |
addTemplate("{{destruir|1=" + plantilla + "}}", "Destruir: " + plantilla); |
||
} else if (mw.util.getParamValue('FBplant')) { |
} else if (mw.util.getParamValue('FBplant') !== null) { |
||
var plantilla = mw.util.getParamValue('FBplant'); |
var plantilla = mw.util.getParamValue('FBplant'); |
||
addTemplate(plantilla, "Plantilla: " + plantilla); |
addTemplate(plantilla, "Plantilla: " + plantilla); |
||
} else if (mw.util.getParamValue('FBplagio')) { |
} else if (mw.util.getParamValue('FBplagio') !== null) { |
||
var url = mw.util.getParamValue('FBplagio'); |
var url = mw.util.getParamValue('FBplagio'); |
||
addTemplate('{{plagio|1=' + url + '|2=--~~~~}}', "Plagio desde " + url); |
addTemplate('{{plagio|1=' + url + '|2=--~~~~}}', "Plagio desde " + url); |
||
} else if (mw.util.getParamValue('FBdelete')) { |
} else if (mw.util.getParamValue('FBdelete') !== null) { |
||
var motivo = mw.util.getParamValue('FBdelete'); |
var motivo = mw.util.getParamValue('FBdelete'); |
||
if (motivo != 'default') { |
if (motivo !== 'default') { |
||
$('#wpReason').val(motivo); |
$('#wpReason').val(motivo); |
||
} |
} |
||
$('#deleteconfirm').submit(); |
$('#deleteconfirm').submit(); |
||
} else if (mw.util.getParamValue('FBwarn')) { |
} else if (mw.util.getParamValue('FBwarn') !== null) { |
||
var warning = mw.util.getParamValue('FBwarn'); |
var warning = mw.util.getParamValue('FBwarn'); |
||
addTemplateEnd('{{subst:prueba' + decodeURI(warning) + '}} --~~~~', 'Aviso al usuario'); |
addTemplateEnd('{{subst:prueba' + decodeURI(warning) + '}} --~~~~', 'Aviso al usuario'); |
||
} else if (mw.util.getParamValue('FBblock')) { |
} else if (mw.util.getParamValue('FBblock') !== null) { |
||
$('#mw-input-wpExpiry').val("31 hours"); |
$('#mw-input-wpExpiry').val("31 hours"); |
||
$('#mw-input-wpReason').val('[[WP:VN|Vandalismo de páginas]]'); |
$('#mw-input-wpReason').val('[[WP:VN|Vandalismo de páginas]]'); |
Revisión del 04:25 7 mar 2012
/**
* FastButtons de Racso
* <nowiki>
*/
// Protege contra doble inclusión
if (typeof window.fastButtons == 'undefined') {
importScript('Special:Mypage/FB.js');
//Checker
var fastButtons = {
PAGENAME: '',
FBList: '',
ufb: ', usando [[Wikipedia:FastButtons|Fastbuttons]]',
wikiURL: mw.util.wikiScript('index') + '?title=',
isSysop: false
};
//Enlaza con window
if (typeof window.fastButtons == 'undefined') {
window.fastButtons = fastButtons;
}
//Scope local para no contaminar espacio global
(function () {
//*********************************************************************
//Funciones generales
//*********************************************************************
//readInputButton: ejecuta el código de un botón de acción que lee datos. Lee un dato del usuario.
fastButtons.readInputButton = function (mensaje, buttonType, wikiAction) {
wikiAction = typeof wikiAction == 'undefined' ? 'edit' : wikiAction;
var input = window.prompt(decodeURI(mensaje));
if (input != null) {
location.href = fastButtons.wikiURL + wikiAction + '&' + buttonType + '=' + encodeURI(input);
}
};
//addTemplate: añade una plantilla al inicio de la página, y guarda.
function addTemplate(plantilla, resumen) {
$('#wpTextbox1').val(plantilla + '\n' + $('#wpTextbox1').val());
$('#wpSummary').val(resumen + fastButtons.ufb);
$('#editform').submit();
}
//addTemplateEnd: añade una plantilla al final de la página, y guarda.
function addTemplateEnd(plantilla, resumen) {
$('#wpTextbox1').val($('#wpTextbox1').val() + '\n' + plantilla);
$('#wpSummary').val(resumen + fastButtons.ufb);
$('#editform').submit();
}
//addFastButton: genera la cadena para añadir un botón, tomando ciertos parámetros.
function addFastButton(buttonLabel, buttonType, typeParam, wikiAction) {
typeParam = typeof typeParam == 'undefined' ? buttonLabel : typeParam;
wikiAction = typeof wikiAction == 'undefined' ? 'edit' : wikiAction;
return '[<a href="' + fastButtons.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>] ';
}
//addBlockFastButton: genera la cadena para añadir un botón de bloqueo rápido. Es un botón con código más específico,
//por lo que se hizo por aparte en vez de complicar las demás funciones generalizándolas tanto.
function addBlockFastButton() {
var targetName = '';
if (location.href.match("Especial:Bloquear/")) {
targetName = decodeURI(location.href.substring(location.href.indexOf("Especial:Bloquear/") + 18));
} else if (location.href.match("Especial:Contribuciones/")) {
targetName = decodeURI(location.href.substring(location.href.indexOf("Especial:Contribuciones/") + 24));
}
if (targetName == '') {
return '';
}
return '[<a href="' + mw.util.wikiScript('index') + '?title=Especial:Bloquear/' + targetName + '&FBblock">31h, vandalismo</a>] ';
}
//*********************************************************************
//Funciones de carga [por defecto] de los botones.
//*********************************************************************
//BOTONES PARA NO-SYSOP
function loadNoSysop() {
var tmp = '';
tmp += addFastButton('Vandalismo', "FBdest");
tmp += addFastButton('Pruebas de edición', "FBdest");
tmp += addFastButton('No enciclopédico', "FBdest");
tmp += addFastButton('Infraesbozo', "FBdest");
tmp += addFastButton('Promocional', "FBdest");
tmp += addActionFastButton("Plagio", "fastButtons.readInputButton('URL','FBplagio');");
tmp += addActionFastButton("Otro", "fastButtons.readInputButton('Motivo','FBdest');");
return tmp;
}
//BOTONES PARA SYSOP
function loadSysop() {
var tmp = '';
tmp += addFastButton('Borrado rápido', 'FBdelete', 'default', 'delete');
tmp += addActionFastButton("Borrar", "fastButtons.readInputButton('Motivo', 'FBdelete', 'delete');");
return tmp;
}
//PLANTILLAS (BOTONES GENERALES)
function loadTemplates() {
var tmp = '';
tmp += addFastButton('SRA', 'FBplant', '{{sinrelevancia|{{subst:CURRENTDAY}}|{{subst:CURRENTMONTHNAME}}}}');
tmp += addFastButton('Wikificar', 'FBplant', '{{wikificar|t={{subst:CURRENTTIMESTAMP}}}}');
tmp += addFastButton('Promocional', 'FBplant', '{{promocional|{{subst:CURRENTDAY}}|{{subst:CURRENTMONTHNAME}}}}');
tmp += addFastButton('Fuente primaria', 'FBplant', '{{fuente primaria|{{subst:CURRENTDAY}}|{{subst:CURRENTMONTHNAME}}}}');
tmp += addFastButton('Referencias', 'FBplant', '{{referencias}}');
tmp += addFastButton('Wikcionario', 'FBplant', '{{wikci}}');
tmp += addFastButton('Wikilibros', 'FBplant', '{{a wikilibros}}');
tmp += addFastButton('Wikiversidad', 'FBplant', '{{a wikiversidad}}');
return tmp;
}
//BOTONES DE VARIAS FUNCIONALIDADES (BOTONES GENERALES)
function loadMisc() {
var tmp = '',
warnMenu = encodeURI("Aviso:\n(nada): Prueba\n0a: Etiqueta\n" + "0b: Estilo\n0c: Spam\n2: Ediciones sin sentido\n2a: Blanqueo\n3: Detente\n4: Última advertencia\n5: Bloqueo");
if(mw.config.get('wgNamespaceNumber') !== 3) {
return tmp;
}
tmp += addActionFastButton("Advertencia", "fastButtons.readInputButton(\'" + warnMenu + "\','FBwarn');");
return tmp;
}
//*********************************************************************
//Añadir los botones
//*********************************************************************
function iniciar() {
//Extraer datos de la página
var numGruposDeUsuario = mw.config.get('wgUserGroups').length;
for (var i = 0; i < numGruposDeUsuario; i++) {
if (mw.config.get('wgUserGroups')[i] == "sysop") {
fastButtons.isSysop = true;
break;
}
}
fastButtons.PAGENAME = encodeURI(mw.config.get('wgPageName'));
if (fastButtons.PAGENAME.match("&")) {
fastButtons.PAGENAME = fastButtons.PAGENAME.replace("&", "%26");
}
fastButtons.wikiURL = fastButtons.wikiURL + fastButtons.PAGENAME + "&action=";
if (mw.config.get('wgCanonicalNamespace') != "Special") {
//Botones de destruir. Sólo aparecen a no-bibliotecarios.
if (fastButtons.isSysop == false) {
if (typeof botonesNoSysop == 'function') {
tmp = botonesNoSysop();
} else {
tmp = loadNoSysop();
}
if (tmp != '') {
fastButtons.FBList = fastButtons.FBList + 'Destruir: ' + tmp + '<br>';
}
} else { //Botones para bibliotecarios
if (typeof botonesSysop == 'function') {
tmp = botonesSysop();
} else {
tmp = loadSysop();
}
if (tmp != '') {
fastButtons.FBList = fastButtons.FBList + 'Sysop: ' + tmp + '<br>';
}
}
//Plantillas. Aparecen a todos los usuarios.
if (typeof botonesPlantillas == 'function') {
tmp = botonesPlantillas();
} else {
tmp = loadTemplates();
}
if (tmp != '') {
fastButtons.FBList = fastButtons.FBList + 'Plantillas: ' + tmp + '<br>';
}
//Otros. Aparecen a todos los usuarios.
if (typeof botonesOtros == 'function') {
tmp = botonesOtros();
} else {
tmp = loadMisc();
}
if (tmp != '') {
fastButtons.FBList = fastButtons.FBList + 'Otros: ' + tmp;
}
} else {
if (fastButtons.isSysop == true) {
if (typeof botonesBloqueo == 'function') {
tmp = botonesBloqueo();
} else {
tmp = addBlockFastButton();
}
if (tmp != '') { //El <br> de más es porque el botón es peligroso y aparece muy pegado a las demás opciones
fastButtons.FBList = fastButtons.FBList + '<br>Bloqueo: ' + tmp;
}
}
}
}
/* Mostrar los botones en la página */
$(function () {
iniciar();
if ($('#contentSub').html() != '') {
$('#contentSub').html($('#contentSub').html() + '<br>');
}
$('#contentSub').html($('#contentSub').html() + fastButtons.FBList);
if (mw.util.getParamValue('FBdest') !== null) {
var plantilla = mw.util.getParamValue('FBdest');
addTemplate("{{destruir|1=" + plantilla + "}}", "Destruir: " + plantilla);
} else if (mw.util.getParamValue('FBplant') !== null) {
var plantilla = mw.util.getParamValue('FBplant');
addTemplate(plantilla, "Plantilla: " + plantilla);
} else if (mw.util.getParamValue('FBplagio') !== null) {
var url = mw.util.getParamValue('FBplagio');
addTemplate('{{plagio|1=' + url + '|2=--~~~~}}', "Plagio desde " + url);
} else if (mw.util.getParamValue('FBdelete') !== null) {
var motivo = mw.util.getParamValue('FBdelete');
if (motivo !== 'default') {
$('#wpReason').val(motivo);
}
$('#deleteconfirm').submit();
} else if (mw.util.getParamValue('FBwarn') !== null) {
var warning = mw.util.getParamValue('FBwarn');
addTemplateEnd('{{subst:prueba' + decodeURI(warning) + '}} --~~~~', 'Aviso al usuario');
} else if (mw.util.getParamValue('FBblock') !== null) {
$('#mw-input-wpExpiry').val("31 hours");
$('#mw-input-wpReason').val('[[WP:VN|Vandalismo de páginas]]');
$('.visualClear').submit();
}
});
})(); // Fin de función anónima
} //fin de chequeo
//</nowiki>