MediaWiki:WikidataLink.js

Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
/*
Collegamento all'elemento di Wikidata
*/
function wikidataLink () {
        var wiki = 'itwiki'; //codice di lingua della tua wiki
        
        var namespace = mw.config.get( 'wgCanonicalNamespace' );
        // modifico per evitare l'aggiunta del  namespace Autore
        if( (namespace === '' || namespace === "Autore")&& $("#t-wikibase").length==0 ) {
                var page = mw.config.get( 'wgTitle' );
        } else { if ( namespace === "Project" && mw.config.get( 'wgTitle' ).indexOf("Autore citato/")===0) {
                var page=  mw.config.get( 'wgTitle' ).replace("Autore citato/","");
               } else {
                       var page = namespace + ':' + mw.config.get( 'wgTitle' );
                      }
        }
 
        $.ajax( {
                url: '//www.wikidata.org/w/api.php',
                data: {
                        'format': 'json',
                        'action': 'wbgetentities',
                        'sites': wiki,
                        'titles': page,
                        'language': mw.config.get( 'wgPageContentLanguage' )
                },
                dataType: 'jsonp',
                success: function( data ) {
                        if( data.success ) {
                                for( var i in data.entities ) {
                                        if( i != -1 ) {
                                                $("body").data("wikidata",data);
                                                $("body").data("wikidataID",data.entities[i].title.toLowerCase());
                                                mw.util.addPortletLink( 'p-tb', '//www.wikidata.org/wiki/' + data.entities[i].title, 'Wikidata' );
                                        }
                                }       
                        }
                }
        } );
} 

$(document).ready(function () {wikidataLink();});