Module:Documentation: Difference between revisions
From Video Credit Archive
Content deleted Content added
wikpedia>Jackmcbarn add a link to run the test cases from the sandbox page |
Cocopuff2018 (talk | contribs) m 1 revision imported: Requested By User |
||
(38 intermediate revisions by 18 users not shown) | |||
Line 3: | Line 3: | ||
-- Get required modules. |
-- Get required modules. |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local htmlBuilder = require('Module:HtmlBuilder') |
|||
local messageBox = require('Module:Message box') |
local messageBox = require('Module:Message box') |
||
Line 128: | Line 127: | ||
--]] |
--]] |
||
local env = p.getEnvironment(args) |
local env = p.getEnvironment(args) |
||
local root = |
local root = mw.html.create() |
||
root |
root |
||
:wikitext(p.protectionTemplate(env)) |
|||
:wikitext(p.sandboxNotice(args, env)) |
|||
-- This div tag is from {{documentation/start box}}, but moving it here |
-- This div tag is from {{documentation/start box}}, but moving it here |
||
-- so that we don't have to worry about unclosed tags. |
-- 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)) |
|||
⚫ | |||
.newline() |
|||
⚫ | |||
return tostring(root) |
return tostring(root) |
||
end |
end |
||
Line 333: | Line 331: | ||
-- |
-- |
||
-- Messages: |
-- Messages: |
||
-- 'sandbox-notice-image' --> '[[Image:Sandbox. |
-- 'sandbox-notice-image' --> '[[Image:Sandbox.svg|50px|alt=|link=]]' |
||
-- 'sandbox-notice-blurb' --> 'This is the $1 for $2.' |
-- 'sandbox-notice-blurb' --> 'This is the $1 for $2.' |
||
-- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).' |
-- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).' |
||
Line 357: | Line 355: | ||
-- "This is the template sandbox for [[Template:Foo]] (diff)." |
-- "This is the template sandbox for [[Template:Foo]] (diff)." |
||
local text = '' |
local text = '' |
||
local frame = mw.getCurrentFrame() |
|||
local isPreviewing = frame:preprocess('{{REVISIONID}}') == '' -- True if the page is being previewed. |
|||
local pagetype |
local pagetype |
||
if subjectSpace == 10 then |
if subjectSpace == 10 then |
||
Line 369: | Line 365: | ||
local templateLink = makeWikilink(templateTitle.prefixedText) |
local templateLink = makeWikilink(templateTitle.prefixedText) |
||
local compareUrl = env.compareUrl |
local compareUrl = env.compareUrl |
||
if |
if compareUrl then |
||
⚫ | |||
⚫ | |||
local compareDisplay = message('sandbox-notice-compare-link-display') |
local compareDisplay = message('sandbox-notice-compare-link-display') |
||
local compareLink = makeUrlLink(compareUrl, compareDisplay) |
local compareLink = makeUrlLink(compareUrl, compareDisplay) |
||
text = text .. message('sandbox-notice-diff-blurb', {pagetype, templateLink, compareLink}) |
text = text .. message('sandbox-notice-diff-blurb', {pagetype, templateLink, compareLink}) |
||
⚫ | |||
⚫ | |||
end |
end |
||
-- Get the test cases page blurb if the page exists. This is something like |
-- Get the test cases page blurb if the page exists. This is something like |
||
Line 380: | Line 376: | ||
local testcasesTitle = env.testcasesTitle |
local testcasesTitle = env.testcasesTitle |
||
if testcasesTitle and testcasesTitle.exists then |
if testcasesTitle and testcasesTitle.exists then |
||
if testcasesTitle. |
if testcasesTitle.contentModel == "Scribunto" then |
||
local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display') |
local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display') |
||
local testcasesRunLinkDisplay = message('sandbox-notice-testcases-run-link-display') |
local testcasesRunLinkDisplay = message('sandbox-notice-testcases-run-link-display') |
||
Line 406: | Line 402: | ||
-- 'protection-template' --> 'pp-template' |
-- 'protection-template' --> 'pp-template' |
||
-- 'protection-template-args' --> {docusage = 'yes'} |
-- 'protection-template-args' --> {docusage = 'yes'} |
||
⚫ | |||
local title = env.title |
local title = env.title |
||
⚫ | |||
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. |
|||
⚫ | |||
⚫ | |||
protectionLevels = env.protectionLevels |
protectionLevels = env.protectionLevels |
||
if not protectionLevels then |
if not protectionLevels then |
||
return nil |
return nil |
||
end |
end |
||
local |
local editProt = protectionLevels.edit and protectionLevels.edit[1] |
||
local |
local moveProt = protectionLevels.move and protectionLevels.move[1] |
||
if editProt then |
|||
if moveLevels and moveLevels[1] == 'sysop' or editLevels and editLevels[1] then |
|||
-- The page is |
-- The page is edit-protected. |
||
mProtectionBanner = require('Module:Protection banner') |
|||
local frame = mw.getCurrentFrame() |
|||
local reason = message('protection-reason-edit') |
|||
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 |
else |
||
return nil |
return nil |
||
Line 448: | Line 445: | ||
local links |
local links |
||
local content = args.content |
local content = args.content |
||
if not content then |
if not content or args[1] then |
||
-- No need to include the links if the documentation is on the template page itself. |
-- No need to include the links if the documentation is on the template page itself. |
||
local linksData = p.makeStartBoxLinksData(args, env) |
local linksData = p.makeStartBoxLinksData(args, env) |
||
Line 486: | Line 483: | ||
if not title or not docTitle then |
if not title or not docTitle then |
||
return nil |
return nil |
||
⚫ | |||
if docTitle.isRedirect then |
|||
docTitle = docTitle.redirectTarget |
|||
end |
end |
||
Line 553: | Line 553: | ||
-- |
-- |
||
-- Messages: |
-- Messages: |
||
-- 'documentation-icon-wikitext' --> '[[File:Template- |
-- 'documentation-icon-wikitext' --> '[[File:Test Template Info-Icon - Version (2).svg|50px|link=|alt=]]' |
||
-- 'template-namespace-heading' --> 'Template documentation' |
-- 'template-namespace-heading' --> 'Template documentation' |
||
-- 'module-namespace-heading' --> 'Module documentation' |
-- 'module-namespace-heading' --> 'Module documentation' |
||
Line 613: | Line 613: | ||
-- Renders the start box html. |
-- Renders the start box html. |
||
-- @data - a table of data generated by p.makeStartBoxData. |
-- @data - a table of data generated by p.makeStartBoxData. |
||
local sbox = |
local sbox = mw.html.create('div') |
||
sbox |
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 |
local links = data.links |
||
if links then |
if links then |
||
sbox |
sbox:tag('span') |
||
:addClass(data.linksClass) |
|||
:attr('id', data.linksId) |
|||
:wikitext(links) |
|||
end |
end |
||
return tostring(sbox) |
return tostring(sbox) |
||
Line 648: | Line 648: | ||
local content = args.content |
local content = args.content |
||
if not content and docTitle and docTitle.exists then |
if not content and docTitle and docTitle.exists then |
||
content = args._content or mw.getCurrentFrame():expandTemplate{title = docTitle.prefixedText} |
|||
content = frame:expandTemplate{title = docTitle.prefixedText} |
|||
end |
end |
||
-- The line breaks below are necessary so that "=== Headings ===" at the start and end |
-- The line breaks below are necessary so that "=== Headings ===" at the start and end |
||
-- of docs are interpreted correctly. |
-- of docs are interpreted correctly. |
||
return '\n' .. (content or '') .. '\n' |
return '\n' .. (content or '') .. '\n' |
||
end |
|||
p.contentTitle = makeInvokeFunc('_contentTitle') |
|||
function p._contentTitle(args, env) |
|||
env = env or p.getEnvironment(args) |
|||
local docTitle = env.docTitle |
|||
if not args.content and docTitle and docTitle.exists then |
|||
return docTitle.prefixedText |
|||
else |
|||
⚫ | |||
end |
|||
end |
end |
||
Line 716: | Line 727: | ||
-- Add sandbox and testcases links. |
-- Add sandbox and testcases links. |
||
-- "Editors can experiment in this template's sandbox and testcases pages." |
-- "Editors can experiment in this template's sandbox and testcases pages." |
||
text = text .. p.makeExperimentBlurb(args, env) |
text = text .. (p.makeExperimentBlurb(args, env) or '') |
||
text = text .. '<br />' |
text = text .. '<br />' |
||
if not args.content and not args[1] then |
if not args.content and not args[1] then |
||
Line 797: | Line 808: | ||
-- 'mirror-edit-summary' --> 'Create sandbox version of $1' |
-- 'mirror-edit-summary' --> 'Create sandbox version of $1' |
||
-- 'mirror-link-display' --> 'mirror' |
-- 'mirror-link-display' --> 'mirror' |
||
⚫ | |||
-- 'sandbox-link-display' --> 'sandbox' |
-- 'sandbox-link-display' --> 'sandbox' |
||
-- 'testcases-link-display' --> 'testcases' |
-- 'testcases-link-display' --> 'testcases' |
||
-- 'testcases-edit-link-display'--> 'edit' |
-- 'testcases-edit-link-display'--> 'edit' |
||
⚫ | |||
-- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox' |
-- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox' |
||
-- 'testcases-create-link-display' --> 'create' |
-- 'testcases-create-link-display' --> 'create' |
||
Line 845: | Line 856: | ||
local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay) |
local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay) |
||
local mirrorSummary = message('mirror-edit-summary', {makeWikilink(templatePage)}) |
local mirrorSummary = message('mirror-edit-summary', {makeWikilink(templatePage)}) |
||
local mirrorPreload = message('mirror-link-preload') |
|||
local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', 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 mirrorDisplay = message('mirror-link-display') |
||
local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay) |
local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay) |
||
Line 857: | Line 872: | ||
local testcasesEditDisplay = message('testcases-edit-link-display') |
local testcasesEditDisplay = message('testcases-edit-link-display') |
||
local testcasesEditLink = makeUrlLink(testcasesEditUrl, testcasesEditDisplay) |
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 |
|||
⚫ | |||
end |
|||
else |
else |
||
local testcasesPreload |
local testcasesPreload |