Difference between revisions 51772 and 51773 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. (contracted; show full)-- 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.docSubpage = 'doc' -- The name of the subpage typically used for documentation pages. cfg.sandboxSubpage = 'sandbox' -- The name of the template subpage typically used for sandboxes. cfg.testcasesSubpage = 'testcases' -- The name of the template subpage typically used for test cases. cfg.printSubpage = 'Print' -- The name of the template subpage used for print versions.⏎ 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.sandboxNoticeTemplate = 'template sandbox notice' -- The name of the template to display at the top of sandbox pages. cfg.sandboxNoticeLivepageParam = 1 -- The parameter of the sandbox notice template to send the cfg.livepageArg to. (contracted; show full) cfg.mirrorLinkDisplay = 'mirror' -- The text to display for "mirror" links. cfg.testcasesLinkDisplay = 'testcases' -- The text to display for "testcases" links. cfg.testcasesEditLinkDisplay = 'edit' -- The text to display for test cases "edit" links. cfg.testcasesCreateLinkDisplay = 'create' -- The text to display for test cases "create" links. ⏎ cfg.docLinkDisplay = '/' .. cfg.docSubpage -- The text to display when linking to the /doc subpage. cfg.subpagesLinkDisplay = 'Subpages of this $1' -- The text to display for the "subpages of this page" link. $1 is cfg.templatePagetype, cfg.modulePagetype or cfg.defaultPagetype, depending on whether the current page is in the template namespace, the module namespace, or another namespace. cfg.printLinkDisplay = '/' .. cfg.printSubpage -- The text to display when linking to the /doc subpage. -- Sentences used in the end box. cfg.transcludedFromBlurb = 'The above [[Wikipedia:Template documentation|documentation]] is [[Wikipedia:Transclusion|transcluded]] from $1.' -- Notice displayed when the docs are transcluded from another page. $1 is a wikilink to that page. cfg.createModuleDocBlurb = 'You might want to $1 a documentation page for this [[Wikipedia:Lua|Scribunto module]].' -- Notice displayed in the module namespace when the documentation subpage does not exist. $1 is a link to create the documentation page with the preload cfg.modulePreload and the display cfg.createLinkDisplay. cfg.templatePossessive = "template's" -- Possessive case for "template". cfg.modulePossessive = "module's" -- Possessive case for "module". cfg.experimentBlurb = 'Editors can experiment in this $1 $2 and $3 pages.' -- Text inviting editors to experiment in sandbox and test cases pages. It is only shown in the template and module namespaces. $1 is cfg.templatePossessive or cfg.modulePossessive depending on what namespace we are in. $2 is a link to the sandbox in the format "cfg.sandboxLinkDisplay (cfg.sandboxEditLinkDisplay | cfg.compareLinkDisplay)" if the sandbox exists, and the format "cfg.sandboxLinkDisplay (cfg.sandboxCreateLinkDisplay | cfg.mirrorLinkDisplay)" if the sandbox doesn't exist. If the sandbox link doesn't exist, the create link preloads the page with cfg.templateSandboxPreload or cfg.moduleSandboxPreload depending on the current namespace. $3 is a link to the test cases page in the format "cfg.testcasesLinkDisplay (cfg.testcasesEditLinkDisplay)" if the test cases page exists, and in the format "cfg.testcasesLinkDisplay (cfg.testcasesCreateLinkDisplay)" if the test cases page doesn't exist. If the test cases page doesn't exist, the create link preloads the page with cfg.templateTestcasesPreload or cfg.moduleTestcasesPreload depending on the current namespace. -- Other display settings cfg.documentationIconWikitext = '[[File:Template-info.png|50px|link=|alt=Documentation icon]]' -- The wikitext for the icon shown at the top of the template. cfg.templateNamespaceHeading = 'Template documentation' -- The heading shown in the template namespace. cfg.moduleNamespaceHeading = 'Module documentation' -- The heading shown in the module namespace. cfg.fileNamespaceHeading = 'Summary' -- The heading shown in the file namespace. cfg.otherNamespacesHeading = 'Documentation' -- The heading shown in other namespacesmirrorEditSummary = 'Create sandbox version of $1' -- The default edit summary to use when a user clicks the "mirror" link. $1 is a wikilink to the template page. cfg.experimentBlurb = 'Editors can experiment in this $1 $2 and $3 pages.' -- Text inviting editors to experiment in sandbox and test cases pages. It is only shown in the template and module namespaces. $1 is cfg.templatePossessive or cfg.modulePossessive depending on what namespace we are in. $2 is a link to the sandbox in the format "cfg.sandboxLinkDisplay (cfg.sandboxEditLinkDisplay | cfg.compareLinkDisplay)" if the sandbox exists, and the format "cfg.sandboxLinkDisplay (cfg.sandboxCreateLinkDisplay | cfg.mirrorLinkDisplay)" if the sandbox doesn't exist. If the sandbox link doesn't exist, the create link preloads the page with cfg.templateSandboxPreload or cfg.moduleSandboxPreload depending on the current namespace. If the page doesn't exist, the mirror link uses the edit summar cfg.mirrorEditSummary. $3 is a link to the test cases page in the format "cfg.testcasesLinkDisplay (cfg.testcasesEditLinkDisplay)" if the test cases page exists, and in the format "cfg.testcasesLinkDisplay (cfg.testcasesCreateLinkDisplay)" if the test cases page doesn't exist. If the test cases page doesn't exist, the create link preloads the page with cfg.templateTestcasesPreload or cfg.moduleTestcasesPreload depending on the current namespace. cfg.addCategoriesBlurb = 'Please add categories to the $1 subpage.' -- Text to direct users to add categories to the /doc subpage. Not used if the "content" or "docname fed" arguments are set, as then it is not clear where to add the categories. $1 is a link to the /doc subpage with a display value of cfg.docLinkDisplay. cfg.printBlurb = 'A [[Help:Books/for experts#Improving the book layout|print version]] of this template exists at $1. If you make a change to this template, please update the print version as well.' -- Text to display if a /Print subpage exists. $1 is a link to the subpage with a display value of cfg.printLinkDisplay. -- Other display settings cfg.documentationIconWikitext = '[[File:Template-info.png|50px|link=|alt=Documentation icon]]' -- The wikitext for the icon shown at the top of the template. cfg.templateNamespaceHeading = 'Template documentation' -- The heading shown in the template namespace. cfg.moduleNamespaceHeading = 'Module documentation' -- The heading shown in the module namespace. cfg.fileNamespaceHeading = 'Summary' -- The heading shown in the file namespace. cfg.otherNamespacesHeading = 'Documentation' -- The heading shown in other namespaces. cfg.templatePagetype = 'template' -- The pagetype to display for template pages. cfg.modulePagetype = 'module' -- The pagetype to display for Lua module pages. cfg.defaultPagetype = 'page' -- The pagetype to display for pages other than templates or Lua modules. -- Category settings cfg.displayPrintCategory = true -- Set to true to enable output of cfg.printCategory if a /Print subpage exists. cfg.printCategory = 'Templates with print versions' -- Category to output if cfg.displayPrintCategory is set to true, and a /Print subpage exists. cfg.displayStrangeUsageCategory = true -- Set to true to enable output of cfg.strangeUsageCategory if the module is used on a /doc subpage or a /testcases subpage. cfg.strangeUsageCategory = 'Wikipedia pages with strange ((documentation)) usage' -- Category to output if cfg.displayStrangeUsageCategory is set to true and the module is used on a /doc subpage or a /testcases subpage. cfg.strangeUsageCategoryMainspaceSort = 'Main:' -- Category sort key prefix to use for cfg.strangeUsageCategory in the main namespace. The prefix is followed by the full page name. ---------------------------------------------------------------------------- -- End configuration ---------------------------------------------------------------------------- -- Get required modules. local getArgs = require('Module:Arguments').getArgs (contracted; show full) if display then return mw.ustring.format('[[%s|%s]]', page, display) else return mw.ustring.format('[[%s]]', page) end end local function makeCategoryLink(cat, sort) local catns = mw.site.namespaces[14].name return makeWikilink(catns .. '/' .. cat, sort) end⏎ ⏎ local function makeUrlLink(url, display) return mw.ustring.format('[%s %s]', url, display) end local function makeToolbar(...) local ret = {} local lim = select('#', ...) if lim < 1 then (contracted; show full) sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink) else local sandboxPreload = subjectSpace == 828 and cfg.moduleSandboxPreload or cfg.templateSandboxPreload local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, cfg.sandboxCreateLinkDisplay) local mirrorSummary = 'Create sandbox version of ' .. makeWikilink(templatePageformatMessage(cfg.mirrorEditSummary, {makeWikilink(templatePage)}) local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, cfg.mirrorLinkDisplay) sandboxLinks = cfg.sandboxLinkDisplay .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink) end local testcaseTitle = mw.title.new(testcases) if testcaseTitle.exists then local testcasesLink = makeWikilink(testcases, cfg.testcasesLinkDisplay) local testcasesEditLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit'}, cfg.testcasesEditLinkDisplay) testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink) else local testcasesPreload = subjectSpace == 828 and cfg.moduleTestcasesPreload or cfg.templateTestcasesPreload local testcasesCreateLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit', preload = testcasesPreload}, cfg.testcasesCreateLinkDisplay) testcasesLinks = cfg.testcasesLinkDisplay .. ' ' .. makeToolbar(testcasesCreateLink) end text = text .. formatMessage(cfg.experimentBlurb, {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 text = text .. 'Please add categories to the ' .. makeWikilink(docpage, '/' .. cfg.docSubpage) .. ' subpage.'local docPathLink = makeWikilink(docpage, cfg.docLinkDisplay) text = text .. formatMessage(cfg.addCategoriesBlurb, {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 = 'template' elseif subjectSpace == 828 then pagetype = 'module' else pagetype = 'page' end text = text .. ' ' .. makeWikilink('Special:PrefixIndex/' .. templatePage .. '/', 'Subpages of this ' .. pagetype) end -- Show the "print" link if it exists. local printPage = templatePage .. '/Print' local printTitle = mw.title.new(printPage) if printTitle.exists then text = text .. '<br />A [[Help:Books/for experts#Improving the book layout|print version]] of this template exists at ' .. makeWikilink(printPage, '/Print') .. '. If you make a change to this template, please update the print version as well.' .. '[[Category:Templates with print versions]]' end end end fmargs.text = text -- Return the fmbox output. return messageBox.main('fmbox', fmargs) end function p.addTrackingCategories() -- Check if {{documentation}} is transcluded on a /doc or /testcases page. local ret = '' local subpage = currentTitle.subpageText if subpage == cfg.docSubpage or subpage == cfg.testcasesSubpage then local sort = (currentTitle.namespace == 0 and 'Main:' or '') .. currentTitle.prefixedText -- Sort on namespace. ret = ret .. makeWikilink('Category:Wikipedia pages with strange ((documentation)) usage'cfg.templatePagetype elseif subjectSpace == 828 then pagetype = cfg.modulePagetype else pagetype = cfg.defaultPagetype end text = text .. ' ' .. makeWikilink('Special:PrefixIndex/' .. templatePage .. '/', formatMessage(cfg.subpagesLinkDisplay, {pagetype})) end -- Show the "print" link if it exists. local printPage = templatePage .. '/' .. cfg.printSubpage local printTitle = mw.title.new(printPage) if printTitle.exists then local printLink = makeWikilink(printPage, cfg.printLinkDisplay) text = text .. '<br />' .. formatMessage(cfg.printBlurb, {printLink}) .. (cfg.displayPrintCategory and makeCategoryLink(cfg.printCategory) or '') end end end fmargs.text = text -- Return the fmbox output. return messageBox.main('fmbox', fmargs) end function p.addTrackingCategories() -- Check if {{documentation}} is transcluded on a /doc or /testcases page. local ret = '' local subpage = currentTitle.subpageText if cfg.displayStrangeUsageCategory and (subpage == cfg.docSubpage or subpage == cfg.testcasesSubpage) then local sort = (currentTitle.namespace == 0 and cfg.strangeUsageCategoryMainspaceSort or '') .. currentTitle.prefixedText -- Sort on namespace. ret = ret .. makeCategoryLink(cfg.strangeUsageCategory, sort) end return ret end function p.docspace() -- Determines the namespace of the documentation. if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then -- Pages in the Article, File, MediaWiki or Category namespaces must have their -- /doc, /sandbox and /testcases pages in talk space. return mw.site.namespaces[subjectSpace].talk.name else 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.sandboxSubpage or subpage == cfg.testcasesSubpage 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=51773.
![]() ![]() 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.
|