MediaWiki:Gadget-SimilarTitles.js
Vai alla navigazione
Vai alla ricerca
Nota: Dopo aver salvato le preferenze, perché i cambi abbiano effetto, devi bypassare la cache del tuo browser. Mozilla / Firefox / Safari: tieni premuto Shift mentre clicchi Reload, o premi Ctrl-Shift-R (Cmd-Shift-R per Apple Mac); Google Chrome: premi Ctrl o Shift mentre clicchi F5; IE: premi Ctrl mentre clicchi Refresh, o premi Ctrl-F5; Konqueror:: clicca semplicemente il pulsante di Reload, o premi F5; se usi Opera devi cancellare completamente la chache nel menu Tools→Preferences.
/** * 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 conf = mw.config.get( [ 'wgAction', 'wgArticleId', 'wgNamespaceNumber', 'wgPageName', ] ); if( 'edit' !== conf.wgAction || 0 !== conf.wgNamespaceNumber || 0 !== conf.wgArticleId ) { return; } var data = { action: 'opensearch', search: conf.wgPageName, profile: 'normal', limit: window.similarTitlesOpts.maxResults }; mw.loader.using( 'mediawiki.api', 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 ); } } ); } ); } );