Module:Authority control

function getCatForId( id ) local title = mw.title.getCurrentTitle local namespace = title.namespace if namespace == 0 then return '' elseif namespace == 2 and not title.isSubpage then return '' else return '' end end

function viafLink( id ) if not string.match( id, '^%d+$' ) then return false end return '[http://viaf.org/viaf/' .. id .. ' ' .. id .. ']' end

function lccnLink( id ) cleanedId = '' if string.match( id, '^%l%l?%l?/%d%d%d?%d?/%d%d%d%d%d%d$' ) then cleanedId = string.gsub( id, '(%l+)/(%d+)/(%d+)$', '%1%2%3' ) end if string.match( id, '^%%l%l?%l?%d%d%d%d%d%d%d%d%d?%d?$' ) then cleanedId = id   end if cleanedId == '' then return false end return '[http://id.loc.gov/authorities/names/' .. cleanedId .. ' ' .. cleanedId .. ']' end

--In this order: name of the parameter, label, propertyId in Wikidata, formattting function local conf = { { 'VIAF', 'VIAF', 0, viafLink }, { 'LCCN', 'LCCN', 0, lccnLink } } local p = {}

function p.authorityControl( frame ) local parentArgs = frame:getParent.args --Create rows local elements = {} for k, params in pairs( conf ) do       local val = parentArgs[params[1]] if val and val ~= '' then local link = params[4]( val ) if link then table.insert( elements, params[2] .. ': ' .. link .. ' ' .. getCatForId( params[1] ) ) else table.insert( elements, ' The ' .. params[1] .. ' id ' .. val .. ' is not valid. ' ) end end end local Navbox = require('Module:Navbox') return Navbox._navbox( {       name  = 'Authority control',        bodyclass = 'hlist',        group1 = 'Authority control',        list1 = table.concat( elements, ' * ' )    } ) end

return p