Difference between revisions of "Module:Authority control"
Jump to navigation
Jump to search
en>Tpt m |
en>Tpt (fix errors) |
||
| Line 14: | Line 14: | ||
end | end | ||
| − | local | + | local conf = { |
{ 'VIAF', '[[Virtual International Authority File|VIAF]]', 0, viafLink } | { 'VIAF', '[[Virtual International Authority File|VIAF]]', 0, viafLink } | ||
} | } | ||
| Line 21: | Line 21: | ||
function p.authorityControl( frame ) | function p.authorityControl( frame ) | ||
| − | local parentArgs = frame | + | local parentArgs = frame:getParent().args |
--Create rows | --Create rows | ||
| − | local | + | local elements = {} |
| − | for k, conf | + | for k, params in pairs( conf ) do |
| − | if parentArgs[ | + | if parentArgs[params[1]] and parentArgs[params[1]] ~= '' then |
| − | table. | + | table.insert( elements, params[2] .. ': ' .. params[4]( parentArgs[params[1]] ) ) |
end | end | ||
end | end | ||
| − | |||
local Navbox = require('Module:Navbox') | local Navbox = require('Module:Navbox') | ||
| − | return | + | return Navbox._navbox( { |
name = 'Authority control', | name = 'Authority control', | ||
bodyclass = 'hlist', | bodyclass = 'hlist', | ||
group1 = '[[Authority control]]', | group1 = '[[Authority control]]', | ||
| − | list1 = table.concat( | + | list1 = table.concat( elements, '*' ) |
} ) | } ) | ||
end | end | ||
return p | return p | ||
Revision as of 07:05, 6 April 2013
Documentation for this module may be created at Module:Authority control/doc
function outputError( message, cat )
local str = '<span class="error">' .. message .. '</span>'
if cat then
str = str .. '[[Category:' .. cat .. ']]'
end
return str
end
function viafLink( id )
if not string.match( id, '^%d+$' ) then
return outputError( 'The VIAF id ' .. id .. ' is not valid.', 'Wikipedia articles with faulty authority control identifiers (VIAF)' )
end
return '<span class="uid">[http://viaf.org/viaf/' .. id .. ' ' .. id .. ']</span>'
end
local conf = {
{ 'VIAF', '[[Virtual International Authority File|VIAF]]', 0, viafLink }
}
local p = {}
function p.authorityControl( frame )
local parentArgs = frame:getParent().args
--Create rows
local elements = {}
for k, params in pairs( conf ) do
if parentArgs[params[1]] and parentArgs[params[1]] ~= '' then
table.insert( elements, params[2] .. ': ' .. params[4]( parentArgs[params[1]] ) )
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