MediaWiki:Gadget-VFonLine.js: differenze tra le versioni
Contenuto cancellato Contenuto aggiunto
m opzioni jshint |
utilizzo di OOjs UI al posto di jQuery UI |
||
Riga 1:
/**
* Gadget-VFonLine.js
* Aggiunge a Speciale:OsservatiSpeciali e Speciale:UltimeModifiche le funzionalità
* dette 'Vandal Fighter on Line' (VFOL). *
* http://it.wikipedia.org/w/index.php?title=Wikipedia:Monobook.js/VFonLine.js&oldid=27133290
* http://it.wikipedia.org/w/index.php?title=MediaWiki:Gadget-VFonLine.js&oldid=38709825
*
* @author
*/
/* global mediaWiki, jQuery, OO */
( function ( mw, $ ) {
Riga 15:
// Per retrocompatibilità con il vecchio gadget, whitelist e blacklist sono contenute in due cookie.
// Le operazioni sui cookie sono isolate
/**
* Restituisce il contenuto del cookie 'wikiVFOL', che può valere 'abilitato' o 'disabilitato'.
*
* @return {string} Il contenuto del cookie 'wikiVFOL'
*/
function getState() {
return $.cookie( 'wikiVFOL' ) === 'abilitato' ? 'abilitato' : 'disabilitato';
}
/**
* Salva la stringa 'abilitato' o 'disabilitato' nel cookie 'wikiVFOL'.
*
* @param {string} state - la stringa da salvare.
*/
function setState( state ) {
$.cookie( 'wikiVFOL', state, { expires: 365, path: '/' } );
}
/**
* Restituisce il contenuto dei cookie per la whitelist e la blacklist.
*
* @param {string} id - L'identificativo per scegliere whitelist (vfol1) o blacklist(vfol2)
* @return {string} Il contenuto del cookie
*/
function getList( id ) {
var content = $.cookie( id === 'vfol1' ? 'wikiWhiteList' : 'wikiBlackList' );
Line 29 ⟶ 46:
}
/**
* Salva la whitelist o la blacklist nei relativi cookie.
*
* @param {string} id - L'identificativo per scegliere whitelist (vfol1) o blacklist(vfol2)
* @param {string} content - Il contenuto del cookie
*/
function setList( id, content ) {
$.cookie( id === 'vfol1' ? 'wikiWhiteList' : 'wikiBlackList',
Line 34 ⟶ 57:
}
/**
* Crea la finestra di dialogo per modificare whitelist e blacklist.
*
* @return {Object} L'oggetto derivato da OO.ui.Dialog che rappresenta la finestra
*/
function buildConfigDialog() {
var style = '.gvf-container-button { width: 100%; text-align: center; margin-top: 10px }';
$( '<style>' ).text( style ).appendTo( 'head' );
function ConfigDialog( config ) {
ConfigDialog.parent.call( this, config );
}
OO.inheritClass( ConfigDialog, OO.ui.Dialog );
ConfigDialog.static.name = 'configDialog';
ConfigDialog.prototype.initialize = function () {
var self = this;
ConfigDialog.parent.prototype.initialize.call( this );
var textInput = new OO.ui.MultilineTextInputWidget( {
} );
var textInputLayout = new OO.ui.FieldLayout( textInput, {
align: 'top'
} );
var okButton = new OO.ui.ButtonWidget( {
label: 'Salva',
} ).on( 'click', function () {
var text = textInput.getValue();
text = text.replace( /^\s*/gm, '' );
text = text.replace( /\s*$/gm, '' );
setList( self.currId, text.replace( /\n/g, '@' ) );
self.close();
} );
var cancelButton = new OO.ui.ButtonWidget( {
label: 'Annulla'
} ).on( 'click', function () {
self.close();
} );
var buttons = new OO.ui.HorizontalLayout( {
items: [ okButton, cancelButton ],
classes: [ 'gvf-container-button' ]
} );
this.textInput = textInput;
this.textInputLayout = textInputLayout;
this.panelLayout = new OO.ui.PanelLayout( { padded: true, expanded: false } );
this.panelLayout.$element.append( textInputLayout.$element, buttons.$element );
this.$body.append( this.panelLayout.$element );
};
ConfigDialog.prototype.getBodyHeight = function () {
return this.panelLayout.$element.outerHeight( true );
};
return new ConfigDialog( {
size: 'small'
} );
}
/**
* Aggiunge o rimuove i portlet link 'Modifica la whitelist' e 'Modifica la blacklist'.
*
* @param {boolean} visible - Se impostato a true aggiunge i portlet link, altrimenti li rimuove
*/
function togglePortletLinks( visible ) {
var configDialog, windowManager;
if ( visible ) {
mw.util.addPortletLink( 'p-tb', '#', 'Modifica la whitelist', 'vfol1',
Line 67 ⟶ 127:
var id = $( this ).attr( 'id' );
event.preventDefault();
mw.loader.using( [ '
configDialog = buildConfigDialog();
windowManager = new OO.ui.WindowManager();
$( 'body' ).append( windowManager.$element );
windowManager.addWindows( [ configDialog ] );
}
configDialog.textInput.setValue( getList( id ).replace( /@/g, '\n' ) );
configDialog.textInputLayout.setLabel( 'VFOL Configurazione ' + ( id === 'vfol1' ? 'whitelist' : 'blacklist' ) );
configDialog.currId = id;
windowManager.openWindow( configDialog );
} );
} );
Line 76 ⟶ 145:
}
/**
* Gestore del click sui link "wl" e "bl".
*
* @param {string} username - L'utente sul quale si è effettuato il click
* @param {string} action - La stringa su cui si è cliccato (+wl, -wl, +bl o -bl)
*/
function anchorHandler( username, action ) {
var id = action.substring( 1, 3 ) === 'wl' ? 'vfol1' : 'vfol2';
var idx = $.inArray( username, users );
if ( action.charAt( 0 ) === '+' && idx === -1 ) {
users.unshift( username );
Line 94 ⟶ 167:
}
/**
* Funzione di utilità per editWatchlist, modifica una entry
* in OsservatiSpeciali o UltimeModifiche.
*
* @param {string} $el - L'elemento jQuery da modificare
* @param {string[]} usersWl - Utenti nella whitelist
* @param {string[]} usersBl - Utenti nella blacklist
* @param {string} color - Colore da applicare alla riga, per le modifiche raggruppate
* @return {string} Il colore applicato alla riga, per le modifiche raggruppate
*/
function editEntry( $el, usersWl, usersBl, color ) {
var $wl, $bl, inWl, inBl, username;
Line 110 ⟶ 192:
$wl = $( '<a>' ).attr( 'href', '#' ).text( inWl ? '-wl' : '+wl' );
$bl = $( '<a>' ).attr( 'href', '#' ).text( inBl ? '-bl' : '+bl' );
$.each( [ $wl, $bl ], function ( i, el ) {
el.click( function () {
username = $( this ).parent( 'span' ).prev( 'a.mw-userlink' ).text();
Line 122 ⟶ 204:
}
/**
* Modifica la pagine Speciale:OsservatiSpeciali o Speciale:UltimeModifiche.
*/
function editWatchlist() {
var usersWl
$( 'h4' ).each( function () {
// visualizzazione avanzata con modifiche raggruppate: gruppo di modifiche
Line 133 ⟶ 216:
$( this ).find( 'tr:not( :first )' ).each( function () {
var color = editEntry( $( this ), usersWl, usersBl );
edits[ color ] = true;
} );
$( this ).find( 'tr:first' ).each( function () {
editEntry( $( this ), usersWl, usersBl,
edits[ '#ffcccc' ] ? '#ffcccc' :
edits[ '#ffffbb' ] ? '#ffffbb' :
!edits[ '' ] ? '#ccffcc' : '' );
} );
} );
Line 154 ⟶ 237:
$( function () {
// setup portlet link
var state = getState();
var portletLink = mw.util.addPortletLink( 'p-tb', '#', 'VFonLine ' + state, 'vfol' );
$( portletLink ).click( function ( event ) {
event.preventDefault();
Line 166 ⟶ 248:
} );
togglePortletLinks( state === 'abilitato' );
// modifica watchlist
if ( $.inArray( mw.config.get( 'wgPageName' ), [ 'Speciale:OsservatiSpeciali', 'Speciale:UltimeModifiche' ] ) !== -1 &&
state === 'abilitato' ) {
editWatchlist();
|