Jump to content

Module:Documentation: Difference between revisions

add a templateTitle object to the env functions, and reformat the experimentBlurb function to make it fit on the page
m>Mr. Stradivarius
(allow for nil values of makeDocPageBlurb)
m>Mr. Stradivarius
(add a templateTitle object to the env functions, and reformat the experimentBlurb function to make it fit on the page)
Line 203: Line 203:
return mw.site.namespaces[env.title.namespace].subject.id
return mw.site.namespaces[env.title.namespace].subject.id
end
end
 
function envFuncs.docspace()
function envFuncs.docspace()
-- The name of the documentation namespace.
-- The name of the documentation namespace.
Line 215: Line 215:
end
end
end
end
 
function envFuncs.templatePage()
function envFuncs.templatePage()
-- The template page with no namespace or interwiki prefixes.
-- The template page with no namespace or interwiki prefixes.
Line 225: Line 225:
return title.text
return title.text
end
end
end
function envFuncs.templateTitle()
-- The template (or module, etc.) title object.
local title = env.title
local subpage = title.subpageText
local ret
if subpage == message('sandboxSubpage', 'string') or subpage == message('testcasesSubpage', 'string') then
ret = title.basePageTitle
else
ret = title
end
if not ret then
error(message('titleArgError', 'string', {titleArg}))
end
return ret
end
end


Line 633: Line 649:
local templatePage = env.templatePage
local templatePage = env.templatePage
-- Get title objects.
-- Get title objects.
local templateSuccess, templateTitle = env:grab('templateTitle')
if not templateSuccess then
return err(templateTitle)
end
local sandboxSuccess, sandboxTitle = env:grab('sandboxTitle')
local sandboxSuccess, sandboxTitle = env:grab('sandboxTitle')
if not sandboxSuccess then
if not sandboxSuccess then
Line 644: Line 664:
local sandboxLinks, testcasesLinks
local sandboxLinks, testcasesLinks
if sandboxTitle.exists then
if sandboxTitle.exists then
local sandboxLink = makeWikilink(sandboxTitle.prefixedText, message('sandboxLinkDisplay', 'string'))
local sandboxPage = sandboxTitle.prefixedText
local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, message('sandboxEditLinkDisplay', 'string'))
local sandboxDisplay = message('sandboxLinkDisplay', 'string')
local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, message('compareLinkDisplay', 'string'))
local sandboxLink = makeWikilink(sandboxPage, sandboxDisplay)
local sandboxEditUrl = sandboxTitle:fullUrl{action = 'edit'}
local sandboxEditDisplay = message('sandboxEditLinkDisplay', 'string')
local sandboxEditLink = makeUrlLink(sandboxEditUrl, sandboxEditDisplay)
local compareUrl = mw.uri.fullUrl('Special:ComparePages', {page1 = templateTitle.prefixedText, page2 = sandboxPage})
compareUrl = tostring(compareUrl)
local compareDisplay = message('compareLinkDisplay', 'string')
local compareLink = makeUrlLink(compareUrl, compareDisplay)
sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink)
sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink)
else
else
local sandboxPreload = subjectSpace == 828 and message('moduleSandboxPreload', 'string') or message('templateSandboxPreload', 'string')
local sandboxPreload
local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, message('sandboxCreateLinkDisplay', 'string'))
if subjectSpace == 828 then
sandboxPreload = message('moduleSandboxPreload', 'string')
else
sandboxPreload = message('templateSandboxPreload', 'string')
end
local sandboxCreateUrl = sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}
local sandboxCreateDisplay = message('sandboxCreateLinkDisplay', 'string')
local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay)
local mirrorSummary = message('mirrorEditSummary', 'string', {makeWikilink(templatePage)})
local mirrorSummary = message('mirrorEditSummary', 'string', {makeWikilink(templatePage)})
local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, message('mirrorLinkDisplay', 'string'))
local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}
local mirrorDisplay = message('mirrorLinkDisplay', 'string')
local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay)
sandboxLinks = message('sandboxLinkDisplay', 'string') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
sandboxLinks = message('sandboxLinkDisplay', 'string') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
end
end
if testcasesTitle.exists then
if testcasesTitle.exists then
local testcasesLink = makeWikilink(testcasesTitle.prefixedText, message('testcasesLinkDisplay', 'string'))
local testcasesPage = testcasesTitle.prefixedText
local testcasesEditLink = makeUrlLink(testcasesTitle:fullUrl{action = 'edit'}, message('testcasesEditLinkDisplay', 'string'))
local testcasesDisplay = message('testcasesLinkDisplay', 'string')
local testcasesLink = makeWikilink(testcasesPage, testcasesDisplay)
local testcasesEditUrl = testcasesTitle:fullUrl{action = 'edit'}
local testcasesEditDisplay = message('testcasesEditLinkDisplay', 'string')
local testcasesEditLink = makeUrlLink(testcasesEditUrl, testcasesEditDisplay)
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
else
else
local testcasesPreload = subjectSpace == 828 and message('moduleTestcasesPreload', 'string') or message('templateTestcasesPreload', 'string')
local testcasesPreload
local testcasesCreateLink = makeUrlLink(testcasesTitle:fullUrl{action = 'edit', preload = testcasesPreload}, message('testcasesCreateLinkDisplay', 'string'))
if subjectSpace == 828 then
testcasesPreload = message('moduleTestcasesPreload', 'string')
else
testcasesPreload = message('templateTestcasesPreload', 'string')
end
local testcasesCreateUrl = testcasesTitle:fullUrl{action = 'edit', preload = testcasesPreload}
local testcasesCreateDisplay = message('testcasesCreateLinkDisplay', 'string')
local testcasesCreateLink = makeUrlLink(testcasesCreateUrl, testcasesCreateDisplay)
testcasesLinks = message('testcasesLinkDisplay', 'string') .. ' ' .. makeToolbar(testcasesCreateLink)
testcasesLinks = message('testcasesLinkDisplay', 'string') .. ' ' .. makeToolbar(testcasesCreateLink)
end
end
return message(subjectSpace == 828 and 'experimentBlurbModule' or 'experimentBlurbTemplate', 'string', {sandboxLinks, testcasesLinks})
local messageName
if subjectSpace == 828 then
messageName = 'experimentBlurbModule'
else
messageName = 'experimentBlurbTemplate'
end
return message(messageName, 'string', {sandboxLinks, testcasesLinks})
end
end


Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.