Module:Bongolium500/main page modules: Difference between revisions
From Tardis Wiki, the free Doctor Who reference
Bongolium500 (talk | contribs) No edit summary |
Bongolium500 (talk | contribs) No edit summary |
||
Line 12: | Line 12: | ||
local outputWidget = cache.get(PREFIX .. currentDate) or "" | local outputWidget = cache.get(PREFIX .. currentDate) or "" | ||
if outputWidget == "" then | if outputWidget == "" then | ||
local year, month, day = string.match(currentDate, "(%d+)-(%d+)-(%d+)") | local year, month, day = string.match(currentDate, "(%d+)-(%d+)-(%d+)") | ||
local monthName = MONTHS[tonumber(month)] | local monthName = MONTHS[tonumber(month)] | ||
local pageName = day .. " " .. monthName .. " (people)" | local pageName = day .. " " .. monthName .. " (people)" | ||
- | local outputWidget = "<div class=\"mainpage-birthdays\ tech\" id=\"birthdays\"><h2>[[" .. pageName .. "|Today's Birthdays!]]</h2> \n <table>" | ||
local pageText = frame:callParserFunction('#dpl:', {include='*', title=pageName}):gsub(".*-->", ""):gsub("<!--.*", "") | local pageText = frame:callParserFunction('#dpl:', {include='*', title=pageName}):gsub(".*-->", ""):gsub("<!--.*", "") | ||
local events = textUtil.split(pageText, "*") | local events = textUtil.split(pageText, "*") | ||
Line 39: | Line 38: | ||
end | end | ||
outputWidget = outputWidget .. "\n<tr><td>" .. image .. "Happy birthday to " .. person .. "! " .. source .. "</td></tr>" | outputWidget = outputWidget .. "\n<tr><td>" .. image .. "Happy birthday to " .. person .. "! " .. source .. "</td></tr>" | ||
outputWidget = outputWidget:gsub("'\"`UNIQ.*", "") | |||
end | end | ||
end | end | ||
outputWidget = outputWidget .. "</table>\n<span class=\"mw-customtoggle-birthdayReferences\">'''Click to view references.'''</span>\n<span class=\"mw-collapsible mw-collapsed\" id=\"mw-customcollapsible-birthdayReferences\">''Not all references may be for the birthdays above.''" .. frame:expandTemplate{title="reflist", args={2}} .. "</span> | outputWidget = outputWidget .. "</table></div>" -- for references: \n<span class=\"mw-customtoggle-birthdayReferences\">'''Click to view references.'''</span>\n<span class=\"mw-collapsible mw-collapsed\" id=\"mw-customcollapsible-birthdayReferences\">''Not all references may be for the birthdays above.''" .. frame:expandTemplate{title="reflist", args={2}} .. "</span> | ||
cache.set(PREFIX .. currentDate, outputWidget) | cache.set(PREFIX .. currentDate, outputWidget) | ||
end | end |
Revision as of 21:35, 15 November 2022
Documentation for this module may be created at Module:Bongolium500/main page modules/doc
local smwUtil = require('Module:SMW')
local textUtil = require('Module:TextUtil')
local cache = require('mw.ext.LuaCache')
local p = {}
local h = {}
local MONTHS = {"January", "Feburary", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"}
function p.birthdayModule(frame)
local PREFIX = "MAINPAGEBIRTHDAY-"
local currentDate = os.date("%F")
local outputWidget = cache.get(PREFIX .. currentDate) or ""
if outputWidget == "" then
local year, month, day = string.match(currentDate, "(%d+)-(%d+)-(%d+)")
local monthName = MONTHS[tonumber(month)]
local pageName = day .. " " .. monthName .. " (people)"
local outputWidget = "<div class=\"mainpage-birthdays\ tech\" id=\"birthdays\"><h2>[[" .. pageName .. "|Today's Birthdays!]]</h2> \n <table>"
local pageText = frame:callParserFunction('#dpl:', {include='*', title=pageName}):gsub(".*-->", ""):gsub("<!--.*", "")
local events = textUtil.split(pageText, "*")
local birthdays = {}
local position = "left"
for _, event in pairs(events) do
if string.find(event, "born") then
local birthday = event:gsub(".* %- ", "")
local temp = textUtil.split(birthday, "%.")
local person = temp[1]:gsub(" was born.*", "")
local source = temp[2]
local pageName = person:gsub(".*%[%[", ""):gsub("|.*", "")
local smwImage = mw.smw.ask( "[[" .. pageName .. "]]" .. "\n|?Has image")[1]["Has image"]
local image = ""
if smwImage then
image = "<span style=\"float:" .. position .. ";padding:2px;\">[[" .. smwImage .. "|75px]]</span>"
if position == "left" then
position = "right"
else
position = "left"
end
end
outputWidget = outputWidget .. "\n<tr><td>" .. image .. "Happy birthday to " .. person .. "! " .. source .. "</td></tr>"
outputWidget = outputWidget:gsub("'\"`UNIQ.*", "")
end
end
outputWidget = outputWidget .. "</table></div>" -- for references: \n<span class=\"mw-customtoggle-birthdayReferences\">'''Click to view references.'''</span>\n<span class=\"mw-collapsible mw-collapsed\" id=\"mw-customcollapsible-birthdayReferences\">''Not all references may be for the birthdays above.''" .. frame:expandTemplate{title="reflist", args={2}} .. "</span>
cache.set(PREFIX .. currentDate, outputWidget)
end
return outputWidget
end
return p