Changes

Jump to: navigation, search

Module:Documentation

1,412 bytes added, 07:47, 1 January 2014
create a formatMessage function for formatting cfg messages in an arbitrary order
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.
-- 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.
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.transcludedFrom = 'The above [[Wikipedia:Template documentation|documentation]] is [[Wikipedia:Transclusion|transcluded]] from $1.' -- Notice displayed when the docs are transcluded from another page. $1 is a wikilink to that page.
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.
local htmlBuilder = require('Module:HtmlBuilder')
local messageBox = require('Module:Message box')
local libraryUtil = require('libraryUtil')
local p = {}
-- Constants.
local currentTitle = mw.title.getCurrentTitle()
local subjectSpace = mw.site.namespaces[currentTitle.namespace].subject.id-- The number of the current subject namespace. -- Often-used functionslocal gsub = mw.ustring.gsublocal 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)
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 ' .formatMessage(cfg. transcludedFrom, {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 = 'Template:Documentation/preload-module-doc'cfg.modulePreload}, cfg.createLinkDisplay) text = text .. 'You might want to ' .formatMessage(cfg. createModuleDoc, {createLink }) .. ' a documentation page for this [[Wikipedia:Lua|Scribunto module]].<br />'
end
-- Add links to /sandbox and /testcases when appropriate.
Anonymous user

Navigation menu