MediaWiki:Gadget-nav-requisiti.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
m mw.util.addCSS
aggiungo versione 2 che conta anche gli edit cancellati, vedi discussione
Riga 16:
// la finestra di dialogo per la ricerca delle informazioni utente
var searchDialog;
var searchDialog2;
 
/**
Line 54 ⟶ 55:
} ).done( function ( data ) {
contribsHandler( data.query.usercontribs );
} );
}
 
function getUserContribs2( user, endDateObject, contribsHandler ) {
var contribs = {};
var thirtyDays = 30 * 24 * 60 * 60 * 1000, sixtyDays = 60 * 24 * 60 * 60 * 1000;
var basePath = 'https://xtools.wmcloud.org/api/user/simple_editcount/it.wikipedia/' + user + '/all//';
$.when(
$.get( basePath + endDateObject.toISOString().slice( 0, 10 ) ),
$.get( basePath + new Date( endDateObject.getTime() - sixtyDays ).toISOString().slice( 0, 10 ) )
).then( function ( data1, data2 ) {
contribs.d1 = data1[0].live_edit_count + data1[0].deleted_edit_count;
contribs.d2 = data2[0].live_edit_count + data2[0].deleted_edit_count;
if ( contribs.d2 > 0 ) {
return $.Deferred().resolve();
} else {
return $.get(
basePath + new Date( endDateObject.getTime() - thirtyDays ).toISOString().slice( 0, 10 )
);
}
} ).then( function ( data3 ) {
if ( data3 ) {
contribs.d3 = data3.live_edit_count + data3.deleted_edit_count;
}
contribsHandler( contribs );
} );
}
Line 93 ⟶ 119:
info += '50esima modifica: ' + ( contribs.length >= 50 ? parseTimestamp( contribs[49].timestamp ) : totcontribs ) + '<br/>';
info += '500esima modifica: ' + ( contribs.length >= 500 ? parseTimestamp( contribs[499].timestamp ) : totcontribs );
return info;
}
 
function formatResult2( registration, contribs ) {
var info = '';
info += 'Registrazione: ' + (registration ? parseTimestamp( registration ) : 'pre 2006') + '<br/>';
info += 'Almeno una modifica 30 giorni prima: ' + ( contribs.d2 > 0 || contribs.d3 > 0 ? '✓' : '✗' ) + '<br/>';
info += 'Almeno una modifica 60 giorni prima: ' + ( contribs.d2 > 0 ? '✓' : '✗' ) + '<br/>';
info += '50esima modifica: ' + ( contribs.d1 >= 50 ? '✓' : '✗' ) + '<br/>';
info += '500esima modifica: ' + ( contribs.d1 >= 500 ? '✓' : '✗' );
return info;
}
Line 112 ⟶ 148:
} else {
searchDialog.resultLabel.setLabel( $( '<p>L\'utente ' + user + ' non &egrave; registrato.</p>' ) );
}
} );
}
}
 
function searchHandler2() {
var user = $.trim( searchDialog2.textInput.getValue() );
var date = $.trim( searchDialog2.dateInput.getValue() );
var dateObject = new Date( date );
if ( !user ) {
searchDialog2.resultLabel.setLabel( $( '<p>Il nome utente &egrave; obbligatorio.</p>' ) );
} else if ( !date || !/^\d{4}\-\d\d\-\d\d$/.test( date ) || isNaN( dateObject ) ) {
searchDialog2.resultLabel.setLabel( $( '<p>Inserire una data valida.</p>' ) );
} else {
searchDialog2.resultLabel.setLabel( 'Ricerca in corso...' );
getUserInfo( user, function ( userInfo ) {
if ( userInfo.userid ) {
getUserContribs2( user, dateObject, function ( contribs ) {
searchDialog2.resultLabel.setLabel( $( '<p>' + formatResult2( userInfo.registration, contribs ) + '</p>' ) );
} );
} else {
searchDialog2.resultLabel.setLabel( $( '<p>L\'utente ' + user + ' non &egrave; registrato.</p>' ) );
}
} );
Line 159 ⟶ 217:
this.panelLayout = new OO.ui.PanelLayout( { padded: true, expanded: false } );
this.panelLayout.$element.append( textInputLayout.$element, resultLabel.$element, buttons.$element );
this.$body.append( this.panelLayout.$element );
};
SearchDialog.prototype.getBodyHeight = function () {
return this.panelLayout.$element.outerHeight( true );
};
return new SearchDialog( {
size: 'small'
} );
}
 
function buildSearchDialog2() {
var style = '.grv-container { height: 100px; margin: .4em 0 .6em }' +
'.grv-container-button { width: 100%; text-align: center }';
mw.util.addCSS( style );
function SearchDialog( config ) {
SearchDialog.parent.call( this, config );
}
OO.inheritClass( SearchDialog, OO.ui.Dialog );
SearchDialog.static.name = 'searchDialog';
SearchDialog.prototype.initialize = function () {
SearchDialog.parent.prototype.initialize.call( this );
var resultLabel = new OO.ui.LabelWidget( {
classes: [ 'grv-container' ],
label: ' '
} );
var textInput = new mw.widgets.UserInputWidget();
textInput.on( 'enter', searchHandler );
var textInputLayout = new OO.ui.FieldLayout( textInput, {
label: 'Nome utente:',
align: 'top'
} );
var dateInput = new OO.ui.TextInputWidget( {
label: 'Formato YYYY-MM-DD'
} );
var dateInputLayout = new OO.ui.FieldLayout( dateInput, {
label: 'Data inizio votazione:',
align: 'top'
} );
var searchButton = new OO.ui.ButtonWidget( {
label: 'Cerca',
} ).on( 'click', searchHandler2 );
var cancelButton = new OO.ui.ButtonWidget( {
label: 'Annulla'
} ).on( 'click', function () {
searchDialog2.close();
} );
var buttons = new OO.ui.HorizontalLayout( {
items: [ searchButton, cancelButton ],
classes: [ 'grv-container-button' ],
align: 'top'
} );
this.textInput = textInput;
this.dateInput = dateInput;
this.resultLabel = resultLabel;
this.panelLayout = new OO.ui.PanelLayout( { padded: true, expanded: false } );
this.panelLayout.$element.append( textInputLayout.$element, dateInputLayout.$element, resultLabel.$element, buttons.$element );
this.$body.append( this.panelLayout.$element );
};
Line 171 ⟶ 285:
$( function () {
var windowManager;
var windowManager2;
var portletLink = mw.util.addPortletLink( 'p-navigation', '#', 'Verifica requisiti di voto' );
var portletLink2 = mw.util.addPortletLink( 'p-navigation', '#', 'Verifica requisiti di voto v2' );
$( portletLink ).click( function ( event ) {
event.preventDefault();
Line 187 ⟶ 303:
.fail( function () {
console.error( 'Impossibile avviare l\'accessorio "requisiti".' );
} );
} );
$( portletLink2 ).click( function ( event ) {
event.preventDefault();
mw.loader.using( [ 'mediawiki.api', 'oojs-ui-core', 'oojs-ui-widgets',
'oojs-ui-windows', 'mediawiki.widgets.UserInputWidget' ] )
.done( function () {
if ( !searchDialog2 ) {
searchDialog2 = buildSearchDialog2();
windowManager2 = new OO.ui.WindowManager();
$( 'body' ).append( windowManager2.$element );
windowManager2.addWindows( [ searchDialog2 ] );
}
windowManager2.openWindow( searchDialog2 );
} );
} );