Module:Item infobox: Difference between revisions
Jump to navigation
Jump to search
(Created page with "------------------------------------------------------------------------------- -- -- Module:Item infobox -- -- This module implements Template:I...") |
(Use invoker factory from Module:Util.) |
||
Line 7: | Line 7: | ||
require('Module:No globals') | require('Module:No globals') | ||
local m_util = require('Module:Util') | local m_util = require('Module:Util') | ||
local m_cargo = require('Module:Cargo') | local m_cargo = require('Module:Cargo') | ||
Line 21: | Line 20: | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
-- | -- Main functions | ||
-- ---------------------------------------------------------------------------- | -- ---------------------------------------------------------------------------- | ||
local | local function _query_item_infobox(args) | ||
function | |||
--[[ | --[[ | ||
Queries for an item infobox. | Queries for an item infobox. | ||
Line 38: | Line 32: | ||
]] | ]] | ||
local tables = { | local tables = { | ||
'items', | 'items', | ||
Line 58: | Line 48: | ||
query.where = string.format( | query.where = string.format( | ||
'_pageData._pageName="%s"', | '_pageData._pageName="%s"', | ||
args.page | |||
) | ) | ||
-- Join with _pageData in order to check for page redirect | -- Join with _pageData in order to check for page redirect | ||
Line 72: | Line 62: | ||
return table.concat(out, '') | return table.concat(out, '') | ||
end | 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 | return p |
Revision as of 15:19, 17 January 2022
The above documentation is transcluded from Module:Item infobox/doc.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
Editors can experiment in this module's sandbox and testcases pages.
Subpages of this module.
-------------------------------------------------------------------------------
--
-- Module:Item infobox
--
-- This module implements Template:Item infobox.
-------------------------------------------------------------------------------
require('Module:No globals')
local m_util = require('Module:Util')
local m_cargo = require('Module:Cargo')
-- 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)'}
]]
local tables = {
'items',
'_pageData',
'maps',
'areas',
}
local fields = {
'items.html_extra',
'_pageData._pageNameOrRedirect',
'maps.area_id',
'areas.id',
'areas.infobox_html',
}
local query = {}
query.where = string.format(
'_pageData._pageName="%s"',
args.page
)
-- Join with _pageData in order to check for page redirect
query.join = 'items._pageName = _pageData._pageNameOrRedirect, items._pageID = maps._pageID, maps.area_id = areas.id'
local results = m_cargo.query(tables, fields, query)
if #results == 0 then
error(i18n.errors.no_results_found)
end
local out = {
results[1]['items.html_extra'],
results[1]['areas.infobox_html'],
}
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