Module:PageDates: Difference between revisions

From HighSpell Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
function p.dates(frame)
function p.dates(frame)
     local title = mw.title.getCurrentTitle()
     local title = mw.title.getCurrentTitle()
    local page = mw.site.pages[title.fullText]
    if not page then
        return "Page not found."
    end
    local revisions = page:getRevisions{ limit = 2, dir = "newer" }
    if not revisions or #revisions == 0 then
        return "No revision history found."
    end
     local lang = mw.language.getContentLanguage()
     local lang = mw.language.getContentLanguage()


    local createdTimestamp = revisions[1].timestamp
     -- Only thing Scribunto gives us reliably:
    local createdDate = lang:formatDate("j F Y", createdTimestamp)
 
     -- Get latest revision timestamp (regardless of limit)
     local updatedTimestamp = title:getTimestamp()
     local updatedTimestamp = title:getTimestamp()
     local updatedDate = lang:formatDate("j F Y", updatedTimestamp)
     local updatedDate = lang:formatDate("j F Y", updatedTimestamp)


     if createdDate == updatedDate then
     -- Since we can't get the true creation timestamp, fallback phrasing
        return string.format("It was added on %s.", createdDate)
     return string.format("This page was last updated on %s.", updatedDate)
     else
        return string.format("It was added on %s and revised on or before %s.", createdDate, updatedDate)
    end
end
end


return p
return p

Revision as of 22:58, 4 June 2025

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

local p = {}

function p.dates(frame)
    local title = mw.title.getCurrentTitle()
    local lang = mw.language.getContentLanguage()

    -- Only thing Scribunto gives us reliably:
    local updatedTimestamp = title:getTimestamp()
    local updatedDate = lang:formatDate("j F Y", updatedTimestamp)

    -- Since we can't get the true creation timestamp, fallback phrasing
    return string.format("This page was last updated on %s.", updatedDate)
end

return p