This module generates calendars for Portal:Current events and Category:Current events archives. The current day and the previous six days are linked to the corresponding section of the page. The module also supports archival calendars when month and year parameters are passed. Note that the Current Month version will only link the previous six days and will include a link of form: More January 2025 events....
{{#invoke:current events calendar|main|year=[four digit numerical year]|month=[One or two digit number from 1 to 12]}}
Example: Current Events front page version
This version assumes that it is displayed in a page that will set padding/margins/gutters in parent containing elements. It will expand to a maximum of 350px wide and remain centered in the column. It includes a link to the full month's page in the footer. Only the six most recent days of the month will have hyperlinks, reflecting the 6 most recent days of content on the Portal:Current events page.
This version assumes that it is displayed in a page that uses a table-based layout and expect individual children to set their margins and padding. It will expand to a maximum of 350px wide and puts an 8px margin on the top and left side of the calendar. It has no footer. All days will have links to the appropriate section of the page it is displayed in.
-- 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.--]]localp={}localfunctionmakeWikilink(link,display)ifdisplaythenreturnstring.format('[[%s|%s]]',link,display)elsereturnstring.format('[[%s]]',link)endendlocalfunctiongetDateStuff(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.--]]locallang=mw.language.getContentLanguage()localfirstOfMonth=lang:formatDate('01-m-Y',argsDate)return{argsDate=argsDate,year=tonumber(lang:formatDate('Y',argsDate)),month=lang:formatDate('F',argsDate),monthAndYear=lang:formatDate('F Y',argsDate),previousMonthAndYear=lang:formatDate('F Y',firstOfMonth..' -1 month'),nextMonthAndYear=lang:formatDate('F Y',firstOfMonth..' +1 month'),day=tonumber(lang:formatDate('j',argsDate)),daysInMonth=tonumber(lang:formatDate('j',firstOfMonth..' +1 month -1 day')),-- Weekday of the first day of the month-- Make compatible with Lua tables so we add 1. Sunday = 1, Saturday = 7.firstWeekday=tonumber(lang:formatDate('w',firstOfMonth))+1}endlocalfunctionisLinkworthy(day,currentDay)-- Returns true if the calendar day should be linked, and false if not. Days-- should be linked if they are the current day or if they are within the six-- preceding days, as that is the number of items on the current events page.returncurrentDay-6<=dayandday<=currentDayendlocalfunctionmakeDayStrings(dateStuff)localcalStrings={}localcurrentDay=dateStuff.daylocalcurrentMonth=dateStuff.monthlocalcurrentYear=dateStuff.yearforday=1,dateStuff.daysInMonthdoifdateStuff.argsDateorisLinkworthy(day,currentDay)thentable.insert(calStrings,string.format("[[#%d %s %d|%d]]",currentYear,currentMonth,day,day))elsetable.insert(calStrings,tostring(day))endendreturncalStringsendlocalfunctionexport(dayStrings,dateStuff)-- Generates the calendar HTML.localmonthAndYear=dateStuff.monthAndYearlocalroot=mw.html.create('table')root:addClass('current-events-calendar')-- 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.:addClass(dateStuff.argsDateand'current-events-calendar-archive')-- Headings:tag('caption'):tag('span'):addClass('noprint'):wikitext(makeWikilink('Portal:Current events/'..dateStuff.previousMonthAndYear,'◀')):done():tag('span'):wikitext(makeWikilink('Portal:Current events/'..monthAndYear,monthAndYear)):done():tag('span'):addClass('noprint'):wikitext(makeWikilink('Portal:Current events/'..dateStuff.nextMonthAndYear,'▶'))-- Day of week headingslocaldayHeadingRow=root:tag('tr')localweekdays={'S','M','T','W','T','F','S'}for_,weekdayinipairs(weekdays)dodayHeadingRow:tag('th'):wikitext(weekday)end-- Days-- Tracks the number of day cells. Negative values used for initial blank cells.localcellCount=1-dateStuff.firstWeekdaywhilecellCount<#dayStringsdo-- Weekly rowslocalweeklyRow=root:tag('tr')fori=1,7do-- Always make 7 cells.cellCount=cellCount+1-- Use a blank cell if there is no corresponding dateStringlocaldayString=dayStrings[cellCount]or''weeklyRow:tag('td'):wikitext(dayString)endend-- FooterifnotdateStuff.argsDatethen-- No footer necessary on Archive pages.root:tag('tr'):addClass('current-events-calendar-footer'):addClass('noprint'):tag('td'):attr('colspan','7'):wikitext(makeWikilink('Portal:Current events/'..monthAndYear,'More '..monthAndYear..' events... '))endreturntostring(root)endfunctionp.main(frame)localargsDate=nilifframeandframe.argsandframe.args.yearandframe.args.monththen-- 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-- Construct a date, YYY-M-DD format.argsDate=frame.args.year.."-"..frame.args.month.."-01"endlocaldateStuff=getDateStuff(argsDate)returnframe:extensionTag{name='templatestyles',args={src='Module:Current events calendar/styles.css'}}..export(makeDayStrings(dateStuff),dateStuff)endreturnp