Difference between revisions of "Module:Current events monthly archive"
Jump to navigation
Jump to search
blackwiki>RossO (Last day of month still not working) |
blackwiki>RossO (Intro paragraph converted, Other portions commented out) |
||
| Line 1: | Line 1: | ||
-- This module renders the introductory content on Monthly archive pages for the [[Portal:Current events]]. | -- This module renders the introductory content on Monthly archive pages for the [[Portal:Current events]]. | ||
-- Test this against Portal:Current events/September 2011/Sandbox | -- Test this against Portal:Current events/September 2011/Sandbox | ||
| + | -- Test this against User:RossO/sandbox/Current events monthly intro | ||
| + | |||
--[[ | --[[ | ||
Incoming expected variables: | Incoming expected variables: | ||
| Line 19: | Line 21: | ||
local dayStrings = p.makeDayStrings(dateStuff) | local dayStrings = p.makeDayStrings(dateStuff) | ||
return p.export(dayStrings, dateStuff) | return p.export(dayStrings, dateStuff) | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
end | end | ||
| Line 77: | Line 71: | ||
-- Weekday of the first day of the month | -- Weekday of the first day of the month | ||
| − | local | + | local firstDayOfMonthName = lang:formatDate('l', firstOfMonth) |
| − | + | dateStuff.firstDayOfMonthName = firstDayOfMonthName | |
| − | |||
| − | dateStuff. | ||
-- Days in month | -- Days in month | ||
| Line 88: | Line 80: | ||
-- Weekday of the last day of the month | -- Weekday of the last day of the month | ||
| − | local | + | local lastDayOfMonthName = lang:formatDate('l', firstOfMonth .. ' +1 month -1 day') |
| − | + | dateStuff.lastDayOfMonthName = lastDayOfMonthName | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | dateStuff. | ||
return dateStuff | return dateStuff | ||
| Line 125: | Line 109: | ||
-- Intro paragraph | -- Intro paragraph | ||
local monthAndYear = dateStuff.monthAndYear | local monthAndYear = dateStuff.monthAndYear | ||
| − | local | + | local monthOrdinal = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth and final"} |
| − | |||
local root = mw.html.create('div') | local root = mw.html.create('div') | ||
root | root | ||
| + | :tag('hr') | ||
| + | :done() | ||
:tag('p') | :tag('p') | ||
| − | :wikitext("'''[[" .. dateStuff.monthName .. "]] [[" .. dateStuff.year .. "]]''' was the " .. | + | :wikitext("'''''[[" .. dateStuff.monthName .. "]] [[" .. dateStuff.year .. "]]''' was the " .. monthOrdinal[dateStuff.monthNumber] .. " month of that " .. dateStuff.leapDesc .. " year. ") |
| − | :wikitext("The month, which began on a [[" .. | + | :wikitext("The month, which began on a [[" .. dateStuff.firstDayOfMonthName .. "]], ended on a [[" .. dateStuff.lastDayOfMonthName .. "]] after " .. dateStuff.daysInMonth .. " days.''") |
| − | |||
:done() | :done() | ||
:tag('h2') | :tag('h2') | ||
| Line 138: | Line 122: | ||
:done() | :done() | ||
:tag('p') | :tag('p') | ||
| − | :wikitext("''This is an [[Portal:Current events/How to archive the portal|archived version]] of Wikipedia's [[Portal:Current events|Current events Portal]] from | + | :wikitext("''This is an [[Portal:Current events/How to archive the portal|archived version]] of Wikipedia's [[Portal:Current events|Current events Portal]] from [[" .. dateStuff.monthName .. " " .. dateStuff.year .. "]].''") |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
:done() | :done() | ||
| + | -- :tag('div') | ||
| + | -- :css{border='solid 1px black',display='flex'} | ||
| + | -- :tag('div') | ||
| + | -- :css{border='solid 1px black',flex='100%'} | ||
| + | -- :tag('p') | ||
| + | -- :wikitext("{{Portal:Current events/Month Inclusion|2011 September}}") | ||
| + | -- :done() | ||
| + | -- :done() | ||
| + | -- :tag('div') | ||
| + | -- :css{border='solid 1px black',flex='300px'} | ||
| + | -- :tag('div') | ||
| + | -- :wikitext("{{Portal:Current events/September 2011/Calendar}}") | ||
| + | -- :done() | ||
| + | -- :tag('div') | ||
| + | -- :wikitext("{{Portal:Current events/September 2011/Sidebar}}") | ||
| + | -- :done() | ||
| + | -- :done() | ||
| + | -- :done() | ||
| + | -- :tag('h2') | ||
| + | -- :wikitext("References") | ||
| + | -- :done() | ||
| + | -- :tag('div') | ||
| + | -- :wikitext("{{reflist}}") | ||
| + | -- :done() | ||
| + | -- :tag('div') | ||
| + | -- :wikitext("{{commons category|September 2011}}") | ||
| + | -- :done() | ||
| + | -- :tag('div') | ||
| + | -- :wikitext("{{Portal:Current events/Events by month}}") | ||
| + | -- :done() | ||
| + | -- :tag('div') | ||
| + | -- :wikitext("[[Category:September|2011]] [[Category:2011|*2011-09]] [[Category:Current events archives]]") | ||
| + | -- :done() | ||
return tostring(root) | return tostring(root) | ||
Revision as of 18:29, 28 September 2017
Usage
{{#invoke:Current events monthly archive|main}}
{{#invoke:Current events monthly archive|main|year=1996|month=12}}
This will eventually be extended to support the layout components for the Portal:Current events archive pages.
-- This module renders the introductory content on Monthly archive pages for the [[Portal:Current events]].
-- Test this against Portal:Current events/September 2011/Sandbox
-- Test this against User:RossO/sandbox/Current events monthly intro
--[[
Incoming expected variables:
frame.args.year = Integer value for year
frame.args.month = Integer value for month, 1 based.
--]]
local p = {}
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
argsDate = frame.args.year .. "-" .. frame.args.month .. "-01" -- Construct a date, YYY-M-DD format.
end
local dateStuff = p.getDateStuff(argsDate, frame.args.month, frame.args.year)
local dayStrings = p.makeDayStrings(dateStuff)
return p.export(dayStrings, dateStuff)
end
function p.getDateStuff(argsDate, monthNumber, yearNumber)
--[[
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.
Reference: https://www.mediawiki.org/wiki/Help:Extension:ParserFunctions#.23time
--]]
-- 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
--Leap Year
local leapBool = tonumber(lang:formatDate('L', argsDate))
dateStuff.leapBool = leapBool
local leapDesc = "common"
if (leapBool == 1) then
leapDesc = "leap"
end
dateStuff.leapDesc = leapDesc
-- Month and Name
local monthName = lang:formatDate('F', argsDate)
dateStuff.monthName = monthName
dateStuff.monthNumber = tonumber(monthNumber)
-- 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
dateStuff.previousMonthAndYear = lang:formatDate('F Y', firstOfMonth .. ' -1 month')
-- Next month and year
dateStuff.nextMonthAndYear = lang:formatDate('F Y', firstOfMonth .. ' +1 month')
-- Day
local dayNumber = lang:formatDate('j', argsDate)
dayNumber = tonumber(dayNumber)
dateStuff.dayNumber = dayNumber
-- Weekday of the first day of the month
local firstDayOfMonthName = lang:formatDate('l', firstOfMonth)
dateStuff.firstDayOfMonthName = firstDayOfMonthName
-- Days in month
local daysInMonth = lang:formatDate('j', firstOfMonth .. ' +1 month -1 day')
daysInMonth = tonumber(daysInMonth)
dateStuff.daysInMonth = daysInMonth
-- Weekday of the last day of the month
local lastDayOfMonthName = lang:formatDate('l', firstOfMonth .. ' +1 month -1 day')
dateStuff.lastDayOfMonthName = lastDayOfMonthName
return dateStuff
end
function p.makeDayStrings(dateStuff)
local calStrings = {}
local currentDay = dateStuff.dayNumber
local currentMonth = dateStuff.monthName
local currentYear = dateStuff.year
local makeDayLink = p.makeDayLink
for dayCount = 1, dateStuff.daysInMonth do
if dateStuff.argsDate then
calStrings[#calStrings + 1] = makeDayLink(dayCount, currentMonth, currentYear)
else
calStrings[#calStrings + 1] = tostring(dayCount)
end
end
return calStrings
end
function p.makeDayLink(day, month, year)
return string.format("'''[[#%d %s %d| %d ]]'''", year, month, day, day)
end
function p.export(dayStrings, dateStuff)
-- Intro paragraph
local monthAndYear = dateStuff.monthAndYear
local monthOrdinal = {"first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth and final"}
local root = mw.html.create('div')
root
:tag('hr')
:done()
:tag('p')
:wikitext("'''''[[" .. dateStuff.monthName .. "]] [[" .. dateStuff.year .. "]]''' was the " .. monthOrdinal[dateStuff.monthNumber] .. " month of that " .. dateStuff.leapDesc .. " year. ")
:wikitext("The month, which began on a [[" .. dateStuff.firstDayOfMonthName .. "]], ended on a [[" .. dateStuff.lastDayOfMonthName .. "]] after " .. dateStuff.daysInMonth .. " days.''")
:done()
:tag('h2')
:wikitext("[[Portal:Current events]]")
:done()
:tag('p')
:wikitext("''This is an [[Portal:Current events/How to archive the portal|archived version]] of Wikipedia's [[Portal:Current events|Current events Portal]] from [[" .. dateStuff.monthName .. " " .. dateStuff.year .. "]].''")
:done()
-- :tag('div')
-- :css{border='solid 1px black',display='flex'}
-- :tag('div')
-- :css{border='solid 1px black',flex='100%'}
-- :tag('p')
-- :wikitext("{{Portal:Current events/Month Inclusion|2011 September}}")
-- :done()
-- :done()
-- :tag('div')
-- :css{border='solid 1px black',flex='300px'}
-- :tag('div')
-- :wikitext("{{Portal:Current events/September 2011/Calendar}}")
-- :done()
-- :tag('div')
-- :wikitext("{{Portal:Current events/September 2011/Sidebar}}")
-- :done()
-- :done()
-- :done()
-- :tag('h2')
-- :wikitext("References")
-- :done()
-- :tag('div')
-- :wikitext("{{reflist}}")
-- :done()
-- :tag('div')
-- :wikitext("{{commons category|September 2011}}")
-- :done()
-- :tag('div')
-- :wikitext("{{Portal:Current events/Events by month}}")
-- :done()
-- :tag('div')
-- :wikitext("[[Category:September|2011]] [[Category:2011|*2011-09]] [[Category:Current events archives]]")
-- :done()
return tostring(root)
end
return p