Modulis:Wikidata label

Vikipēdijas lapa
Jump to navigation Jump to search
Dokumentācijas ikona Moduļa dokumentācija[izveidot]
local p = {}
local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')

function p._q(args)
	local reasonator = args.r
	local id = args[1]
	local first = string.sub( id, 1,1 )
	
	if first == "Q" or first == "q" then id = string.sub(id, 2) end
	
	local entity = mw.wikibase.getEntity("Q"..id)
	
	if entity and entity.labels then
		local label = entity.labels['lv']
		if label then
			link = '[[:d:Q'..id..'|'..label.value..' <small>(Q'..id..')</small>]]'
		     elseif entity.labels['en'] then
			link = '[[:d:Q'..id..'|'..entity.labels['en'].value..' <small>(angliski; Q'..id..')</small>]]'
		     else
			link = "[[:d:Q"..id.."|''nav nosaukuma'' <small>(Q"..id..")</small>]]"
		end
	end

	if yesno(reasonator) then
		link = link .. ' [[Attēls:Wikidata-Reasonator small logo.svg|12px|Skatīt vienumu Reasonator rīkā|link=//tools.wmflabs.org/reasonator/?q=Q' .. id .. '&lang=lv]]'
	end

return link
end

function p.q(frame)
	local args = getArgs(frame, {
		wrappers = 'Veidne:Q'
	})
	return p._q(args)
end

function p._p(args)
	local id = args[1]
	local first = string.sub( id, 1,1 )
	
	if first == "P" or first == "p" then id = string.sub(id, 2) end
	
	local entity = mw.wikibase.getEntity("P"..id)
	
	if entity and entity.labels then
		local label = entity.labels['lv']
		if label then
			link = '[[:d:Property:P'..id..'|'..label.value..' <small>(P'..id..')</small>]]'
		     else
			link = '[[:d:Property:P'..id..'|'..entity.labels['en'].value..' <small>(angliski; P'..id..')</small>]]'
		end
	end

return link
end

function p.p(frame)
	local args = getArgs(frame, {
		wrappers = 'Veidne:P'
	})
	return p._p(args)
end

return p