Module:Used by

From Team Fortress Wiki
Jump to: navigation, search
Parameter Output
all
{{Used by|all}}
All classes
all-except (max: 3)
{{Used by|all-except|Soldier|etc.}}
All classes (except Soldier)
All classes (except Soldier and Pyro)
All classes (except Soldier, Pyro, and Engineer)
classname (max: 5)
{{Used by|Soldier|etc.}}
Soldier
Soldier, Pyro
Soldier, Pyro, Engineer
Soldier, Pyro, Engineer, Demoman
Soldier, Pyro, Engineer, Demoman, Heavy

local p = {}

function common_string(args)
  return mw.getCurrentFrame():expandTemplate{title='Common string', args=args}
end

function get_args(frame)
    local args = {}
    for _, arg in ipairs(frame.args) do
        table.insert(args, arg)
    end
    if #args > 0 then return args end

    for _, arg in ipairs(frame:getParent().args) do
        table.insert(args, arg)
    end

    return args
end

function p.classes(frame)
    local args = get_args(frame)

    if args[1] == 'all' then
        return common_string{'infobox-used-by-all'}
    elseif args[1] == 'all-except' then
        table.remove(args, 1) -- Remove the 'all-except' argument
        assert(#args >= 1, "You must provide at least 1 class when using 'all-except'.")
        assert(#args <= 3, "You must provide at most 3 classes when using 'all-except'.")
        return common_string{'infobox-used-by-all-except-' .. #args, unpack(args)}
    else
        assert(#args >= 1, "You must provide at least 1 class when using this function.")
        assert(#args <= 5, "You must provide at most 5 classes when using this function.")
        return common_string{'infobox-used-by-' .. #args, unpack(args)}
    end
end

return p