Документация

Содержит функции форматирования для биологических свойств и квалификаторов.

local p = {}

--Property:P225
function p.formatTaxonNameClaim( context, options, statement )
	local title = context.formatSnak( options, statement.mainsnak )

	local authors = '';
	local dates = '';
	--taxon author
	if ( statement.qualifiers ) then
		if ( statement.qualifiers.P405 ) then
			local options405 = options:extends({
				["value-module"] = "Wikidata/Biology",
				["value-function"] = "formatTaxonAuthorSnak",
				["conjunction"] = " & ",
			});

			authors = {}
			for _, qualifier in pairs( statement.qualifiers.P405 ) do
				table.insert(authors, context.formatSnak( options405, qualifier ) );
			end
			authors = mw.text.listToText( authors, ", ", " & " )
		end
		
		--Date of release
		if ( statement.qualifiers.P574 ) then
			dates = ', ' .. context.formatSnak( {}, statement.qualifiers.P574[1] )
		end
	end

	result = options.frame:expandTemplate{ title = 'btname', args = { title, authors } }
		.. dates
		.. context.formatRefs( options, statement )
	return result
end

-- Qualifier P405
function p.formatTaxonAuthorSnak( context, options, value )
	local entityId = value.id

	local abbr = nil
	local statements = mw.wikibase.getBestStatements( entityId, 'P428' )
					or mw.wikibase.getBestStatements( entityId, 'P835' )
					or {}
	for _, statement in pairs( statements ) do
		if statement.mainsnak.snaktype == 'value' then
			abbr = statement.mainsnak.datavalue.value
			break
		end
	end

    local link = mw.wikibase.getSitelink( entityId ) or ( ":d:" .. entityId )
    local label = abbr or mw.wikibase.getLabel( entityId ) or entityId

	return "[[" .. link .. "|" .. label .. "]]"
end

return p