FANDOM


local p = {}
 
function p.YearNav(frame)
    --Pattern = frame.args[1] or -1
    Pattern = -1
 
    if Pattern==-1 then
        Pattern = "####-10 ・・ ####-1 ・ #### ・ ####+1 ・・ ####+10" --Default. Will be overwritten if something was there.
        pairscounter = 0
        for i,v in pairs(frame.args) do
            if pairscounter>0 then
                Pattern = "|" .. Pattern
                Pattern = i .. "=" .. v .. Pattern
            else
                Pattern= i .. "=" .. v
            end
            pairscounter = pairscounter+1
        end
    end
 
    --Prefix = title.nsText
    --Namespace = title.namespace
    --PageName = title.text
    Prefix = "Category"
    Namespace = 0
    PageName = "1987 Sandwiches"
 
    _, _, OriginalYear = string.find(PageName, "(%d%d%d%d)")
    PageWithout = string.gsub(PageName, OriginalYear, "@@@@")
 
    CurrentText = Pattern
 
    itsthere, _, _, _ = string.find(CurrentText, "####([%+%-])(%d+)")
 
    while itsthere do --Continue while there are still instances in the pattern to alter
        _, _, plusminus, amount = string.find(CurrentText, "####([%+%-])(%d+)")
        if plusminus=="-" then
            NewYear = OriginalYear - amount
        else --assume it's plus
            NewYear = OriginalYear + amount
        end
        NewPageName = string.gsub(PageWithout, "@@@@", NewYear)
        if Namespace==0 then
            ReplacementSection = "[[" .. NewPageName .. "]]"
        else
            ReplacementSection = "[[:" .. Prefix .. ":" .. NewPageName .. "|" .. NewPageName .. "]]"
        end
        CurrentText = string.gsub(CurrentText, "####[%+%-]%d+", ReplacementSection, 1)
        itsthere, _, _, _ = string.find(CurrentText, "####([%+%-])(%d+)")
    end
 
    CurrentText = string.gsub(CurrentText, "####", PageName)
 
    return CurrentText
 
end
 
function p.YearNavLive(frame)
    Pattern = frame.args[1] or -1
 
    if Pattern==-1 then
        Pattern = "####-10 ・・ ####-1 ・ #### ・ ####+1 ・・ ####+10" --Default. Will be overwritten if something was there.
        for i,v in pairs(frame.args) do
            Pattern= i .. "=" .. v
        end
    end
 
    ThisPageTitle = mw.title.getCurrentTitle()
    Prefix = ThisPageTitle.nsText
    Namespace = ThisPageTitle.namespace
    PageName = ThisPageTitle.text
    --Prefix = "Category"
    --Namespace = 0
    --PageName = "1987 Sandwiches"
 
    _, _, OriginalYear = string.find(PageName, "(%d%d%d%d)")
    PageWithout = string.gsub(PageName, OriginalYear, "@@@@")
 
    CurrentText = Pattern
 
    itsthere, _, _, _ = string.find(CurrentText, "####([%+%-])(%d+)")
 
    while itsthere do --Continue while there are still instances in the pattern to alter
        _, _, plusminus, amount = string.find(CurrentText, "####([%+%-])(%d+)")
        if plusminus=="-" then
            NewYear = OriginalYear - amount
        else --assume it's plus
            NewYear = OriginalYear + amount
        end
        NewPageName = string.gsub(PageWithout, "@@@@", NewYear)
        if Namespace==0 then
            ReplacementSection = "[[" .. NewPageName .. "]]"
        else
            ReplacementSection = "[[:" .. Prefix .. ":" .. NewPageName .. "|" .. NewPageName .. "]]"
        end
        CurrentText = string.gsub(CurrentText, "####[%+%-]%d+", ReplacementSection, 1)
        itsthere, _, _, _ = string.find(CurrentText, "####([%+%-])(%d+)")
    end
 
    CurrentText = string.gsub(CurrentText, "####", PageName)
 
    return CurrentText
 
end
 
 
function p.test(frame)
    Pattern = frame.args[1] or "####-10 ・・ ####-1 ・ #### ・ ####+1 ・・ ####+10"
    --Prefix = title.nsText
    --Namespace = title.namespace
    --PageName = title.text
    Prefix = "Category"
    Namespace = 1
    PageName = "1987 Sandwiches"
 
    _, _, OriginalYear = string.find(PageName, "(%d%d%d%d)")
    PageWithout = string.gsub(PageName, OriginalYear, "@@@@")
 
    CurrentText = Pattern
 
    itsthere, _, _, _ = string.find(CurrentText, "####([%+%-])(%d+)")
 
    while itsthere do --Continue while there are still instances in the pattern to alter
        _, _, plusminus, amount = string.find(CurrentText, "####([%+%-])(%d+)")
        if plusminus=="-" then
            NewYear = OriginalYear - amount
        else --assume it's plus
            NewYear = OriginalYear + amount
        end
        NewPageName = string.gsub(PageWithout, "@@@@", NewYear)
        if Namespace==0 then
            ReplacementSection = "[[" .. NewPageName .. "]]"
        else
            ReplacementSection = "[[:" .. Prefix .. ":" .. NewPageName .. "|" .. NewPageName .. "]]"
        end
        CurrentText = string.gsub(CurrentText, "####[%+%-]%d+", ReplacementSection, 1)
        itsthere, _, _, _ = string.find(CurrentText, "####([%+%-])(%d+)")
    end
 
    CurrentText = string.gsub(CurrentText, "####", PageName)
 
    CurrentText = "<nowiki>" .. CurrentText .. "</nowiki>"
 
    return CurrentText
 
end
 
function p.test2(frame)
    Pattern = frame.args[1]
    --Prefix = title.nsText
    --Namespace = title.namespace
    --PageName = title.text
    Prefix = "Category"
    Namespace = 1
    PageName = "1987 Sandwiches"
 
    return Pattern
end
 
function p.test3(frame)
    Pattern = frame.args[1]
    --Prefix = title.nsText
    --Namespace = title.namespace
    --PageName = title.text
    Prefix = "Category"
    Namespace = 1
    PageName = "1987 Sandwiches"
 
    return "<table style='background:linear-gradient(to right,rgba(255,255,255,0),#e1e7f6,rgba(255,255,255,0));'><tr><td>####-7 ・・ ####-1 ・ '''####''' ・ ####+1 ・・ ####+7</td></tr></table>"
end
 
function p.test4(frame)
    Pattern = frame.args[1]
    Pattern = string.gsub(Pattern, "<pre>", "")
    Pattern = string.gsub(Pattern, "</pre>", "")
    return Pattern
end
 
function p.test5(frame)
    Pattern = frame.args[1]
    Pattern = string.gsub(Pattern, "LEFTIE", "<")
    Pattern = string.gsub(Pattern, "RIGHTIE", ">")
    return Pattern
end
 
function p.test6(frame)
    Pattern = frame.args[1]
    Pattern = string.gsub(Pattern, "EQUALS", "=")
    return Pattern
end
 
function p.test7(frame)
    Pattern = frame.args['dumb']
    return Pattern
end
 
function p.test8(frame)
    TheInput = frame.args[1] or -1
    if TheInput==-1 then
        for i,v in pairs(frame.args) do
            TheInput= i .. "=" .. v
        end
    end
    return TheInput
end
 
 
return p