Jump to content

Module:Documentation: Difference between revisions

split out docpage blurb code
m>Mr. Stradivarius
m (fix the docpage thing again)
m>Mr. Stradivarius
(split out docpage blurb code)
Line 184: Line 184:
})
})


-- Get the title.
function envFuncs.title()
function envFuncs.title()
-- The title object for the current page, or a test page passed with args.page.
local title
local title
local titleArg = args[message('titleArg', 'string')]
local titleArg = args[message('titleArg', 'string')]
Line 199: Line 199:
end
end


-- Get the subject namespace number.
function envFuncs.subjectSpace()
function envFuncs.subjectSpace()
-- The subject namespace number.
return mw.site.namespaces[env.title.namespace].subject.id
return mw.site.namespaces[env.title.namespace].subject.id
end
end
-- Get the name of the documentation namespace.
function envFuncs.docspace()
function envFuncs.docspace()
-- The name of the documentation namespace.
local subjectSpace = env.subjectSpace
local subjectSpace = env.subjectSpace
if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then
if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then
Line 216: Line 216:
end
end
-- Get the template page with no namespace or interwiki prefixes.
function envFuncs.templatePage()
function envFuncs.templatePage()
-- The template page with no namespace or interwiki prefixes.
local title = env.title
local title = env.title
local subpage = title.subpageText
local subpage = title.subpageText
Line 228: Line 228:


function envFuncs.docTitle()
function envFuncs.docTitle()
-- Title object of the /doc subpage.
local title = env.title
local title = env.title
local docname = args[1] -- User-specified doc page.
local docname = args[1] -- User-specified doc page.
Line 240: Line 241:
function envFuncs.docpageRoot()
function envFuncs.docpageRoot()
-- The base page of the /doc, /sandbox, and /testcases subpages.
-- For some namespaces this is the talk page, rather than the template page.
local title = env.title
local title = env.title
return (env.docspace or title.nsText) .. ':' .. (env.templatePage or title.text)
return (env.docspace or title.nsText) .. ':' .. (env.templatePage or title.text)
Line 245: Line 248:
function envFuncs.sandboxTitle()
function envFuncs.sandboxTitle()
-- Title object for the /sandbox subpage.
local titleArg = env.docpageRoot .. '/' .. message('sandboxSubpage', 'string')
local titleArg = env.docpageRoot .. '/' .. message('sandboxSubpage', 'string')
local title = mw.title.new(titleArg)
local title = mw.title.new(titleArg)
Line 254: Line 258:
function envFuncs.testcasesTitle()
function envFuncs.testcasesTitle()
-- Title object for the /testcases subpage.
local titleArg = env.docpageRoot .. '/' .. message('testcasesSubpage', 'string')
local titleArg = env.docpageRoot .. '/' .. message('testcasesSubpage', 'string')
local title = mw.title.new(titleArg)
if not title then
error(message('titleArgError', 'string', {titleArg}))
end
return title
end
function envFuncs.printTitle()
-- Title object for the /Print subpage.
local titleArg = env.templatePage .. '/' .. message('printSubpage', 'string')
local title = mw.title.new(titleArg)
local title = mw.title.new(titleArg)
if not title then
if not title then
Line 541: Line 556:
text = text .. linkBox
text = text .. linkBox
else
else
if docExist then
text = text .. p.makeDocPageBlurb(args, env)
-- /doc exists; link to it.
local docLink = makeWikilink(docpage)
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, message('editLinkDisplay', 'string'))
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, message('historyLinkDisplay', 'string'))
text = text .. message('transcludedFromBlurb', 'string', {docLink}) .. ' ' .. makeToolbar(editLink, historyLink) .. '<br />'
elseif subjectSpace == 828 then
-- /doc does not exist; ask to create it.
local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = message('modulePreload', 'string')}, message('createLinkDisplay', 'string'))
text = text .. message('createModuleDocBlurb', 'string', {createLink}) .. '<br />'
end
-- Add links to /sandbox and /testcases when appropriate.
-- Add links to /sandbox and /testcases when appropriate.
if subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 then
if subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 then
Line 588: Line 593:
-- Return the fmbox output.
-- Return the fmbox output.
return messageBox.main('fmbox', fmargs)
return messageBox.main('fmbox', fmargs)
end
function p.makeDocPageBlurb(args, env)
-- Get the title object.
local success, docTitle = env:grab('docTitle')
if not success then
-- docTitle is the error message.
return docTitle
end
-- Make the blurb.
local ret
if docTitle.exists then
-- /doc exists; link to it.
local docLink = makeWikilink(docTitle.prefixedText)
local editUrl = docTitle:fullUrl{action = 'edit'}
local editDisplay = message('editLinkDisplay', 'string')
local editLink = makeUrlLink(editUrl, editDisplay)
local historyUrl = docTitle:fullUrl{action = 'history'}
local historyDisplay = message('historyLinkDisplay', 'string')
local historyLink = makeUrlLink(historyUrl, historyDisplay)
ret = message('transcludedFromBlurb', 'string', {docLink})
.. ' '
.. makeToolbar(editLink, historyLink)
.. '<br />'
elseif env.subjectSpace == 828 then
-- /doc does not exist; ask to create it.
local createUrl = docTitle:fullUrl{action = 'edit', preload = message('modulePreload', 'string')}
local createDisplay = message('createLinkDisplay', 'string')
local createLink = makeUrlLink(createUrl, createDisplay)
ret = message('createModuleDocBlurb', 'string', {createLink})
.. '<br />'
end
return ret
end
end


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