Module:Tempnotice

From The Satanic Wiki
Revision as of 05:20, 2 May 2021 by WikiGOD (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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("Module:Utility")
 
function p.main(frame)
    local oArgTable = require("Module: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]]