Difference between revisions of "Module:Authority control"

From Betting Wiki
Jump to navigation Jump to search
en>Tpt
m
en>Tpt
(fix errors)
Line 14: Line 14:
 
end
 
end
  
local config = {
+
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.getParent().args
+
     local parentArgs = frame:getParent().args
 
     --Create rows
 
     --Create rows
     local lines = {}
+
     local elements = {}
     for k, conf in config do
+
     for k, params in pairs( conf ) do
         if parentArgs[conf[0]] and parentArgs[conf[0]] ~= '' then
+
         if parentArgs[params[1]] and parentArgs[params[1]] ~= '' then
             table.append( lines, conf[1] .. ': ' .. conf[3]( parentArgs[conf[0]] ) )
+
             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 navbox._navbox( {
+
     return Navbox._navbox( {
 
         name  = 'Authority control',
 
         name  = 'Authority control',
 
         bodyclass = 'hlist',
 
         bodyclass = 'hlist',
 
         group1 = '[[Authority control]]',
 
         group1 = '[[Authority control]]',
         list1 = table.concat( lines, '*' )
+
         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