FANDOM


--<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]]

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.