Module:Motd
| This module is rated as ready for general use. It has reached a mature state, is considered relatively stable and bug-free, and may be used wherever appropriate. It can be mentioned on help pages and other Wikipedia resources as an option for new users. To minimise server load and avoid disruptive output, improvements should be developed through sandbox testing rather than repeated trial-and-error editing. |
| Editing of this module by new or unregistered users is currently disabled. See the protection policy and protection log for more details. If you cannot edit this module and you wish to make a change, you can submit an edit request, discuss changes on the talk page, request unprotection, log in, or create an account. |
Usage
{{#invoke:Motd|read|archive}}
archives are pages like Wikipedia:Motto_of_the_day/Schedule/Archive_2012. (2012 to 2015)
{{#invoke:Motd|read11|archive}}
archives are pages like Wikipedia:Motto_of_the_day/Schedule/Archive_2009. (up to 2011)
The read routine produces an output that has been manually cut-and-pasted into Module:Motd/data/2012 etc., and in some cases further modified. Ideally, each year should have one motto per day, possibly appropriate to that day. The read function produces the data to paste and the main function calls on this data for its output.
{{#invoke:Motd|main|day = day|year = year}}
Picks a motto. Defaults to 2012 for year, current day for day. Years 2006 to 2015 exist, but 2006, 2014, 2015 themselves don't have a full set of days. Haven't checked the others to be sure either.
--This module aims to a) extract motds from various sources and return a data file to be copied
-- b) use that data file to return a motd chosen from within it
--MOTD is [[WP:Motto of the day]], not message!
--Note: it's been a while since I last touched Lua, so I may have a slow start
local p = {}
function p.main(frame)
mottos = mw.loadData("Module:Motd/data/2012")
yday = os.date("!*t", nil).yday -- should be day of year, we'll see...
return frame:preprocess(mottos[yday])
end
function p.read(frame)
local parent=frame.getParent(frame) or {}
local currentpage, from, to
---- args in the #invoke itself trump args in the parent frame
currentpage = (parent and parent.args.page) or frame.args.page
from = (parent and parent.args.from) or frame.args.from or 0
to = (parent and parent.args.to) or frame.args.to or 9999
from, to = tonumber(from), tonumber(to) -- they get passed in as strings!
-- from and to are kludges to get part of the data when I start getting too much expanded template errors (not needed!)
-- I'm not sure getting the current page makes sense but I had the code handy so I'll leave it.
local pagepointer
if not(currentpage) then
pagepointer=mw.title.getCurrentTitle()
assert(pagepointer,"failed to access getCurrentTitle")
currentpage=pagepointer.fullText
else pagepointer=mw.title.new(currentpage)
assert(pagepointer,"failed to access mw.title.new("..tostring(currentpage)..")")
end
---- get the text of the currentpage
local text=pagepointer.getContent(pagepointer)
assert (text,"error: failed to get text from ".. currentpage)
local linkmatch = "%[%[(.-)%]%]"
local prowl=mw.ustring.gmatch(text,linkmatch)
local archive={}
local link=prowl()
local count = 0
while link do
if (count >= from) and (count <= to) then
link = mw.ustring.gmatch(link,"(.-)%|")() or link
flag, contents = pcall(frame.expandTemplate, frame, {title = link, args = nil})
-- table.insert(archive,'[==[' .. link .. ']==],</nowiki><br><nowiki>')
-- I don't think I actually need to include the link for this use
table.insert(archive,'[==[' .. contents .. ']==],</nowiki><br><nowiki>')
end
count = count + 1
link=prowl()
end
local output=""
for i = 1, table.maxn(archive) do
output=output..(archive[i] or "")
end
output = mw.ustring.gsub(output,",</nowiki><br><nowiki>$","</nowiki><br><nowiki>")
output = "<nowiki>return {</nowiki><br><nowiki>"..output.."}</nowiki>"
return frame.preprocess(frame,output)
end
function p.read11(frame) -- this is a copy of p.read being customized for 2010-2011
local parent=frame.getParent(frame) or {}
local currentpage, from, to
---- args in the #invoke itself trump args in the parent frame
currentpage = (parent and parent.args.page) or frame.args.page
from = (parent and parent.args.from) or frame.args.from or 0
to = (parent and parent.args.to) or frame.args.to or 9999
from, to = tonumber(from), tonumber(to) -- they get passed in as strings!
-- from and to are kludges to get part of the data when I start getting too much expanded template errors
-- I'm not sure getting the current page makes sense but I had the code handy so I'll leave it.
local pagepointer
if not(currentpage) then
pagepointer=mw.title.getCurrentTitle()
assert(pagepointer,"failed to access getCurrentTitle")
currentpage=pagepointer.fullText
else pagepointer=mw.title.new(currentpage)
assert(pagepointer,"failed to access mw.title.new("..tostring(currentpage)..")")
end
---- get the text of the currentpage
local text=pagepointer.getContent(pagepointer)
assert (text,"error: failed to get text from ".. currentpage)
local linkmatch = "(.-)%[%[(.-)%]%]"
local prowl=mw.ustring.gmatch(text,linkmatch)
local archive={}
local contents, link = prowl()
local count = 0
while link do
if (count >= from) and (count <= to) then
link = mw.ustring.gmatch(link,"(.-)%|")() or link
-- table.insert(archive,'[==[' .. link .. ']==],</nowiki><br><nowiki>')
-- I don't think I actually need to include the link for this use
table.insert(archive,'[==[' .. contents .. ']==],</nowiki><br><nowiki>')
end
count = count + 1
contents, link=prowl()
end
if contents then
table.insert(archive,'[==[' .. contents .. ']==],</nowiki><br><nowiki>')
end
local output=""
for i = 1, table.maxn(archive) do
output=output..(archive[i] or "")
end
output = mw.ustring.gsub(output,",</nowiki><br><nowiki>$","</nowiki><br><nowiki>")
output = "<nowiki>return {</nowiki><br><nowiki>"..output.."}</nowiki>"
return frame.preprocess(frame,output)
end
return p