Module:Documentation: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
m (fix the docpage thing again) |
(split out docpage blurb code) |
||
Line 184: | Line 184: | ||
}) |
}) |
||
⚫ | |||
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 |
||
⚫ | |||
function envFuncs.subjectSpace() |
function envFuncs.subjectSpace() |
||
⚫ | |||
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() |
||
⚫ | |||
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 |
||
⚫ | |||
function envFuncs.templatePage() |
function envFuncs.templatePage() |
||
⚫ | |||
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) |
|||
⚫ | |||
error(message('titleArgError', 'string', {titleArg})) |
|||
⚫ | |||
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 |
||
text = text .. p.makeDocPageBlurb(args, env) |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = message('modulePreload', 'string')}, message('createLinkDisplay', 'string')) |
|||
⚫ | |||
⚫ | |||
-- 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) |
|||
⚫ | |||
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 |
end |
||