Module:Documentation: Difference between revisions

finish converting existing values to use env table
m>Mr. Stradivarius
(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)
m>Mr. Stradivarius
(finish converting existing values to use env table)
Line 243: Line 243:


function p._startBox(args, env)
function p._startBox(args, env)
local title = env.title
-- Arg processing from {{documentation}}.
-- Arg processing from {{documentation}}.
local preload = args[message('preloadArg', 'string')] -- Allow custom preloads.
local preload = args[message('preloadArg', 'string')] -- Allow custom preloads.
Line 257: Line 259:
docpage = docname
docpage = docname
else
else
local namespace = docspace or currentTitle.nsText
local namespace = docspace or title.nsText
local pagename = templatePage or currentTitle.text
local pagename = templatePage or title.text
docpage = namespace .. ':' .. pagename .. '/' .. message('docSubpage', 'string')
docpage = namespace .. ':' .. pagename .. '/' .. message('docSubpage', 'string')
end
end
Line 317: Line 319:
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, message('editLinkDisplay', 'string'))
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, message('editLinkDisplay', 'string'))
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, message('historyLinkDisplay', 'string'))
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, message('historyLinkDisplay', 'string'))
local purgeLink = makeUrlLink(currentTitle:fullUrl{action = 'purge'}, message('purgeLinkDisplay', 'string'))
local purgeLink = makeUrlLink(title:fullUrl{action = 'purge'}, message('purgeLinkDisplay', 'string'))
local text = '[%s] [%s] [%s] [%s]'
local text = '[%s] [%s] [%s] [%s]'
text = text:gsub('%[', '[') -- Replace square brackets with HTML entities.
text = text:gsub('%[', '[') -- Replace square brackets with HTML entities.
Line 343: Line 345:
p.content = makeInvokeFunc('_content')
p.content = makeInvokeFunc('_content')


function p._content(args)
function p._content(args, env)
local content = args[message('contentArg', 'string')]
local content = args[message('contentArg', 'string')]
if not content then
if not content then
Line 351: Line 353:
content = frame:preprocess('{{ ' .. docpage .. ' }}')
content = frame:preprocess('{{ ' .. docpage .. ' }}')
else
else
docpage = p.docspace() .. ':' .. p.templatePage() .. '/' .. message('docSubpage', 'string')
docpage = env.docspace .. ':' .. env.templatePage .. '/' .. message('docSubpage', 'string')
if mw.title.new(docpage).exists then
if mw.title.new(docpage).exists then
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
Line 369: Line 371:
p.endBox = makeInvokeFunc('_endBox')
p.endBox = makeInvokeFunc('_endBox')


function p._endBox(args)
function p._endBox(args, env)
local title = env.title
local subjectSpace = env.subjectSpace
 
-- Argument processing in {{documentation}}.
-- Argument processing in {{documentation}}.
local content = args[message('contentArg', 'string')]
local content = args[message('contentArg', 'string')]
local linkBox = args[message('linkBoxArg', 'string')] -- So "link box=off" works.
local linkBox = args[message('linkBoxArg', 'string')] -- So "link box=off" works.
local docspace = p.docspace()
local docspace = env.docspace
local docname = args[1] -- Other docname, if fed.
local docname = args[1] -- Other docname, if fed.
local templatePage = p.templatePage()
local templatePage = env.templatePage


-- Argument processing in {{documentation/end box2}}.
-- Argument processing in {{documentation/end box2}}.
local docpageRoot = (docspace or currentTitle.nsText) .. ':' .. (templatePage or currentTitle.text)
local docpageRoot = (docspace or title.nsText) .. ':' .. (templatePage or title.text)
local docpage
local docpage
if docname then
if docname then
Line 390: Line 395:
local sandbox = docpageRoot .. '/' .. message('sandboxSubpage', 'string')
local sandbox = docpageRoot .. '/' .. message('sandboxSubpage', 'string')
local testcases = docpageRoot .. '/' .. message('testcasesSubpage', 'string')
local testcases = docpageRoot .. '/' .. message('testcasesSubpage', 'string')
templatePage = currentTitle.nsText .. ':' .. templatePage
templatePage = title.nsText .. ':' .. templatePage


-- Output from {{documentation/end box}}
-- Output from {{documentation/end box}}
Line 490: Line 495:
----------------------------------------------------------------------------
----------------------------------------------------------------------------


function p.addTrackingCategories()
function p.addTrackingCategories(env)
-- Check if {{documentation}} is transcluded on a /doc or /testcases page.
-- Check if {{documentation}} is transcluded on a /doc or /testcases page.
local title = env.title
local ret = ''
local ret = ''
local subpage = currentTitle.subpageText
local subpage = title.subpageText
if message('displayStrangeUsageCategory', 'boolean') and (subpage == message('docSubpage', 'string') or subpage == message('testcasesSubpage', 'string')) then
if message('displayStrangeUsageCategory', 'boolean') and (subpage == message('docSubpage', 'string') or subpage == message('testcasesSubpage', 'string')) then
local sort = (currentTitle.namespace == 0 and message('strangeUsageCategoryMainspaceSort', 'string') or '') .. currentTitle.prefixedText -- Sort on namespace.
local sort = (title.namespace == 0 and message('strangeUsageCategoryMainspaceSort', 'string') or '') .. title.prefixedText -- Sort on namespace.
ret = ret .. makeCategoryLink(message('strangeUsageCategory', 'string'), sort)
ret = ret .. makeCategoryLink(message('strangeUsageCategory', 'string'), sort)
end
end
Anonymous user