Module:Documentation: Difference between revisions
Content deleted Content added
fix purge link destination |
create a formatMessage function for formatting cfg messages in an arbitrary order |
||
Line 44:
cfg.fileDocpagePreload = 'Template:Documentation/preload-filespace' -- A preload file for documentation page in the file namespace.
cfg.docpagePreload = 'Template:Documentation/preload-filespace' -- A preload file for template documentation pages in all namespaces.
cfg.modulePreload = 'Template:Documentation/preload-module-doc' -- A preload file for Lua module documentation pages.
-- Settings for the {{fmbox}} template.
Line 59 ⟶ 60:
-- The following settings configure the values displayed by the module.
-- Text displayed in wikilinks.
cfg.viewLinkDisplay = 'view' -- The text to display for "view" links.
cfg.editLinkDisplay = 'edit' -- The text to display for "edit" links.
Line 72 ⟶ 74:
cfg.testcasesEditLinkDisplay = 'edit' -- The text to display for test cases "edit" links.
cfg.testcasesCreateLinkDisplay = 'create' -- The text to display for test cases "create" links.
-- Sentences used in the end box.
cfg.createModuleDoc = 'You might want to $1 a documentation page for this [[Wikipedia:Lua|Scribunto module]].' -- Notice displayed in the module namespace when the documentation subpage does not exist. $1 is a link to create the documentation page with the preload cfg.modulePreload and the display cfg.createLinkDisplay.
-- Other display settings
cfg.documentationIconWikitext = '[[File:Template-info.png|50px|link=|alt=Documentation icon]]' -- The wikitext for the icon shown at the top of the template.
cfg.templateNamespaceHeading = 'Template documentation' -- The heading shown in the template namespace.
Line 86 ⟶ 94:
local htmlBuilder = require('Module:HtmlBuilder')
local messageBox = require('Module:Message box')
local libraryUtil = require('libraryUtil')
local p = {}
Line 91 ⟶ 100:
-- Constants.
local currentTitle = mw.title.getCurrentTitle()
local subjectSpace = mw.site.namespaces[currentTitle.namespace].subject.id -- The number of the current subject namespace.
-- Often-used functions
local gsub = mw.ustring.gsub
local checkType = libraryUtil.checkType
----------------------------------------------------------------------------
-- Helper functions
----------------------------------------------------------------------------
local function formatMessage(msg, 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('Foo $2 bar $1.', {'baz', 'qux'}) will return "Foo qux bar baz."
--]]
checkType('formatMessage', 1, msg, 'string')
checkType('formatMessage', 2, valArray, 'table')
local function getMessageVal(match)
match = tonumber(match)
return valArray[match] or error('formatMessage: No value found for key $' .. match, 2)
end
local ret = gsub(msg, '$([1-9][0-9]*)', getMessageVal)
return ret
end
local function makeWikilink(page, display)
Line 380 ⟶ 411:
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, cfg.editLinkDisplay)
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, cfg.historyLinkDisplay)
▲ text = text .. 'The above [[Wikipedia:Template documentation|documentation]] is [[Wikipedia:Transclusion|transcluded]] from '
▲ .. 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 =
text = text ..
end
-- Add links to /sandbox and /testcases when appropriate.
|