Module:WeeklyEvent: Difference between revisions
Jump to navigation
Jump to search
use prev instead of this for latest (want "This" week's link as "Next" meeting link) |
update for "next" to properly reflect "cur"rent week Tag: Reverted |
||
| Line 5: | Line 5: | ||
end | end | ||
function p.links(frame) | |||
local | local args = frame:getParent().args | ||
local prefix = args.prefix or 'Meeting Notes' | |||
local joiner = args.joiner or ' ' | |||
local weekday = args.weekday or 'Tuesday' | |||
-- show segment iff arg PROVIDED (nil => omit); blank string allowed | |||
local t_prev = args.text_prev -- label for last occurrence | |||
local | local t_cur = args.text_this -- label for upcoming occurrence (semantic "this" == next weekday) | ||
local | local t_next = args.text_next -- label for occurrence after upcoming | ||
local t_next = args.text_next | |||
local preload = args.preload | local preload = args.preload | ||
local t_create = args.create_text -- label for create link; requires preload too | |||
-- Semantics: | |||
-- prev = last weekday | |||
-- cur = next weekday (the one you're about to write) | |||
-- next = weekday after cur | |||
local prevdate = d('Y m d', 'last ' .. weekday) | local prevdate = d('Y m d', 'last ' .. weekday) | ||
local nextdate = d('Y m d', 'next ' .. weekday) | local curdate = d('Y m d', 'next ' .. weekday) | ||
local nextdate = d('Y m d', 'next ' .. weekday .. ' + 7 days') | |||
local prevTitle = table.concat({prefix, prevdate}, joiner) | local prevTitle = table.concat({prefix, prevdate}, joiner) | ||
local curTitle = table.concat({prefix, curdate}, joiner) | |||
local nextTitle = table.concat({prefix, nextdate}, joiner) | local nextTitle = table.concat({prefix, nextdate}, joiner) | ||
local | local parts = {} | ||
local function add_link(title, label) | |||
table.insert(parts, string.format('[[%s|%s]]', title, label or '')) | |||
end | end | ||
if t_prev ~= nil then add_link(prevTitle, t_prev) end | |||
if t_cur ~= nil then add_link(curTitle, t_cur) end | |||
if t_next ~= nil then add_link(nextTitle, t_next) end | |||
if preload then | -- Create link targets the upcoming occurrence (curTitle), not the later one. | ||
local url = mw.uri.canonicalUrl( | if preload and preload ~= '' and t_create ~= nil then | ||
local url = mw.uri.canonicalUrl(curTitle, { action='edit', preload=preload }) | |||
table.insert(parts, string.format('[%s %s]', tostring(url), t_create)) | |||
end | end | ||
local out = mw.text.trim(table.concat(parts, ' · ')) | |||
return frame:extensionTag{ | return frame:extensionTag{ | ||
name = 'span', | name = 'span', | ||
content = out, | content = out, | ||
args = { class = 'weekly-event-inline' } | args = { class = 'weekly-event-inline' } | ||
} | } | ||
end | end | ||
return p | return p | ||
Revision as of 18:29, 23 February 2026
https://dev.fandom.com/wiki/Lua_reference_manual/Scribunto_libraries
https://en.wikipedia.org/wiki/Wikipedia:Comparable_Lua_functions_to_wikitext
local p = {}
local function d(fmt, rel)
return mw.getContentLanguage():formatDate(fmt, rel)
end
function p.links(frame)
local args = frame:getParent().args
local prefix = args.prefix or 'Meeting Notes'
local joiner = args.joiner or ' '
local weekday = args.weekday or 'Tuesday'
-- show segment iff arg PROVIDED (nil => omit); blank string allowed
local t_prev = args.text_prev -- label for last occurrence
local t_cur = args.text_this -- label for upcoming occurrence (semantic "this" == next weekday)
local t_next = args.text_next -- label for occurrence after upcoming
local preload = args.preload
local t_create = args.create_text -- label for create link; requires preload too
-- Semantics:
-- prev = last weekday
-- cur = next weekday (the one you're about to write)
-- next = weekday after cur
local prevdate = d('Y m d', 'last ' .. weekday)
local curdate = d('Y m d', 'next ' .. weekday)
local nextdate = d('Y m d', 'next ' .. weekday .. ' + 7 days')
local prevTitle = table.concat({prefix, prevdate}, joiner)
local curTitle = table.concat({prefix, curdate}, joiner)
local nextTitle = table.concat({prefix, nextdate}, joiner)
local parts = {}
local function add_link(title, label)
table.insert(parts, string.format('[[%s|%s]]', title, label or ''))
end
if t_prev ~= nil then add_link(prevTitle, t_prev) end
if t_cur ~= nil then add_link(curTitle, t_cur) end
if t_next ~= nil then add_link(nextTitle, t_next) end
-- Create link targets the upcoming occurrence (curTitle), not the later one.
if preload and preload ~= '' and t_create ~= nil then
local url = mw.uri.canonicalUrl(curTitle, { action='edit', preload=preload })
table.insert(parts, string.format('[%s %s]', tostring(url), t_create))
end
local out = mw.text.trim(table.concat(parts, ' · '))
return frame:extensionTag{
name = 'span',
content = out,
args = { class = 'weekly-event-inline' }
}
end
return p