Module:Document status
More actions
This Lua module implements Template:Document status. Editors should use the template; it supplies the parent-frame arguments expected by the module and loads its styles. See template parameters and editorial guidance.
Entry point and behavior
main(frame) reads frame:getParent().args: status (or positional 1), canon, note, replacement and nocat. A direct invocation with only the invocation's own arguments does not supply these parent arguments.
Supported states are Canon, Fanon, Approved, Unapproved, Draft, Archived, Deprecated and Unassessed. Keys are trimmed and case-insensitive. An empty status becomes Unassessed; an invalid status also becomes Unassessed and displays a parameter warning.
An independent canon=Canon or canon=Fanon can accompany an editorial state. Conflicting or unsupported combinations produce a warning. A replacement is accepted only as a valid internal, nonnegative-namespace title; the module does not check whether that page exists.
Categories
Automatic categorization is limited to Main, Solomonari and CotRH. nocat=yes, true or 1 disables it. No status or canon decision is inferred from the page's namespace or title. Invalid parameters add the maintenance category only where categorization is enabled.
Example through the template
{{Document status|status=Draft|note=Example only.|nocat=yes}}
local p = {}
local states = {
canon = {'Canon', '(SC) Canon', 'Part of the stated house continuity.'},
fanon = {'Fanon', 'Fanon documents', 'Community interpretation outside established house canon.'},
approved = {'Approved', 'Approved documents', 'Accepted through the wiki’s editorial review process.'},
unapproved = {'Unapproved', 'Unapproved documents', 'Not approved for publication in the mainline archive.'},
draft = {'Draft', 'Draft documents', 'Work in progress; details may change.'},
archived = {'Archived', 'Archived documents', 'Retained for reference rather than active use.'},
deprecated = {'Deprecated', 'Deprecated documents', 'Outdated material; consult its replacement where available.'},
unassessed = {'Unassessed', 'Pages needing status review', 'Editorial status has not yet been assessed.'}
}
local function key(v) return mw.ustring.lower(mw.text.trim(v or '')) end
function p.main(frame)
local a = frame:getParent().args
local s = key(a.status or a[1]); if s == '' then s = 'unassessed' end
local c = key(a.canon)
local title = mw.title.getCurrentTitle()
local categorize = (title.namespace == 0 or title.namespace == 3000 or title.namespace == 3002)
local nc = key(a.nocat); if nc == 'yes' or nc == 'true' or nc == '1' then categorize = false end
local categories = {}; local invalid = false
local function add(cat) if categorize then categories[cat] = true end end
local state = states[s]
if not state then state = states.unassessed; s = 'unassessed'; invalid = true end
add(state[2])
local label = state[1]
if c ~= '' then
if (c == 'canon' or c == 'fanon') and s ~= 'canon' and s ~= 'fanon' then
label = label .. ' · ' .. states[c][1]; add(states[c][2])
elseif c ~= s then invalid = true end
end
if invalid then add('Pages with invalid document status') end
local box = mw.html.create('div'):addClass('document-status'):addClass('document-status--' .. s)
box:attr('role','note')
box:tag('span'):addClass('document-status__label'):wikitext('[[Help:Document status|' .. label .. ']]'):done()
box:tag('span'):addClass('document-status__description'):wikitext(state[3]):done()
local note = mw.text.trim(a.note or '')
if note ~= '' then box:tag('span'):addClass('document-status__note'):wikitext(note):done() end
local replacement = mw.text.trim(a.replacement or '')
if replacement ~= '' then
local dest = mw.title.new(replacement)
if dest and not dest.isExternal and dest.namespace >= 0 then
box:tag('span'):addClass('document-status__note'):wikitext('See [[' .. dest.prefixedText .. ']].'):done()
else invalid = true; add('Pages with invalid document status') end
end
if invalid then box:tag('span'):addClass('document-status__note'):wikitext('Check the status parameters; see [[Help:Document status]].'):done() end
local result = tostring(box)
local cats = {}; for cat in pairs(categories) do cats[#cats + 1] = cat end; table.sort(cats)
for _,cat in ipairs(cats) do result = result .. '[[Category:' .. cat .. ']]' end
return result
end
return p