Module:Taxonbar
require('Module:No globals')
local conf = require( "Module:Taxonbar/conf" )
local function getIdsFromWikidata( item, property ) local ids = {} if not item.claims[property] then return ids end for _, statement in pairs( item.claims[property] ) do if statement.mainsnak.datavalue then table.insert( ids, statement.mainsnak.datavalue.value ) end end return ids end
local function getLink( property, val ) local link = if mw.ustring.find( val, '//' ) then link = val else if type(property) == 'number' then link = mw.wikibase.getEntityObject('P'..property).claims.P1630[1].mainsnak.datavalue.value elseif type(property) == 'string' then link = property end link = mw.ustring.gsub(link, '$1', val) end link = mw.ustring.gsub(link, '^[Hh][Tt][Tt][Pp]([Ss]?)://', 'http%1://') -- fix wikidata URL val = mw.ustring.match(val, '([^=/]*)/?$') -- get display name from end of URL if mw.ustring.find( link, '//' ) then return '['..link..' '..val..']' else return ''..val..'' end end
local function createRow( id, label, rawValue, link, withUid ) if link then local outStr = '*' .. label .. ' <span' if withUid then outStr = outStr..' class="uid"' end return outStr..'>' .. link .. '\n' else return '* The identifier ' .. id .. ' ' .. rawValue .. ' is not valid.\n' end end
local function copyTable(inTable) if type(inTable) ~= 'table' then return inTable end local outTable = setmetatable({}, getmetatable(inTable)) for key, value in pairs (inTable) do outTable[copyTable(key)] = copyTable(value) end return outTable end
local p = {}
function p.authorityControlTaxon( frame ) local parentArgs = copyTable(frame:getParent().args) local stringArgs = false --Make args case insensitive for k, v in pairs( frame:getParent().args ) do if type(k) == 'string' then v = mw.ustring.lower(v) local lowerk = mw.ustring.lower(k) if not parentArgs[lowerk] or parentArgs[lowerk] == then parentArgs[lowerk] = v parentArgs[k] = nil end if v and v ~= and v ~= 'no' and lowerk ~= 'from' then stringArgs = true end end 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] and not parentArgs[name] then parentArgs[name] = parentArgs[alias] parentArgs[alias] = nil end end --Create rows local elements, title = {}, {} if parentArgs['from'] == then parentArgs['from'] = nil end local item = mw.wikibase.getEntity(parentArgs['from']) if item then title = mw.title.new(item:getLabel()) else title = mw.title.getCurrentTitle() end if (not parentArgs['wikidata'] or parentArgs['wikidata'] == ) and (title.namespace == 0) then if parentArgs['from'] then parentArgs['wikidata'] = parentArgs['from'] elseif item then parentArgs['wikidata'] = item.id end end if title.namespace == 0 or stringArgs then --Only in the main namespace or if there are manual overrides local sourcesFound = false for _, params in pairs( conf.databases ) do params[1] = mw.ustring.lower(params[1]) --Wikidata fallback if requested if (item ~= nil and item.claims ~= nil) and params[3] ~= 0 and (not parentArgs[params[1]] or parentArgs[params[1]] == ) then local wikidataIds = getIdsFromWikidata( item, 'P' .. params[3] ) if wikidataIds[1] then parentArgs[params[1]] = wikidataIds[1] end end local val = parentArgs[params[1]] if val and val ~= and mw.ustring.lower(val) ~= 'no' and params[3] ~= 0 then table.insert( elements, createRow( params[1], params[2] .. ':', val, getLink( params[3], val ), true ) ) if params[1] ~= 'wikidata' then sourcesFound = true end end end
local Navbox = require('Module:Navbox')
if sourcesFound then return Navbox._navbox( { name = 'Taxonbar', bodyclass = 'hlist', listclass = , group1 = 'Taxon identifiers', --.. elementscats, list1 = table.concat( elements ) } ) else return "" end end end
return p