Jump to content

Module:Contentious topics/talk notice

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by HouseBlaster (talk | contribs) at 00:22, 27 May 2025 (save a WIP). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

local p = {}

-- Maps normalized topic names to sub-template names (special cases)
local topicMap = {
    aa2 = 'Contentious topics/Armenia-Azerbaijan talk notice',
    ['a-a'] = 'Contentious topics/Armenia-Azerbaijan talk notice',
    ['a-i'] = 'Contentious topics/Arab-Israeli talk notice',
    gmo = 'Contentious topics/gmo talk notice',
    tt = 'Contentious topics/The Troubles talk notice',
}

local function collectTopics(args)
    local seen = {}
    local topics = {}

    local function addTopic(value)
        if value then
            value = mw.text.trim(value)
            if value ~= '' and not seen[value] then
                seen[value] = true
                table.insert(topics, value)
            end
        end
    end

    addTopic(args.topic)
    addTopic(args.t)
    addTopic(args[1])
    for i = 2, 10 do
        addTopic(args[i])
    end

    return topics
end

function p.main(frame)
    local args = frame:getParent().args
    local topics = collectTopics(args)
    local specialTopics = {}
    local otherTopics = {}

    for _, topic in ipairs(topics) do
        if topicMap[topic] then
            table.insert(specialTopics, topic)
        else
            table.insert(otherTopics, topic)
        end
    end

    local output = {}

    -- Render special topics individually
    for _, topic in ipairs(specialTopics) do
        table.insert(output, frame:expandTemplate{
            title = 'Template wrapper',
            args = {['_template'] = topicMap[topic]}
        })
    end

    -- Render all other topics combined using the base template
    if #otherTopics > 0 then
        local baseArgs = {
            _template = 'Contentious topics/page restriction talk notice base',
            topic = table.concat(otherTopics, ','),
            protection = args.protection,
            ['0RR'] = args['0RR'],
            ['1RR'] = args['1RR'],
            ['consensus-required'] = args['consensus-required'],
            BRD = args.BRD,
            other = args.other,
            ['placed-date'] = args['placed-date'],
            nocat = args.nocat,
            small = args.small,
        }
        table.insert(output, frame:expandTemplate{
            title = 'Template wrapper',
            args = baseArgs
        })
    end

    return table.concat(output, '\n')
end

return p