Module:T-TLD: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 118: Line 118:
     end
     end
}
}
-- === PIC/RVC Link Processor ===
template.config.processors.RVC = function(value, args)
    local val = tostring(value)
    if val:find("gtldresult.icann.org") then
        return string.format("[%s Here]", val)
    elseif val:match("^%d+$") then
        return string.format("[https://gtldresult.icann.org/applicationstatus/applicationdetails/%s Here]", val)
    end
    return val
end
template.config.processors.PIC = template.config.processors.RVC
-- IDN property provider
Blueprint.registerPropertyProvider(template, function(template, args)
    local props = {}
    if args._idnFlag then props["Is IDN"] = "true" end
    return props
end)
-- IDN detection preprocessor
local function detectIDNStatus(template, args)
    args._idnFlag = false
    if args.idn and args.idn ~= '' then
        local idnVal = string.lower(args.idn)
        if idnVal == 'yes' or idnVal == 'true' or idnVal == '1' then
            args._idnFlag = true
            local titleObj = mw.title.getCurrentTitle()
            local pageName = titleObj and titleObj.text or ''
            local puny = Blueprint.protectedExecute(
                template,
                'IDN_toASCII',
                function()
                    return getPunycode().encode(pageName:gsub('^%.',''))
                end,
                pageName
            )
            args.ascii = 'xn--' .. puny
        end
    end
    return args
end


-- === Field Processors ===
-- === Field Processors ===
Line 182: Line 139:
     return TemplateHelpers.normalizeCountries(value)
     return TemplateHelpers.normalizeCountries(value)
end
end
-- === PIC/RVC Link Processor ===
template.config.processors.RVC = function(value, args)
    local val = tostring(value)
    if val:find("gtldresult.icann.org") then
        return string.format("[%s Here]", val)
    elseif val:match("^%d+$") then
        return string.format("[https://gtldresult.icann.org/applicationstatus/applicationdetails/%s Here]", val)
    end
    return val
end
template.config.processors.PIC = template.config.processors.RVC


-- === Category Provider ===
-- === Category Provider ===
Line 206: Line 176:
     return cats
     return cats
end)
end)
-- IDN property provider
Blueprint.registerPropertyProvider(template, function(template, args)
    local props = {}
    if args._idnFlag then props["Is IDN"] = "true" end
    return props
end)
-- IDN detection preprocessor
local function detectIDNStatus(template, args)
    args._idnFlag = false
    if args.idn and args.idn ~= '' then
        local idnVal = string.lower(args.idn)
        if idnVal == 'yes' or idnVal == 'true' or idnVal == '1' then
            args._idnFlag = true
            local titleObj = mw.title.getCurrentTitle()
            local pageName = titleObj and titleObj.text or ''
            local puny = Blueprint.protectedExecute(
                template,
                'IDN_toASCII',
                function()
                    return getPunycode().encode(pageName:gsub('^%.',''))
                end,
                pageName
            )
            args.ascii = 'xn--' .. puny
        end
    end
    return args
end


-- ================================================================================
-- ================================================================================