跳转到内容

模組:InterwikiCorrispondingArticle

维基百科,自由的百科全书

这是Module:InterwikiCorrispondingArticle当前版本,由1F616EMO留言 | 贡献编辑于2022年12月5日 (一) 11:26。这个网址是本页该版本的固定链接。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
-- <nowiki>

local p = {}

-- srcwiki: Source wiki ID
-- srcname: Article title in srcwiki
-- destwiki: (optional) output wiki ID. If empty, use the current wiki.
function p.get(srcwiki,srcname,destwiki)
	local entityID = mw.wikibase.getEntityIdForTitle(srcname, srcwiki)
	if not entityID then return end
	local entity = mw.wikibase.getEntity(entityID)
	return entity:getSitelink(destwiki) 
end

function p.main(frame)
	local args = frame.args
	
	local srcwiki = args[1]
	local srcname = args[2]
	local destwiki = args[3]
	
	assert(srcwiki and srcwiki ~= "");assert(srcname and srcname ~= "")
	if destwiki == "" then destwiki = nil end
	
	local destname = p.get(srcwiki,srcname,destwiki)
	return destname or srcname -- Fallback to src name
end

function p.link(frame)
	local args = frame.args
	
	local srcwiki = args[1]
	local srcname = args[2]
	local destwiki = args[3]
	local dispname = args[4]
	
	assert(srcwiki and srcwiki ~= "");assert(srcname and srcname ~= "")
	if destwiki == "" then destwiki = nil end
	if dispname == "" then dispname = nil end
	
	local destname = p.get(srcwiki,srcname,destwiki)
	if not destname then
		return dispname or srcname
	end
	if dispname then
		return "[[" .. destname .. "|" .. dispname .. "]]"
	else
		return "[[" .. destname .. "]]"
	end
end

return p
--</nowiki>