Jump to content

Module:ItemPage

From Apogea Wiki
Revision as of 20:21, 30 January 2026 by Dane (talk | contribs) (Module for conditional item page sections (via create-page on MediaWiki MCP Server))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Documentation for this module may be created at Module:ItemPage/doc

local p = {}

-- Check if item has any sources
local function hasSources(itemName)
    local sources = mw.ext.cargo.query('ItemSource', '_pageName', {
        where = 'item="' .. itemName .. '"',
        limit = 1
    })
    return sources and #sources > 0
end

-- Main display function
function p.display(frame)
    local args = frame:getParent().args
    local itemName = args.item or args[1] or mw.title.getCurrentTitle().text
    
    local output = {}
    
    -- Always output the infobox
    table.insert(output, frame:preprocess('{{Infobox Item}}'))
    
    -- Conditionally output Sources section
    if hasSources(itemName) then
        table.insert(output, '\n== Sources ==')
        table.insert(output, frame:preprocess('{{ItemSources}}'))
    end
    
    return table.concat(output, '\n')
end

return p