Jump to content

Module:ItemPage: Difference between revisions

From Apogea Wiki
Dane (talk | contribs)
Module for conditional item page sections (via create-page on MediaWiki MCP Server)
Tag: Recreated
 
Dane (talk | contribs)
Add default_form:Item output (via update-page on MediaWiki MCP Server)
 
Line 25: Line 25:
         table.insert(output, frame:preprocess('{{ItemSources}}'))
         table.insert(output, frame:preprocess('{{ItemSources}}'))
     end
     end
   
    -- Set the default form for this page
    table.insert(output, frame:preprocess('{{#default_form:Item}}'))
      
      
     return table.concat(output, '\n')
     return table.concat(output, '\n')

Latest revision as of 20:27, 30 January 2026

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
    
    -- Set the default form for this page
    table.insert(output, frame:preprocess('{{#default_form:Item}}'))
    
    return table.concat(output, '\n')
end

return p