MediaWiki
Difference between revisions of "Common.js"
(Page créée avec « // Replace Wikidata IDs with their [label, description] $( '.wb-external-id' ).each( function() { if ( $( this ).attr( 'href' ).lastIndexOf( 'https://www.wikidata.org'... ») |
m |
||
Line 22: | Line 22: | ||
description = entity.descriptions[ lang ].value; | description = entity.descriptions[ lang ].value; | ||
− | node.html( '< | + | node.html( label + ' <i>(' + node.text() + ')</i><br><small>' + description + '</small>' ) |
} ); | } ); | ||
} | } | ||
} ); | } ); |
Revision as of 15:13, 4 April 2018
// Replace Wikidata IDs with their [label, description]
$( '.wb-external-id' ).each( function() {
if ( $( this ).attr( 'href' ).lastIndexOf( 'https://www.wikidata.org', 0 ) === 0 ) {
var wikidataApi = new mw.ForeignApi( 'https://www.wikidata.org/w/api.php', {
anonymous: true,
parameters: { 'origin': '*' },
ajax: { timeout: 10000 }
} ),
lang = mw.config.get( 'wgUserLanguage' ),
node = $( this );
wikidataApi.get( {
'action': 'wbgetentities',
'format': 'json',
'ids': node.text(),
'props': 'labels|descriptions',
'languages': lang,
'languagefallback': 1,
'origin': '*'
} ).then( function( data ) {
var entity = data.entities[ node.text() ],
label = entity.labels[ lang ].value,
description = entity.descriptions[ lang ].value;
node.html( label + ' <i>(' + node.text() + ')</i><br><small>' + description + '</small>' )
} );
}
} );