Difference between revisions 51794 and 51795 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) else return title.text end end function envFuncs.docTitle() local title = env.title local docname = args[1] -- Other docname, if fedUser-specified doc page. local docspace = env.ge if docname then⏎ docspace local templatePage = env.templatePage local docpage if docname then docpage = docname elsege = docname else docpage = env.docpageRoot .. '/' .. message('docSubpage', 'string') end return mw.title.new(docpage) end function envFuncs.docpageRoot() local namespace = title = env.title return (env.docspace or title.nsText⏎ local pagename = ) .. ':' .. (env.templatePage or title.text) docpage = namespace .. ':' .. pagenameend function envFuncs.sandboxTitle() local titleArg = env.docpageRoot .. '/' .. message('sandboxSubpage', 'string') local title = mw.title.new(titleArg) if not title then error(message('titleArgError', 'string', {titleArg})) end return title end function envFuncs.testcasesTitle() local titleArg = env.docpageRoot .. '/' .. message('doctestcasesSubpage', 'string') end returnlocal title = mw.title.new(docpagetitleArg) if not title then error(message('titleArgError', 'string', {titleArg})) end return title end⏎ function env:grab(key) local success, val = pcall(function() return self[key] end) return success, val end return env end (contracted; show full) function p.renderStartBoxLinks(data) -- Render the [view][edit][history][purge] or [create] links. local ret local docTitle = data.docTitle local title = data.title if docTitle.exists then local viewLink = makeWikilink(doc Title.prefixedTextpage, data.viewLinkDisplay) local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, data.editLinkDisplay) local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, data.historyLinkDisplay) local purgeLink = makeUrlLink(title:fullUrl{action = 'purge'}, data.purgeLinkDisplay) ret = '[%s] [%s] [%s] [%s]' ret = ret:gsub('%[', '[') -- Replace square brackets with HTML entities. (contracted; show full) text = text .. message('createModuleDocBlurb', 'string', {createLink}) .. '<br />' end -- 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. local sandboxLinks, testcasesLinks local pagePossessive = subjectSpace == 828 and message('modulePossessive', 'string') or message('templatePossessive', 'string') local sandboxTitle = mw.title.new(sandbox) if sandboxTitle.exists then local sandboxLink = makeWikilink(sandbox, message('sandboxLinkDisplay', 'string')) local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, message('sandboxEditLinkDisplay', 'string')) local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, message('compareLinkDisplay', 'string')) sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink) else local sandboxPreload = subjectSpace == 828 and message('moduleSandboxPreload', 'string') or message('templateSandboxPreload', 'string') local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, message('sandboxCreateLinkDisplay', 'string')) local mirrorSummary = message('mirrorEditSummary', 'string', {makeWikilink(templatePage)}) local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, message('mirrorLinkDisplay', 'string')) sandboxLinks = message('sandboxLinkDisplay', 'string') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink) end local testcaseTitle = mw.title.new(testcases) if testcaseTitle.exists then local testcasesLink = makeWikilink(testcases, message('testcasesLinkDisplay', 'string')) local testcasesEditLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit'}, message('testcasesEditLinkDisplay', 'string')) testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink) else local testcasesPreload = subjectSpace == 828 and message('moduleTestcasesPreload', 'string') or message('templateTestcasesPreload', 'string') local testcasesCreateLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit', preload = testcasesPreload}, message('testcasesCreateLinkDisplay', 'string')) testcasesLinks = message('testcasesLinkDisplay', 'string') .. ' ' .. makeToolbar(testcasesCreateLink) end text = text .. message('experimentBlurb', 'string', {pagePossessive, sandboxLinks, testcasesLinks}) .. '<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', fmargstext = 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) end function p.makeEndBoxExperimentBlurb(args, env) -- Renders the text "Editors can experiment in this template's sandbox (edit | diff) and testcases (edit) pages." local subjectSpace = env.subjectSpace local templatePage = env.templatePage -- Get title objects. local sandboxSuccess, sandboxTitle = env:grab('sandboxTitle') if not sandboxSuccess then return err(sandboxTitle) end local testcasesSuccess, testcasesTitle = env:grab('testcasesTitle') if not testcasesSuccess then return err(testcasesTitle) end -- Make links. local sandboxLinks, testcasesLinks if sandboxTitle.exists then local sandboxLink = makeWikilink(sandboxTitle.prefixedText, message('sandboxLinkDisplay', 'string')) local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, message('sandboxEditLinkDisplay', 'string')) local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, message('compareLinkDisplay', 'string')) sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink) else local sandboxPreload = subjectSpace == 828 and message('moduleSandboxPreload', 'string') or message('templateSandboxPreload', 'string') local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, message('sandboxCreateLinkDisplay', 'string')) local mirrorSummary = message('mirrorEditSummary', 'string', {makeWikilink(templatePage)}) local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, message('mirrorLinkDisplay', 'string')) sandboxLinks = message('sandboxLinkDisplay', 'string') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink) end if testcasesTitle.exists then local testcasesLink = makeWikilink(testcasesTitle.prefixedText, message('testcasesLinkDisplay', 'string')) local testcasesEditLink = makeUrlLink(testcasesTitle:fullUrl{action = 'edit'}, message('testcasesEditLinkDisplay', 'string')) testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink) else local testcasesPreload = subjectSpace == 828 and message('moduleTestcasesPreload', 'string') or message('templateTestcasesPreload', 'string') local testcasesCreateLink = makeUrlLink(testcasesTitle:fullUrl{action = 'edit', preload = testcasesPreload}, message('testcasesCreateLinkDisplay', 'string')) testcasesLinks = message('testcasesLinkDisplay', 'string') .. ' ' .. makeToolbar(testcasesCreateLink) end return message(subjectSpace == 828 and 'experimentBlurbModule' or 'experimentBlurbTemplate', 'string', {sandboxLinks, testcasesLinks}) end ---------------------------------------------------------------------------- -- Tracking categories ---------------------------------------------------------------------------- function p.addTrackingCategories(env) -- Check if {{documentation}} is transcluded on a /doc or /testcases page. local title = env.title local ret = '' local subpage = title.subpageText if message('displayStrangeUsageCategory', 'boolean') and (subpage == message('docSubpage', 'string') or subpage == message('testcasesSubpage', 'string')) then 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=51795.
![]() ![]() 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.
|