Content deleted Content added
No edit summary |
m Reverted edit by 213.147.181.177 (talk) to last version by 130.64.64.65 |
||
(17 intermediate revisions by 9 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('strict')
local p = {}
local cfg -- Data structure from ~/events
local eventdata -- Data structure from ~/localfiles/<holiday name>
--[[--------------------------< inlineError >-----------------------
Line 36 ⟶ 39:
if arg == "" or arg == nil then
return nil
else▼
return mw.text.trim(arg)▼
end
end
local function trimArg2(arg)
if arg == nil then
return nil
return mw.text.trim(arg)▼
end
end
Line 73 ⟶ 74:
if display and ('' ~= display) then
return table.concat ({'[[', link, '|', display, ']]'});
else▼
return table.concat ({'[[', link, ']]'});▼
end
end
else -- no_link
if display and ('' ~= display) then -- if there is display text
return display; -- return that
return link or ''; -- return the target article name or empty string▼
end
end
end
Line 153 ⟶ 152:
local function makeDate(year, month, day, df, format)
▲ end
end
Line 186 ⟶ 184:
]]
local function dateOffset(origdate, offset)
local year, month, day = origdate:match ('(%d%d%d%d)-(%d%d)-(%d%d)')
Line 201 ⟶ 199:
]]
local function renderHoli(cfg,eventdata,calcdate,date,df,format,tname,cite)
local hits = 0
Line 210 ⟶ 208:
-- user-supplied date calculator
if cfg.datatype == "calculator" then
startdate = calcdate
enddate = dateOffset(startdate, cfg.days - 1)
return inlineError("holiday", '
-- read dates from localfile -- it assumes dates are in chrono order, need a more flexible method
Line 242 ⟶ 240:
enddate = dateOffset(startdate, cfg.days - 1)
elseif startdate and not enddate then
return inlineError("
else
return inlineError("
end
end
Line 288 ⟶ 286:
if startdate == enddate or cfg.days == "1" then -- single date
return prepend1 .. startdate .. endoutoffset .. cite
return prepend1 .. startdate .. format .. prepend2 .. enddate .. endoutoffset .. cite▼
end
end
Line 311 ⟶ 308:
local cite = nil -- leave a citation at end
local calcdate = ""
▲ track = {} -- global tracking-category table
--- Determine holiday
Line 319 ⟶ 314:
holiday = trimArg(args.event) -- event alias
if not holiday then
return inlineError("holiday",
end
end
Line 326 ⟶ 321:
date = trimArg(args.year) -- required
if not date then
return inlineError("year",
elseif not isValidDate(date, "01", "01") then
return inlineError("year",
end
--- Determine format type
format = trimArg(args.format)
if not format or format ~= "infobox" then
format = "none"▼
format = "none"
end
-- 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 363:
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 381:
cite = trimArg2(args.cite)
if cite then
if (cite ~= "no") then
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
▲ cite = frame:preprocess('<ref name="' .. holiday .. ' dates">{{cite web |url=' .. cfg.citeurl .. ' |title=
cite =
end
▲ elseif cfg.datatype == "calculator" then
cite = ""
▲ cite = (cfg.source and (frame:preprocess('<ref name="' .. holiday .. ' dates">' .. cfg.source .. '</ref>')))
end
else
|