Module:Documentation: Difference between revisions

finish converting existing values to use env table
(start conversion to a p.getEnv function rather than using globals; I've only got as far as the start box, so the module currently won't run)
(finish converting existing values to use env table)
Line 243:
 
function p._startBox(args, env)
local title = env.title
 
-- Arg processing from {{documentation}}.
local preload = args[message('preloadArg', 'string')] -- Allow custom preloads.
Line 257 ⟶ 259:
docpage = docname
else
local namespace = docspace or currentTitletitle.nsText
local pagename = templatePage or currentTitletitle.text
docpage = namespace .. ':' .. pagename .. '/' .. message('docSubpage', 'string')
end
Line 317 ⟶ 319:
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, message('editLinkDisplay', 'string'))
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, message('historyLinkDisplay', 'string'))
local purgeLink = makeUrlLink(currentTitletitle:fullUrl{action = 'purge'}, message('purgeLinkDisplay', 'string'))
local text = '[%s] [%s] [%s] [%s]'
text = text:gsub('%[', '[') -- Replace square brackets with HTML entities.
Line 343 ⟶ 345:
p.content = makeInvokeFunc('_content')
 
function p._content(args, env)
local content = args[message('contentArg', 'string')]
if not content then
Line 351 ⟶ 353:
content = frame:preprocess('{{ ' .. docpage .. ' }}')
else
docpage = penv.docspace() .. ':' .. penv.templatePage() .. '/' .. message('docSubpage', 'string')
if mw.title.new(docpage).exists then
local frame = mw.getCurrentFrame()
Line 369 ⟶ 371:
p.endBox = makeInvokeFunc('_endBox')
 
function p._endBox(args, env)
local title = env.title
local subjectSpace = env.subjectSpace
 
-- Argument processing in {{documentation}}.
local content = args[message('contentArg', 'string')]
local linkBox = args[message('linkBoxArg', 'string')] -- So "link box=off" works.
local docspace = penv.docspace()
local docname = args[1] -- Other docname, if fed.
local templatePage = penv.templatePage()
 
-- Argument processing in {{documentation/end box2}}.
local docpageRoot = (docspace or currentTitletitle.nsText) .. ':' .. (templatePage or currentTitletitle.text)
local docpage
if docname then
Line 390 ⟶ 395:
local sandbox = docpageRoot .. '/' .. message('sandboxSubpage', 'string')
local testcases = docpageRoot .. '/' .. message('testcasesSubpage', 'string')
templatePage = currentTitletitle.nsText .. ':' .. templatePage
 
-- Output from {{documentation/end box}}
Line 490 ⟶ 495:
----------------------------------------------------------------------------
 
function p.addTrackingCategories(env)
-- Check if {{documentation}} is transcluded on a /doc or /testcases page.
local title = env.title
local ret = ''
local subpage = currentTitletitle.subpageText
if message('displayStrangeUsageCategory', 'boolean') and (subpage == message('docSubpage', 'string') or subpage == message('testcasesSubpage', 'string')) then
local sort = (currentTitletitle.namespace == 0 and message('strangeUsageCategoryMainspaceSort', 'string') or '') .. currentTitletitle.prefixedText -- Sort on namespace.
ret = ret .. makeCategoryLink(message('strangeUsageCategory', 'string'), sort)
end