-- Module:Infobox (patched with safe guards for missing extensions/modules)
local p = {}
-- ============================================================
-- Helpers
-- ============================================================
-- Safe wrappers to avoid runtime errors if extensions/modules are missing.
local function safe_extension_tag(frame, tag_args)
local ok, res = pcall(function() return frame:extensionTag(tag_args) end)
if ok and res then
return res
else
return ''
end
end
local function safe_require(modname)
local ok, mod = pcall(require, modname)
if ok then return mod end
return nil
end
-- ============================================================
-- Main code
-- ============================================================
-- locals from original module
local args = {}
local root
local lists = {
hlist_t = { found = true, styles = 'Module:Hlist/styles.css' },
plainlist_t = { found = true, styles = 'Module:Plainlist/styles.css' }
}
-- Replace loadTemplateStyles with safe version
local function loadTemplateStyles()
local frame = mw.getCurrentFrame()
local hlist_templatestyles = ''
if lists.hlist_t.found then
hlist_templatestyles = safe_extension_tag(frame, {
name = 'templatestyles',
args = { src = lists.hlist_t.styles }
})
end
local plainlist_templatestyles = ''
if lists.plainlist_t.found then
plainlist_templatestyles = safe_extension_tag(frame, {
name = 'templatestyles',
args = { src = lists.plainlist_t.styles }
})
end
local base_templatestyles = safe_extension_tag(frame, {
name = 'templatestyles',
args = { src = 'Module:Infobox/styles.css' }
})
local templatestyles = ''
if args['templatestyles'] then
templatestyles = safe_extension_tag(frame, {
name = 'templatestyles',
args = { src = args['templatestyles'] }
})
end
local child_templatestyles = ''
if args['child templatestyles'] then
child_templatestyles = safe_extension_tag(frame, {
name = 'templatestyles',
args = { src = args['child templatestyles'] }
})
end
local grandchild_templatestyles = ''
if args['grandchild templatestyles'] then
grandchild_templatestyles = safe_extension_tag(frame, {
name = 'templatestyles',
args = { src = args['grandchild templatestyles'] }
})
end
return table.concat({
hlist_templatestyles,
plainlist_templatestyles,
base_templatestyles,
templatestyles,
child_templatestyles,
grandchild_templatestyles
})
end
-- Example: Navbar safe load
local function renderNavbar()
local Navbar = safe_require('Module:Navbar')
if Navbar and Navbar._navbar then
root:wikitext(Navbar._navbar{
args.name,
mini = 1,
})
else
root:wikitext(args.name or '')
end
end
-- Example: Italic title safe load
local function renderItalicTitle()
local ItalicTitle = safe_require('Module:Italic title')
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
if ItalicTitle and ItalicTitle._main then
root:wikitext(ItalicTitle._main({}))
else
-- fallback: do nothing
end
end
end
-- ============================================================
-- Exports
-- ============================================================
p._loadTemplateStyles = loadTemplateStyles
p._renderNavbar = renderNavbar
p._renderItalicTitle = renderItalicTitle
return p