2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2010-10-20 20:11:15 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2010-10-20 20:11:15 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2010-10-20 20:11:15 +02:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
*/
|
2010-10-20 20:11:15 +02:00
|
|
|
|
2010-06-24 22:13:51 +02:00
|
|
|
var ReconciliationManager = {
|
2011-08-04 22:37:14 +02:00
|
|
|
customServices : [], // services registered by core and extensions
|
|
|
|
standardServices : [], // services registered by user
|
|
|
|
_urlMap : {}
|
2010-06-26 07:34:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ReconciliationManager._rebuildMap = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
var map = {};
|
|
|
|
$.each(ReconciliationManager.getAllServices(), function(i, service) {
|
|
|
|
if ("url" in service) {
|
|
|
|
map[service.url] = service;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ReconciliationManager._urlMap = map;
|
2010-06-26 07:34:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ReconciliationManager.getServiceFromUrl = function(url) {
|
2011-08-04 22:37:14 +02:00
|
|
|
return ReconciliationManager._urlMap[url];
|
2010-06-24 22:13:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ReconciliationManager.getAllServices = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
return ReconciliationManager.customServices.concat(ReconciliationManager.standardServices);
|
2010-06-24 22:13:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ReconciliationManager.registerService = function(service) {
|
2011-08-04 22:37:14 +02:00
|
|
|
ReconciliationManager.customServices.push(service);
|
|
|
|
ReconciliationManager._rebuildMap();
|
|
|
|
|
|
|
|
return ReconciliationManager.customServices.length - 1;
|
2010-06-24 22:13:51 +02:00
|
|
|
};
|
|
|
|
|
2019-12-24 09:07:23 +01:00
|
|
|
ReconciliationManager.registerStandardService = function(url, f, silent) {
|
|
|
|
var dismissBusy = function() {};
|
|
|
|
if (!silent) {
|
|
|
|
dismissBusy = DialogSystem.showBusy($.i18n('core-recon/contact-service')+"...");
|
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2012-10-13 00:29:53 +02:00
|
|
|
$.ajax(
|
|
|
|
url,
|
|
|
|
{ "dataType" : "jsonp",
|
|
|
|
"timeout":10000
|
|
|
|
}
|
|
|
|
)
|
|
|
|
.success(function(data, textStatus, jqXHR) {
|
|
|
|
data.url = url;
|
|
|
|
data.ui = { "handler" : "ReconStandardServicePanel" };
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2012-10-13 00:29:53 +02:00
|
|
|
index = ReconciliationManager.customServices.length +
|
|
|
|
ReconciliationManager.standardServices.length;
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2012-10-13 00:29:53 +02:00
|
|
|
ReconciliationManager.standardServices.push(data);
|
|
|
|
ReconciliationManager._rebuildMap();
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2012-10-13 00:29:53 +02:00
|
|
|
ReconciliationManager.save();
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2012-10-13 00:29:53 +02:00
|
|
|
dismissBusy();
|
2011-08-04 22:37:14 +02:00
|
|
|
|
2012-10-13 00:29:53 +02:00
|
|
|
if (f) {
|
|
|
|
f(index);
|
|
|
|
}
|
|
|
|
})
|
2012-10-12 22:33:33 +02:00
|
|
|
.error(function(jqXHR, textStatus, errorThrown) {
|
2019-12-24 09:07:23 +01:00
|
|
|
if (!silent) {
|
|
|
|
dismissBusy();
|
|
|
|
alert($.i18n('core-recon/error-contact')+': ' + textStatus + ' : ' + errorThrown + ' - ' + url);
|
|
|
|
}
|
2012-10-12 22:33:33 +02:00
|
|
|
});
|
2010-06-24 22:13:51 +02:00
|
|
|
};
|
|
|
|
|
2010-06-26 07:34:54 +02:00
|
|
|
ReconciliationManager.unregisterService = function(service, f) {
|
2011-08-04 22:37:14 +02:00
|
|
|
for (var i = 0; i < ReconciliationManager.customServices.length; i++) {
|
|
|
|
if (ReconciliationManager.customServices[i] === service) {
|
|
|
|
ReconciliationManager.customServices.splice(i, 1);
|
|
|
|
break;
|
2010-06-26 07:34:54 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
for (var i = 0; i < ReconciliationManager.standardServices.length; i++) {
|
|
|
|
if (ReconciliationManager.standardServices[i] === service) {
|
|
|
|
ReconciliationManager.standardServices.splice(i, 1);
|
|
|
|
break;
|
2010-06-26 07:34:54 +02:00
|
|
|
}
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2012-10-12 21:49:33 +02:00
|
|
|
ReconciliationManager._rebuildMap();
|
2011-08-04 22:37:14 +02:00
|
|
|
ReconciliationManager.save(f);
|
2010-06-26 07:34:54 +02:00
|
|
|
};
|
|
|
|
|
2010-06-24 22:13:51 +02:00
|
|
|
ReconciliationManager.save = function(f) {
|
2019-10-14 15:28:00 +02:00
|
|
|
Refine.wrapCSRF(function(token) {
|
|
|
|
$.ajax({
|
|
|
|
async: false,
|
|
|
|
type: "POST",
|
|
|
|
url: "command/core/set-preference?" + $.param({
|
|
|
|
name: "reconciliation.standardServices"
|
|
|
|
}),
|
|
|
|
data: {
|
|
|
|
"value" : JSON.stringify(ReconciliationManager.standardServices),
|
|
|
|
csrf_token: token
|
|
|
|
},
|
|
|
|
success: function(data) {
|
|
|
|
if (f) { f(); }
|
|
|
|
},
|
|
|
|
dataType: "json"
|
|
|
|
});
|
2011-08-04 22:37:14 +02:00
|
|
|
});
|
2010-06-24 22:13:51 +02:00
|
|
|
};
|
|
|
|
|
2019-12-24 09:07:23 +01:00
|
|
|
ReconciliationManager.getOrRegisterServiceFromUrl = function(url, f, silent) {
|
2017-08-16 01:05:40 +02:00
|
|
|
var service = ReconciliationManager.getServiceFromUrl(url);
|
|
|
|
if (service == null) {
|
|
|
|
ReconciliationManager.registerStandardService(url, function(idx) {
|
|
|
|
ReconciliationManager.save(function() {
|
2017-08-17 13:40:56 +02:00
|
|
|
f(ReconciliationManager.standardServices[idx]);
|
2017-08-16 01:05:40 +02:00
|
|
|
});
|
2019-12-24 09:07:23 +01:00
|
|
|
}, silent);
|
2017-08-16 01:05:40 +02:00
|
|
|
} else {
|
|
|
|
f(service);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
ReconciliationManager.ensureDefaultServicePresent = function() {
|
2018-11-21 18:30:00 +01:00
|
|
|
var lang = $.i18n('core-recon/wd-recon-lang');
|
2017-08-16 01:05:40 +02:00
|
|
|
var url = "https://tools.wmflabs.org/openrefine-wikidata/"+lang+"/api";
|
2019-12-24 09:07:23 +01:00
|
|
|
ReconciliationManager.getOrRegisterServiceFromUrl(url, function(service) { }, true);
|
2017-08-16 01:05:40 +02:00
|
|
|
return url;
|
|
|
|
};
|
|
|
|
|
2010-06-24 22:13:51 +02:00
|
|
|
(function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
async: false,
|
2012-10-13 19:47:08 +02:00
|
|
|
url: "command/core/get-preference?" + $.param({
|
2011-08-04 22:37:14 +02:00
|
|
|
name: "reconciliation.standardServices"
|
|
|
|
}),
|
|
|
|
success: function(data) {
|
2017-02-08 00:59:12 +01:00
|
|
|
if (data.value && data.value != "null" && data.value != "[]") {
|
2011-08-04 22:37:14 +02:00
|
|
|
ReconciliationManager.standardServices = JSON.parse(data.value);
|
|
|
|
ReconciliationManager._rebuildMap();
|
|
|
|
} else {
|
2017-08-16 01:05:40 +02:00
|
|
|
ReconciliationManager.ensureDefaultServicePresent();
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
dataType: "json"
|
|
|
|
});
|
2010-06-24 22:13:51 +02:00
|
|
|
})();
|