Sari la conținut

Modul:Taxobox

De la Wikipedia, enciclopedia liberă

Documentația acestui modul poate fi creată la Modul:Taxobox/doc

local getArgs = require('Modul:Arguments').getArgs
local infobox = require('Modul:Infobox')
local infoboxImage = require('Modul:InfoboxImage').InfoboxImage
local wikidata = require('Modul:Wikidata')
local StringUtils = require('Modul:StringUtils')
local join = require('Modul:Separated entries')._main
local p = {}
local taxonorder = {
	'Q22666877', -- superdomeniu
	'Q146481', --domeniu
	'Q3491996', --subdomeniu
	'Q19858692', --supraregn
	'Q36732', --regn
	'Q2752679', --subregn
	'Q3150876', --infraregn
	'Q3978005', --supraîncrengătură
	'Q38348', --încrengătură
	'Q1153785', --subîncrengătură
	'Q2361851', --infraîncrengătură
	'Q334460', --divisio
	'Q3491997', --subdivisio
	'Q3504061', --supraclasă
	'Q37517', --clasă
	'Q5867051', --subclasă
	'Q2007442', --infraclasă
	'Q6054425', --supracohortă
	'Q2981883', --cohortă
	'Q6541077', --subcohortă
	'Q4226087', --infracohortă
	'Q30093070', --diviziune
	'Q30093105', --subdiviziune
	'Q21061732', --serie
	'Q5868144', --supraordin
	'Q36602', --ordin
	'Q6054237', --magnordin
	'Q5867959', --subordin
	'Q2889003', --infraordin
	'Q6311258', -- parvordin
	'Q10861426', --secțiune
	'Q10861375', -- subsecțiune zoologică
	'Q2136103', --suprafamilie
	'Q10296147', --epifamilie
	'Q35409', --familie
	'Q164280', --subfamilie
	'Q5481039', --infrafamilie
	'Q14817220', --supratrib
	'Q227936', --trib
	'Q3965313', --subtrib
	'Q3798630', --infratrib
	'Q1783100', --supragen
	'Q34740', --gen
	'Q3238261', --subgen
	'Q3181348', -- secțiune botanică
	'Q5998839', --subsecțiune botanică
	'Q3025161', --serie
	'Q13198444', -- subserie
	'Q1783100', --supraspecie
	'Q7432', --specie
	'Q68947', --subspecie
	'Q21446603', --infraspecie
	'Q767728', --varietate
    'Q855769', --tulpină
}
local argMap = {
	superdomain = 'Q22666877',	supradomeniu = 'Q22666877',
	domain = 'Q146481',	domeniu = 'Q146481',
	subdomain = 'Q3491996',	subdomeniu = 'Q3491996',
	superregnum = 'Q19858692',	supraregn = 'Q19858692',
	regnum = 'Q36732', regn = 'Q36732', kingdom = 'Q36732',
	subregnum = 'Q2752679', subregn = 'Q2752679',
	infraregnum = 'Q3150876', infraregn = 'Q3150876',
	superdivisio = 'Q3978005', superdiviziune = 'Q3978005', superphylum = 'Q3978005', --supraîncrengătură
	divisio = 'Q38348', phylum = 'Q38348', --încrengătură
	subphylum = 'Q1153785', subdivisio = 'Q1153785', --subîncrengătură
	infraphylum = 'Q2361851', --infraîncrengătură
	microphylum = 'Q1153785',
	superclassis = 'Q3504061', --supraclasă
	classis = 'Q37517', --clasă
	subclassis = 'Q5867051', --subclasă
	infraclassis = 'Q2007442', --infraclasă
	supracohors = 'Q6054425', --supracohortă
	cohors = 'Q2981883', --cohortă
	subcohors = 'Q6541077', --subcohortă
	infracohors = 'Q4226087', --infracohortă
	magnordo = 'Q6054237',
	superordo = 'Q5868144', --supraordin
	ordo = 'Q36602', --ordin
	subordo = 'Q5867959', --subordin
	infraordo = 'Q2889003', --infraordin
	parvordo = 'Q6311258',
	zoosectio = 'Q3181348', -- secțiune zoologică
	zoosubsectio = 'Q10861375',
	superfamilia = 'Q2136103', --suprafamilie
	epifamilia = 'Q10296147', --epifamilie
	familia = 'Q35409', --familie
	subfamilia = 'Q164280', --subfamilie
	infrafamilia = 'Q5481039', --infrafamilie
	supertribus = 'Q14817220', --supratrib
	tribus = 'Q227936', --trib
	subtribus = 'Q3965313', --subtrib
	infratribus = 'Q3798630', --infratrib
	supergenus = 'Q1783100', --supragen
	genus = 'Q34740', --gen
	subgenus = 'Q3238261', --subgen
	sectio = 'Q3181348', -- secțiune botanică
	subsectio = 'Q5998839',
	series2 = 'Q3025161', --serie
	subseries2 = 'Q13198444', -- subserie
	superspecies = 'Q1783100', --supraspecie
	species = 'Q7432', --specie
	subspecies = 'Q68947', --subspecie
	infraspecies = 'Q21446603', --infraspecie
	variety = 'Q767728', varietate = 'Q767728', -- varietate
	strain = 'Q855769', -- tulpină
}

local function extractStatusFromWikidata()
	local statusClaims = wikidata.findClaimsForProperty(nil, 'P141') -- iucn conservation status
	local statusDescriptions = {}
	if statusClaims and #statusClaims > 0 then
		for statusIdx, statusClaim in ipairs(statusClaims) do
			local statusQString = StringUtils.prependIfMissing({tostring(statusClaim.mainsnak.datavalue.value['numeric-id']), 'Q'})
			local statusImg = wikidata.findOneValueNoRef('P18', statusQString)
			if statusImg then statusImg = mw.ustring.gsub(statusImg, '.svg', ' ro.svg') end
			local statusTxt = wikidata.findLabel(statusQString)
			local statusCats = wikidata.getBestEntityIdsList(nil, 'P910')
			statusDescriptions[statusIdx] = ''
			if statusImg then statusDescriptions[statusIdx] = statusDescriptions[statusIdx] .. '[[Fișier:' .. statusImg .. '|frameless]]' end
			if statusTxt then statusDescriptions[statusIdx] = statusDescriptions[statusIdx] .. tostring(mw.html.create('br')) .. statusTxt end
			if statusCats then
				for catIdx,catId in ipairs(statusCats) do
					local localCatTitle = mw.wikibase.sitelink('Q' .. catId)
					if localCatTitle and mw.ustring.len(mw.text.trim(localCatTitle)) > 0 then
						statusDescriptions[statusIdx] = statusDescriptions[statusIdx] .. '[[' .. localCatTitle .. ']]'
					end
				end
			end
			statusDescriptions[statusIdx] = statusDescriptions[statusIdx] .. wikidata.outputReferences(statusClaim)
		end
	end
	return statusDescriptions
end

local function extractStatusFromArgs(args)
	local statusData = {}
	statusData['iucn2.3'] = {}
	statusData['iucn2.3']['ex'] = {image='Status iucn2.3 EX ro.svg', text='Dispărut', cat='Specii dispărute'}
	statusData['iucn2.3']['ew'] = {image='Status iucn2.3 EW ro.svg', text='Stare de dispariție', cat='Specii dispărute în stare sălbatică'}
	statusData['iucn2.3']['cr'] = {image='Status iucn2.3 CR ro.svg', text='Critic', cat='Specii în pericol critic de dispariție'}
	statusData['iucn2.3']['en'] = {image='Status iucn2.3 EN ro.svg', text='În pericol', cat='Specii amenințate'}
	statusData['iucn2.3']['vu'] = {image='Status iucn2.3 VU ro.svg', text='Vulnerabil', cat='Specii în stare vulnerabilă'}
	statusData['iucn2.3']['lr'] = {image='Status iucn2.3 blank.svg', text='Risc minim', cat='Invalid conservation status'}
	statusData['iucn2.3']['cd'] = {image='Status iucn2.3 CD ro.svg', text='[[Conservation Dependent]]', cat='IUCN Red List conservation dependent species'}
	statusData['iucn2.3']['lr/cd'] = statusData['iucn2.3']['cd']
	statusData['iucn2.3']['nt'] = {image='Status iucn2.3 NT ro.svg', text='Risc scăzut (NT)', cat='Specii amenințate moderat'}
	statusData['iucn2.3']['lr/nt'] = statusData['iucn2.3']['nt']
	statusData['iucn2.3']['lc'] = {image='Status iucn2.3 LC ro.svg', text='Risc scăzut (LC)', cat='Specii cu risc scăzut'}
	statusData['iucn2.3']['lr/lc'] = statusData['iucn2.3']['lc']
	statusData['iucn2.3']['dd'] = {image='Status iucn2.3 blank.svg', text='Date insuficiente'}
	statusData['iucn2.3']['ne'] = {text='Neevaluată'}
	statusData['iucn2.3']['nr'] = {text='Nerecunoscută'}
	statusData['iucn2.3']['pe'] = {image='Status iucn2.3 CR ro.svg', text='Critic, posibilă dispariție', cat='Specii în pericol critic de dispariție'}
	statusData['iucn2.3']['pew'] = {image='Status iucn2.3 CR ro.svg', text='Critic, posibilă dispariție în sălbăticie', cat='Specii în pericol critic de dispariție'}

	statusData['iucn3.1'] = {}
	statusData['iucn3.1']['ex'] = {image='Status iucn3.1 EX ro.svg', text='Dispărut', cat='Specii dispărute'}
	statusData['iucn3.1']['ew'] = {image='Status iucn3.1 EW ro.svg', text='Stare de dispariție', cat='Specii dispărute în stare sălbatică'}
	statusData['iucn3.1']['cr'] = {image='Status iucn3.1 CR ro.svg', text='Critic', cat='Specii în pericol critic de dispariție'}
	statusData['iucn3.1']['en'] = {image='Status iucn3.1 EN ro.svg', text='În pericol', cat='Specii amenințate'}
	statusData['iucn3.1']['vu'] = {image='Status iucn3.1 VU ro.svg', text='Vulnerabil', cat='Specii în stare vulnerabilă'}
	statusData['iucn3.1']['nt'] = {image='Status iucn3.1 NT ro.svg', text='Risc scăzut (NT)', cat='Specii amenințate moderat'}
	statusData['iucn3.1']['lc'] = {image='Status iucn3.1 LC ro.svg', text='Risc scăzut (LC)', cat='Specii cu risc scăzut'}
	statusData['iucn3.1']['dd'] = {image='Status iucn3.1 blank.svg', text='Date insuficiente'}
	statusData['iucn3.1']['ne'] = {text='Neevaluată'}
	statusData['iucn3.1']['nr'] = {text='Nerecunoscută'}
	statusData['iucn3.1']['pw'] = {image='Status iucn3.1 LC ro.svg', text='Critic, posibilă dispariție', cat='Specii în pericol critic de dispariție'}
	statusData['iucn3.1']['pew'] = {image='Status iucn3.1 LC ro.svg', text='Critic, posibilă dispariție în sălbăticie', cat='Specii în pericol critic de dispariție'}
	
	statusData['iucn'] = statusData['iucn3.1']
	
	local ret = {}
	for i=1,2 do
		local statusArgName = 'status'
		if i ~= 1 then statusArgName = statusArgName .. tostring(i) end
		local statusObj = statusData[mw.ustring.lower(args[statusArgName .. '_system'])][mw.ustring.lower(args[statusArgName])]
		if statusObj == nil then return '' end
		local retTxt = ''
		if statusObj.image then retTxt = retTxt .. '[[Fișier:' .. statusObj.image .. '|frameless]]' end
		if statusObj.text then retTxt = retTxt .. tostring(mw.html.create('br')) .. statusObj.text end
		if statusObj.cat then retTxt = retTxt .. '[[Categorie:' .. statusObj.cat .. ']]' end
		table.insert(ret, retTxt)
	end
	return ret
end

local function extractTaxonomyFromArgs(args)
	local taxonomy = nil
	for argN,argV in pairs(args) do
		if argMap[argN] then
			if taxonomy == nil then taxonomy = {} end
			taxonomy[argMap[argN]] = argV
		end
	end
	if args['binomial'] then
		if taxonomy == nil then taxonomy = {} end
		taxonomy.name = binomial
	end
	local argAuthority = args['binomial_authority'] or args['binomial authority'] or args['autoritate_binomial'] or args['binomial_autoritate']
	if argAuthority then
		if taxonomy == nil then taxonomy = {} end
		taxonomy.author = argAuthority
	end
	return nil
end

local function extractTaxonomyFromWikidata() 
	local taxonomy = nil
	local taxonNameClaims = wikidata.findClaimsForProperty(nil, 'P225') -- taxon name
	local taxonRanks = wikidata.getBestEntityIdsList(nil, 'P105') -- taxon rank list
	local qTaxonRank = nil
	if taxonRanks and #taxonRanks > 0 then qTaxonRank = StringUtils.prependIfMissing({taxonRanks[1], 'Q'}) end -- taxon rank
	local rankValue = { deprecated = 0, normal = 1, preferred = 2 }
	if taxonNameClaims and #taxonNameClaims > 0 then
		table.sort(taxonNameClaims, function(c1, c2) return rankValue[c1.rank] > rankValue[c2.rank] end)
		taxonomy = {}
		taxonomy.qrank = qTaxonRank
		taxonomy.name = wikidata.printSnak(taxonNameClaims[1].mainsnak) .. wikidata.outputReferences(taxonNameClaims[1])
		if taxonNameClaims[1].qualifiers and taxonNameClaims[1].qualifiers['P405'] then -- taxon author
			local taxonAuthorNamesList = {}
			for taxonAuthorIdx,taxonAuthorQualifier in ipairs(taxonNameClaims[1].qualifiers['P405']) do
				local taxonAuthorCitation = nil
				if taxonAuthorQualifier.datatype == 'wikibase-item' and taxonAuthorQualifier.datavalue.type == 'wikibase-entityid' then
					local taxonAuthorQID = StringUtils.prependIfMissing({tostring(taxonAuthorQualifier.datavalue.value['numeric-id']), 'Q'})
					taxonAuthorCitation = wikidata.findOneValueNoRef('P428', taxonAuthorQID) -- botanist author abbreviation
					if taxonAuthorCitation == nil then
						taxonAuthorCitation = wikidata.findOneValueNoRef('P835', taxonAuthorQID) --author citation (zoology)
					end
					local taxonAuthorLink = nil
					if taxonAuthorCitation == nil then
						taxonAuthorLink = wikidata.printSnak(taxonAuthorQualifier)
					else 
						taxonAuthorLink = '[[' .. (mw.wikibase.sitelink(taxonAuthorQID) or (':d:' .. taxonAuthorQID)) .. '|' .. taxonAuthorCitation .. ']]'
					end
					taxonAuthorLink = taxonAuthorLink .. wikidata.outputReferences(taxonAuthorQualifier)
					table.insert(taxonAuthorNamesList, taxonAuthorLink)
				end
			end
			taxonAuthorNamesList.separator = ', '
			taxonomy.author = join(taxonAuthorNamesList)
		end
		if taxonNameClaims[1].qualifiers and taxonNameClaims[1].qualifiers['P574'] and taxonNameClaims[1].qualifiers['P574'][1] then
			local d = wikidata.extractDateFromClaim(taxonNameClaims[1].qualifiers['P574'][1])
			if d and d.year then taxonomy.publicationDate = tostring(d.year) end
		end
	end
	local taxonParentIdList = wikidata.getBestEntityIdsList(nil, 'P171') -- parent taxon
	while taxonParentIdList and #taxonParentIdList > 0 do
		if taxonomy == nil then taxonomy = {} end
		local taxonParentId = taxonParentIdList[1]
		local qTaxonParentId = StringUtils.prependIfMissing({taxonParentId, 'Q'})
		local taxonParentName = wikidata.findOneValueNoRef('P225', qTaxonParentId) -- taxon name
		local taxonSitelink = mw.wikibase.sitelink(qTaxonParentId) or (':d:' .. qTaxonParentId)
		local taxonRankId = wikidata.getBestEntityIdsList(qTaxonParentId, 'P105') -- taxon rank
		if taxonRankId and taxonRankId[1] then
			local qTaxonRankId = StringUtils.prependIfMissing({taxonRankId[1], 'Q'})
			taxonomy[qTaxonRankId] = '[[' .. taxonSitelink .. '|' .. (taxonParentName or qTaxonParentId)  .. ']]'
		end
		taxonParentIdList = wikidata.getBestEntityIdsList(qTaxonParentId, 'P171') -- parent taxon
	end
	return taxonomy
end

local function getNameAndAuthority(qId)
	local qItem = StringUtils.prependIfMissing({qId, 'Q'})
	local sName = wikidata.findOneValueNoRef('P225', qItem)
	local sClaims = wikidata.findClaimsForProperty(qItem, 'P225')
	local authors = nil
	local year = nil
	local nStatus = nil
	if sName and sClaims and #sClaims > 0 and sClaims[1].qualifiers then
		if sClaims[1].qualifiers['P405'] then
			local taxonAuthorNamesList = {}
			for taxonAuthorIdx,taxonAuthorQualifier in ipairs(sClaims[1].qualifiers['P405']) do
				local taxonAuthorCitation = nil
				if taxonAuthorQualifier.datatype == 'wikibase-item' and taxonAuthorQualifier.datavalue.type == 'wikibase-entityid' then
					local taxonAuthorQID = StringUtils.prependIfMissing({tostring(taxonAuthorQualifier.datavalue.value['numeric-id']), 'Q'})
					taxonAuthorCitation = wikidata.findOneValueNoRef('P428', taxonAuthorQID) -- botanist author abbreviation
					if taxonAuthorCitation == nil then
						taxonAuthorCitation = wikidata.findOneValueNoRef('P835', taxonAuthorQID) --author citation (zoology)
					end
					local taxonAuthorLink = nil
					if taxonAuthorCitation == nil then
						taxonAuthorLink = wikidata.printSnak(taxonAuthorQualifier)
					else 
						taxonAuthorLink = '[[' .. (mw.wikibase.sitelink(taxonAuthorQID) or (':d:' .. taxonAuthorQID)) .. '|' .. taxonAuthorCitation .. ']]'
					end
					taxonAuthorLink = taxonAuthorLink .. wikidata.outputReferences(taxonAuthorQualifier)
					table.insert(taxonAuthorNamesList, taxonAuthorLink)
				end
			end
			taxonAuthorNamesList.separator = ', '
			authors = join(taxonAuthorNamesList)
		end
		if sClaims[1].qualifiers['P574'] and sClaims[1].qualifiers['P574'][1] then
		    local d = wikidata.extractDateFromClaim(sClaims[1].qualifiers['P574'][1])
		    if d and d.year then year = tostring(d.year) end
		end
		if sClaims[1].qualifiers['P1135'] and sClaims[1].qualifiers['P1135'][1] then
			nomStatus = sClaims[1].qualifiers['P1135'][1]
		    if nomStatus.datatype == 'wikibase-item' and nomStatus.datavalue.type == 'wikibase-entityid' then
		    	local nomStatusQID = StringUtils.prependIfMissing({tostring(nomStatus.datavalue.value['numeric-id']), 'Q'})
				nStatus = wikidata.findLinkToItem(nomStatusQID, false, false, true)
			end
		end
	end
	local entry = nil
	if sName then
		entry = {}
		entry.name = sName
		entry.author = authors
		entry.year = year
		entry.nomStatus = nStatus
	end
	mw.logObject(entry)
	return entry
end

local function extractSynonymsFromWikidata()
	local synonymEntries = nil
	local synonyms1420 = wikidata.getBestEntityIdsList(nil, 'P1420') -- synonyms
	local synonyms694 = wikidata.getBestEntityIdsList(nil, 'P694') -- synonyms nom.nov.
	if synonyms1420 == nil and synonyms694 == nil then
		return nil
	end
	local synonyms = {}
	for syn = 1, #synonyms1420 do
		synonyms[synonyms1420[syn]] = true
	end
	for syn = 1, #synonyms694 do
		synonyms[synonyms694[syn]] = true
	end
	local synTableIdx = 1
	if synonyms then
		synonymEntries = {}
		for synonymId,synonymBool in pairs(synonyms) do
			local synonymEntry = getNameAndAuthority(synonymId)
			
			if synonymEntry then 
				synonymEntries[synTableIdx] = synonymEntry 
				synTableIdx = synTableIdx + 1
			end
		end
	end
	if synonymEntries then
		table.sort(synonymEntries, function(c1, c2) 
			if c1 and c2 and c1.year and c2.year then 
				if c1.year == c2.year then return c1.name < c2.name end
				return c1.year < c2.year
			end
			if c1 and c1.year then return true end
			if c2 and c2.year then return false end
			return c1.name < c2.name
		end)
	end
	return synonymEntries
end

local function isValueSnak(snak)
	return snak and snak.snaktype == 'value'
end

local function hasValueSnak(claim)
	return claim and claim.type == 'statement' and isValueSnak(claim.mainsnak)
end

local function findImageAndCaption(entityId, propertyId, defaultCaption)
	local wikidataImages = wikidata.findBestClaimsForProperty(entityId, propertyId)
	local imageName, imageCaption
	if wikidataImages and #wikidataImages > 0 then
		local wikidataImage = wikidataImages[1]
		if hasValueSnak(wikidataImage) and wikidataImage.mainsnak.datavalue then
			imageName = wikidataImage.mainsnak.datavalue.value
			local roDescr = defaultCaption
			if wikidataImage.qualifiers and wikidataImage.qualifiers['P2096'] then
				for _,eachImageDescrLangString in pairs(wikidataImage.qualifiers['P2096']) do
					if isValueSnak(eachImageDescrLangString) and eachImageDescrLangString.datavalue and eachImageDescrLangString.datavalue.value.language == 'ro' then
						roDescr = eachImageDescrLangString.datavalue.value.text or roDescr
					end
				end
			end
			if roDescr == defaultCaption and wikidataImage.qualifiers and wikidataImage.qualifiers['P180'] then
				local subjList = {}
				for _,eachSubj in pairs(wikidataImage.qualifiers['P180']) do
					subjDescrQID = StringUtils.prependIfMissing({tostring(eachSubj.datavalue.value.id), 'Q'})
					
					local subjLabel = wikidata.findLabel(subjDescrQID, 'ro')
					subjDescr = "[[" .. (mw.wikibase.sitelink(subjDescrQID) or (':d:' .. subjDescrQID)) .. '|' .. StringUtils._capitalize({subjLabel}) .. "]]"
					if subjLabel == wikidata.findOneValueNoRef('P225', subjDescrQID) then
						subjDescr = "''" .. subjDescr .. "''"
					end

					table.insert(subjList, subjDescr)
				end
				subjList.separator = ', '
				roDescr = join(subjList) or roDescr
			end
			imageCaption = roDescr
		end
	end
	return imageName, imageCaption
end

p._displayInfobox = function(args)
	local ibArgs = { antet = 'biota' }
	if args['colour'] then ibArgs['culoare cadru'] = args['colour'] end
	local wdLabel = wikidata.findLabel()
	if wdLabel == wikidata.findOneValueNoRef('P225', nil) then
		wdLabel = "''" .. wdLabel .. "''"
	end
	local title = args['nume'] or args['name'] or wdLabel
	if title == nil or mw.ustring.len(mw.text.trim(title)) == 0 then
		title = mw.title.getCurrentTitle().text
	end
	if args['temporal_range'] then
		title = title .. tostring(mw.html.create('br')) .. tostring(mw.html.create('small'):wikitext('Fosilă: ' .. args['temporal_range']))
	end
	ibArgs['title'] = StringUtils._capitalize({title})
	local img = {}
	if args['image'] then 
		img[1] = args['image']
		ibArgs['image'] = infoboxImage{image=img[1], sizedefault='280px', upright='1', alt=args['image_alt']} 
		ibArgs['caption'] = args['image_caption']
	else
		imagewd, captionwd = findImageAndCaption(nil, 'P18', nil)
		img[1] = imagewd
		ibArgs['image'] = infoboxImage{image=img[1], sizedefault='280px', upright='1', alt=args['image_alt']} 
		ibArgs['caption'] = captionwd
	end
	img[2] = args['image2']
	if img[2] then ibArgs['image2'] = infoboxImage{image=img[2], sizedefault='280px', upright='1', alt=args['image2_alt']} end
	ibArgs['caption2'] = args['image2_caption']
	
	local entryIndex = 1
	local statusDescriptions = nil
	if args['status'] and args['status_system'] then
		statusDescriptions = extractStatusFromArgs(args)
	else
		statusDescriptions = extractStatusFromWikidata()
	end
	if statusDescriptions and #statusDescriptions > 0 then
		ibArgs['header' .. tostring(entryIndex)] = '[[Stare de conservare]]'
		entryIndex = entryIndex + 1
		for statDescIdx=1,#statusDescriptions,1 do
			ibArgs['data' .. tostring(entryIndex)] = statusDescriptions[statDescIdx]
			entryIndex = entryIndex + 1
		end
	end
	
	local taxonomy = extractTaxonomyFromArgs(args)
	if taxonomy == nil or #taxonomy == 0 then
		taxonomy = extractTaxonomyFromWikidata()
	end
	if taxonomy then
		ibArgs['header' .. tostring(entryIndex)] = '[[Clasificare științifică]]'
		entryIndex = entryIndex + 1
		
		for _k,eachTaxonOrder in pairs(taxonorder) do
			if taxonomy[eachTaxonOrder] then
				ibArgs['label' .. tostring(entryIndex)] = '[[' .. (mw.wikibase.sitelink(eachTaxonOrder) or (':d:' .. eachTaxonOrder)) .. '|' .. StringUtils.capitalize({wikidata.findLabel(eachTaxonOrder)}) .. ']]'
				ibArgs['data' .. tostring(entryIndex)] = taxonomy[eachTaxonOrder]
				entryIndex = entryIndex + 1
			end
		end
		if taxonomy.name then
			if taxonomy.qrank == 'Q7432' then
				ibArgs['header' .. tostring(entryIndex)] = '[[Nume binomial]]'
			else
				if taxonomy.qrank then
					ibArgs['header' .. tostring(entryIndex)] = '[[' .. (mw.wikibase.sitelink(taxonomy.qrank) or (':d:' .. taxonomy.qrank)) .. '|' .. StringUtils.capitalize({wikidata.findLabel(taxonomy.qrank)}) .. ']]'
				else
					ibArgs['header' .. tostring(entryIndex)] = 'Rang necunoscut'
				end
			end				
			entryIndex = entryIndex + 1
			ibArgs['data' .. tostring(entryIndex)] = "'''" .. tostring(mw.html.create('span'):addClass('binomial'):wikitext(taxonomy.name)) .. "'''"
			entryIndex = entryIndex + 1
			if taxonomy.author then
				ibArgs['data' .. tostring(entryIndex)] = tostring(tostring(mw.html.create('small'):wikitext(join({taxonomy.author, taxonomy.publicationDate, separator = ', '}))))
				entryIndex = entryIndex + 1
			end
		end
	end
	
	taxonomicTypes = wikidata.getBestEntityIdsList(nil, 'P427') 
	if taxonomicTypes and #taxonomicTypes > 0 then
		for typeIdx,taxonomicType in ipairs(taxonomicTypes) do
			local qType = StringUtils.prependIfMissing({taxonomicType, 'Q'})
			local taxType = getNameAndAuthority(qType)
			if taxType then
				ibArgs['header' .. tostring(entryIndex)] = 'Tip taxonomic'
				entryIndex = entryIndex + 1
				ibArgs['data' .. tostring(entryIndex)] = "''[[" .. (mw.wikibase.sitelink(qType) or (':d:' .. qType)) .. '|' .. taxType.name .. "]]''"
				if taxType.author then
					ibArgs['data' .. tostring(entryIndex)] = ibArgs['data' .. tostring(entryIndex)] .. ' ' .. tostring(tostring(mw.html.create('small'):wikitext(join({taxType.author, taxType.year, separator = ', '}))))
				end
				if taxType.nomStatus then
					ibArgs['data' .. tostring(entryIndex)] = ibArgs['data' .. tostring(entryIndex)] .. ' ' .. tostring(tostring(mw.html.create('small'):wikitext('(' .. taxType.nomStatus .. ')')))
				end
				entryIndex = entryIndex + 1
			end
		end
	end
	
	local rangeMap = args['range_map']
	if rangeMap then
		ibArgs['data' .. tostring(entryIndex)] = infoboxImage{image=rangeMap, sizedefault='280px', upright='1', alt=args['image_alt']}
		entryIndex = entryIndex + 1
	else
		rangeMap, rangeCaption = findImageAndCaption(nil, 'P181', 'Areal de răspândire')
		if rangeMap then
			ibArgs['data' .. tostring(entryIndex)] = infoboxImage{image=rangeMap, sizedefault='280px', upright='1'}
			entryIndex = entryIndex + 1
			ibArgs['data' .. tostring(entryIndex)] = rangeCaption
			entryIndex = entryIndex + 1
		end
	end
	local synonymEntries = extractSynonymsFromWikidata()
	if synonymEntries and #synonymEntries > 0 then
		ibArgs['header' .. tostring(entryIndex)] = 'Sinonime'
		entryIndex = entryIndex + 1
		for synIdx=1,#synonymEntries,1 do
			local entry = synonymEntries[synIdx]
			local synonymData = "''" .. entry.name .. "''"
			if entry.author then
				synonymData = synonymData .. ' ' .. tostring(mw.html.create('small'):wikitext(join({entry.author, entry.year, separator = ', '})))
			end
	        if entry.nomStatus then
				synonymData = synonymData .. ' ' .. tostring(mw.html.create('small'):wikitext('(' .. entry.nomStatus .. ')'))
	        end
			ibArgs['data' .. tostring(entryIndex)] = synonymData
			entryIndex = entryIndex + 1
		end
	end

	ibArgs.doc = 'Taxobox-wd'
	ibArgs.wikidata = 'y'
	return infobox._infobox(ibArgs)
end

p.infobox = function(frame)
	local args = getArgs(frame)
	return p._displayInfobox(args)
end

return p