Module:New pages: Difference between revisions

From Eli's Software Encyclopedia
mNo edit summary
mNo edit summary
Line 1: Line 1:
local p = {}
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
        rdate = string.format('%s-%s-%s %s:%s', year, month, day, hour, minute)
    else
        rdate = 'Invalid Timestamp' -- Handle invalid timestamps
    end
end


function p.main()
function p.main()
Line 19: Line 28:
ruser = page.user
ruser = page.user
-- Parse and format the timestamp
rrow = string.format('%s - [[%s]] by [[User:%s|%s]]', dateFormatter(rdate), rtitle, ruser, ruser )
    local year, month, day, hour, minute, second = rdate:match("^(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)")
    if year and month and day and hour and minute then
        rdate = string.format('%s-%s-%s %s:%s', year, month, day, hour, minute)
    else
        rdate = 'Invalid Timestamp' -- Handle invalid timestamps
    end
rrow = string.format('%s - [[%s]] by [[User:%s|%s]]', rdate, rtitle, ruser, ruser )


    ul:tag('li'):wikitext(rrow)
    ul:tag('li'):wikitext(rrow)

Revision as of 15:51, 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
        	rdate = string.format('%s-%s-%s %s:%s', year, month, day, hour, minute)
    	else
        	rdate = '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