Module:PageDates: Difference between revisions

Created page with "local p = {} function p.dates(frame) local title = mw.title.getCurrentTitle() local firstRev = title:getFirstRevision() local lastRev = title:getLatestRevID() if not firstRev then return "Page history not available." end local createdTimestamp = firstRev.timestamp local updatedTimestamp = title:getTimestamp() local lang = mw.language.getContentLanguage() local createdDate = lang:formatDate("j F Y", createdTimestamp) loc..."
 
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 firstRev = title:getFirstRevision()
     local page = mw.site.pages[title.fullText]
    local lastRev = title:getLatestRevID()


     if not firstRev then
     if not page then
         return "Page history not available."
         return "Page not found."
     end
     end


     local createdTimestamp = firstRev.timestamp
     local revisions = page:getRevisions{ limit = 2, dir = "newer" }
     local updatedTimestamp = title:getTimestamp()
    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
     local createdDate = lang:formatDate("j F Y", createdTimestamp)
     local createdDate = lang:formatDate("j F Y", createdTimestamp)
    -- Get latest revision timestamp (regardless of limit)
    local updatedTimestamp = title:getTimestamp()
     local updatedDate = lang:formatDate("j F Y", updatedTimestamp)
     local updatedDate = lang:formatDate("j F Y", updatedTimestamp)