אונטערשייד צווישן ווערסיעס פון "באַניצער:בוט צמא לדעת/coords.js"
קפיצה לניווט
קפיצה לחיפוש
אין תקציר עריכה |
אין תקציר עריכה |
||
שורה 9: | שורה 9: | ||
"gapnamespace": "8000", | "gapnamespace": "8000", | ||
"gapfilterredir": "nonredirects", | "gapfilterredir": "nonredirects", | ||
"gapfrom": ' | "gapfrom": 'בעלי חיים', | ||
"gaplimit": "50", | "gaplimit": "50", | ||
"prop": "categories|langlinks", | "prop": "categories|langlinks", |
רעוויזיע פון 07:46, 8 דעצעמבער 2023
mw.loader.using(['mediawiki.jqueryMsg']).done(function () {
function listPages() {
const api = new mw.Api();
api.get({
"action": "query",
"format": "json",
"generator": "allpages",
"utf8": 1,
"gapnamespace": "8000",
"gapfilterredir": "nonredirects",
"gapfrom": 'בעלי חיים',
"gaplimit": "50",
"prop": "categories|langlinks",
"clcategories": "קאַטעגאָריע:ארטיקלען מיט קאארדינאטן",
"cllimit": "max",
"lllimit": "max"
}).done((data) => {
//console.table(data);
const list = data.query.pages;
console.timeLog('מדידת זמן', 'a');
console.table(list);
var sum = 0;
for (const p in list) {
const pageName = list[p].title;
if (!("categories" in list[p])) {
if ("langlinks" in list[p]) {
for (const l in list[p].langlinks) {
if (list[p].langlinks[l].lang == "he") {
console.log(list[p].langlinks[l], list[p].langlinks[l]['*'])
hebCoord(pageName, list[p].langlinks[l]['*'])
}
}
} else {
wikidataCoord(pageName);
}
}
sum++;
if (sum >= 49) {
console.log('last was: ', pageName);
}
}
})
};
function hebCoord(page, hepage) {
console.log(hepage + ' : ' + page);
console.timeLog('מדידת זמן', '2');
var params = {
"action": "query",
"format": "json",
"titles": hepage,
"prop": "coordinates"
};
$.ajax({
url: '//he.wikipedia.org/w/api.php',
data: params,
dataType: 'jsonp',
cache: true
})
.done(function (data) {
console.log('at last done');
$(function () {
if (!("query" in data) || !("pages" in data.query)) {
console.log('no query data!', page, hepage)
} else {
for (var p in data.query.pages) {
console.log('about to test coordinates for: ', p)
if (("coordinates" in data.query.pages[p]) && ("primary" in data.query.pages[p].coordinates[0])) {
console.log('adding coordinates for: ', p)
var params = {
"action": "edit",
"format": "json",
"title": page,
"summary": "קאארדינאט",
"minor": 1,
"bot": 1,
"prependtext": '{{Coord|' + data.query.pages[p].coordinates[0].lat + '|' + data.query.pages[p].coordinates[0].lon + '|display=title}}',
"utf8": 1
},
api = new mw.Api();
api.postWithToken('csrf', params).done(function (data) {
console.table(data);
console.timeLog('מדידת זמן', 3);
});
}
}
}
}
)
});
}
function wikidataCoord(page) {
$.ajax({
url: '//www.wikidata.org/w/api.php',
data: {
'format': 'json',
'action': 'wbgetentities',
'sites': "yiwiki",
'titles': page.replace("רוי:", ""),//.replace('מדינת ישראל', 'ישראל'),
'props': 'sitelinks',
'languages': 'en',
'sitefilter': 'enwiki'
},
dataType: 'jsonp',
cache: true
})
.done(function (data) {
console.log(data);
if (data.success) {
//console.table(data.success);
$(function () {
for (var e in data.entities) {
if (e == -1) return;
var labels = data.entities[e].sitelinks;
if (!labels.enwiki) return console.log('ל' + page + ' אין מידע ויקינתונים.');
const interwiki = labels.enwiki.title;
//console.table(e);
console.log(interwiki + ' : ' + page);
console.timeLog('מדידת זמן', '2');
var params = {
"action": "query",
"format": "json",
"titles": interwiki,
"prop": "coordinates"
};
$.ajax({
url: '//en.wikipedia.org/w/api.php',
data: params,
dataType: 'jsonp',
cache: true
})
.done(function (data) {
console.log('at last done');
$(function () {
for (var p in data.query.pages) {
console.log('about to test coordinates for: ', p)
if (("coordinates" in data.query.pages[p]) && ("primary" in data.query.pages[p].coordinates[0])) {
console.log('adding coordinates for: ', p)
var params = {
"action": "edit",
"format": "json",
"title": page,
"summary": "קאארדינאט",
"minor": 1,
"bot": 1,
"prependtext": '{{Coord|' + data.query.pages[p].coordinates[0].lat + '|' + data.query.pages[p].coordinates[0].lon + '|display=title}}',
"utf8": 1
},
api = new mw.Api();
api.postWithToken('csrf', params).done(function (data) {
console.table(data);
console.timeLog('מדידת זמן', 3);
});
}
}
}
)
});
}
});
}
});
}
if (mw.config.get('wgUserGroups').indexOf('bot') !== -1 && (mw.config.get('wgAction') != 'edit') && confirm('להריץ?')) {
console.time('מדידת זמן');
listPages();
}
})