Module:New pages

From Eli's Software Encyclopedia
Revision as of 15:54, February 17, 2025 by WikiVisor (talk | contribs)

Documentation for this module may be created at Module:New pages/doc

local p = {}

local function dateFormatter(timstamp)
    	local year, month, day, hour, minute, second = timstamp:match("^(%d+)-(%d+)-(%d+)T(%d+):(%d+):(%d+)")
    	if year and month and day and hour and minute then
        	timstamp = string.format('%s-%s-%s %s:%s', year, month, day, hour, minute)
    	else
        	timstamp = '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