local p = local args =
local data_module_prefix = "Module:Solar eclipse/db/"local infobox_image = nil -- lazy load
local function InfoboxImage(image) if (image and image ~= ) then if infobox_image
local function ifnotempty(s,a,b) if (s and s ~= ) then return a else return b endend
local function ifexist(page) if not page then return false end if mw.title.new(page).exists then return true end return falseend
local function parsedate(y,m,d) local lang = mw.language.getContentLanguage d = (tonumber(d) < 10) and ('0' .. tonumber(d)) or (d) m = (tonumber(m) < 10) and ('0' .. tonumber(m)) or (m) local success, result = pcall(lang.formatDate, lang, 'F j, Y', y .. '-' .. m .. '-' .. d) return success and result or nilend
local function parsecoord(frame, s) local lat = s:match('^%s*([%d][%d.]*)%s*[NS]%s*[%d][%d.]*[EW]%s*$') local NS = s:match('^%s*[%d][%d.]*%s*([NS])%s*[%d][%d.]*[EW]%s*$') local lon = s:match('^%s*[%d][%d.]*%s*[NS]%s*([%d][%d.]*)[EW]%s*$') local EW = s:match('^%s*[%d][%d.]*%s*[NS]%s*[%d][%d.]*([EW])%s*$') if(lat and NS and lon and EW) then return frame:expandTemplate else return s endend
local function parsekm(frame, s) if(s and s:match('^%s*[%d][%d.]*%s*$')) then return frame:expandTemplate else if(s and s ~= ) then return s .. ' km' else return nil end endend
local function parsetime(s) if(s and s ~= ) then local min = s:match('^%s*(%d+)m%s*%d+s%s*$') local sec = s:match('^%s*%d+m%s*(%d+)s%s*$') if(min and sec) then return tostring(tonumber(min)*60 + tonumber(sec)) .. ' s' .. ' (' .. min .. ' min ' .. sec .. ' s)' end end return send
local function cataloglink(c, y, m, d) y, m, d = tonumber(y), tonumber(m), tonumber(d) if tonumber(c) and y and m and d then d = (d < 10) and ('0' .. d) or d m = (m < 10) and ('0' .. m) or m return '.. y .. m .. d .. ' ' .. c .. '' else return c endend
local function loadsolardb(frame, s) local yearstr = s:match('^%s*(%d%d%d%d)[A-Z][a-z][a-z]%d%d%s*$') or local function setarg(k, v) if(v and v ~= ) then v = mw.ustring.gsub(v, '^%s*%-(%d)', '−%1') args[k] = v end end if(yearstr ~= ) then local dbsubpage = math.floor((tonumber(yearstr) - 1) / 50) * 5 local dbpage = data_module_prefix .. tostring(dbsubpage) if (ifexist(dbpage)) then local data = mw.loadData(dbpage) local dargs = data[s] or error('Error: unknown date ' .. s .. ' in Infobox solar eclipse', 0) setarg('date', parsedate(dargs['y'], dargs['m'] or dargs['m3'] or dargs['m2'], dargs['d'] or dargs['d2'])) setarg('image', (dargs['Ph'] and dargs['Ph'] ~= ) and '' or nil) setarg('caption', dargs['PhCap']) setarg('map', (dargs['Map'] and dargs['Map'] ~= ) and '' or nil) setarg('map_caption', 'Map') setarg('type_ref', ) setarg('cat', cataloglink(dargs['Cat'], dargs['y'], dargs['m'] or dargs['m3'] or dargs['m2'], dargs['d'] or dargs['d2'])) setarg('nature', dargs['Ty']) setarg('gamma', dargs['Gam']) setarg('magnitude', dargs['Mag']) setarg('saros', dargs['Saros'] and '' .. dargs['Saros'] .. '') setarg('saros_sequence', dargs['Mem']) setarg('saros_total', dargs['Max']) setarg('max_eclipse_ref', ) setarg('duration', parsetime(dargs['Dur'])) setarg('location', ) setarg('coords', parsecoord(frame,dargs['Loc'])) setarg('max_width', parsekm(frame,dargs['Wid'])) setarg('times_ref', ) setarg('start_partial', dargs['TiPB']) setarg('start_total', dargs['TiTB']) setarg('start_central', ) setarg('greatest_eclipse', dargs['TiG']) setarg('end_central', ) setarg('end_total', dargs['TiTE']) setarg('end_partial', dargs['TiPE']) end endend
local function infobox(frame) local abovestr = ifnotempty(args['date'], "Solar eclipse of " .. (args['date'] or ), "For instructions on use, see ") local bgcolor = args['background'] or args['bgcolour'] or local mapstr = ifnotempty(args['map'], "
" .. (InfoboxImage(args['map']) or ) .. ifnotempty(args['map_caption'], "
" .. (args['map_caption'] or ) .. "
", ) .. '
')
return frame:expandTemplate
end
function p.box(frame) args = require('Module:Arguments').getArgs(frame,)
if(args['2'] and args['2'] ~= ) then loadsolardb(frame,args['2']) elseif(args['1'] and args['1'] ~= ) then loadsolardb(frame,args['1']) end
return infobox(frame)end
return p