Přeskočit na obsah

Modul:Wikidata/Formatters/wikibase-entityid

Tato stránka je zamčena
Z Wikipedie, otevřené encyklopedie

require 'Modul:No globals'

local p = {}

local function constructLink(label, link, entityId, options)
	if link then
		if label then
			return '[[' .. link .. '|' .. label .. ']]'
		else
			return '[[' .. link .. ']]'
		end
	else
		return label or p.getLinkWhenNonexistingLabel(entityId)
	end
end

function p.getLinkWhenNonexistingLabel(entityId)
	local i18n = mw.loadData('Modul:Wikidata/i18n')
	local Category = require 'Modul:Kategorie'
	local ImageFormatter = require 'Modul:ImageFormatter'

	return ImageFormatter.makeImage('Wikidata-edit.svg', {
		description = i18n['missing-label'],
		link = 'd:' .. entityId,
		size = '27x17px'
		}) .. '<code>[[d:' .. entityId .. '|' .. entityId .. ']]</code>'
		.. Category.makeCategory(i18n.categories["missing-label"])
end

function p.formatEntityWithGender(entityId, options)
	local Module = require 'Modul:Wikidata'
	local lib = require 'Modul:Wikidata/lib'
	local gender_prop = lib.props.gender
	local gender = Module.getRawValueFromLua{
		entity = options.entity,
		property = gender_prop
		}

	local label
	if gender == 'Q6581072' then
		local label_prop = lib.props.femaleVariant
		label = Module.formatStatements{
			id = entityId,
			limit = 1,
			property = label_prop,
			rank = 'valid',
			sort = 'rank',
			withlang = 'cs'
		}
	end
	if not label then
		label = mw.wikibase.label(entityId)
	end
	local link = mw.wikibase.sitelink(entityId)
	return constructLink(label, link, entityId, options)
end

function p.formatEntityId(entityId, options)
	local label = mw.wikibase.label(entityId)
	local link = mw.wikibase.sitelink(entityId)
	return constructLink(label, link, entityId, options)
end

return p