FANDOM


--Automatically changes categories/templates after xx days
-- use in template or directly
-- Syntax = {{#invoke:Autochangecat|main|days=2|category1=Dev|category2=Developers|template=true}}
-- 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, sArg1, sArg2 = oArgTable["days"], oArgTable["category1"] or oArgTable["template1"], oArgTable["category2"] or oArgTable["template2"]
    local bTemplate = oArgTable["template"]
    local sNewCategory = p.changeCategory(iDays,sArg1,sArg2,bTemplate)
    return sNewCategory
end
 
function p.changeCategory(iDays,sArg1,sArg2,bChangeTemplate)
    local sCat =""
    if (iDays and sArg1 and sArg2) then
        local iFutureDate = u.addDays (os.date("%Y-%m-%d"),iDays)
        local iDaysLeft = u.datediff(os.date("%Y-%m-%d"),iFutureDate)
        local sPrefix = "[[".. "Category:"
        local sSuffix = "]]"
        if (bChangeTemplate=="true") then
            sPrefix = "{{"
            sSuffix = "}}"
        end
        local sCategoryPrefix = sPrefix 
        if (iDaysLeft<1) then
            sCat = preprocess(sCategoryPrefix .. sArg2 .. sSuffix)
        else
            sCat = preprocess(sCategoryPrefix .. 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

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.