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: "'..
parentArgs['from'..f]..'" is not a valid Wikidata entity ID.
')
end
end
if label and label ~= '' then
title = mw.title.new(label)
end
if title == nil and parentArgs['title'..f] then
title = mw.title.new(parentArgs['title'..f])
end
if title == nil and f == 1 then
title = currentTitle
end  
if title then
if isNilOrEmpty( parentArgs['wikidata'..f] ) and
(title.namespace == 0) then
if parentArgs['from'..f] then
parentArgs['wikidata'..f] = parentArgs['from'..f]
elseif item then
parentArgs['wikidata'..f] = item.id
end
end
if title.namespace == 0 or stringArgs then --only in mainspace or if manual overrides exist
local sourceCount = 0
for _, params in pairs( conf.databases ) do
params[1] = mw.ustring.lower(params[1])
local propId = params[3]
--Wikidata fallback if requested
if (item and item.claims) and
(type(propId) == 'string' or (type(propId) == 'number' and propId > 0)) then
local wikidataId = getIdFromWikidata( item, 'P'..propId )
local v = parentArgs[params[1]..f]
if wikidataId then
if isNilOrEmpty(v) then
parentArgs[params[1]..f] = wikidataId
else
if v and v ~= 'no' and v ~= wikidataId then
tCats[11] = ''
elseif v and v == wikidataId then
tCats[10] = ''
end
end
end
end
if (item and item.claims) and
( (type(propId) == 'number' and propId < 0)) then
local wikidataId = getIdFromWikidata( item, 'P'..-propId )
--mw.addWarning ("propId=" .. tostring(propId) .. "; wikidata=" .. tostring(wikidataId))
local v = parentArgs[params[1]..f]
if v == 'yes' then
if wikidataId then
parentArgs[params[1]..f] = wikidataId
else
parentArgs[params[1]..f] = nil -- don't want to use 'yes' as id
end
end
end
local val = parentArgs[params[1]..f]
if val and val ~= '' and mw.ustring.lower(val) ~= 'no' then
if type(propId) == 'number' then
if propId < 0 then propId = -propId end --allow link
if propId > 0 then --link
table.insert( elements, createRow( params[1], params[2]..':', val, getLink( propId, params[1], val ).text, true ) )
else --propId == 0; no link
table.insert( elements, createRow( params[1], params[2]..':', val, val, true ) )
end
else
table.insert( elements, createRow( params[1], params[2]..':', val, getLink( propId, params[1], val ).text, true ) )
end
if params[1] ~= 'wikidata' and params[1] ~= 'wikispecies' then
sourceCount = sourceCount + 1
end
end
end --for  
if sourceCount >= 45 then tCats[26] = ''
elseif sourceCount >= 40 then tCats[25] = '' --endashes
elseif sourceCount >= 35 then tCats[24] = ''
elseif sourceCount >= 30 then tCats[23] = ''
elseif sourceCount >= 25 then tCats[22] = ''
elseif sourceCount >= 20 then tCats[21] = ''
end  
--Generate navbox title
if sourceCount > 0 then
rowCount = rowCount + 1
if firstRow == 0 then firstRow = f end
--set title from wikidata if it doesn't exist
if isNilOrEmpty( parentArgs['title'..f] ) then
parentArgs['noTitle'..f] = true
parentArgs['title'..f] = title.text
end
--if it exists now, set row heading to title
if not isNilOrEmpty( parentArgs['title'..f] ) then
navboxParams['group'..f] = TaxonItalics.italicizeTaxonName(parentArgs['title'..f], false)
else
navboxParams['group'..f] = ''
end
navboxParams['list'..f] = table.concat( elements )
elseif currentEntityId and (currentEntityId == parentArgs['from'..f] or fromTitleCount == 1) then
tCats[19] = ''
else
tCats[20] = ''
end  
--Categorize
if not isNilOrEmpty( parentArgs['from'..f] ) then
tCats[1] = '' --blank "missing from" if 'from' exists
if parentArgs['from'..f] == currentEntityId then
tCats[2] = '' --blank "desynced" if 'from' matches current page
end
end
if tCats[1] ~= '' then
tCats[2] = '' --cannot be "desynced" if no 'from' params
end
end --if title.namespace == 0 or stringArgs
end --if title
end --for f = 1, fromTitleCount, 1  
if rowCount > 0 then
local Navbox = require('Module:Navbox')
if rowCount > 1 then
--remove duplicates and don't bother moving page title to top
local rowIDs = {}
for f = 1,fromTitleCount,1
do
if not isNilOrEmpty( parentArgs['title'..f] ) then
if rowIDs[parentArgs['wikidata'..f]] then --remove duplicate
navboxParams['group'..f] = nil
navboxParams['list'..f] = nil
else
rowIDs[parentArgs['wikidata'..f]] = true
end
end
end
if parentArgs['title'..2] and parentArgs['title'..2] == currentTitle.text then
if currentItem and parentArgs['from'..2] == currentItem['id'] then
tCats[8] = ''
else
tCats[7] = ''
end
end
--adjust navbox for number of rows
navboxParams['title'] = 'உயிரின வகைப்பாட்டு
இனங்காட்டிகள்'
if rowCount >= 4 then
navboxParams['navbar'] = 'plain'
else
navboxParams['state'] = 'off'
navboxParams['navbar'] = 'off'
end
elseif parentArgs['noTitle'..firstRow] then
navboxParams['group'..firstRow] = 'உயிரின வகைப்பாட்டு
இனங்காட்டிகள்'
else
navboxParams['group'..firstRow] = 'உயிரின வகைப்பாட்டு
இனங்காட்டிகள்
'..navboxParams['group'..firstRow]
end  
--return navbox
outString = Navbox._navbox(navboxParams)
end --if rowCount > 0  
--Add categories
if string.sub(currentTitle.subpageText,1,9) == 'testcases' then parentArgs['demo'] = true end
if not isNilOrEmpty( parentArgs['demo'] ) then
outString = outString..mw.text.nowiki(table.concat(tCats))..'
'
elseif currentTitle.namespace == 0 then
outString = outString..table.concat(tCats)
end  
return outString..errors
end  
return p