MediaWiki:Gadget-WikidataTab.js
Ocio: Daspò ver salvà, podaria esare neçesario snetare ła cache dal propio navegadore web par vedare i canbiamenti.
- Firefox / Safari: tegner strucà el boton de łe letare grande Shift e schiciare sora Ricarga, o se nò struca Ctrl-F5 o Ctrl-R (⌘-R so Mac)
- Google Chrome: strucare Ctrl-Shift-R (⌘-Shift-R so on Mac)
- Internet Explorer / Edge: tegner strucà el boton Ctrl e schiciare so Ajorna, o sinò Ctrl-F5
- Opera: Va in tel Menu → Inpostasion (Opera → Prefarense so on Mac) e pò in Privacy & sicuresa → Sneta dati del navegadore → Imajini e file in te ła cache.
// Gadget-WikidataTab
if ($.inArray(mw.config.get('wgNamespaceNumber'),[0,4,10,12,14,100])+1)
$(function($) {
var translate = {
'vec': {
notfound: "Item de Wikidata no catà",
nolabel: "(Targheta mancante)",
nodescription: "(Nisuna descrision)"
},
'it': {
notfound: "Item de Wikidata no catà",
nolabel: "(Targheta mancante)",
nodescription: "(Nisuna descrision)"
},
'en': {
notfound: "Wikidata item not found",
nolabel: "(No label)",
nodescription: "(no description given)"
}
},
pagename=mw.config.get('wgPageName').replace(/_/g, " ");
$.ajax({
url:'//www.wikidata.org/w/api.php',
data:{
'format':'json',
'action':'wbgetentities',
'sites':mw.config.get('wgDBname'),
'titles':pagename,
'props':'info|labels|descriptions|aliases',
'languages':mw.config.get('wgPageContentLanguage')
},
dataType:'jsonp',
success: function(data) {
var d=$("<li>");
$("#p-views ul").append(d);
if (data.success){
var lang=mw.config.get('wgPageContentLanguage'), m=translate[lang] || translate.vec;
for (var i in data.entities) {
if (i == -1) {
d.append(
$("<span>")
.append(
$("<a>")
.attr("href","//www.wikidata.org/wiki/Special:CreateItem?setlang=vec&label="+pagename+"&site=vecwiki&page="+pagename)
.attr("title", m.notfound)
.append(
$("<img>")
.attr("src","//upload.wikimedia.org/wikipedia/commons/e/e8/Wikidata-favicon.png")
.attr("style","margin-bottom: 5px; opacity:0.3; filter:alpha(opacity=30);")
)
)
);
}else{
var item=data.entities[i], i=0, aliases=[];
try {
for (; i < item.aliases[lang].length; i++) {
aliases.push(item.aliases[lang][i].value);
}
}catch(e){}
d.append(
$("<span>")
.append(
$("<a>")
.attr("href", "//www.wikidata.org/wiki/" + item.title)
.attr("title", ((item.labels && item.labels[lang]) ? item.labels[lang].value : m.nolabel) + " (" + item.title + "):" + ((item.descriptions && item.descriptions[lang]) ? item.descriptions[lang].value : m.nodescription))
.append(
$("<img>")
.attr("src", "//upload.wikimedia.org/wikipedia/commons/e/e8/Wikidata-favicon.png")
.attr("style", "margin-bottom: 5px;")
)
)
);
} // else
} // for
} // if success
} // succeess function
}); // ajax
}); // ready
if(((mw.config.get('wgNamespaceNumber') != 2) || (mw.config.get('wgNamespaceNumber') != 3)) && (mw.config.get('wgNamespaceNumber') != -1)) {
location.search.indexOf( 'printable=yes' ) === -1
&& mw.config.get( 'wgPageContentModel' ) !== 'wikibase-item'
&& mw.config.get( 'wgPageContentModel' ) !== 'wikibase-property'
&& mw.config.get( 'wgPageContentModel' ) !== 'wikibase-lexeme'
&& mw.config.get( 'wgPageContentModel' ) !== 'flow-board'
&& mw.loader.using( [ 'mediawiki.jqueryMsg', 'mediawiki.user' ] ).done( function () {
var translate = {
'vec': {
notfound: "Item Wikidata no catà.",
intro: "Wikidata: ",
nolabel: "(Targheta mancante)",
nodescription: "Nisuna descrision",
aliases: "{{PLURAL:$1|El alias|I alias}}: ",
noaliases: "Vodo"
},
'it': {
notfound: "Item Wikidata no catà.",
intro: "Wikidata: ",
nolabel: "(Targheta mancante)",
nodescription: "Nisuna descrision",
aliases: "{{PLURAL:$1|El alias|I alias}}: ",
noaliases: "Vodo"
},
'en': {
notfound: "Wikidata item not found.",
intro: "Wikidata: ",
nolabel: "(No label)",
nodescription: "no description given",
aliases: "{{PLURAL:$1|Alias|Aliases}}: ",
noaliases: "None"
},
};
var namespace = mw.config.get( 'wgNamespaceNumber' ),
lang = mw.config.get( 'wgContentLanguage' ),
page = ( namespace -= ( namespace > 0 && namespace % 2 ) ) === 0
? mw.config.get( 'wgTitle' )
: mw.config.get( 'wgFormattedNamespaces' )[ namespace ] + ':' + mw.config.get( 'wgTitle' );
namespace !== 2 && namespace !== -1 && $.ajax( {
url: '//www.wikidata.org/w/api.php',
data: {
'format': 'json',
'action': 'wbgetentities',
'sites': mw.config.get( 'wgDBname' ),
'titles': page,
'props': 'info|labels|descriptions|aliases',
'languages': lang,
'maxage': mw.config.get( "wgUserName" ) === null ? 900 : 30,
'smaxage': mw.config.get( "wgUserName" ) === null ? 900 : 30,
//'maxlag': 1
},
dataType: 'jsonp',
cache: true
} )
.done( function ( data ) {
if ( data.success ) {
$( function () {
var $d = $( '<div>' ).addClass( 'WDI-box' ),
userLang = mw.config.get( 'wgUserLanguage' ),
m = Object.prototype.hasOwnProperty.call( translate, userLang ) ? translate[ userLang ] : translate.en;
mw.messages.set( 'WDI-aliases', m.aliases );
$.each( data.entities, function ( entity, item ) {
if ( entity == -1 ) {
$d.append( $( '<a>' ).attr( 'href',
'//www.wikidata.org/wiki/Special:NewItem?site=' +
mw.config.get( 'wgDBname' ) +
'&page=' + encodeURIComponent( page ) +
'&label=' + encodeURIComponent( page ) +
'&lang=' + lang
).text( m.notfound ) );
} else {
var label = item.labels[ lang ] && item.labels[ lang ].value,
description = item.descriptions[ lang ] && item.descriptions[ lang ].value,
aliases = $.map( item.aliases[ lang ] || [], function ( alias ) {
return alias.value;
} );
if ( window.WDIlimitaliases && WDIlimitaliases < aliases.length ){
for( ; WDIlimitaliases < aliases.length; aliases.pop() ) ;
aliases.push( '...' );
}
$d.append(
$( '<a>' )
.attr( 'href', '//www.wikidata.org/wiki/' + item.title )
.text( m.intro + ( label || m.nolabel ) ),
' – ',
$( '<a>' )
.attr( 'href', '//www.wikidata.org/wiki/' + item.title )
.text( item.title ),
':',
$( '<span>' ).text( ' ' ),
$( '<q>' )
.text( description || m.nodescription )
.addClass( description ? 'WDI-desc' : 'WDI-desc WDI-nodesc' ),
'<b> · ',
$( '<span>' ).text( mw.msg( 'WDI-aliases', aliases.length ) + ( aliases.join( '؛ ' ) || m.noaliases ) )
);
}
});
$d.appendTo( '#contentSub' );
var ss=document.getElementById("contentSub");
ss.style.padding="5px";
ss.style.border="1px dotted #fafafa";
ss.style.background="#fafafa";
ss.style.margin="0px";
ss.style.marginTop="5px";
});
}
} );
});
}
// End Gadget-WikidataTab ----------------------------------------------------