Module:Bongolium500/main page modules

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.recentReleases(frame) local args = frame.args if not args["count"] or not type(tonumber(args["count"])) == "number" then args["count"] = 8 end local outputText = "\n" local done = false local i = 1 local side = "left" while not done do outputText = outputText .. "" .. frame:preprocess(args[i]:gsub("{!%-%-" .. side .. "%-.-%-align%-%-}", ""):gsub("{!%-%-left%-", ""):gsub("{!%-%-right%-", ""):gsub("%-align%-%-}", "")) .. " \n" if side == "left" then side = "right" else side = "left" end i = i + 1 if i > tonumber(args["count"]) then done = true elseif args[i] == null or args[i] == "" then done = true end end outputText = outputText .. " "	return outputText end

function p.releaseModule(frame) local PREFIX = "MAINPAGERELEASE-" local currentDate = frame.args[1] 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 .. " (releases)" local outputWidget = " On this day in... " local pageText = frame:callParserFunction('#dpl:', {include='*', title=pageName}):gsub(".*-->", ""):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 = "75px " if position == "left" then position = "right" else position = "left" end end outputWidget = outputWidget .. "\n " .. image .. "Happy birthday to " .. person .. "! " .. source .. " "				outputWidget = outputWidget:gsub("'\"`UNIQ.*", "")			end		end		outputWidget = outputWidget .. "  "		cache.set(PREFIX .. currentDate, outputWidget)	end	return outputWidget end

return p