Module:Item infobox: Difference between revisions

From Path of Exile Wiki
Jump to navigation Jump to search
(Improved using item query from Module:Item util. The most recent version of a map can be queried using the name of the map.)
No edit summary
Line 32: Line 32:
     ]]
     ]]
      
      
    args.item_name = args.item_name or args[1]
     local qargs = {}
     local qargs = {}
     qargs.tables = {
     qargs.tables = {

Revision as of 18:08, 19 January 2022

Module documentation[view] [edit] [history] [purge]


Lua logo

This module depends on the following other modules:

Implements {{item infobox}}.

-------------------------------------------------------------------------------
-- 
--                             Module:Item infobox
-- 
-- This module implements Template:Item infobox.
-------------------------------------------------------------------------------

require('Module:No globals')
local m_util = require('Module:Util')
local m_item_util = require('Module:Item util')

-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox('Item infobox')

-- The cfg table contains all localisable strings and configuration, to make it
-- easier to port this module to another wiki.
local cfg = use_sandbox and mw.loadData('Module:Item infobox/config/sandbox') or mw.loadData('Module:Item infobox/config')

local i18n = cfg.i18n

-- ----------------------------------------------------------------------------
-- Main functions
-- ----------------------------------------------------------------------------

local function _query_item_infobox(args)
    --[[
    Queries for an item infobox.
    
    Examples
    --------
    =p.query_item_infobox{page='Map:Beach Map (Betrayal)'}
    ]]
    
    args.item_name = args.item_name or args[1]
    local qargs = {}
    qargs.tables = {
        'maps',
        'areas',
    }
    qargs.join = 'items._pageID = maps._pageID, maps.area_id = areas.id'
    qargs.fields = {
        'items.html_extra=item_infobox',
        'areas.infobox_html=area_infobox',
    }
    local result = m_item_util.query_item(args, qargs)
    if result.error then
        return result.error
    end
    local out = {
        result['item_infobox'],
        result['area_infobox'] or '',
    }
    return table.concat(out)
end

-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------

local p = {}

-- 
-- Template:Item infobox
-- 
p.query_item_infobox = m_util.misc.invoker_factory(_query_item_infobox, {
    wrappers = cfg.wrappers.query_item_infobox,
})

return p