Модуль:Wikidata/Biology

Википедия деп сайттан

Биологтуг шынарлар база квалификаторлар форматтылаар функцияларлыг модуль.


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 id = "Q" .. value["numeric-id"];
	local entity = mw.wikibase.getEntityObject( id )

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

    local link = entity:getSitelink()
    local label = entity:getLabel()

	return "[[" .. ( link or ( ":d:" .. id ) ) .. "|" .. ( abbr or label or id ) .. "]]";
end

return p