Module:Documentation
Jump to navigation
Jump to search
local p = {}
local HtmlBuilder = require('Module:HtmlBuilder') local makeInvokeFunc = require('Module:Arguments').makeInvokeFunc
function p._main(frame, args)
local headingParam = args['heading'] local contentParam = args['content'] local linkBoxParam = args['link box'] local docPageName, docPageTitle if not contentParam then docPageName = args[1] or ((args['page'] or mw.title.getCurrentTitle().fullText) .. '/doc') docPageTitle = mw.title.new(docPageName) -- Expensive end
local root = HtmlBuilder.create()
local startBox = root:tag('div') startBox:cssText('clear: both; margin: 1em 0 0 0; border: 1px solid #aaa; background-color: #ecfcf4; padding: 12px')
-- Add heading if non-empty if headingParam ~= then local heading = startBox:tag('span') heading:cssText('font-weight: bold; font-size: 125%') if headingParam then heading:wikitext(headingParam) else heading:wikitext(' Documentation') end
-- Add action links if doc is not on template page if not contentParam then local actions = startBox:tag('span') actions:addClass('plainlinks') actions:cssText('font-size: small; font-weight: 400; margin-left: 1em; vertical-align: baseline; line-height: 1em; display: inline-block')
local function escapeBrackets(s) -- Replace brackets with HTML entities s = s:gsub('%[', '[') s = s:gsub('%]', ']') return s end
if docPageTitle.exists then format = '[%s] [%s] [%s] [%s]' local viewLink = 'view' local editLink = '[' .. docPageTitle:fullUrl{action = 'edit'} .. ' edit]' local historyLink = '[' .. docPageTitle:fullUrl{action = 'history'} .. ' history]' local purgeLink = '[' .. docPageTitle:fullUrl{action = 'purge'} .. ' purge]' actions:wikitext(mw.ustring.format(escapeBrackets('[%s] [%s] [%s] [%s]'), viewLink, editLink, historyLink, purgeLink)) else local createLink = '[' .. docPageTitle:fullUrl{action = 'edit'} .. ' create]' actions:wikitext(mw.ustring.format(escapeBrackets('[%s]'), createLink)) end end end
-- Transclude doc contents if contentParam then startBox:wikitext(contentParam) elseif docPageTitle.exists then startBox:wikitext(frame:expandTemplate{title = ':' .. docPageName}) end
-- Prevent floating items from sticking out of doc box local clear = startBox:tag('div') clear:css('clear', 'both')
if not contentParam and linkBoxParam ~= 'off' and docPageTitle.exists then local endBox = root:tag('div') endBox:addClass('plainlinks') endBox:cssText('clear: both; width: 100%; border: 1px solid #aaa; margin: .2em 0; background-color: #ecfcf4')
local endBoxNode = endBox:tag('div') endBoxNode:cssText('border: none; width: 100%; padding: .25em .9em; font-style: italic') if linkBoxParam then endBoxNode:wikitext(linkBoxParam) else endBoxNode:wikitext('The above documentation is transcluded from ', docPageName, '.') endBoxNode:tag('small') endBoxNode:cssText('font-style: normal')
local editUrl = docPageTitle:fullUrl{action = 'edit'} local historyUrl = docPageTitle:fullUrl{action = 'history'} endBoxNode:wikitext('([', editUrl, ' edit] | [', historyUrl, ' history])') end end
return tostring(root)
end
p.main = makeInvokeFunc(p._main, {passFrameParam = true, inherited = true})
return p