Module:Guide: Difference between revisions
Jump to navigation
Jump to search
(Created page with "------------------------------------------------------------------------------- -- -- 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(...") |
No edit summary |
||
| Line 69: | Line 69: | ||
tpl_args.date = tpl_args.date or h.get_last_revision_date() | tpl_args.date = tpl_args.date or h.get_last_revision_date() | ||
local page_title = mw.title.getCurrentTitle() | local page_title = mw.title.getCurrentTitle() | ||
if page_title | if page_title:inNamespaces(cfg.guide_namespace) then | ||
tpl_args.subject = tpl_args.subject or m_util.html.error{msg=i18n.errors.no_subject} | tpl_args.subject = tpl_args.subject or m_util.html.error{msg=i18n.errors.no_subject} | ||
Revision as of 21:49, 2 July 2025
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.get_last_revision_date()
return mw.getCurrentFrame():preprocess('{{#time:F j, Y|{{REVISIONTIMESTAMP}}}}')
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
return value
end
return m_util.cast.version(value, {return_type='string'})
end,
},
date = {
field = 'date',
type = 'Date',
},
}
}
-- ----------------------------------------------------------------------------
-- Main functions
-- ----------------------------------------------------------------------------
local function _main(tpl_args)
tpl_args = tpl_args or {}
tpl_args.date = tpl_args.date or h.get_last_revision_date()
local page_title = mw.title.getCurrentTitle()
if page_title: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.passive_skills,
}
-- Attach
mw.getCurrentFrame():expandTemplate{title = cfg.attach_templates.passive_skills}
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,
string.format('{{#dateformat:%s|mdy}}', tpl_args.date)
))
local mbox = mw.getCurrentFrame():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, {
wrappers = cfg.wrappers.guide,
})
p.guide = p.main
--
-- Template:Guide list
--
p.guide_list = m_util.misc.invoker_factory(_guide_list, {
wrappers = cfg.wrappers.guide_list,
})
return p