Difference between revisions 51808 and 51809 on wikimaniawiki-- This module implements {{documentation}}. -- Get required modules. local getArgs = require('Module:Arguments').getArgs local htmlBuilder = require('Module:HtmlBuilder') local messageBox = require('Module:Message box') -- Get the config table. (contracted; show full)---------------------------------------------------------------------------- -- End box ---------------------------------------------------------------------------- p.endBox = makeInvokeFunc('_endBox') function p._endBox(args, env) local title = env.title local subjectSpace = env.subjectSpace -- Argument processing in {{documentation}}. local content = args.content local linkBox = args['link box'] -- So "link box=off" works. local docspace = env.docspace local docname = args[1] -- Other docname, if fed. local templatePage = env.templatePage -- Argument processing in {{documentation/end box2}}. local docpageRoot = (docspace or title.nsText) .. ':' .. (templatePage or title.text) local docpage if docname then docpage = docname else docpage = docpageRoot .. '/' .. message('docSubpage', 'string') end local docTitle = mw.title.new(docpage) local docExist = docTitle.exists local docnameFed = args[1] and true local sandbox = docpageRoot .. '/' .. message('sandboxSubpage', 'string') local testcases = docpageRoot .. '/' .. message('testcasesSubpage', 'string') templatePage = title.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. if linkBox == 'off' or not (docExist or subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10) then return nil end -- Assemble the arguments for {{fmbox}}. local fmargs = {} fmargs.id = message('fmboxId', 'string') -- Sets 'documentation-meta-data' fmargs.image = message('fmboxImageNone', 'string') -- Sets 'none' fmargs.style = message('fmboxStyle', 'string') -- Sets 'background-color: #ecfcf4' fmargs.textstyle = message('fmboxTextstyle', 'string') -- 'font-style: italic;' -- Assemble the fmbox text field. local text = '' if linkBox then -- Use custom link box content if it is defined. text = text .. linkBox else text = text .. (p.makeDocPageBlurb(args, env) or '') -- Add links to /sandbox and /testcases when appropriate. if subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 then -- We are in the user, module or template namespaces. text = text .. p.makeEndBoxExperimentBlurb(args, env) text = text .. '<br />' -- Show the categories text, but not if "content" fed or "docname fed" since then it is unclear where to add the categories. if not content and not docnameFed then local docPathLink = makeWikilink(docpage, message('docLinkDisplay', 'string')) text = text .. message('addCategoriesBlurb', 'string', {docPathLink}) end -- Show the "subpages" link. if subjectSpace ~= 6 then -- Don't show the link in file space. local pagetype if subjectSpace == 10 then pagetype = message('templatePagetype', 'string') elseif subjectSpace == 828 then pagetype = message('modulePagetype', 'string') else pagetype = message('defaultPagetype', 'string') end text = text .. ' ' .. makeWikilink('Special:PrefixIndex/' .. templatePage .. '/', message('subpagesLinkDisplay', 'string', {pagetype})) end -- Show the "print" link if it exists. local printPage = templatePage .. '/' .. message('printSubpage', 'string') local printTitle = mw.title.new(printPage) if printTitle.exists then local printLink = makeWikilink(printPage, message('printLinkDisplay', 'string')) text = text .. '<br />' .. message('printBlurb', 'string', {printLink}) .. (message('displayPrintCategory', 'boolean') and makeCategoryLink(message('printCategory', 'string')) or '') end end end fmargs.text = text -- Return the fmbox output. return messageBox.main('fmbox', fmargs-- This function generates the end box (also known as the link box). -- Get environment data. local subjectSpace = env.subjectSpace local success, docTitle = env:grab('docTitle') if not success then return docTitle -- Error message end -- 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. if linkBox == 'off' or not ( docTitle.exists or subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 ) then return nil end -- Assemble the arguments for {{fmbox}}. local fmargs = {} fmargs.id = message('fmboxId', 'string') -- Sets 'documentation-meta-data' fmargs.image = message('fmboxImageNone', 'string') -- Sets 'none' fmargs.style = message('fmboxStyle', 'string') -- Sets 'background-color: #ecfcf4' fmargs.textstyle = message('fmboxTextstyle', 'string') -- 'font-style: italic;' -- Assemble the fmbox text field. local text = '' if linkBox then -- Use custom link box content if it is defined. text = text .. linkBox else text = text .. (p.makeDocPageBlurb(args, env) or '') -- Add links to /sandbox and /testcases when appropriate. if subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10 then -- We are in the user, module or template namespaces. text = text .. p.makeEndBoxExperimentBlurb(args, env) text = text .. '<br />' -- Show the categories text, but not if "content" fed or "docname fed" -- since then it is unclear where to add the categories. if not content and not docnameFed then text = text .. (p.makeCategoriesBlurb(args, env) or '') end -- Show the "subpages" link. if subjectSpace ~= 6 then -- Don't show the link in file space. text = text .. ' ' .. (p.makeSubpagesBlurb(args, env) or '') end -- Show the "print" link if it exists. local printBlurb = p.makePrintBlurb(args, env) if printBlurb then text = text .. '<br />' .. printBlurb end end end fmargs.text = text -- Return the fmbox output. return messageBox.main('fmbox', fmargs) end function p.makePrintBlurb(args, env) -- Get the /Print title object local success, printTitle = env:grab('printTitle') if not success then return printTitle -- Error message end -- Make the print blurb. local ret if printTitle.exists then local printLink = makeWikilink(printTitle.prefixedText, message('printLinkDisplay', 'string')) ret = message('printBlurb', 'string', {printLink}) local displayPrintCategory = message('displayPrintCategory', 'boolean') if displayPrintCategory then ret = ret .. makeCategoryLink(message('printCategory', 'string')) end end return ret end function p.makeSubpagesBlurb(args, env) -- Get the template title object local success, templateTitle = env:grab('templateTitle') if not success then return templateTitle -- Error message. end -- Make the subpages blurb. local pagetype if subjectSpace == 10 then pagetype = message('templatePagetype', 'string') elseif subjectSpace == 828 then pagetype = message('modulePagetype', 'string') else pagetype = message('defaultPagetype', 'string') end return makeWikilink( 'Special:PrefixIndex/' .. templateTitle.prefixedText .. '/', message('subpagesLinkDisplay', 'string', {pagetype})⏎ ) end function p.makeCategoriesBlurb(args, env) -- Get the title object. local success, docTitle = env:grab('docTitle') if not success then -- docTitle is the error message. (contracted; show full) local sort = (title.namespace == 0 and message('strangeUsageCategoryMainspaceSort', 'string') or '') .. title.prefixedText -- Sort on namespace. ret = ret .. makeCategoryLink(message('strangeUsageCategory', 'string'), sort) end return ret 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=51809.
![]() ![]() 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.
|