Anonymous user
Module:Current events calendar: Difference between revisions
no edit summary
Vivaporius (talk | contribs) m (1 revision imported) |
en>Centrist16 No edit summary |
||
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 81 ⟶ 101:
function p.makeDayLink(day, month, year)
return string.format("'''[[#%d %s %d| %d ]]'''", year, month, day, day)
end
Line 88 ⟶ 108:
local monthAndYear = dateStuff.monthAndYear
local root = mw.html.create('table')
-- The next two lines help to make the table-layout-based Archive pages look good. When the
-- Archives have been converted to a grid-based layout, this logic can be removed, and the
-- corressponding CSS margin attribute can be simplified.
local temporaryMarginAdjustment = "auto !important"
if dateStuff.argsDate then temporaryMarginAdjustment = "8px 0 0 8px" end
root
:addClass('infobox')
:css{
display = 'table',
width = '100%',
float = 'initial',
['max-width'] = '350px',
margin = temporaryMarginAdjustment,
['text-align'] = 'center',
['background-color'] = '#f5faff',
border = '1px solid #cedff2'
▲ }
-- Headings
:tag('tr')
:css('background-color', '#cedff2')
:tag('
:css{['
:wikitext(makeWikilink('Portal:Current events/' .. dateStuff.previousMonthAndYear, '<<'))▼
:addClass('noprint')
:done()
:done()
:tag('
:attr('colspan', '5')
:css{
:wikitext(makeWikilink('Portal:Current events/' .. monthAndYear, monthAndYear))
:done()
:tag('
:css{['
:wikitext(makeWikilink('Portal:Current events/' .. dateStuff.nextMonthAndYear, '>>'))▼
:addClass('noprint')
-- Day of week headings
Line 112 ⟶ 150:
local weekdays = {'S', 'M', 'T', 'W', 'T', 'F', 'S'}
for i, weekday in ipairs(weekdays) do
dayHeadingRow:tag('
:css{['width'] = '14%', ['text-align'] = 'center'}
:wikitext(weekday)
end
-- Days
local
for i = 1, 7 do -- Always make 7 cells.▼
firstDayRow:tag('td')▼
:attr('colspan', tostring(colspan))▼
firstDayRow:tag('td')▼
▲ end
end▼
▲ for i = 1, 7 do
cellCount = cellCount + 1
local dayString = dayStrings[cellCount] or " " -- Use a blank cell if there is no corresponding dateString
:css{['text-align'] = 'center'}
▲ otherDayRow:tag('td')
:wikitext(dayString)
end
Line 145 ⟶ 169:
-- Footer
if not dateStuff.argsDate then -- No footer necessary on Archive pages.
▲ root:tag('tr')
root:tag('
:css{['padding-top'] = '3px', ['padding-bottom'] = '5px', ['font-size'] = '78%', ['text-align'] = 'left'}▼
:wikitext(' ' .. makeWikilink('Portal:Current events/' .. monthAndYear, 'More ' .. monthAndYear .. ' events...'))▼
▲ :css{['padding-top'] = '3px', ['padding-bottom'] = '5px', ['font-size'] = '78%', ['text-align'] = '
▲ :wikitext(
▲ end
return tostring(root)
|