Module:Documentation: Difference between revisions

Jump to navigation Jump to search
use the cfg key only with formatMessage in order to generate more descriptive error messages
(make the formatMessage error message more informative, at the risk of including long cfg messages in the error message)
(use the cfg key only with formatMessage in order to generate more descriptive error messages)
Line 24:
----------------------------------------------------------------------------
 
local function formatMessage(msgcfgKey, valArray)
--[[
-- Formats a message, usually from the cfg table.
-- Values from valArray can be specified in the message by using $1 for [1], $2 for [2], etc.
-- SoFor formatMessage('Fooexample, $2if barthe $1message cfg.',fooMessage {'baz',had 'qux'})the willvalue return "'Foo qux$2 bar baz$1."',
-- formatMessage('fooMessage', {'baz', 'qux'}) would return "Foo qux bar baz."
--]]
checkType('formatMessage', 1, msgcfgKey, 'string')
checkType('formatMessage', 2, valArray, 'table')
local msg = cfg[cfgKey] or error('formatMessage: no message found for cfg key "' .. cfgKey .. '"', 2)
 
local function getMessageVal(match)
match = tonumber(match)
return valArray[match] or error('formatMessage: Nono value found for key $' .. match .. '. Messagein wasmessage "cfg.' .. msg .. '"'cfgKey, 42)
end
 
Line 330 ⟶ 332:
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, cfg.editLinkDisplay)
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, cfg.historyLinkDisplay)
text = text .. formatMessage(cfg.'transcludedFromBlurb', {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 = cfg.modulePreload}, cfg.createLinkDisplay)
text = text .. formatMessage(cfg.'createModuleDocBlurb', {createLink}) .. '<br />'
end
-- Add links to /sandbox and /testcases when appropriate.
Line 350 ⟶ 352:
local sandboxPreload = subjectSpace == 828 and cfg.moduleSandboxPreload or cfg.templateSandboxPreload
local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, cfg.sandboxCreateLinkDisplay)
local mirrorSummary = formatMessage(cfg.'mirrorEditSummary', {makeWikilink(templatePage)})
local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, cfg.mirrorLinkDisplay)
sandboxLinks = cfg.sandboxLinkDisplay .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
Line 364 ⟶ 366:
testcasesLinks = cfg.testcasesLinkDisplay .. ' ' .. makeToolbar(testcasesCreateLink)
end
text = text .. formatMessage(cfg.'experimentBlurb', {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
local docPathLink = makeWikilink(docpage, cfg.docLinkDisplay)
text = text .. formatMessage(cfg.'addCategoriesBlurb', {docPathLink})
end
-- Show the "subpages" link.
Line 380 ⟶ 382:
pagetype = cfg.defaultPagetype
end
text = text .. ' ' .. makeWikilink('Special:PrefixIndex/' .. templatePage .. '/', formatMessage(cfg.'subpagesLinkDisplay', {pagetype}))
end
-- Show the "print" link if it exists.
Line 387 ⟶ 389:
if printTitle.exists then
local printLink = makeWikilink(printPage, cfg.printLinkDisplay)
text = text .. '<br />' .. formatMessage(cfg.'printBlurb', {printLink})
.. (cfg.displayPrintCategory and makeCategoryLink(cfg.printCategory) or '')
end
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu