Modul:Interwiki
Utseende
Dokumentation [visa] [redigera] [historik] [rensa sidcachen]
local p = { }
thiswiki = 'svwiki' -- the code of this wiki, HAS TO BE CHANGED WHEN COPYING MODULE
thislanguage = 'sv' -- the code of the present language
-- language-codes with underscore '_', have to be translated to '-', to be readable for MediaWiki
-- add more codes, when new are added to the Wikimedia-family
local langcode = {
['bat_smg'] = 'bat-smg',
['be_x_old'] = 'be-x-old',
['cbk_zam'] = 'cbk-zam',
['fiu_vro'] = 'fiu-vro',
['map_bms'] = 'map-bms',
['nds_nl'] = 'nds-nl',
['roa_rup'] = 'roa-rup',
['roa_tara'] = 'roa-tara',
['zh_classical'] = 'zh-classical',
['zh_min_nan'] = 'zh-min-nan', -- a comma has to be added when new lines are added
['zh_yue'] = 'zh-yue'
}
p460 = function(entity) -- access the first valid value of P2959 and thereafter all P460 values
local p460list = ''
if entity and entity.claims and entity.claims["P2959"] then
for i, j in pairs(entity:getBestStatements( "P2959" )) do
if j.mainsnak.snaktype == 'value' then
return 'Q' .. j.mainsnak.datavalue.value['numeric-id']
end
end
end
if entity and entity.claims and entity.claims["P460"] then
for i, j in pairs(entity.claims["P460"]) do
if j.mainsnak.snaktype == 'value' then
if not (p460list == '') then p460list = p460list .. ',' end
p460list = p460list .. "Q"..tostring(j.mainsnak.datavalue.value["numeric-id"])
end
end
return p460list
end
return nil
end
p.interwiki = function(frame)
local s = {}
local entity = mw.wikibase.getEntity()
local qids = frame.args.qid or frame:getParent().args.qid or p460(entity) -- uses parameter qid of the module if it exists, otherwise follow P460
if frame.args.qid == '' or frame:getParent().args.qid == '' then
qids = p460(entity)
end
if qids then
local qidtable = mw.text.split(qids,',')
for q = 1, #qidtable do
qid = qidtable[q]
local entity2 = mw.wikibase.getEntity(qid)
if entity2 and entity2.sitelinks then
for i, j in pairs(entity2.sitelinks) do
if j.site ~= thiswiki and j.site ~= 'wikidatawiki' and j.site ~= 'commonswiki' and j.site ~= 'specieswiki' and j.site ~= 'metawiki' and j.site ~= 'mediawikiwiki' then -- excludes the own wiki and some wikiprojects that are not Wikipedia, even if their code ends with 'wiki'
if mw.ustring.sub( j.site, mw.ustring.len(j.site) - 3 ) == 'wiki' then -- excludes Wikisource, Wikiquote, Wikivoyage etc
local lang = langcode[mw.ustring.sub( j.site, 1, mw.ustring.len(j.site) - 4 )] or mw.ustring.sub( j.site, 1, mw.ustring.len(j.site) - 4 )
if (entity and not entity.sitelinks[j.site]) or not entity then -- excludes interwiki to projects that already have sitelinks in the present page
table.insert(s, '[[' .. lang .. ':' .. j.title .. ']]' ) -- put together a interwiki-link to other projects
end
end
end
end
end
end
end
if #s > 0 then
table.insert(s, "[[Kategori:Sidor som hämtar kompletterande interwiki med hjälp av Modul:Interwiki]]")
end
return table.concat(s, '')
end
return p