Module:New pages: Difference between revisions

From Eli's Software Encyclopedia
mNo edit summary
mNo edit summary
 
(9 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {}
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()
function p.main()
local data = mw.ext.externalData.getExternalData {
local data = mw.smw.ask {
url = 'http://elisoftware.org/w/api.php?action=query&format=json&list=recentchanges&rcnamespace=0&rcprop=title%7Ctimestamp%7Cuser&rclimit=20&rctype=new',
'[[:+]][[Creation date::+]]',
format = 'JSON'
'mainlabel=-',
'?Creation date#-F[Y-m-d H:i:s]=timestamp',
'?#-=title',
'?Page creator#-=user',
'sort=Creation date',
'order=desc',
'limit=20',
'@deferred'
} or {}
} or {}


Line 20: Line 18:
local html = mw.html.create()
local html = mw.html.create()
local ul = html:tag('ul')
local ul = html:tag('ul'):attr('id', 'new-pages')
for _, page in ipairs(data) do
for _, page in ipairs(data) do
Line 26: Line 24:
rtitle = page.title
rtitle = page.title
rdate = page.timestamp
rdate = page.timestamp
ruser = page.user
ruser = page.user or 'User:Eli'
rname = ruser:match("([^:]+)$")
rrow = string.format('%s - [[%s]] by [[User:%s|%s]]', dateFormatter(rdate), rtitle, ruser, ruser )
 
rrow = string.format('%s - [[%s]] by [[%s|%s]]', rdate, rtitle, ruser, rname )


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

Latest revision as of 11:57, December 10, 2025

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

local p = {}

function p.main()
	
	local data = mw.smw.ask {
		'[[:+]][[Creation date::+]]',
		'mainlabel=-',
		'?Creation date#-F[Y-m-d H:i:s]=timestamp',
		'?#-=title',
		'?Page creator#-=user',
		'sort=Creation date',
		'order=desc',
		'limit=20',
		'@deferred'
	} or {}

	local rtitle, rdate, ruser, rrow
	
	local html = mw.html.create()
	local ul = html:tag('ul'):attr('id', 'new-pages')
	
	for _, page in ipairs(data) do
		
		rtitle = page.title
		rdate = page.timestamp
		ruser = page.user or 'User:Eli'
		rname = ruser:match("([^:]+)$")

		rrow = string.format('%s - [[%s]] by [[%s|%s]]', rdate, rtitle, ruser, rname )

	    ul:tag('li'):wikitext(rrow)
	end
	
	return html
	
end

return p