This module is rated as beta, and is ready for widespread use. It is still new and should be used with some caution to ensure the results are as expected.
localp={}locallang-- Lazy initializelocalfunctionformatDate(fmt,d)lang=langormw.language.getContentLanguage()localsuccess,newDate=pcall(lang.formatDate,lang,fmt,d)ifsuccessthenreturnnewDateelseerror(string.format("invalid date '%s' passed to getDate",tostring(date)))endendlocalfunctioncaltoc(days,unk,footer,month,year)localweekdays={'Mon','Tue','Wed','Thu','Fri','Sat','Sun'}localj=tonumber(formatDate('N','1 '..month..' '..year))localN=tonumber(formatDate('t','1 '..month..' '..year))localres={}table.insert(res,'__NOTOC__<table role="navigation" id="toc" class="calendar-toc wikitable toc" style="text-align:center">')table.insert(res,'<tr><th colspan=7 style="background:inherit"><span style="font-weight:bold">'..month..' '..year..'</span></th></tr>')table.insert(res,'<tr><th scope="col">'..table.concat(weekdays,'</th><th scope="col">')..'</th></tr>')locald=1-jlocalskip=falsewhiled<=Ndotable.insert(res,'<tr>')fori=1,7dod=d+1ifd>0andd<=Nthenlocalf=days[tostring(d)]iffandf=='df'thentable.insert(res,'<td>[[#'..d..' '..month..'|'..d..']]</td>')elseiffandf=='mf'thentable.insert(res,'<td>[[#'..month..' '..d..'|'..d..']]</td>')elsetable.insert(res,'<td>'..d..'</td>')endskip=falseelseif(skip==false)thenlocalcs=(d<=0)and(1-d)or(8-i)localv=''ifd>Nandcs>2andunkthenv='[[#'..unk..'|'..unk..']]'unk=nilendifcs<7orv~=''thentable.insert(res,'<td'..(cs>1and' colspan='..csor'')..'>'..v..'</td>')endskip=trueendendtable.insert(res,'</tr>')endifunk~=nilthentable.insert(res,'<tr><td colspan=7>[[#'..unk..'|'..unk..']]</td></tr>')endif#footer>0thentable.insert(res,'<tr>')if#footer>1thentable.insert(res,'<td colspan=7 style="padding: 0.2em;">')fork,vinipairs(footer)dotable.insert(res,'* [[#'..v..'|'..v..']]')endtable.insert(res,'</td>')elsetable.insert(res,'<td colspan=7>[[#'..table.concat(footer,'')..'|'..table.concat(footer,'')..']]</td>')endtable.insert(res,'</tr>')endtable.insert(res,'</table>')returntable.concat(res,'\n')endlocalfunctiongetYear(s,y)ifyandmw.ustring.match(y,'^%d+$')thenreturnyendy=mw.ustring.gsub(s,'^.-(%d+).-$','%1')returnyendlocalfunctiongetMonth(s,m)localmnames={['January']=1,['February']=2,['March']=3,['April']=4,['May']=5,['June']=6,['July']=7,['August']=8,['September']=9,['October']=10,['November']=11,['December']=12}ifmandmnames[m]thenreturnmendfork,ninpairs(mnames)doifmw.ustring.match(sor'',k)thenreturnkendendreturn''endfunctionp.main(frame)localargs=frame.argslocalpargs=frame:getParent().argslocalcurrent_title=mw.title.getCurrentTitle()localcontent=current_title:getContent()ifargs['_demo']orpargs['_demo']thencontent=args['_demo']orpargs['_demo']or''endifnotcontentthenerror"The current page has no content"end-- Remove commentscontent=mw.ustring.gsub(content,'<!--.-?-->','')-- Get the month and year localpagename=current_title.textlocalmonth=getMonth(pagename,args['month']orpargs['month']or'')localyear=getYear(pagename,args['year']orpargs['year']or'')-- Get list of valid footer links localextra=args['extra']orpargs['extra']or''localfooterlinks={}ifextra~=''thenfooterlinks=mw.text.split(extra,'%s*=%s*')elsefooterlinks={"See also","References","Notes","Further reading","External links"}endlocalvalidfooter={}fork,vinipairs(footerlinks)dovalidfooter[v]=1end-- Get all the level two headings for days of the monthlocaldays={}localfounddays={}localfooter={}localunknown=nilforvinmw.ustring.gmatch(content,"%f[^\n]==%s*([^\r\n]-)%s*==%f[^=]")dov=mw.ustring.gsub(v,'^[=%s]*(.-)[%s=]*','%1')localdf=mw.ustring.gsub(v,'^(%d+[%-–%d]*)%s*'..month..'$','%1')localmf=mw.ustring.gsub(v,'^'..month..'%s*(%d+[%-–%d]*)$','%1')iftonumber(df)thendays[df]='df'table.insert(founddays,df)elseiftonumber(mf)thendays[df]='mf'table.insert(founddays,mf)elseifv=="Unknown date"thenunknown="Unknown date"elseifvalidfooter[v]thentable.insert(footer,v)endendreturncaltoc(days,unknown,footer,month,year)endreturnp