User:Phe/Interwiki.js: Difference between revisions
Appearance
< User:Phe
Content deleted Content added
m Created page with '// add_interwiki() perform one request per entry in this array (-1 if the native // wiki has its own entry here). So don't add too much entry, pywikipedia interwiki // bots can h...' |
Pathoschild (talk | contribs) migrated deprecated functions |
||
Line 32: | Line 32: | ||
{ |
{ |
||
for (var lang in author_ns_prefix) { |
for (var lang in author_ns_prefix) { |
||
if (lang == wgContentLanguage) |
if (lang == mw.config.get('wgContentLanguage')) |
||
continue; |
continue; |
||
// well, hard coded... domain name would be extracted from wgServer... |
// well, hard coded... domain name would be extracted from mw.config.get('wgServer')... |
||
var base_url = "http://" + lang + ".wikisource.org" |
var base_url = "http://" + lang + ".wikisource.org" |
||
+ wgScriptPath |
+ mw.config.get('wgScriptPath') |
||
+ "/api.php?format=json&redirects"; |
+ "/api.php?format=json&redirects"; |
||
Line 43: | Line 43: | ||
//+ '&callback=get_interwiki&action=query&prop=langlinks&lllimit=32&titles=' |
//+ '&callback=get_interwiki&action=query&prop=langlinks&lllimit=32&titles=' |
||
+ '&callback=get_interwiki&action=query&meta=siteinfo&titles=' |
+ '&callback=get_interwiki&action=query&meta=siteinfo&titles=' |
||
+ encodeURIComponent(author_ns_prefix[lang] + ':' + wgTitle); |
+ encodeURIComponent(author_ns_prefix[lang] + ':' + mw.config.get('wgTitle')); |
||
create_script_obj(url); |
create_script_obj(url); |
Latest revision as of 23:02, 16 August 2015
// add_interwiki() perform one request per entry in this array (-1 if the native
// wiki has its own entry here). So don't add too much entry, pywikipedia interwiki
// bots can handle the missing interwikis. No entry has been added for any wiki
// w/o an Author: dedicated namespace, biggest missing are de: and es:.
var author_ns_prefix = {
'en' : 'Author',
'fr' : 'Auteur',
'it' : 'Autore',
'pt' : 'Autor',
}
function get_interwiki(data)
{
var wpTextbox1 = document.getElementById("wpTextbox1");
if (wpTextbox1 && !data.query.pages["-1"]) {
for (var ids in data.query.pages) {
wpTextbox1.value += '[[' + data.query.general.lang + ':' + data.query.pages[ids].title + ']]\n'
break;
}
}
}
function create_script_obj(url)
{
var scriptObj = document.createElement("script");
scriptObj.setAttribute("type", "text/javascript");
scriptObj.setAttribute("src", url);
document.body.appendChild(scriptObj);
}
function add_interwiki()
{
for (var lang in author_ns_prefix) {
if (lang == mw.config.get('wgContentLanguage'))
continue;
// well, hard coded... domain name would be extracted from mw.config.get('wgServer')...
var base_url = "http://" + lang + ".wikisource.org"
+ mw.config.get('wgScriptPath')
+ "/api.php?format=json&redirects";
var url = base_url
//+ '&callback=get_interwiki&action=query&prop=langlinks&lllimit=32&titles='
+ '&callback=get_interwiki&action=query&meta=siteinfo&titles='
+ encodeURIComponent(author_ns_prefix[lang] + ':' + mw.config.get('wgTitle'));
create_script_obj(url);
}
}