local instanceOf = instanceOfState.mainsnak.datavalue.value.id
if acceptableInstanceOf_All[instanceOf] then
tCats[4] = ''
break
end
end
end  
--Cleanup args
for k, v in pairs( :getParent.args ) do
if type(k) == 'string' then
--make args case insensitive
local lowerk = mw.ustring.lower(k)
if isNilOrEmpty( parentArgs[lowerk] ) then
parentArgs[k] = nil
parentArgs[lowerk] = v
end
--remap abc to abc1
if mw.ustring.find(lowerk,'%d$') == nil then --if no number at end of param
if isNilOrEmpty( parentArgs[lowerk..'1'] ) then
parentArgs[lowerk] = nil
lowerk = lowerk..'1'
parentArgs[lowerk] = v
end
end
if v and v ~= '' then
--remap 'for' to 'title'
if mw.ustring.sub(lowerk,1,3) == 'for' then
local forTitle = mw.ustring.gsub(lowerk,'^for','title',1)
if isNilOrEmpty( parentArgs[forTitle] ) then
parentArgs[lowerk] = nil
lowerk = forTitle
parentArgs[lowerk] = v
end
end
--find highest from or title param
if mw.ustring.sub(lowerk,1,4) == 'from' then
local fromNumber = tonumber(mw.ustring.sub(lowerk,5,-1))
if fromNumber and fromNumber >= fromTitleCount then fromTitleCount = fromNumber end
--look for duplicate froms while we're here
if mw.ustring.find(v, '^Q%d') then
if tFroms[v] then
tCats[6] = ''
tFroms[v] = tFroms[v] + 1
else
tFroms[v] = 1
iFroms = iFroms + 1
end
if iFroms == 2 then
tCats[14] = ''
end
end
elseif mw.ustring.sub(lowerk,1,5) == 'title' then
local titleNumber = tonumber(mw.ustring.sub(lowerk,4,-1))
if titleNumber and titleNumber >= fromTitleCount then fromTitleCount = titleNumber end
elseif mw.ustring.lower(v) ~= 'no' then
stringArgs = true
tCats[9] = ''
end
end
end --if type(k) == 'string'
end --for  
--Check for unknown parameters
--create knowns list
local acceptableArgs = { from = true, } --master list of l/c acceptable args
for _, d in pairs( conf.databases ) do
if d[1] ~= 'Wikidata' then --made obsolete by from
acceptableArgs[mw.ustring.lower(d[1])] = true
end
end
for _, a in pairs( conf.aliases ) do
acceptableArgs[mw.ustring.lower(a[1])] = true
end
--create trimmed parents list
local baseParentArgs = {} --condensed list of l/c parent args w/o trailing #s
for k, _ in pairs( parentArgs ) do
if type(k) == 'string' then
local lowerk = mw.ustring.lower(k)
local base = mw.ustring.gsub(lowerk, '[%d]*$', '')
baseParentArgs[base] = true
elseif type(k) == 'number' then
tCats[13] = ''
end
end
--compare lists and spit out unknowns
local unknownParams = {}
for k, _ in pairs( baseParentArgs ) do
if acceptableArgs[k] == nil then
tCats[12] = ''
unknownParams[#unknownParams + 1] = k
end
end
--warn if unknown(s) present
if #unknownParams > 0 then
local plural = 's'
local itthem = 'them'
if #unknownParams == 1 then
plural = ''
itthem = 'it'
end
errors = errors..require('Module:If preview')._warning({
mw.ustring.format(
'Unknown parameter%s <code>%s</code>. Please correct %s or consider adding %s to Wikidata.',
plural,
table.concat(unknownParams, '</code>, <code>'),
itthem,
itthem
})
end  
--Append basionym to arg list, if not already provided
if currentItem then
local currentBasState = currentItem:getBestStatements('P566')[1] --basionym
if currentBasState then
local basionymId = currentBasState.mainsnak.datavalue.value.id
if basionymId and resolveEntity._id(basionymId) and tFroms[basionymId] == nil then
--check that basionym is a strict instance of taxon
local basionymItem = mw.wikibase.getEntity(basionymId)
if basionymItem then
for _, instanceOfState in pairs ( basionymItem:getBestStatements('P31') ) do --instance of
local instanceOf = instanceOfState.mainsnak.datavalue.value.id
if acceptableInstanceOf_Strict[instanceOf] then
--housekeeping
tFroms[basionymId] = 1
iFroms = iFroms + 1
fromTitleCount = fromTitleCount + 1
--append basionym & track
parentArgs['from'..fromTitleCount] = basionymId
tCats[15] = ''
break
end end end end end end  
--Append original combination to arg list, if not already provided
if currentItem then
local currentOCState = currentItem:getBestStatements('P1403')[1] --original combination
if currentOCState then
local orcoId = currentOCState.mainsnak.datavalue.value.id
if orcoId and resolveEntity._id(orcoId) and tFroms[orcoId] == nil then
--check that orco is a strict instance of taxon
local orcoItem = mw.wikibase.getEntity(orcoId)
if orcoItem then
for _, instanceOfState in pairs ( orcoItem:getBestStatements('P31') ) do --instance of
local instanceOf = instanceOfState.mainsnak.datavalue.value.id
if acceptableInstanceOf_Strict[instanceOf] then
--housekeeping
tFroms[orcoId] = 1
iFroms = iFroms + 1
fromTitleCount = fromTitleCount + 1
--append orco & track
parentArgs['from'..fromTitleCount] = orcoId
tCats[16] = ''
break
end end end end end end  
--Append monotypic genus/species to arg list of monotypic species/genus, if not already provided
if currentItem then
for _, instanceOfState in pairs ( currentItem:getBestStatements('P31') ) do --instance of
local taxonRank = nil
local parentItem = nil
local parentTaxon = nil
local parentTaxonRank = nil
local parentMonoGenus = nil --holy grail/tbd
local instanceOf = instanceOfState.mainsnak.datavalue.value.id
if instanceOf and (instanceOf == 'Q310890' or instanceOf == 'Q47487597') then --monotypic/fossil taxon
local taxonRankState = currentItem:getBestStatements('P105')[1] --taxon rank
if taxonRankState then taxonRank = taxonRankState.mainsnak.datavalue.value.id end  
if taxonRank and taxonRank == 'Q7432' then --species
--is monotypic species; add genus
local parentTaxonState = currentItem:getBestStatements('P171')[1] --parent taxon
if parentTaxonState then parentTaxon = parentTaxonState.mainsnak.datavalue.value.id end
--confirm parent taxon rank == genus & monotypic
if parentTaxon and resolveEntity._id(parentTaxon) then
parentItem = mw.wikibase.getEntity(parentTaxon)
if parentItem then
local parentTaxonRankState = parentItem:getBestStatements('P105')[1] --taxon rank
if parentTaxonRankState then parentTaxonRank = parentTaxonRankState.mainsnak.datavalue.value.id end
if parentTaxonRank and parentTaxonRank == 'Q34740' then --parent == genus
for _, parentInstanceOfState in pairs ( parentItem:getBestStatements('P31') ) do --instance of
local parentInstanceOf = parentInstanceOfState.mainsnak.datavalue.value.id
if parentInstanceOf and
(parentInstanceOf == 'Q310890' or parentInstanceOf == 'Q47487597') then --monotypic/fossil taxon
parentMonoGenus = parentTaxon --confirmed
break
end
end
if parentMonoGenus and tFroms[parentMonoGenus] == nil then
--housekeeping
tFroms[parentMonoGenus] = 1
iFroms = iFroms + 1
fromTitleCount = fromTitleCount + 1
--append monotypic genus & track
parentArgs['from'..fromTitleCount] = parentMonoGenus
tCats[17] = ''
break
end
end
end
end
if parentMonoGenus == nil or tFroms[parentMonoGenus] == nil then
tCats[18] = ''
break
end
elseif taxonRank and taxonRank == 'Q34740' then --genus
--TODO:
--is monotypic genus; add species (no way to easily find these (yet?))
--...
end  
end
end --for
end --if currentItem  
--Setup navbox
local navboxParams = {
name = 'Taxonbar',
body,
list,
group,
}  
for f = 1, fromTitleCount, 1
do
local elements, title = {}, nil
--cleanup parameters
if parentArgs['from'..f] == '' then parentArgs['from'..f] = nil end
if parentArgs['title'..f] == '' then parentArgs['title'..f] = nil end
--remap aliases
for _, a in pairs( conf.aliases ) do
local alias, name = mw.ustring.lower(a[1]), mw.ustring.lower(a[2])
if parentArgs[alias..f] and parentArgs[name..f] == nil then
parentArgs[name..f] = parentArgs[alias..f]
parentArgs[alias..f] = nil
end
end
--Fetch Wikidata item
local from = resolveEntity._id(parentArgs['from'..f])
local item = mw.wikibase.getEntity(from)
local label = nil
if type(item) == 'table' then
local statements = item:getBestStatements('P225')[1] --taxon name
if statements then
local datavalue = statements.mainsnak.datavalue
if datavalue then
label = datavalue.value
end
end
label = label or item:getLabel
else
if parentArgs['from'..f] then
tCats[1] = ''
tCats[5] = ''
errors = errors..mw.text.tag('strong', {}, 'Error: "'..