MediaWiki:ABFeasySubmit.js
Apariencia
Nota: Después de guardar, debes refrescar la caché de tu navegador para ver los cambios. Internet Explorer: mantén presionada Ctrl mientras pulsas Actualizar. Firefox: mientras presionas Mayús pulsas el botón Actualizar, (o presiona Ctrl-Shift-R). Los usuarios de Google Chrome y Safari pueden simplemente pulsar el botón Recargar. Para más detalles e instrucciones acerca de otros exploradores, véase Ayuda:Cómo limpiar la caché.
/**
* HTML error reporting interface for abusefilter.
*
* @author [[User:Steinsplitter]], [[User:Perhelion]], [[User:Rotpunkt]]
* Based on the following script by [[:it:Utente:Rotpunkt]]: https://it.wikipedia.org/w/index.php?title=MediaWiki:Gadget-Form-valutazione-enc.js&oldid=92052404
* Adopted for eswiki by [[User:SRuizR]] from https://commons.wikimedia.org/w/index.php?title=MediaWiki:ABFeasySubmit.js&oldid=515117740
* <nowiki>
*/
/* eslint indent:["error","tab",{"outerIIFEBody":0}] */
/* global mediaWiki, jQuery */
( function ( mw, $ ) {
'use strict';
// Page which contains the form
var formPage = 'Wikipedia:Filtro de ediciones/Portal/Archivo/Reporte de falsos positivos/Formulario',
// Page where the report should be submitted
encPage = 'Wikipedia:Filtro de ediciones/Portal/Archivo/Reporte de falsos positivos/Actual',
// Element configuration
elements = {
'gmc-abfpage': {
tipo: 'textbox',
placeholder: 'Pagename',
msg: 'Por favor escribe el nombre de la página donde tuviste el problema (solo el nombre de la página, no escribas la URL)'
},
'gmc-sandbox': {
tipo: 'textarea',
msg: '¿Qué intentabas hacer y qué motivo te dio el sistema para impedir tu edición?'
},
'gmc-crea': {
tipo: 'button',
text: 'Enviar reporte'
}
},
user; // Sometimes REVISIONUSER is exposed to a server replag, so use only as fallback
if ( mw.config.get( 'wgPageName' ) !== formPage /* && mw.config.get( 'wgPageName' ) !== formPage + '/Sandbox'*/ ) { return; }
// enable report from
$( '#enableo2specialform' ).show();
// remove "old" buttons
$( '#olderportbutton' ).hide();
// add
$( '#jsabfformworks' ).show();
$( '#firstHeading, #siteSub, #catlinks, .catlinks' ).hide();
/**
* View the MSG
* @param {string} msg - Msg to display.
* @param {boolean} spinner - If true start spinner.
* @param {string} url - Url string
*/
function showMessage( msg, spinner, url ) {
var $dialog = $( '#gmc-dialog' );
$dialog.empty().append( msg );
if ( spinner ) {
$dialog.append( '<br><br>', $.createSpinner( { size: 'large', type: 'block' } ), '<br>' );
}
$dialog.dialog( {
title: 'Reportar un problema',
width: 340,
modal: true,
buttons: {
Ok: function () {
$( this ).dialog( 'close' );
if ( url ) {
window.location.href = url;
}
}
}
} );
}
/**
* Resolve the CAPTCHA.
* @param {string} captchaUrl - Url of the image.
* @param {function} inputHandler - Input field.
*/
function showCaptcha( captchaUrl, inputHandler ) {
var $dialog = $( '#gmc-dialog' ).empty(),
$div = $( '<div>', { style: 'text-align:center' } ),
$img = $( '<img>', { src: captchaUrl } ),
$captchaWord = $( '<input>', { type: 'text', size: 40 } );
$div.append( $img, '<br><br>', $captchaWord ).appendTo( $dialog );
$dialog.dialog( {
title: 'Por favor resuelva el Captcha:',
modal: true,
buttons: {
Ok: function () {
$( this ).dialog( 'close' );
inputHandler( $captchaWord.val() );
},
Annulla: function () {
$( this ).dialog( 'close' );
}
}
} );
}
/**
* Create the new request.
* @param {string} abfpage - Pagename.
* @param {string} sandbox - Text 1
* @param {object} params - additional mw.Api.newSection params
*/
function createRequest( abfpage, sandbox, params ) {
// First check username, because we allow anon
user = mw.config.get( 'wgUserName' ) || user;
if ( !user ) {
// Get anon name as late as possible, as the user could still login on another window.
return new mw.Api().get( { meta: 'userinfo' } ).always( function ( r ) {
if ( r.query && ( r = r.query.userinfo ) ) {
user = r.name;
} else { user = '{{subst:REVISIONUSER}}'; }
createRequest( abfpage, sandbox, params );
} );
}
var text = '{{subst:Reportefalsopositivo|' +
'\n|Nombre del artículo=' + abfpage +
( sandbox ? '\n|Problema encontrado=' + sandbox : '' ) +
'}}\n\n';
showMessage( 'Publicando reporte…', true );
return new mw.Api().newSection( encPage, 'Report by ' + user, text, params )
.done( function ( data ) {
var url, msg;
if ( data && ( data = data.edit ) && ( data = data.captcha ) && data.id && data.url ) {
showCaptcha( data.url, function ( text ) {
createRequest( abfpage, sandbox, {
captchaid: data.id,
captchaword: text
} );
} );
} else {
url = mw.config.get( 'wgArticlePath' ).replace( '$1', encPage + '#footer' );
msg = 'El reporte se ha publicado en:<br>' +
'<a href="' + url + '">' + encPage + '</a><br><br>' +
'Haz clic en OK para ir al reporte.';
showMessage( msg, null, url );
}
} )
.fail( function ( code, data ) {
showMessage( 'Error al crear el reporte: ' + data.error.info );
} );
}
/**
* Section to create the button
*/
function submitHandler() {
var abfpage, sandbox, error;
abfpage = $.trim( $( '#gmc-abfpage' ).val() );
sandbox = $.trim( $( '#gmc-sandbox' ).val() );
if ( !sandbox ) {
$( '#gmc-sandbox' ).focus();
error = elements[ 'gmc-sandbox' ].msg;
}
if ( error ) {
showMessage( 'ERROR: ' + error );
} else {
createRequest( abfpage, sandbox );
}
}
function buildForm() {
// Special warning regarding -logged out- for anons.
if ( mw.user.isAnon() ) {
$( '#userisanon' ).show();
}
// verify that all necessary placeholder elements exist on the page
for ( var id in elements ) {
if ( elements.hasOwnProperty( id ) ) {
if ( !$( '#' + id ).length ) {
mw.log.warn( '[ABFeasySubmit.js]: ' + id + ' not found.' );
return;
}
}
}
// div for the messeges
$( '<div>', { id: 'gmc-dialog' } ).appendTo( 'body' );
// Create the HTML elements
$.each( elements, function ( id, el ) {
var $el = {
checkbox: [ '<input>', { type: 'checkbox' } ],
textbox: [ '<input>', { type: 'text', size: 80 } ],
textarea: [ '<textarea>', { style: 'width:100%; height:100%;' } ],
button: [ '<button>', { text: el.text, 'class': 'mw-ui-button mw-ui-progressive', click: submitHandler } ]
}[ el.tipo ];
$el = $( $el[ 0 ], $el[ 1 ] );
// eaventual attrib placeholders
if ( el.placeholder ) {
$el.attr( 'placeholder', el.placeholder );
}
$el.attr( 'id', id );
$( '#' + id ).replaceWith( $el );
} );
}
$.when( mw.loader.using( [
'jquery.ui',
'jquery.spinner',
'mediawiki.user',
'mediawiki.api'
] ), $.ready ).then( buildForm );
}( mediaWiki, jQuery ) );
// </nowiki>