Content deleted Content added
No edit summary |
use require('strict') instead of require('Module:No globals') |
||
(20 intermediate revisions by 4 users not shown) | |||
Line 1:
--[[
Display Gregorian date of a holiday that moves year to year. Date data can be obtained from multiple sources as configured in
"localfile" = local
"calculator" = user-supplied date calculator
"wikidata" = <tbd> for holidays with their own date entity page such as https://www.wikidata.org/wiki/Q51224536
]]
require('
local p = {}
local cfg -- Data structure from ~/
local eventdata -- Data structure from ~/localfiles/<holiday name>
--[[--------------------------< inlineError >-----------------------
Line 155 ⟶ 156:
local function makeDate(year, month, day, df, format)
end
Line 216 ⟶ 217:
enddate = dateOffset(startdate, cfg.days - 1)
else
return inlineError("holiday", '
end
Line 244 ⟶ 245:
enddate = dateOffset(startdate, cfg.days - 1)
elseif startdate and not enddate then
return inlineError("
else
return inlineError("
end
end
Line 313 ⟶ 314:
local cite = nil -- leave a citation at end
local calcdate = ""
▲ track = {} -- global tracking-category table
--- Determine holiday
Line 321 ⟶ 320:
holiday = trimArg(args.event) -- event alias
if not holiday then
return inlineError("holiday",
end
end
Line 328 ⟶ 327:
date = trimArg(args.year) -- required
if not date then
return inlineError("year",
elseif not isValidDate(date, "01", "01") then
return inlineError("year",
end
Line 342 ⟶ 341:
-- Load configuration file
local eventsfile = mw.loadData ('Module:Calendar date/
if eventsfile.hebrew_calendar[mw.ustring.upper(holiday)] then
cfg = eventsfile.hebrew_calendar[mw.ustring.upper(holiday)]
elseif eventsfile.christian_events[mw.ustring.upper(holiday)] then
cfg = eventsfile.christian_events[mw.ustring.upper(holiday)]
elseif eventsfile.carnivals[mw.ustring.upper(holiday)] then
cfg = eventsfile.carnivals[mw.ustring.upper(holiday)]
elseif eventsfile.chinese_events[mw.ustring.upper(holiday)] then
cfg = eventsfile.chinese_events[mw.ustring.upper(holiday)]
elseif eventsfile.misc_events[mw.ustring.upper(holiday)] then
cfg = eventsfile.misc_events[mw.ustring.upper(holiday)]
else
return inlineError("holiday", '
end
-- If datatype = localfile
if cfg.datatype == "localfile" then
local eventfile = nil
eventfile = mw.loadData(cfg.datasource)
if eventfile.event then
eventdata = eventfile.event
else
return inlineError("holiday", '
end
Line 365 ⟶ 371:
local year, month, day = calcdate:match ('(%d%d%d%d)-(%d%d)-(%d%d)')
if not isValidDate(year, month, day) then
return inlineError("holiday", '
end
else
return inlineError("holiday", '
end
Line 383 ⟶ 389:
cite = trimArg2(args.cite)
if cite then
if (cite ~= "no") then
cite = ""
if cfg.citeurl and cfg.accessdate and cfg.source and cfg.name then
local citetitle = cfg.citetitle
cite = frame:preprocess('<ref name="' .. holiday .. ' dates">{{cite web |url=' .. cfg.citeurl .. ' |title=Dates for ' .. cfg.name .. ' |publisher=' .. cfg.source .. ' |via=[[Template:' .. tname .. '|' .. tname .. ']] and [[Module:' .. tname .. '/localfiles/' .. holiday .. '|' .. holiday .. ']] |accessdate=' .. cfg.accessdate .. '}}</ref>')▼
if citetitle == nil then
citetitle = 'Dates for ' .. cfg.name
end
▲ cite = frame:preprocess('<ref name="' .. holiday .. ' dates">{{cite web |url=' .. cfg.citeurl .. ' |title=
cite =
else
cite = ""
end
else
▲ elseif cfg.datatype == "calculator" then
cite = ""
▲ cite = (cfg.source and (frame:preprocess('<ref name="' .. holiday .. ' dates">' .. cfg.source .. '</ref>')))
end
else
|