Module:Contract

Module documentation[view][edit][history][purge]
This documentation is transcluded from Module:Contract/doc. Changes can be proposed in the talk page.
Function list
L 6 — convertCategories
L 21 — Contract.main

require('strict')

local Contract = {}

--- @param categories table Plain text categories in array
local function convertCategories(categories)
    local mapped = {}
    for _, category in pairs(categories) do
        if category ~= nil then
            if string.sub(category, 1, 2) ~= '[[' then
                category = string.format('[[Category:%s]]', category)
            end

            table.insert(mapped, category)
        end
    end
    return table.concat(mapped)
end

-- @param frame table https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Frame_object
function Contract.main(frame)
    local args = require('Module:Arguments').getArgs(frame)
    local infobox = require('Module:InfoboxNew'):new()
    local categories = {"Contracts"}

    local faction_placeholders = {
        arachne = 'Arachne_placeholder.jpg',
        cyac = 'Cyac_placeholder.jpg',
        mida = 'Mida_placeholder.jpg',
        nucal = 'Nucal_placeholder.jpg',
        sekgen = 'Sekgen_placeholder.jpg',
        traxus = 'Traxus_placeholder.jpg'
    }

    if not args['image'] and args['faction'] then
        args['image'] = faction_placeholders[string.lower(args['faction'])]
    end

    infobox:renderImage(args['image'])

    infobox:renderHeader({
        title = args['name'],
        subtitle = args['faction']
    })

    if args['faction'] then
        table.insert(categories, args['faction'] .. " contracts")
    end

    local zone_label = "Zone"
    if args['zone'] and (string.lower(args['zone']) == "multizone" or string.find(args['zone'], ',')) then
        zone_label = "Zones"
    end

    infobox:renderSection({
        content = {
            infobox:renderItem({
                label = "Type",
                data = args['type']
            }),
            infobox:renderItem({
                label = zone_label,
                data = args['zone']
            })
        },
        col = 2
    })

    infobox:renderSection({
        content = {
            infobox:renderItem({
                label = "Requirements",
                data = args['requirements']
            })
        },
        col = 2
    })

    if args['prev'] then
        args['prev'] = '[[' .. args['prev'] .. ']]'
    end
    if args['next'] then
        args['next'] = '[[' .. args['next'] .. ']]'
    end

    infobox:renderSection({
        title = "Series",
        content = {
            infobox:renderItem({
                label = "Previous",
                data = args['prev']
            }),
            infobox:renderItem({
                label = "Next",
                data = args['next']
            })
        },
        col = 2
    })

    infobox:renderSection({
        title = "Story",
        content = {
            infobox:renderItem({
                data = args['description'],
            })
        }
    })

    if args['restriction'] then
        args['restriction'] = "<br>''" .. string.upper(args['restriction']) .. "''"
    end

    local objectives = {}
    table.insert(objectives, infobox:renderItem({
        data = args['objective description'],
        desc = args['restriction']
    }))

    -- intentionally limited to 10
    for i = 1, 10 do
        if args['objective' .. i] then
            table.insert(objectives, infobox:renderItem({
                label = 'Objective ' .. i,
                data = args['objective' .. i],
                desc = args['factionrep' .. i] and string.format("%s %s faction reputation", args['factionrep' .. i], args['faction']) or ''
            }))
        else
            break
        end
    end

    infobox:renderSection({
        title = "Objectives",
        content = table.concat(objectives)
    })

    local style = ''

    local styles = {
        arachne = 'Module:Contract/arachne.css',
        cyac = 'Module:Contract/cyac.css',
        mida = 'Module:Contract/mida.css',
        nucal = 'Module:Contract/nucal.css',
        sekgen = 'Module:Contract/sekgen.css',
        traxus = 'Module:Contract/traxus.css'
    }

    if args['faction'] and styles[string.lower(args['faction'])] then
        style = frame:extensionTag {
            name = 'templatestyles', args = { src = styles[string.lower(args['faction'])] }
        }
    end


    mw.ext.seo.set{
        title = args['name'] and args['name'] .. " - CyberAcme, the Marathon wiki",
        site_name = "CyberAcme, the Marathon wiki",
        keywords = args['faction'] and "marathon, contracts, " .. args['faction'] or "marathon, contracts",
        image = args['image']
    }

    if not args['nocat'] then
        categories = convertCategories(categories);
    else
        categories = ""
    end

    return tostring(infobox:renderInfobox(nil, args['name'])) .. style .. categories
end

return Contract