Module:Guide
The above documentation is transcluded from Module:Guide/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:Guide
--
-- This module implements Template:Guide.
-------------------------------------------------------------------------------
require('Module:No globals')
local m_util = require('Module:Util')
-- Should we use the sandbox version of our submodules?
local use_sandbox = m_util.misc.maybe_sandbox('Guide')
local m_cargo = use_sandbox and require('Module:Cargo/sandbox') or require('Module:Cargo')
-- 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:Guide/config/sandbox') or mw.loadData('Module:Guide/config')
local i18n = cfg.i18n
-- ----------------------------------------------------------------------------
-- Helper functions
-- ----------------------------------------------------------------------------
local h = {}
function h.date(value, format)
format = format or 'display'
local lang = mw.getContentLanguage()
local formats = {
display = 'F j, Y',
cargo = 'Y-m-d',
}
if value ~= nil then
value = lang:formatDate(formats[format], value)
end
return value
end
-- ----------------------------------------------------------------------------
-- Cargo tables
-- ----------------------------------------------------------------------------
local tables = {}
tables.guides = {
table = 'guides',
order = {'subject', 'version', 'date'},
fields = {
subject = {
field = 'subject',
type = 'Text',
},
version = {
field = 'version',
type = 'String',
func = function (tpl_args, value)
if value ~= nil then
value = m_util.cast.version(value, {return_type='string'})
end
return value
end,
},
date = {
field = 'date',
type = 'Date',
func = function (tpl_args, value)
return h.date(value, 'cargo')
end,
},
}
}
-- ----------------------------------------------------------------------------
-- Main functions
-- ----------------------------------------------------------------------------
local function _main(tpl_args)
tpl_args = tpl_args or {}
local frame = mw.getCurrentFrame()
local title_obj = mw.title.getCurrentTitle()
if title_obj:inNamespaces(cfg.guide_namespace) then
tpl_args.subject = tpl_args.subject or m_util.html.error{msg=i18n.errors.no_subject}
-- Store Cargo data
m_cargo.store_mapped_args{
tpl_args = tpl_args,
table_map = tables.guides,
}
-- Attach
frame:expandTemplate{title = cfg.attach_templates.guides}
end
-- Make message box
local title = mw.html.create()
if tpl_args.subject then
title
:wikitext(string.format(i18n.message_box.guide_subject, tpl_args.subject))
else
title
:wikitext(i18n.message_box.guide)
end
local text = mw.html.create()
if tpl_args.note then
text
:wikitext(tpl_args.note)
:newline()
:newline()
end
if tpl_args.version then
text
:wikitext(string.format(i18n.message_box.version_valid, tpl_args.version))
:wikitext(' ')
end
text
:wikitext(string.format(
i18n.message_box.last_updated,
h.date(tpl_args.date, 'display')
))
local mbox = frame:expandTemplate{title = i18n.templates.message_box, args = {
type = 'info',
image = i18n.icons.guide,
title = tostring(title),
text = tostring(text),
}}
local cats = m_util.misc.add_category(i18n.categories.guides)
local html = mw.html.create()
:wikitext(mbox)
:wikitext(cats)
return tostring(html)
end
local function _guide_list(tpl_args)
end
-- ----------------------------------------------------------------------------
-- Exported functions
-- ----------------------------------------------------------------------------
local p = {}
p.table_guides = m_cargo.declare_factory{data=tables.guides}
--
-- Template:Guide
--
p.main = m_util.misc.invoker_factory(_main, {
parentFirst = true,
})
p.guide = p.main
--
-- Template:Guide list
--
p.guide_list = m_util.misc.invoker_factory(_guide_list, {
wrappers = cfg.wrappers.guide_list,
})
return p