Module:Interwiki: Difference between revisions
Appearance
Content deleted Content added
mNo edit summary |
Tacsipacsi (talk | contribs) avoid double Wikidata links when the page is already connected to Wikidata but the template is kept as actual interlanguage links don’t seem to work (see phab:T138332#6864007) |
||
| (5 intermediate revisions by 3 users not shown) | |||
| Line 25: | Line 25: | ||
if qids then |
if qids then |
||
local qidtable = mw.text.split(qids,',') |
local qidtable = mw.text.split(qids,',') |
||
for q = 1, #qidtable do |
|||
qid = qidtable[q] |
|||
if qid ~= mw.wikibase.getEntityIdForCurrentPage() then |
|||
table.insert(s, '<li id="t-wikibase" style="display:none;">[[d:' .. qid .. '|' .. frame:callParserFunction{ name = 'int', args = 'Wikibase-dataitem' } .. ']]</li>') |
|||
end |
|||
local entity = mw.wikibase.getEntity(qid) |
local entity = mw.wikibase.getEntity(qid) |
||
if entity and entity.sitelinks then |
if entity and entity.sitelinks then |
||
Latest revision as of 11:33, 26 February 2021
Documentation for this module may be created at Module:Interwiki/doc
local p = { }
thiswiki = 'sourceswiki' -- the code of this wiki, HAVE TO BE CHANGED WHEN COPYING MODULE
thislanguage = 'mul' -- 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'
}
p.interwiki = function(frame)
local s = {}
local qids = frame.args.qid or frame:getParent().args.qid
if qids then
local qidtable = mw.text.split(qids,',')
for q = 1, #qidtable do
qid = qidtable[q]
if qid ~= mw.wikibase.getEntityIdForCurrentPage() then
table.insert(s, '<li id="t-wikibase" style="display:none;">[[d:' .. qid .. '|' .. frame:callParserFunction{ name = 'int', args = 'Wikibase-dataitem' } .. ']]</li>')
end
local entity = mw.wikibase.getEntity(qid)
if entity and entity.sitelinks then
for i, j in pairs(entity.sitelinks) do
if j.site ~= thiswiki then -- excludes this wiki
if mw.ustring.sub( j.site, -10 ) == 'wikisource' then -- excludes non-Wikisource projects
local lang = langcode[mw.ustring.sub( j.site, 1, -11 )] or mw.ustring.sub( j.site, 1, -11 )
table.insert(s, '[[' .. lang .. ':' .. j.title .. ']]' ) -- put together a interwiki-link to other projects
end
end
end
end
end
end
table.insert(s, "[[Category:Pages with interwiki links from Module:Interwiki]]")
return table.concat(s, '')
end
return p