User:Phe/Interwiki.js

// 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); } }