FANDOM


--Automatically changes template after xx days
-- use in template or directly
-- Syntax = {{#invoke:Autochangetemplate|main|days=2|template1=clarify|template2=delete}}
-- This module uses module:utility make sure it import it, or it won't work.
 
local p = {}
local u = require("Module:Utility")
 
function p.main(frame)
    local oArgTableParent,oArgTableChild = u.getArgs(frame)
    oArgTable = oArgTableChild or oArgTableParent
    local iDays, sTemplate1, sTemplate2 = oArgTable["days"], oArgTable["template1"], oArgTable["template2"]
    local sNewTemplate = p.changeTemplate(iDays,sTemplate1,sTemplate2)
    return sNewTemplate
end
 
function p.changeTemplate(iDays,sTemplate1,sTemplate2)
    local sCat =""
    if (iDays and sTemplate1 and sTemplate2) then
        local iFutureDate = u.addDays (os.date("%Y-%m-%d"),iDays)
        local iDaysLeft = u.datediff(os.date("%Y-%m-%d"),iFutureDate)
        local sTemplatePrefix = "{{"
 
        if (iDaysLeft<1) then
            sCat = preprocess(sTemplatePrefix .. sTemplate2 .. "}}")
        else
            sCat = preprocess(sTemplatePrefix .. sTemplate1 .. "}}")
        end
    end
    return sCat
end
 
function preprocess(sText)
    if (mw.getCurrentFrame()) then
        sText = mw.getCurrentFrame():preprocess(sText)
    end
   return sText
end
 
return p

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.