Modul:Exponat etnografic
Aspect
Documentația acestui modul poate fi creată la Modul:Exponat etnografic/doc
local p = {}
local getArgs = require('Modul:Arguments').getArgs
local infoboxImage = require('Modul:InfoboxImage').InfoboxImage
local isNilOrEmpty= require('Modul:StringUtils').isNilOrEmpty
local function etnomonLink(id)
if isNilOrEmpty(id) or mw.ustring.len(id) ~= 32 or mw.ustring.match(id, "[0-9A-F]+") == nil then
return '<div class="error">ID ETNOMON invalid</div>'
end
return 'https://monumente-etnografice.cimec.ro/muzee-in-aer-liber.asp?ID=' .. id
end
local function _generate(args)
-- {{#invoke:InfoboxImage|InfoboxImage|image={{{imagine|Fișier:No image available.svg}}}|size=200px|sizedefault=frameless|suppressplaceholder=no}}
local imageContent = infoboxImage{image=args['imagine'], size='200px', sizedefault='frameless', suppressplaceholder='no', alt=args['nume'] or ''}
image = mw.html.create('td'):attr('width','200px'):wikitext(imageContent)
local nameContent = '{{background color|' .. (args['culoare'] or '') .. '|\'\'\' ' .. (args['marcaj'] or '') .. ' \'\'\'}} \'\'\'' .. args['nume'] .. '\'\'\''
local linesContent = ''
if args['observații'] then linesContent = linesContent .. '<br/>' .. args['observații'] end
local url1 = nil
local url2 = nil
if args['url-muzeu'] then
url1 = '{{plain link|' .. args['url-muzeu'] .. '|Pagina muzeului}}'
end
if args['etnomon'] then
url2 = '{{plain link|1=' .. etnomonLink(args['etnomon']) .. '|2=ETNOMON}}'
end
if url1 ~= nil and url2 ~= nil then
linesContent = linesContent .. '<br/>' .. url1 .. '{{*}}' .. url2
elseif url1 ~= nil then
linesContent = linesContent .. '<br/>' .. url1
elseif url2 ~= nil then
linesContent = linesContent .. '<br/>' .. url2
end
if args['datare'] then linesContent = linesContent .. '<br/>Datare: ' .. args['datare'] end
if args['coord'] then
linesContent = linesContent .. '<br/>Coordonate în muzeu: '
if table.maxn(args['coord']) > 1 then
for coordIndex = 1, table.maxn(args['coord']) do
linesContent = linesContent .. '<br/>{{0}}{{coord|' .. args['coord'][coordIndex]['lat'] .. '|' .. args['coord'][coordIndex]['lon'] .. '}}'
end
else
linesContent = linesContent .. '{{coord|' .. args['coord'][1]['lat'] .. '|' .. args['coord'][1]['lon'] .. '}}'
end
end
if args['origine'] then linesContent = linesContent .. '<br/>Localitatea de origine: ' .. args['origine'] end
if args['cod-lmi'] then linesContent = linesContent .. '<br/><small>{{Monument istoric|' .. args['cod-lmi'] .. '}}</small>' end
if args['commons'] then linesContent = linesContent .. '<br/><small>{{Commons-inline|' .. args['commons'] .. '|' .. args['nume'] .. '}}</small>' end
local textContent = mw.html.create('span'):css('font-size','1.2em'):wikitext(mw.getCurrentFrame():preprocess(nameContent)):allDone()
text = mw.html.create('td'):css('text-align','left'):node(textContent):wikitext(mw.getCurrentFrame():preprocess(mw.getCurrentFrame():preprocess(linesContent))):allDone()
root = mw.html.create('table')
root:attr('width','100%')
:css('border', 'solid black 1px')
:tag('tr')
:node(image)
:node(text)
return tostring(root)
end
local function _processArgs(args)
local processedArgs = {}
local nlStart, nlEnd, nlName
for argN, argV in pairs(args) do
if argV ~= nil and mw.text.trim(argV) == '' then args[argN] = nil end
latStart, latEnd = mw.ustring.find(argN, 'lat')
lonStart, lonEnd = mw.ustring.find(argN, 'lon')
if latStart == 1 then
nlStart = latStart
nlEnd = latEnd
nlCat = 'coord'
nlVar = 'lat'
elseif lonStart == 1 then
nlStart = lonStart
nlEnd = lonEnd
nlCat = 'coord'
nlVar = 'lon'
else
nlStart = nil
end
if nlStart ~= nil then -- handle params with numbers
local varNameWithIndex = mw.ustring.sub(argN, nlStart, mw.ustring.len(argN))
local indexLocation = mw.ustring.find(varNameWithIndex, "%d+") or (1 + #varNameWithIndex)
local variableName = mw.ustring.sub(varNameWithIndex, 1, indexLocation - 1)
local variableIndexStr = mw.ustring.sub(varNameWithIndex, indexLocation, #varNameWithIndex) or ""
local variableIndex
if variableIndexStr == "" then variableIndex = 1 else variableIndex = tonumber(variableIndexStr) end
if processedArgs[nlCat] == nil then processedArgs[nlCat] = {} end
if processedArgs[nlCat][variableIndex] == nil then processedArgs[nlCat][variableIndex] = {} end
processedArgs[nlCat][variableIndex][nlVar] = mw.text.trim(argV)
elseif mw.ustring.match(argN, 'etnomon') ~= nil then -- handle aliases
processedArgs['etnomon'] = mw.text.trim(argV)
else
processedArgs[argN] = mw.text.trim(argV)
end
end --for argN, argV in pairs(args)
-- defaults
if processedArgs['imagine'] == nil then
processedArgs['imagine'] = 'Fișier:No image available.svg'
end
if processedArgs['culoare'] == nil then
processedArgs['culoare'] = 'white'
end
return processedArgs
end
p.etnomonFromArgs = function(args)
local link = etnomonLink(args[1])
if mw.ustring.find(link, 'http') == nil then return link end
if isNilOrEmpty(args[2]) then
return '[' .. link .. ' ETNOMON - Muzeul virtual al monumentelor etnografice în aer liber din România]'
end
return 'Pagina despre [' .. link .. ' \'\'\'' .. args[2] .. '\'\'\'] în [[ETNOMON|Muzeul virtual al monumentelor etnografice în aer liber din România]]'
end
p.etnomon = function(frame)
local args = getArgs(frame, {parentFirst = true})
return p.etnomonFromArgs(args)
end
p.displayFromArgs = function(processedArgs)
local outtext = _generate(processedArgs)
return outtext
end
p.display = function(frame)
local args = getArgs(frame, {parentFirst = true})
local processedArgs = _processArgs(args)
return p.displayFromArgs(processedArgs)
end
return p