Module:Documentation: Difference between revisions
m
Protected "Module:Documentation": much used module ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite) [Delete=Allow only administrators] (indefinite) [Protect=Allow only administrators] (indefinite))
(move remaining inline CSS to TemplateStyles) |
m (Protected "Module:Documentation": much used module ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite) [Delete=Allow only administrators] (indefinite) [Protect=Allow only administrators] (indefinite))) |
||
Line 7:
-- Get the config table.
local cfg = mw.loadData('Module:Documentation/config')
local p = {}
Line 33:
expectType = expectType or 'string'
if type(msg) ~= expectType then
error
end
if not valArray then
Line 41:
local function getMessageVal(match)
match = tonumber(match)
return valArray[match] or error
end
Line 82:
ret[#ret + 1] = select(i, ...)
end
return '<small style="font-style: normal;">(' .. table.concat(ret, ' | ') .. ')</small>'
end
Line 112:
----------------------------------------------------------------------------
-- Main function
----------------------------------------------------------------------------
p.main =
function p._main(args)
Line 143 ⟶ 135:
:tag('div')
:attr('id', message('main-div-id'))
:addClass(message('main-div-
:newline()
:wikitext(p._startBox(args, env))
:wikitext(p._content(args, env))
:tag('div')
:css('clear', 'both') -- So right or left floating items don't stick out of the doc box.
:newline()
:done()
:done()
:wikitext(p._endBox(args, env))
Line 337 ⟶ 334:
-- 'sandbox-notice-blurb' --> 'This is the $1 for $2.'
-- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).'
-- 'sandbox-notice-pagetype-template' --> '[[
-- 'sandbox-notice-pagetype-module' --> '[[
-- 'sandbox-notice-pagetype-other' --> 'sandbox page'
-- 'sandbox-notice-compare-link-display' --> 'diff'
Line 358 ⟶ 355:
-- "This is the template sandbox for [[Template:Foo]] (diff)."
local text = ''
local pagetype
if subjectSpace == 10 then
Line 370 ⟶ 365:
local templateLink = makeWikilink(templateTitle.prefixedText)
local compareUrl = env.compareUrl
if
local compareDisplay = message('sandbox-notice-compare-link-display')
local compareLink = makeUrlLink(compareUrl, compareDisplay)
text = text .. message('sandbox-notice-diff-blurb', {pagetype, templateLink, compareLink})
else
text = text .. message('sandbox-notice-blurb', {pagetype, templateLink})
end
-- Get the test cases page blurb if the page exists. This is something like
Line 396 ⟶ 391:
text = text .. makeCategoryLink(message('sandbox-category'))
omargs.text = text
local ret = '<div style="clear: both;"></div>'
return ret
end
Line 406 ⟶ 402:
-- 'protection-template' --> 'pp-template'
-- 'protection-template-args' --> {docusage = 'yes'}
local protectionLevels, mProtectionBanner
local title = env.title
protectionLevels = env.protectionLevels
if not protectionLevels then
return nil
end
local
local
if editProt then
-- The page is
mProtectionBanner = require('Module:Protection banner')
return mProtectionBanner._main{reason, small = true}
elseif moveProt and moveProt ~= 'autoconfirmed' then
-- The page is move-protected but not edit-protected. Exclude move
-- protection with the level "autoconfirmed", as this is equivalent to
-- no move protection at all.
mProtectionBanner = require('Module:Protection banner')
return mProtectionBanner._main{action = 'move', small = true}
else
return nil
Line 448 ⟶ 445:
local links
local content = args.content
if not content or args[1] then
-- No need to include the links if the documentation is on the template page itself.
local linksData = p.makeStartBoxLinksData(args, env)
Line 495 ⟶ 492:
data.docTitle = docTitle
-- View, display, edit, and purge links if /doc exists.
data.viewLinkDisplay =
data.editLinkDisplay =
data.historyLinkDisplay =
data.purgeLinkDisplay =
-- Create link if /doc doesn't exist.
local preload = args.preload
Line 511 ⟶ 508:
end
data.preload = preload
data.createLinkDisplay =
return data
end
Line 523 ⟶ 520:
local function escapeBrackets(s)
-- Escapes square brackets with HTML entities.
s = s:gsub('%[', '[') -- Replace square brackets with HTML entities.
s = s:gsub('%]', ']')
return s
end
Line 556 ⟶ 553:
--
-- Messages:
-- 'documentation-icon-wikitext' --> '[[File:Test Template Info-Icon - Version (2).svg|50px|link=|alt=
-- 'template-namespace-heading' --> 'Template documentation'
-- 'module-namespace-heading' --> 'Module documentation'
Line 582 ⟶ 579:
data.heading = heading
elseif subjectSpace == 10 then -- Template namespace
data.heading =
elseif subjectSpace == 828 then -- Module namespace
data.heading =
elseif subjectSpace == 6 then -- File namespace
data.heading =
else
data.heading =
end
-- Heading CSS
local headingStyle = args['heading-style']
if headingStyle then
data.headingStyleText = headingStyle
elseif subjectSpace == 10 then
-- We are in the template or template talk namespaces.
data.headingFontWeight = 'bold'
data.headingFontSize = '125%'
else
data.headingFontSize = '150%'
end
Line 606 ⟶ 615:
local sbox = mw.html.create('div')
sbox
:css('padding-bottom', '3px')
:css('border-bottom', '1px solid #aaa')
:css('margin-bottom', '1ex')
:newline()
:tag('span')
:cssText(data.headingStyleText)
:css('font-weight', data.headingFontWeight)
:css('font-size', data.headingFontSize)
:wikitext(data.heading)
local links = data.links
if links then
sbox:tag('span')
:
:wikitext(links)
end
return tostring(sbox)
Line 635 ⟶ 648:
local content = args.content
if not content and docTitle and docTitle.exists then
content = args._content or mw.getCurrentFrame():expandTemplate{title = docTitle.prefixedText}
end
-- The line breaks below are necessary so that "=== Headings ===" at the start and end
-- of docs are interpreted correctly.
return '\n' .. (content or '') .. '\n'
end
Line 669 ⟶ 678:
-- @args - a table of arguments passed by the user
-- @env - environment table containing title objects, etc., generated with p.getEnvironment
--
-- Messages:
-- 'fmbox-id' --> 'documentation-meta-data'
-- 'fmbox-style' --> 'background-color: #ecfcf4'
-- 'fmbox-textstyle' --> 'font-style: italic'
--
-- The HTML is generated by the {{fmbox}} template, courtesy of [[Module:Message box]].
--]=]
Line 694 ⟶ 710:
end
-- Assemble the
local fmargs = {}
fmargs.id = message('fmbox-id') -- Sets 'documentation-meta-data'
fmargs.image = 'none'
fmargs.style = message('fmbox-style') -- Sets 'background-color: #ecfcf4'
fmargs.textstyle = message('fmbox-textstyle') -- 'font-style: italic;'
-- Assemble the fmbox text field.
local text = ''
if linkBox then
Line 719 ⟶ 742:
end
end
fmargs.text = text
return messageBox.main('fmbox', fmargs)
end
Line 737 ⟶ 757:
-- 'history-link-display' --> 'history'
-- 'transcluded-from-blurb' -->
-- 'The above [[
-- is [[
-- 'module-preload' --> 'Template:Documentation/preload-module-doc'
-- 'create-link-display' --> 'create'
-- 'create-module-doc-blurb' -->
-- 'You might want to $1 a documentation page for this [[
--]=]
local docTitle = env.docTitle
if not docTitle
return nil
end
Line 753 ⟶ 773:
local docLink = makeWikilink(docTitle.prefixedText)
local editUrl = docTitle:fullUrl{action = 'edit'}
local editDisplay =
local editLink = makeUrlLink(editUrl, editDisplay)
local historyUrl = docTitle:fullUrl{action = 'history'}
local historyDisplay =
local historyLink = makeUrlLink(historyUrl, historyDisplay)
ret = message('transcluded-from-blurb', {docLink})
Line 765 ⟶ 785:
-- /doc does not exist; ask to create it.
local createUrl = docTitle:fullUrl{action = 'edit', preload = message('module-preload')}
local createDisplay =
local createLink = makeUrlLink(createUrl, createDisplay)
ret = message('create-module-doc-blurb', {createLink})
Line 838 ⟶ 858:
local mirrorPreload = message('mirror-link-preload')
local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = mirrorPreload, summary = mirrorSummary}
if subjectSpace == 828 then
mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = templateTitle.prefixedText, summary = mirrorSummary}
end
local mirrorDisplay = message('mirror-link-display')
local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay)
Line 849 ⟶ 872:
local testcasesEditDisplay = message('testcases-edit-link-display')
local testcasesEditLink = makeUrlLink(testcasesEditUrl, testcasesEditDisplay)
-- for Modules, add testcases run link if exists
if testcasesTitle.contentModel == "Scribunto" and testcasesTitle.talkPageTitle and testcasesTitle.talkPageTitle.exists then
local testcasesRunLinkDisplay = message('testcases-run-link-display')
local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay)
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink, testcasesRunLink)
else
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
end
else
local testcasesPreload
|