Changes

Jump to: navigation, search

Module:Documentation

156 bytes added, 11:34, 1 January 2014
use the cfg key only with formatMessage in order to generate more descriptive error messages
----------------------------------------------------------------------------
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.
-- So formatMessage(For example, if the message cfg.fooMessage had the value 'Foo $2 bar $1.', -- formatMessage('fooMessage', {'baz', 'qux'}) will 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: No no value found for key $' .. match .. 'in message cfg. Message was "' .. msg .. '"'cfgKey, 42)
end
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.
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)
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.
pagetype = cfg.defaultPagetype
end
text = text .. ' ' .. makeWikilink('Special:PrefixIndex/' .. templatePage .. '/', formatMessage(cfg.'subpagesLinkDisplay', {pagetype}))
end
-- Show the "print" link if it exists.
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

Navigation menu