Page MenuHomePhabricator
Paste P8820

Fixed User:FelixReimann/taxobox.js
ActivePublic

Authored by alaa_wmde on Jul 29 2019, 10:32 PM.
/* <nowiki>
*
* taxobox.js by [[User:FelixReimann]] with help from [[User:Ricordisamoa]]
* based on [[User:Ricordisamoa/Wikispecies.js]]
*/
$(document).ready(function(){
mw.hook( 'wikibase.entityPage.entityLoaded' ).add( function( entity ) {
// only on entities, not properties or other namespaces
if ( mw.config.get('wgNamespaceNumber') != 0 ) return ;
if ( mw.config.get('wgAction') != 'view' ) return ;
if( typeof entity.claims=='undefined' ) return;
if( Object.keys( entity.claims ).indexOf( 'P225' ) != -1 ){// 'taxon name' is present
var language = mw.user.options.get('language');
var count = 5;
if (mw.config.get('taxoboxCount')) {
count = mw.config.get('taxoboxCount');
}
var template = '<div class="wikibase-taxobox">{{Taxobox|qid=' + wgPageName + '|count=' + count + '|lang=' + language + '}}<div class="wikibase-taxobox-references" style="clear:right;"><references/></div></div>';
// https://www.wikidata.org/w/api.php?action=parse&text={{Taxobox|qid=Q36146}}&prop=text&contentmodel=wikitext&format=jsonfm
$.getJSON(mw.util.wikiScript('api'),
{
action:'parse',
format:'json',
text:template,
contentmodel:'wikitext',
prop:'text'
},
function(data){
var text=data.parse.text;
$('.wikibase-sitelinkgrouplistview').append(text['*']); // TODO insert text
});
}
} );
});
//</nowiki>

Event Timeline

alaa_wmde created this paste.Jul 29 2019, 10:32 PM
alaa_wmde changed the edit policy from "All Users" to "Trusted-Contributors (Project)".Jul 29 2019, 10:41 PM