MediaWiki:Gadget-tradLink.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
ForeignApi
Validazione lingue via sitematriz
Riga 55:
label: 'Elenco delle lingue da utilizzare per il tool TradLink'
} );
 
function submitHandler() {
var lingue = self.fields.map( function( f ) {
return f.fieldWidget.getValue().trim();
} ).join();
mw.cookie.set( cookieName, lingue, 20 * 365 * 24 * 60 * 60 * 1000 );
optDialog.close();
}
 
var submitButton = new OO.ui.ButtonWidget(
{ label: 'Imposta' }
).on( 'click', submitHandlersubmitDialogHandler );
var cancelButton = new OO.ui.ButtonWidget(
{ label: 'Annulla' }
Riga 90 ⟶ 82:
windowManager.addWindows( [ optDialog ] );
windowManager.openWindow( optDialog );
}
 
function submitDialogHandler() {
new mw.Api().get( {
action: "sitematrix",
smtype: "language",
smlangprop: "code|site",
smsiteprop: "url",
smlimit: 5000,
format: "json"
} ).done( function ( data ) {
var lingue = self.fields.map( function( f ) {
return f.fieldWidget.getValue().trim();
} ).join();
 
var filteredMatrix = {};
for ( var i in data.sitematrix ) {
var siteData = data.sitematrix[i];
if ( lingue.indexOf( siteData.code ) > -1 ) {
filteredMatrix[siteData.code] = siteData;
}
}
for ( var j in lingue ) {
var code = lingue[j];
if ( code === 'it' ) {
OO.ui.alert( 'Il codice "it" non può essere usato' );
return;
}
if ( !( code in filteredMatrix ) ) {
OO.ui.alert( 'Codice lingua non riconosciuto: ' + code );
return;
}
var found = false;
for ( var s in filteredMatrix[code] ) {
if ( filteredMatrix[code][s].url.indexOf( '.wikipedia.org' ) > -1 ) {
found = true;
break;
}
}
if ( !found ) {
OO.ui.alert( 'Non esiste una Wikipedia nella seguente lingua: ' + code );
return;
}
}
 
mw.cookie.set( cookieName, lingue.join(), 20 * 365 * 24 * 60 * 60 * 1000 );
optDialog.close();
} ).fail( function ( e ) {
console.error( 'Impossibile ottenere sitematrix: ' + e );
} );
}