Edge Rewrite
// HTMLRewriter · presentation

This page was redesigned at the edge.

Cloudflare fetched the original article and streamed it through HTMLRewriter to apply an entirely new visual system without rebuilding the source page.

Jump to content

Module:Redirect template printability

From Wikipedia, the free encyclopedia
-- Module:Redirect template printability
-- Centralized logic for deciding redirect printability categories
-- Intended to prevent contradictory categorization (e.g., printworthy + unprintworthy)

local p = {}

-- Helper: normalize input
local function normalize(val)
    if not val then return nil end
    val = mw.text.trim(val):lower()
    if val == 'yes' or val == 'true' or val == '1' then
        return true
    elseif val == 'no' or val == 'false' or val == '0' then
        return false
    else
        return val -- pass raw values like "printworthy" or "unprintworthy"
    end
end

-- Main function
-- Usage example:
-- {{#invoke:Redirect template printability|categorize|default=printworthy}}
-- {{#invoke:Redirect template printability|categorize|default=unprintworthy}}
function p.categorize(frame)
    local args = frame:getParent().args
    local default = normalize(args.default) or 'printworthy'

    -- Flags can be set by other rcats
    local flags = {
        printworthy = false,
        unprintworthy = false
    }

    -- Scan args for overrides
    for k,v in pairs(args) do
        v = normalize(v)
        if v == 'printworthy' then
            flags.printworthy = true
        elseif v == 'unprintworthy' then
            flags.unprintworthy = true
        elseif k == 'printworthy' and v == true then
            flags.printworthy = true
        elseif k == 'unprintworthy' and v == true then
            flags.unprintworthy = true
        end
    end

    -- Apply precedence
    if flags.unprintworthy then
        return '[[Category:Unprintworthy redirects]]'
    elseif flags.printworthy then
        return '[[Category:Printworthy redirects]]'
    elseif default == 'unprintworthy' then
        return '[[Category:Unprintworthy redirects]]'
    else
        return '[[Category:Printworthy redirects]]'
    end
end

return p