Module:Documentation: Difference between revisions
Content deleted Content added
m fix the docpage thing again |
split out docpage blurb code |
||
Line 184:
})
-- Get the title.▼
function envFuncs.title()
-- The title object for the current page, or a test page passed with args.page.
local title
local titleArg = args[message('titleArg', 'string')]
Line 199:
end
-- Get the subject namespace number.▼
function envFuncs.subjectSpace()
return mw.site.namespaces[env.title.namespace].subject.id
end
-- Get the name of the documentation namespace.▼
function envFuncs.docspace()
local subjectSpace = env.subjectSpace
if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then
Line 216:
end
-- Get the template page with no namespace or interwiki prefixes.▼
function envFuncs.templatePage()
local title = env.title
local subpage = title.subpageText
Line 228:
function envFuncs.docTitle()
-- Title object of the /doc subpage.
local title = env.title
local docname = args[1] -- User-specified doc page.
Line 240 ⟶ 241:
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
return (env.docspace or title.nsText) .. ':' .. (env.templatePage or title.text)
Line 245 ⟶ 248:
function envFuncs.sandboxTitle()
-- Title object for the /sandbox subpage.
local titleArg = env.docpageRoot .. '/' .. message('sandboxSubpage', 'string')
local title = mw.title.new(titleArg)
Line 254 ⟶ 258:
function envFuncs.testcasesTitle()
-- Title object for the /testcases subpage.
local titleArg = env.docpageRoot .. '/' .. message('testcasesSubpage', 'string')
local title = mw.title.new(titleArg)
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)
if not title then
Line 541 ⟶ 556:
text = text .. linkBox
else
text = text .. p.makeDocPageBlurb(args, env)
▲ if docExist then
-- /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.▼
text = text .. message('createModuleDocBlurb', 'string', {createLink}) .. '<br />'▼
▲ end
-- Add links to /sandbox and /testcases when appropriate.
if subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 then
Line 588 ⟶ 593:
-- Return the fmbox output.
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
local editUrl = docTitle:fullUrl{action = 'edit'}
local editDisplay = message('editLinkDisplay', 'string')
local editLink = makeUrlLink(editUrl, editDisplay)
local historyUrl = docTitle:fullUrl{action = 'history'}
▲
local historyLink = makeUrlLink(historyUrl, historyDisplay)
▲
.. ' '
.. makeToolbar(editLink, historyLink)
.. '<br />'
▲
local createDisplay = message('createLinkDisplay', 'string')
local createLink = makeUrlLink(createUrl, createDisplay)
.. '<br />'
end
return ret
end
|