跳转到内容

模組:InterwikiCorrispondingArticle

维基百科,自由的百科全书
-- <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>