Module:Documentation: Difference between revisions

m
160 revisions imported from templatewiki:Module:Documentation
(don't cause a script error if p.makeExperimentBlurb returns nil)
m (160 revisions imported from templatewiki:Module:Documentation)
 
(34 intermediate revisions by 21 users not shown)
Line 3:
-- Get required modules.
local getArgs = require('Module:Arguments').getArgs
local htmlBuilder = require('Module:HtmlBuilder')
local messageBox = require('Module:Message box')
 
Line 128 ⟶ 127:
--]]
local env = p.getEnvironment(args)
local root = htmlBuildermw.html.create()
root
.:wikitext(p.protectionTemplate(env))
.:wikitext(p.sandboxNotice(args, env))
-- This div tag is from {{documentation/start box}}, but moving it here
-- so that we don't have to worry about unclosed tags.
.:tag('div')
.:attr('id', message('main-div-id'))
.:addClass(message('main-div-classes'))
.: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))
.:wikitext(p.addTrackingCategories(env))
return tostring(root)
end
Line 356 ⟶ 355:
-- "This is the template sandbox for [[Template:Foo]] (diff)."
local text = ''
local frame = mw.getCurrentFrame()
local isPreviewing = frame:preprocess('{{REVISIONID}}') == '' -- True if the page is being previewed.
local pagetype
if subjectSpace == 10 then
Line 368 ⟶ 365:
local templateLink = makeWikilink(templateTitle.prefixedText)
local compareUrl = env.compareUrl
if isPreviewing or not compareUrl then
text = text .. message('sandbox-notice-blurb', {pagetype, templateLink})
else
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 379 ⟶ 376:
local testcasesTitle = env.testcasesTitle
if testcasesTitle and testcasesTitle.exists then
if testcasesTitle.namespacecontentModel == mw.site.namespaces.Module.id"Scribunto" then
local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display')
local testcasesRunLinkDisplay = message('sandbox-notice-testcases-run-link-display')
Line 405 ⟶ 402:
-- 'protection-template' --> 'pp-template'
-- 'protection-template-args' --> {docusage = 'yes'}
local protectionLevels, mProtectionBanner
local title = env.title
local protectionLevels
local protectionTemplate = message('protection-template')
local namespace = title.namespace
if not (protectionTemplate and (namespace == 10 or namespace == 828)) then
-- Don't display the protection template if we are not in the template or module namespaces.
return nil
end
protectionLevels = env.protectionLevels
if not protectionLevels then
return nil
end
local editLevelseditProt = protectionLevels.edit and protectionLevels.edit[1]
local moveLevelsmoveProt = protectionLevels.move and protectionLevels.move[1]
if editProt then
if moveLevels and moveLevels[1] == 'sysop' or editLevels and editLevels[1] then
-- The page is full-move protected, or full, template, or semiedit-protected.
mProtectionBanner = require('Module:Protection banner')
local frame = mw.getCurrentFrame()
returnlocal frame:expandTemplate{title = protectionTemplate, argsreason = message('protection-templatereason-args', nil, 'tableedit')}
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 447 ⟶ 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 485 ⟶ 483:
if not title or not docTitle then
return nil
end
if docTitle.isRedirect then
docTitle = docTitle.redirectTarget
end
 
Line 552 ⟶ 553:
--
-- Messages:
-- 'documentation-icon-wikitext' --> '[[File:Test Template Info-Icon - Version (2).svg|50px|link=|alt=Documentation icon]]'
-- 'template-namespace-heading' --> 'Template documentation'
-- 'module-namespace-heading' --> 'Module documentation'
Line 612 ⟶ 613:
-- Renders the start box html.
-- @data - a table of data generated by p.makeStartBoxData.
local sbox = htmlBuildermw.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')
.:addClass(data.linksClass)
.:attr('id', data.linksId)
.:wikitext(links)
end
return tostring(sbox)
Line 807 ⟶ 808:
-- 'mirror-edit-summary' --> 'Create sandbox version of $1'
-- 'mirror-link-display' --> 'mirror'
-- 'modulemirror-testcaseslink-preload' --> 'Template:Documentation/preload-module-testcasesmirror'
-- 'sandbox-link-display' --> 'sandbox'
-- 'testcases-link-display' --> 'testcases'
-- 'testcases-edit-link-display'--> 'edit'
-- 'module-testcases-preload' --> 'Template:Documentation/preload-module-testcases'
-- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox'
-- 'testcases-create-link-display' --> 'create'
Line 855 ⟶ 856:
local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay)
local mirrorSummary = message('mirror-edit-summary', {makeWikilink(templatePage)})
local mirrorPreload = message('mirror-link-preload')
local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = templatePagemirrorPreload, 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 867 ⟶ 872:
local testcasesEditDisplay = message('testcases-edit-link-display')
local testcasesEditLink = makeUrlLink(testcasesEditUrl, testcasesEditDisplay)
-- for Modules, add testcases run link if exists
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
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