Content deleted Content added
Testing |
Updated to match Archive-enabled version. |
||
Line 1:
-- This module renders the calendar seen on [[Portal:Current events]].
--[[
Incoming expected variables:
frame.args.year = Integer value for year
frame.args.month = Integer value for month, 1 based.
--]]
local p = {}
Line 11 ⟶ 17:
end
function p.main(frame)
local
if (frame and frame.args and frame.args.year and frame.args.month) then
-- If a date is passed in, assume that the display page is an Archive page.
-- If no date passed in, assume that the display page is the current Current Events page
argsDate = frame.args.year .. "-" .. frame.args.month .. "-01" -- Construct a date, YYY-M-DD format.
end
local dateStuff = p.getDateStuff(argsDate)
local dayStrings = p.makeDayStrings(dateStuff)
return p.export(dayStrings, dateStuff)
end
function p.getDateStuff(argsDate)
--[[
Note: This function takes advantage of the formatDate's second argument to
create data for the archival calendars. If the second arg (argsDate) is nil,
then formatDate assumes the current date/time.
--]]
-- Gets date data.
local dateStuff = {}
local lang = mw.language.getContentLanguage()
dateStuff.argsDate = argsDate
--Year
local year = lang:formatDate('Y', argsDate)
year = tonumber(year)
dateStuff.year = year
-- Month
local month = lang:formatDate('F', argsDate)
dateStuff.month = month
-- Month and year
local monthAndYear = lang:formatDate('F Y', argsDate)
local firstOfMonth = lang:formatDate('01-m-Y', argsDate)
dateStuff.monthAndYear = monthAndYear
-- Previous month and year
Line 37 ⟶ 57:
dateStuff.nextMonthAndYear = lang:formatDate('F Y', firstOfMonth .. ' +1 month')
-- Day
local day = lang:formatDate('j', argsDate)
day = tonumber(day)
dateStuff.day = day
Line 60 ⟶ 80:
local makeDayLink = p.makeDayLink
for day = 1, dateStuff.daysInMonth do
if dateStuff.argsDate or isLinkworthy(day, currentDay) then
calStrings[#calStrings + 1] = makeDayLink(day, currentMonth, currentYear)
else
Line 95 ⟶ 115:
float = 'initial',
['max-width'] = '350px',
margin = 'auto !important',
['text-align'] = 'center',
['background-color'] = '#f5faff',
Line 115 ⟶ 135:
:css{['text-align'] = 'center'}
:wikitext(makeWikilink('Portal:Current events/' .. dateStuff.nextMonthAndYear, '▶'))
-- Day of week headings
Line 124 ⟶ 145:
:wikitext(weekday)
end
-- Days
local cellCount = 1 - dateStuff.firstWeekday -- Tracks the number of day cells. Negative values used for initial blank cells.
Line 139 ⟶ 160:
-- Footer
if not dateStuff.argsDate then -- No footer necessary on Archive pages.
root:tag('
:tag('td')
:attr('colspan', '7') :css{['padding-top'] = '3px', ['padding-bottom'] = '5px', ['font-size'] = '78%', ['text-align'] = 'right'}
:wikitext(' ' .. makeWikilink('Portal:Current events/' .. monthAndYear, 'More ' .. monthAndYear .. ' events... '))
end
return tostring(root)
|