Модуль:Wikidata/P171

Материал из Википедии — свободной энциклопедии
Перейти к навигации Перейти к поиску
Документация
local WDS = require( 'Module:WikidataSelectors' );
local p = {};

--Property:P171 for [[Module:WikidataTree]]
function p.formatTaxonValue( frame, entityId, formatEntityId )
	local entity = mw.wikibase.getEntity( entityId );
	local rankLabel = '';
	local lang = mw.getContentLanguage();
	
	local importantRanksIds = {
		Q7432 = true,
		Q34740 = true,
		Q35409 = true,
		Q36602 = true,
		Q37517 = true,
		Q38348 = true,
		Q36732 = true,
		Q19858692 = true
	};
	local isImportantRank = false;

	-- получение таксономического ранга из элемента
	local taxonRankClaims = WDS.filter( entity.claims, 'P105' )
	if taxonRankClaims and #taxonRankClaims then
		for i, claim in pairs( taxonRankClaims ) do
			if claim.type == 'statement' and claim.mainsnak.snaktype == 'value' then
				rankLabel = mw.wikibase.label( claim.mainsnak.datavalue.value.id );
				if rankLabel ~= '' then
					rankLabel = lang:ucfirst( rankLabel ) .. ':';
				end

				if importantRanksIds[ claim.mainsnak.datavalue.value.id ] == true then
					isImportantRank = true;
				end
				break -- TODO
			end
		end
	end

	if rankLabel == '' then
		rankLabel = 'Без ранга:';
	end

	local collapsed = '';
	if isImportantRank == false then
		collapsed = ' class="mw-collapsible-content" style="display:none"';
		rankLabel = '<span style="color:teal">' .. rankLabel .. '</span>';
	end

	return '<tr' .. collapsed .. '><td width="40%" align="right" valign="top">' ..  rankLabel .. '</td>'
		.. '<td width="60%" align="left">' .. formatEntityId( entityId, { frame = frame } )  .. '</td></tr>';
end

return p