mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 17:23:02 +00:00
(closes #3324) Previously we allowed devs to swap out services that they didn't need. This became difficult now that ES6 exports are immutable bindings. But we can wrap the immutable bindings themselves in a live object, to get back the flexibility that we used to have. This change also drops the `taginfo` accessor on Context, since devs who want to swap out taginfo service with something else can now do so through the live binding. `iD.services.taginfo = myTaginfo()`
39 lines
1021 B
JavaScript
39 lines
1021 B
JavaScript
import { jsonpRequest } from '../util/jsonp_request';
|
|
import { utilQsString } from '../util/index';
|
|
|
|
|
|
var endpoint = 'https://www.wikidata.org/w/api.php?';
|
|
|
|
export default {
|
|
|
|
init: function() {},
|
|
reset: function() {},
|
|
|
|
|
|
// Given a Wikipedia language and article title, return an array of
|
|
// corresponding Wikidata entities.
|
|
itemsByTitle: function(lang, title, callback) {
|
|
if (!title) {
|
|
callback('', {});
|
|
return;
|
|
}
|
|
|
|
lang = lang || 'en';
|
|
jsonpRequest(endpoint + utilQsString({
|
|
action: 'wbgetentities',
|
|
format: 'json',
|
|
sites: lang.replace(/-/g, '_') + 'wiki',
|
|
titles: title,
|
|
languages: 'en', // shrink response by filtering to one language
|
|
callback: '{callback}'
|
|
}), function(data) {
|
|
if (!data || data.error) {
|
|
callback('', {});
|
|
} else {
|
|
callback(title, data.entities || {});
|
|
}
|
|
});
|
|
}
|
|
|
|
};
|