User:Goldzahn/test3.js
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
$(document).ready(function () {
// if ( mw.config.get('wgNamespaceNumber') != 0 ) return ;
if ( mw.config.get('wgAction') != 'view' ) return ;
var d = "<div id='tool_text' <div style='position:absolute;right:300px;top:0px;z-index:1;background-color:#ffe1bc'> tool V1.00<br/>" ;
d += "<input type='text' size='6' value='120' id='input-page-id' /> page-id<br/>";
d += "<span id='backlinks' style='cursor:pointer;background-color:white;padding:1px 5px 1px 5px' >load backlinks of property P19</span>";
d += "</div></div>" ;
$('#mw-content-text').append ( d ) ;
var bl_continue = '120|P19|120'; // + $('#input-page-id').val();
$("#backlinks").on("click", function(event){
bl_continue = '120|P19|' + $('#input-page-id').val();
// Which items use property p19?
$.getJSON ( '//' + 'wikidata.org/w/api.php?callback=?' , {
action : 'query' ,
rawcontinue: '',
bltitle : 'Property:P19' ,
format : 'json' ,
list : 'backlinks' ,
blnamespace: '0',
bllimit : '1',
blcontinue : bl_continue // has to be change for the next query
} , function ( data ) {
var page_id_p19 = data.query.backlinks[0].pageid;
var item_p19 = data.query.backlinks[0].title;
item_p19 = item_p19.toLowerCase(); // Kleinbuchstaben
//console.log ('JSON.title = ' + item_p19); // item with a p19, q...
bl_continue = data['query-continue'].backlinks.blcontinue;
$('#input-page-id').val(bl_continue.match(/\d+$/)); // beliebige ganze Zahl am Ende des Strings
// console.log ('JSON.blcontinue = ' + bl_continue); // .blcontinue);
// What is the value of the item using p19?
$.getJSON ( '//' + 'wikidata.org/w/api.php?callback=?' , {
action : 'wbgetentities' ,
format : 'json' ,
ids : item_p19 ,
props : 'claims'
} , function ( data ) {
var id_1 = 'q' + data.entities[item_p19].claims.p19[0].mainsnak.datavalue.value['numeric-id'] ;
//console.log ('JSON.numeric-id = ' + id_1); // place of birth, q...
// test if main-typ is geographical feature, Q618123
$.getJSON ( '//' + 'wikidata.org/w/api.php?callback=?' , {
action : 'wbgetentities' ,
format : 'json' ,
ids : id_1 ,
props : 'claims'
} , function ( data ) {
var a = data.entities[id_1].claims; // console.log (a);
if (typeof a.p107 != 'undefined') {
var id_2 = 'q' + data.entities[id_1].claims.p107[0].mainsnak.datavalue.value['numeric-id'] ;
//console.log ('JSON.numeric-id = ' + id_2); //main type: geographical feature, Q618123
//console.log ('end $("#backlinks"');
console.log ('item ' + item_p19 + '(page-id:' + page_id_p19 + '): Place of birth (p19), value is ' + id_1 + ', which has the main type ' + id_2);
}
else {
console.log ('item ' + item_p19 + '(page-id:' + page_id_p19 + '): Place of birth(p19), value is ' + id_1 + ', which don´t have a main type.');
};
}); // end getJSON
}); // end getJSON
}); // end getJSON
}); // end $("#backlinks")
});