Module:Tempnotice: Difference between revisions

From The Satanic Wiki
Jump to navigation Jump to search
Mediawiki>Dessamator
mNo edit summary
 
m (1 revision imported)

Revision as of 02:24, 30 April 2021

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

--<pre>Displays a notice for XX days
-- based on the last date the page was saved/edited
-- use in template or directly
-- Syntax = {{#invoke:Tempnotice|main|days=2|notice="This message will self-destruct in ..."|template=true}}
-- Syntax = {{#invoke:Tempnotice|main|days=2|notice=selfdestruct|template=true}}
 
local p = {}
local u = require("Dev:Utility")
 
function p.main(frame)
    local oArgTable = require("Dev:Arguments").getArgs(frame)
 
    if (oArgTable) then
        local iDays = oArgTable["days"]
        local endDate = oArgTable["date"]
        local sArg1 = oArgTable[1]  or oArgTable["notice"]
        local bTemplate = oArgTable["template"]
 
        return p.shownotice(iDays,sArg1,endDate,bTemplate)
    end
end
 
function p.shownotice(iDays,sArg1,endDate,bTemplate)
    local sCat =""
 
    if (iDays or endDate) and sArg1  then
        local revDate =preprocess("{{REVISIONYEAR}}-{{REVISIONMONTH}}-{{REVISIONDAY2}}")
        local dFutureDate = u.addDays (revDate,iDays)
        local todayDate = os.date("%Y-%m-%d")
        local iDaysLeft = u.datediff(dFutureDate,todayDate)
        local isValidDate = u.checkdate(endDate)
        local sPrefix,sSuffix ="",""
 
        if isValidDate then
            iDaysLeft = u.datediff(endDate,os.date("%Y-%m-%d"))
        end
 
        if bTemplate then
            sPrefix = "{{"
            sSuffix = "}}"
        end
        
        if iDaysLeft and iDaysLeft>0 then
            sCat = sPrefix .. sArg1 .. sSuffix
        end
    end
    return sCat
end
 
function preprocess(sText)
    if mw.getCurrentFrame() then
        sText = mw.getCurrentFrame():preprocess(sText)
    end
 
    return sText
end
 
return p
--[[Category:Lua modules]]