Module:Documentation: Difference between revisions

split out experiment blurb code
(use docTitle.prefixedText instead of docpage)
(split out experiment blurb code)
Line 229:
function envFuncs.docTitle()
local title = env.title
local docname = args[1] -- OtherUser-specified docname,doc if fedpage.
local docspace = env.docspace
local templatePage = env.templatePage
local docpage
if docname then
docpage = docname
else
docpage = namespace env.. ':' .. pagenamedocpageRoot .. '/' .. message('docSubpage', 'string')
local namespace = docspace or title.nsText
local pagename = templatePage or title.text
docpage = namespace .. ':' .. pagename .. '/' .. message('docSubpage', 'string')
end
return mw.title.new(docpage)
end
 
function envFuncs.docpageRoot()
local docspacetitle = env.docspacetitle
return (env.docspace or title.nsText) .. ':' .. (env.templatePage or title.text)
end
function envFuncs.sandboxTitle()
local titleArg = env.docpageRoot .. '/' .. message('sandboxSubpage', 'string')
local sandboxTitletitle = mw.title.new(sandboxtitleArg)
if not title then
error(message('titleArgError', 'string', {titleArg}))
end
return title
end
function envFuncs.testcasesTitle()
local titleArg = env.docpageRoot .. '/' .. message('testcasesSubpage', 'string')
local testcaseTitletitle = mw.title.new(testcasestitleArg)
if not title then
error(message('titleArgError', 'string', {titleArg}))
end
return title
end
function env:grab(key)
local success, val = pcall(function() return self[key] end)
Line 363 ⟶ 382:
local title = data.title
if docTitle.exists then
local viewLink = makeWikilink(docTitle.prefixedTextdocpage, data.viewLinkDisplay)
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, data.editLinkDisplay)
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, data.historyLinkDisplay)
Line 536 ⟶ 555:
if subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 then
-- We are in the user, module or template namespaces.
text = text .. p.makeEndBoxExperimentBlurb(args, env)
local sandboxLinks, testcasesLinks
text = text .. '<br />'
local pagePossessive = subjectSpace == 828 and message('modulePossessive', 'string') or message('templatePossessive', 'string')
local sandboxTitle = mw.title.new(sandbox)
if sandboxTitle.exists then
local sandboxLink = makeWikilink(sandbox, message('sandboxLinkDisplay', 'string'))
local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, message('sandboxEditLinkDisplay', 'string'))
local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, message('compareLinkDisplay', 'string'))
sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink)
else
local sandboxPreload = subjectSpace == 828 and message('moduleSandboxPreload', 'string') or message('templateSandboxPreload', 'string')
local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, message('sandboxCreateLinkDisplay', 'string'))
local mirrorSummary = message('mirrorEditSummary', 'string', {makeWikilink(templatePage)})
local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, message('mirrorLinkDisplay', 'string'))
sandboxLinks = message('sandboxLinkDisplay', 'string') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
end
local testcaseTitle = mw.title.new(testcases)
if testcaseTitle.exists then
local testcasesLink = makeWikilink(testcases, message('testcasesLinkDisplay', 'string'))
local testcasesEditLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit'}, message('testcasesEditLinkDisplay', 'string'))
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
else
local testcasesPreload = subjectSpace == 828 and message('moduleTestcasesPreload', 'string') or message('templateTestcasesPreload', 'string')
local testcasesCreateLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit', preload = testcasesPreload}, message('testcasesCreateLinkDisplay', 'string'))
testcasesLinks = message('testcasesLinkDisplay', 'string') .. ' ' .. makeToolbar(testcasesCreateLink)
end
text = text .. message('experimentBlurb', 'string', {pagePossessive, sandboxLinks, testcasesLinks}) .. '<br />'
-- Show the categories text, but not if "content" fed or "docname fed" since then it is unclear where to add the categories.
if not content and not docnameFed then
Line 593 ⟶ 588:
-- Return the fmbox output.
return messageBox.main('fmbox', fmargs)
end
 
function p.makeEndBoxExperimentBlurb(args, env)
-- Renders the text "Editors can experiment in this template's sandbox (edit | diff) and testcases (edit) pages."
local subjectSpace = env.subjectSpace
local templatePage = env.templatePage
-- Get title objects.
local sandboxSuccess, sandboxTitle = env:grab('sandboxTitle')
if not sandboxSuccess then
return err(sandboxTitle)
end
local testcasesSuccess, testcasesTitle = env:grab('testcasesTitle')
if not testcasesSuccess then
return err(testcasesTitle)
end
-- Make links.
local sandboxLinks, testcasesLinks
if sandboxTitle.exists then
local sandboxLink = makeWikilink(sandboxsandboxTitle.prefixedText, message('sandboxLinkDisplay', 'string'))
local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, message('sandboxEditLinkDisplay', 'string'))
local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, message('compareLinkDisplay', 'string'))
sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink)
else
local pagePossessivesandboxPreload = subjectSpace == 828 and message('modulePossessivemoduleSandboxPreload', 'string') or message('templatePossessivetemplateSandboxPreload', 'string')
local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, message('sandboxCreateLinkDisplay', 'string'))
local mirrorSummary = message('mirrorEditSummary', 'string', {makeWikilink(templatePage)})
local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, message('mirrorLinkDisplay', 'string'))
sandboxLinks = message('sandboxLinkDisplay', 'string') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
end
if testcaseTitletestcasesTitle.exists then
local testcasesLink = makeWikilink(testcasestestcasesTitle.prefixedText, message('testcasesLinkDisplay', 'string'))
local testcasesEditLink = makeUrlLink(testcaseTitletestcasesTitle:fullUrl{action = 'edit'}, message('testcasesEditLinkDisplay', 'string'))
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
else
local sandboxPreloadtestcasesPreload = subjectSpace == 828 and message('moduleSandboxPreloadmoduleTestcasesPreload', 'string') or message('templateSandboxPreloadtemplateTestcasesPreload', 'string')
local testcasesCreateLink = makeUrlLink(testcaseTitletestcasesTitle:fullUrl{action = 'edit', preload = testcasesPreload}, message('testcasesCreateLinkDisplay', 'string'))
testcasesLinks = message('testcasesLinkDisplay', 'string') .. ' ' .. makeToolbar(testcasesCreateLink)
end
return message(subjectSpace == 828 and 'experimentBlurbModule' or 'experimentBlurbTemplate', 'string', {sandboxLinks, testcasesLinks})
end