Difference between revisions 51764 and 51765 on wikimaniawiki-- This module implements {{documentation}}. ---------------------------------------------------------------------------- -- Configuration ---------------------------------------------------------------------------- -- Here you can set the values of the parameters and messages used in this module, so that it -- can be easily ported to other wikis. local cfg = {} -- Argument names -- The following are all names of arguments that affect the behaviour of {{documentation}}. -- The comments next to the configuration values are the effects that the argument has -- on the module. (Not the effects of the argument names themselves.) cfg.livepageArg = 'livepage' -- Name of the live template; used in {{template sandbox notice}}. cfg.headingArg = 'heading' -- Custom heading used in the start box. cfg.preloadArg = 'preload' -- Custom preload page for creating documentation. cfg.headingStyleArg = 'heading-style' -- Custom CSS style for the start box heading. cfg.contentArg = 'content' -- Passes documentation content directly from the {{documentation}} invocation. cfg.linkBoxArg = 'link box' -- Specifies a custom link box (end box) or prevents it from being generated. -- Software settings -- The following are software settings that may change from wiki to wiki. For example, the classes -- defined in commons.css or the names of templates. cfg.mainDivId = 'template-documentation' -- The "id" attribute of the main HTML "div" tag. cfg.mainDivClasses = 'template-documentation iezoomfix' -- The CSS classes added to the main HTML "div" tag. cfg.sandboxSubpage = 'sandbox' -- The name of the template subpage typically used for sandboxes. -- Display settings -- The following settings configure the values displayed by the module. cfg.sandboxLinkDisplay = 'sandbox'⏎ ⏎ ---------------------------------------------------------------------------- -- End configuration ---------------------------------------------------------------------------- -- Get required modules. local getArgs = require('Module:Arguments').getArgs local htmlBuilder = require('Module:HtmlBuilder') local messageBox = require('Module:Message box') (contracted; show full) local root = htmlBuilder.create() root .wikitext(p.protectionTemplate()) .wikitext(p.sandboxNotice(args)) -- 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', 'template-documentation') .addClass('template-documentation iezoomfix'cfg.mainDivId) .addClass(cfg.mainDivClasses) .wikitext(p._startBox(args)) .wikitext(p._content(args)) .tag('div') .css('clear', 'both') -- So right or left floating items don't stick out of the doc box. .done() .done() .wikitext(p._endBox(args)) .wikitext(p.addTrackingCategories()) return tostring(root) end function p.sandboxNotice(args) if currentTitle.subpageText == 'cfg.sandbox'Subpage then local frame = mw.getCurrentFrame() local root = htmlBuilder.create() root .tag('div') .css('clear', 'both') .done() .wikitext(frame:expandTemplate{title = 'template sandbox notice', args = {args[cfg.livepageArg]}}) (contracted; show full) docpage = docname else docpage = docpageRoot .. '/doc' end local docTitle = mw.title.new(docpage) local docExist = docTitle.exists local docnameFed = args[1] and true local sandbox = docpageRoot .. '/ sandbox'' .. cfg.sandboxSubpage local testcases = docpageRoot .. '/testcases' templatePage = currentTitle.nsText .. ':' .. templatePage -- Output from {{documentation/end box}} -- First, check whether we should output the end box at all. Add the end box by default if the documentation -- exists or if we are in the user, module or template namespaces. (contracted; show full) if subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 then -- We are in the user, module or template namespaces. local pagePossessive = subjectSpace == 828 and "module's" or "template's" text = text .. 'Editors can experiment in this ' .. pagePossessive .. ' ' local sandboxTitle = mw.title.new(sandbox) if sandboxTitle.exists then local sandboxLink = makeWikilink(sandbox, 'cfg.sandbox'LinkDisplay) local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, 'edit') local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, 'diff') text = text .. sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink) else local sandboxPreload = 'Template:Documentation/preload-' .. (subjectSpace == 828 and 'module-' or '') .. 'sandbox' local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, 'create') local mirrorSummary = 'Create sandbox version of ' .. makeWikilink(templatePage) local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, 'mirror') text = text .. 'cfg.sandboxLinkDisplay .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink) end text = text .. ' and ' local testcaseTitle = mw.title.new(testcases) if testcaseTitle.exists then local testcasesLink = makeWikilink(testcases, 'testcases') local testcasesEditLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit'}, 'edit') text = text .. testcasesLink .. ' ' .. makeToolbar(testcasesEditLink) (contracted; show full) return currentTitle.subjectNsText end end function p.templatePage() -- Determines the template page. No namespace or interwiki prefixes are included. local subpage = currentTitle.subpageText if subpage == 'cfg.sandbox'Subpage or subpage == 'testcases' then return currentTitle.baseText else return currentTitle.text end end return p All content in the above text box is licensed under the Creative Commons Attribution-ShareAlike license Version 4 and was originally sourced from https://wikimania.wikimedia.org/w/index.php?diff=prev&oldid=51765.
![]() ![]() This site is not affiliated with or endorsed in any way by the Wikimedia Foundation or any of its affiliates. In fact, we fucking despise them.
|