Module:WeeklyEvent: Difference between revisions
Jump to navigation
Jump to search
m args |
m local args handling |
||
| Line 14: | Line 14: | ||
function p.links(frame) | function p.links(frame) | ||
local args = frame:getParent().args | local args = frame:getParent().args | ||
local prefix = args.prefix or 'Meeting' | local prefix = args.prefix or 'Meeting Notes' | ||
local joiner = args.joiner or ' ' | |||
local weekday = args.weekday or 'Tuesday' | local weekday = args.weekday or 'Tuesday' | ||
local text_this = args.text_this or 'This week' | local text_this = args.text_this or 'This week' | ||
| Line 25: | Line 26: | ||
local nextdate = d('Y-m-d', 'next ' .. weekday) | local nextdate = d('Y-m-d', 'next ' .. weekday) | ||
local thisTitle = prefix . | local thisTitle = prefix .. joiner .. thisdate | ||
local prevTitle = prefix . | local prevTitle = prefix .. joiner .. prevdate | ||
local nextTitle = prefix . | local nextTitle = prefix .. joiner .. nextdate | ||
local latestTitle, latestText | local latestTitle, latestText | ||
Revision as of 15:49, 22 October 2025
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)
-- uses site content language date parser (Parsoid-safe)
return mw.getContentLanguage():formatDate(fmt, rel)
end
local function page_exists(title)
local t = mw.title.new(title)
return t and t.exists
end
-- args: prefix=Meeting Notes joiner=' ' weekday=Tuesday text_this, text_prev, text_next, preload
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'
local text_this = args.text_this or 'This week'
local text_prev = args.text_prev or 'Last week'
local text_next = args.text_next or 'Next week'
local preload = args.preload -- optional
local thisdate = d('Y-m-d', 'this ' .. weekday)
local prevdate = d('Y-m-d', 'last ' .. weekday)
local nextdate = d('Y-m-d', 'next ' .. weekday)
local thisTitle = prefix .. joiner .. thisdate
local prevTitle = prefix .. joiner .. prevdate
local nextTitle = prefix .. joiner .. nextdate
local latestTitle, latestText
if page_exists(thisTitle) then
latestTitle, latestText = thisTitle, text_this
elseif page_exists(prevTitle) then
latestTitle, latestText = prevTitle, text_prev
else
latestTitle, latestText = nil, "no recent page"
end
local buf = {}
if latestTitle then
table.insert(buf, string.format('[[%s|%s]]', latestTitle, latestText))
else
table.insert(buf, "''no recent page''")
end
table.insert(buf, ' · ')
table.insert(buf, string.format('[[%s|%s]]', nextTitle, text_next))
if preload then
local url = mw.uri.canonicalUrl(nextTitle, { action='edit', preload=preload })
table.insert(buf, ' · ')
table.insert(buf, string.format('[%s create next]', tostring(url)))
end
return table.concat(buf)
end
return p