Module:tearoom
Appearance
- The following documentation is located at Module:tearoom/documentation. [edit]
- Useful links: subpage list • links • transclusions • testcases • sandbox
This module intends to serve {{rft2}}
local export = {}
local m_para = require("Module:parameters")
-- for now, test with User:Pengo/tearoom2
function calc_dateinfo(year, month)
local output = {}
output['year'] = year
output['month'] = month
output['date'] = os.time{day=1, year=year, month=month}
output['month_word'] = os.date('%B', output['date']) -- e.g. "October'
output['urldate'] = '/' .. year .. '/' .. output['month_word'] -- e.g. '/2015/October' (to form Wiktionary:Tea room/2015/October)
local expiryYear = year
local expiryMonth = month + 3
if (expiryMonth > 12) then
expiryYear = expiryYear + 1
expiryMonth = expiryMonth - 12
end
output['expiryYear'] = expiryYear
output['expiryMonth'] = expiryMonth
output['expiryDate'] = os.time{day=1, year=expiryYear, month=expiryMonth}
local today = os.time()
if (today >= output['expiryDate']) then
output['isExpired'] = true
else
output['isExpired'] = false
end
return output
end
function export.subst_rft(frame)
local wikitext = "{{tea room|y=" .. os.date('%Y') .. "|m=" .. os.date('%B');
iparams = {
[1] = {}, -- reason entry was added to the Tea room for conversation
fragment = {}, -- title of Tea room discussion (for linking purposes)
}
local args = m_para.process(frame.args, iparams)
if args[1] ~= nil then
wikitext = wikitext .. "|" .. args[1];
end
if args["fragment"] ~= nil then
wikitext = wikitext .. "|fragment=" .. args["fragment"];
end
if args["section"] ~= nil then
wikitext = wikitext .. "|section=" .. args["section"];
end
return wikitext .. "}}";
end
function export.rft(frame)
iparams = {
[1] = {}, -- reason entry was added to the Tea room for conversation
fragment = {}, -- title of Tea room discussion (for linking purposes)
month = {required=true, type="number"}, -- month of discussion //TODO: allow month words
year = {required=true, type="number"} -- year of discussion
}
local iargs = m_para.process(frame.args, iparams)
local dateinfo = calc_dateinfo(iargs['year'], iargs['month'])
if (dateinfo['isExpired']) then
--print "expired"
else
--print "not expired"
return frame:expandTemplate{title = 'rft', args = iargs}
end
end
function export.rft_talk(frame)
iparams = {
[1] = {}, -- reason entry was added to the Tea room for conversation
fragment = {}, -- title of Tea room discussion (for linking purposes)
month = {required=true, type="number"}, -- month of discussion. 1 = jan. 12 = dec. //TODO: allow month words, e.g. "OCT"
year = {required=true, type="number"} -- year of discussion
--nocat = {default=false, type="boolean"}
}
local iargs = m_para.process(frame.args, iparams)
local dateinfo = calc_dateinfo(iargs['year'], iargs['month'])
local frag = ''
if iargs['fragment'] ~= nil then
frag = '#' .. iargs['fragment']
end
if (dateinfo['isExpired']) then
return "expired: [[Wiktionary:Tea room" .. dateinfo['urldate'] .. frag .. ']]';
else
return "not yet expired. archival url: [[Wiktionary:Tea room" .. dateinfo['urldate'] .. frag .. "]]. "
.. "current url: [[Wiktionary:Tea room" .. frag .. "]]";
end
end
return export