Module:New pages: Difference between revisions
From Eli's Software Encyclopedia
mNo edit summary |
mNo edit summary |
||
| Line 4: | Line 4: | ||
local year, month, day, hour, minute, second = timestamp:match("^(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)") | local year, month, day, hour, minute, second = timestamp:match("^(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)") | ||
if year and month and day and hour and minute then | if year and month and day and hour and minute then | ||
timestamp = string.format('%s-%s-%s %s:%s', year, month, day, hour, minute) | |||
else | else | ||
timestamp = 'Invalid Timestamp' -- Handle invalid timestamps | |||
end | end | ||
end | end | ||
Revision as of 15:52, February 17, 2025
Documentation for this module may be created at Module:New pages/doc
local p = {}
local function dateFormatter(timestamp)
local year, month, day, hour, minute, second = timestamp:match("^(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)")
if year and month and day and hour and minute then
timestamp = string.format('%s-%s-%s %s:%s', year, month, day, hour, minute)
else
timestamp = 'Invalid Timestamp' -- Handle invalid timestamps
end
end
function p.main()
local data = mw.ext.externalData.getExternalData {
url = 'http://elisoftware.org/w/api.php?action=query&format=json&list=recentchanges&rcnamespace=0&rcprop=title%7Ctimestamp%7Cuser&rclimit=20&rctype=new',
format = 'JSON'
} or {}
local rtitle, rdate, ruser, rrow
local html = mw.html.create()
local ul = html:tag('ul')
for _, page in ipairs(data) do
rtitle = page.title
rdate = page.timestamp
ruser = page.user
rrow = string.format('%s - [[%s]] by [[User:%s|%s]]', dateFormatter(rdate), rtitle, ruser, ruser )
ul:tag('li'):wikitext(rrow)
end
return html
end
return p
