MediaWiki:Gadget-SimilarTitles-core.js
Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.
Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.
/**
* Similar titles
*
* When creating a new page, it shows a list of similar titles, to avoid duplicates.
*
* @author [[w:it:Utente:Valerio Bozzolan]] and contributors
* @license [[GNU GPL v3+]] or [[CC BY SA 4.0]] at your opinion
*/
window.similarTitlesOpts = {
// Where to put the tip
container: '#contenitore-titoli-simili', // Vedi [[Template:Pagina inesistente]]
// Header of the tip
preContainer: "<p><b>Verifica però che le seguenti voci non siano quello che stavi cercando:</b></p>",
// Footer of the tip
postContainer: "",
// Max length of the page quote
maxQuote: 100,
// How many similar pages to be shown
maxResults: 5
};
$( function () {
var data = {
action: 'opensearch',
search: mw.config.get( 'wgPageName' ),
profile: 'normal',
limit: window.similarTitlesOpts.maxResults
};
mw.loader.using( 'mediawiki.api' )
.done( function () {
( new mw.Api() ).get( data )
.done( function ( results ) {
var s = results[0];
var titles = results[1];
var quotes = results[2];
var urls = results[3];
if( titles.length ) {
$container = $( window.similarTitlesOpts.container );
$container.append( window.similarTitlesOpts.preContainer );
for( var i = 0; i < titles.length; i++ ) {
var title = titles[ i ];
var quote = quotes[ i ];
var url = urls [ i ];
$p = $('<p>').append(
$('<a>').attr( 'href', url )
.text( title )
.attr( 'target', '_blank' )
);
if( quote ) {
var quoteLimit = window.similarTitlesOpts.maxQuote;
if( quote.length > quoteLimit ) {
quote = quote.substring( 0, quoteLimit) + '…';
}
$p.append( ' – «' + quote + '»' );
}
$container.append( $p );
}
$container.append( window.similarTitlesOpts.postContainer );
}
} )
.fail( function ( e ) {
mw.log.error( 'SimilarTitles: errore nella chiamata API: ' + e );
} );
} )
.fail( function () {
mw.log.error( 'Impossibile avviare l\'accessorio SimilarTitles.' );
} );
} );