وحدة:Wp-or-wd

من أرابيكا، الموسوعة الحرة
اذهب إلى التنقل اذهب إلى البحث
function wp_or_wd(frame)
	local id = frame.args[1] or frame:getParent().args[1]
	local label = frame.args[2] or frame:getParent().args[2] or nil
	if not id or not mw.wikibase.entityExists(id) then
		return '<div class="error">عنصر ويكي بيانات غير موجود</div>'
	end
	local linkTarget = mw.wikibase.getSitelink(id)
	local linkName = mw.wikibase.getLabel(id)
	if linkTarget then
		-- if there is a local Wikipedia article link to it using the label or the article title
		return "[[" .. linkTarget .. (label and ("|" .. label) or '') .. "]]"
	elseif label then
		return "[[:d:" .. id .."|" .. label .. "]]" 
	else		
		-- if there is no local Wikipedia article output the label or link to the Wikidata object to let the user input a proper label
		return "[[:d:" .. id .. (linkName and ("|" .. linkName) or "") .. "]]" 
	end
end

return {wp_or_wd = wp_or_wd}