Module:On This Day: Difference between revisions

Jump to navigation Jump to search
m
maintenance category link fix
No edit summary
m (maintenance category link fix)
 
(15 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local h = {}
local h = {}
local cargo = mw.ext.cargo
 
local utilsCode = require("Module:UtilsCode")
local utilsCargo = require("Module:UtilsCargo")
local utilsLayout = require("Module:UtilsLayout")
local utilsString = require("Module:UtilsString")
local utilsTable = require("Module:UtilsTable")
local utilsVar = require("Module:UtilsVar")


function p._Main(frame)
function p._Main(frame)
local entry = h.GetEntryForToday()
local entry = h.GetEntryForToday()
return h.DisplaySection(entry)
return h.DisplaySection(entry)
end
function p.AddToPreview(frame)
local args = frame:getParent().args
utilsVar.add("entries", args)
end
function p.Preview(frame)
local entries = utilsVar.get("entries")
local eventsByDate = utilsTable.keyBy(entries, function(entry)
return string.sub(entry.date, 6)
end)
local calendar = {
{"January", 31},
{"February", 29},
{"March", 31},
{"April", 30},
{"May", 31},
{"June", 30},
{"July", 31},
{"August", 31},
{"September", 30},
{"October", 31},
{"November", 30},
{"December", 31},
}
local rows = {}
for i, month in ipairs(calendar) do
for day = 1, month[2] do
local d = h.toString(day)
local m = h.toString(i)
local date = m.."-"..d
local event = eventsByDate[date]
table.insert(rows, {
id = date,
cells = {
{
sortValue = date,
content = month[1].." "..day,
},
event and event.date or "",
event and h.DisplaySection(event) or ""
},
})
end
end
local wikitable = utilsLayout.table({
headers = {"Day", "Date", "On This Day"},
rows = rows,
sortable = true,
})
local styles = frame:extensionTag({
name = "templatestyles",
args = { src = "Template:Main Page Infoblocks/Styles.css" }
})
return styles..wikitable
end
function h.toString(num)
if num < 10 then
return "0"..num
else
return tostring(num)
end
end
end


function h.GetEntryForToday()
function h.GetEntryForToday()
local formattedDate = os.date("%m-%d")
local formattedDate = os.date("%m-%d")
local entries = cargo.query("OnThisDay", "date, title, filename, text, link", {})
local entries = utilsCargo.query("OnThisDay", "date, title, filename, text, link", {})
local todayEntries = {}
local todayEntries = {}
Line 25: Line 93:
local result = ""
local result = ""
local header = "On this day"
local header = "On this day"
if not utilsCode.IsEmpty(entry) then
if entry then
header = header .. ", " ..  (os.date("%Y") - tonumber(string.sub(entry["date"], 1, 4))) .. " years ago..."
header = header .. ", " ..  (os.date("%Y") - tonumber(string.sub(entry["date"], 1, 4))) .. " years ago..."
else
else
Line 32: Line 100:
entry["filename"] = "LA Mr. Write Artwork.png"
entry["filename"] = "LA Mr. Write Artwork.png"
entry["title"] = "Nothing happened"
entry["title"] = "Nothing happened"
entry["text"] = "But you can change that! All it takes is one edit to make history. [[Special:RecentChanges|Zelda Wiki history]], that is.\n* [https://discordapp.com/invite/eJnnvYb Join our Discord]\n* [[Guidelines:Getting Started|Learn editing basics]]\n* [[Zelda Wiki:Knight Challenges|Participate in our Knight Challenges]]\n*[[:Category:Articles Needing Attention|Check out pages needing attention]]"
entry["text"] = "But you can change that! All it takes is one edit to make history. [[Special:RecentChanges|Zelda Wiki history]], that is.\n* [https://discordapp.com/invite/eJnnvYb Join our Discord]\n* [[Guidelines:Getting Started|Learn how to edit]]\n* [[:Category:Articles needing attention|Check out pages needing attention]]"
entry["link"] = "Guidelines:Getting Started"
entry["link"] = "Guidelines:Getting Started"
end
end
local purgeButton = mw.html.create("span")
:addClass("plainlinks otd-refresh-button")
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[{{FULLURL:Main Page|action=purge}} refresh]<nowiki>]</nowiki>"))
-- desktop version
local html = mw.html.create("div")
local desktopVersion = mw.html.create("div")
:addClass("infoblock")
:addClass("no-mobile infoblock")
:attr("id", "on-this-day")
:attr("id", "on-this-day")
:node(mw.html.create("div")
:tag("div")
:addClass("infoblock-header")
:addClass("infoblock-header")
:wikitext(header))
:wikitext(header)
:node(mw.html.create("div")
:done()
:addClass("infoblock-content")
:tag("div")
:wikitext("[[File:" .. entry["filename"] .. "|right|200x200px]]<span class='infoblock-title'>" .. entry["title"] .. "</span><br>" .. entry["text"]))
:addClass("infoblock-body")
:node(mw.html.create("div")
:tag("div")
:addClass("infoblock-read-more")
:addClass("infoblock-text")
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[[" .. entry["link"] .. "|Read more...]]<nowiki>]</nowiki>")))
:tag("div")
:addClass("infoblock-title")
-- mobile version
:tag("div")
local mobileVersion = mw.html.create("div")
:addClass("infoblock-title-text")
:addClass("mobile-only infoblock")
:wikitext(entry["title"])
:attr("id", "on-this-day")
:done()
:node(mw.html.create("div")
:tag("span")
:addClass("infoblock-header")
:addClass("plainlinks otd-refresh-button")
:wikitext(header))
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[{{FULLURL:Main Page|action=purge}} refresh]<nowiki>]</nowiki>"))
:node(mw.html.create("div")
:done()
:addClass("infoblock-title")
:done()
:wikitext(entry["title"]))
:tag("div")
:node(mw.html.create("div")
:addClass("infoblock-content")
:addClass("infoblock-content")
:wikitext(entry["text"])
:wikitext("[[File:" .. entry["filename"] .. "|right|150x150px]]" .. entry["text"]))
:done()
:node(mw.html.create("div")
:done()
:addClass("infoblock-read-more")
:tag("div")
:wikitext(mw.getCurrentFrame():preprocess("<nowiki>[</nowiki>[[" .. entry["link"] .. "|Read more...]]<nowiki>]</nowiki>")))
:addClass("infoblock-image")
:wikitext("[[File:" .. entry["filename"] .. "|200x200px]]")
result = tostring(desktopVersion) .. tostring(mobileVersion)
:done()
return result
:done()
 
return tostring(html)
end
end
p.Templates = {
["On This Day"] = {},
["On This Day/Store"] = {},
}


return p
return p
autopatrol, curators, retiredstaff
14,225

edits

Navigation menu