Module:Current events calendar/sandbox: Difference between revisions

Content deleted Content added
style before attacking the infobox use
tstyles
 
(One intermediate revision by the same user not shown)
Line 18:
 
local function getDateStuff(argsDate)
 
--[[
Note: This function takes advantage of the formatDate's second argument to
Line 25 ⟶ 24:
--]]
 
-- 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)
return dateStuff{
dateStuff.monthAndYear = monthAndYear
dateStuff. argsDate = argsDate,
-- Previous month and year
dateStuff.previousMonthAndYear year = tonumber(lang:formatDate('F Y', firstOfMonth .. ' -1 month'argsDate)),
local year month = lang:formatDate('YF', argsDate),
-- Next month and year
dateStuff.nextMonthAndYear monthAndYear = lang:formatDate('F Y', firstOfMonth .. ' +1 month'argsDate),
local daysInMonth previousMonthAndYear = lang:formatDate('jF Y', firstOfMonth .. ' +-1 month -1 day'),
-- Day
local day nextMonthAndYear = lang:formatDate('jF Y', argsDatefirstOfMonth .. ' +1 month'),
day = tonumber(daylang:formatDate('j', argsDate)),
local firstWeekday daysInMonth = tonumber(lang:formatDate('wj', firstOfMonth) --.. Sunday' =+1 0,month Saturday-1 = 6day')),
dateStuff.day = day
-- DaysWeekday inof the first day of the month
firstWeekday = firstWeekday + 1 -- Make compatible with Lua tables so we add 1. Sunday = 1, Saturday = 7.
local daysInMonth = lang:formatDate('j', firstOfMonth .. ' +1 month -1 day')
firstWeekday = tonumber(lang:formatDate('w', firstOfMonth)) + 1
daysInMonth = tonumber(daysInMonth)
}
dateStuff.daysInMonth = daysInMonth
-- Weekday of the first day of the month
local firstWeekday = lang:formatDate('w', firstOfMonth) -- Sunday = 0, Saturday = 6
firstWeekday = tonumber(firstWeekday)
firstWeekday = firstWeekday + 1 -- Make compatible with Lua tables. Sunday = 1, Saturday = 7.
dateStuff.firstWeekday = firstWeekday
return dateStuff
end
 
Line 75 ⟶ 56:
if dateStuff.argsDate or isLinkworthy(day, currentDay) then
table.insert(calStrings, string.format(
"'''[[#%d %s %d|  %d  ]]'''",
currentYear,
currentMonth,
Line 92 ⟶ 73:
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('infoboxcurrent-events-calendar')
-- The next two lines help to makeMake the table-layout-based Archive pages look good. When the Archives
:css{
-- good. When the Archives have been converted to a grid-based layout, this logic can be removed,
display = 'table',
-- logic can be removed, and the corressponding CSS margin attribute can be simplified.
width = '100%',
:addClass(dateStuff.argsDate and 'current-events-calendar-archive')
float = 'initial',
['max-width'] = '350px',
margin = temporaryMarginAdjustment,
['text-align'] = 'center',
['background-color'] = '#f5faff',
border = '1px solid #cedff2'
}
-- Headings
:tag('trcaption')
:csstag('background-color', '#cedff2span')
:tagaddClass('thnoprint')
:wikitext(makeWikilink(
:css{['text-align'] = 'center'}
'Portal:Current events/' .. dateStuff.previousMonthAndYear,
:tag('span')
:addClass('noprint')
))
:wikitext(makeWikilink(
'Portal:Current events/' .. dateStuff.previousMonthAndYear,
'◀'
))
:done()
:done()
:tag('thspan')
:attr('colspan', '5')
:css{['text-align'] = 'center'}
:wikitext(makeWikilink(
'Portal:Current events/' .. monthAndYear,
Line 131 ⟶ 94:
))
:done()
:tag('thspan')
:addClass('noprint')
:css{['text-align'] = 'center'}
:wikitext(makeWikilink(
:tag('span')
'Portal:Current events/' .. dateStuff.nextMonthAndYear,
:addClass('noprint')
''
:wikitext(makeWikilink(
:done())
'Portal:Current events/' .. dateStuff.nextMonthAndYear,
'▶'
))
 
-- Day of week headings
local dayHeadingRow = root:tag('tr')
local weekdays = {'S', 'M', 'T', 'W', 'T', 'F', 'S'}
for i_, weekday in ipairs(weekdays) do
dayHeadingRow:tag('th'):wikitext(weekday)
:css{['width'] = '14%', ['text-align'] = 'center'}
:wikitext(weekday)
end
 
Line 157 ⟶ 116:
cellCount = cellCount + 1
-- Use a blank cell if there is no corresponding dateString
local dayString = dayStrings[cellCount] or " "''
weeklyRow:tag('td'):wikitext(dayString)
:css{['text-align'] = 'center'}
:wikitext(dayString)
end
end
Line 167 ⟶ 124:
if not dateStuff.argsDate then -- No footer necessary on Archive pages.
root:tag('tr')
:addClass('current-events-calendar-footer')
:addClass('noprint')
:tag('td')
:attr('colspan', '7')
:css{
['padding-top'] = '3px',
['padding-bottom'] = '5px',
['font-size'] = '78%',
['text-align'] = 'right'
}
:wikitext(makeWikilink(
'Portal:Current events/' .. monthAndYear,
Line 187 ⟶ 139:
function p.main(frame)
local argsDate = nil
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
Line 194 ⟶ 146:
end
local dateStuff = getDateStuff(argsDate)
return frame:extensionTag{
local dayStrings = makeDayStrings(dateStuff)
name = 'templatestyles',
return export(dayStrings, dateStuff)
args = { src = 'Module:Current events calendar/styles.css' }
local} dayStrings =.. export(makeDayStrings(dateStuff), dateStuff)
end