Difference between revisions 51818 and 51819 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) -- env.testcasesTitle - the /testcases subpage. -- env.printTitle - the print version of the template, located at the /Print subpage. -- -- Data includes: -- env.subjectSpace - the number of the title's subject namespace. -- env.docSpace - the number of the namespace the title puts its documentation in. -- env.docpageRoot - the text of the base page of the /doc, /sandbox and /testcases pages, with namespace. -- env.compare LinkUrl - a URL link of the Special:ComparePages page comparing the sandbox with the template. -- -- All table lookups are passed through pcall so that errors are caught. If an error occurs, the value -- returned will be nil. --]] local env, envFuncs = {}, {} (contracted; show full) local templateTitle = env.templateTitle local docSpace = env.docSpace local docSpaceText = mw.site.namespaces[docSpace].name -- Assemble the link. docSpace is never the main namespace, so we can hardcode the colon. return docSpaceText .. ':' .. templateTitle.text end function envFuncs.compare LinkUrl() -- Diff link between the sandbox and the main template using [[Special:ComparePages]]. local templateTitle = env.templateTitle local sandboxTitle = env.sandboxTitle local compareUrl = mw.uri.fullUrl( 'Special:ComparePages', {page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText} ) compareUrl = tostring(compareUrl) local compareDisplay = message('compareLinkDisplay', 'string') return makeUrlLink(compareUrl, compareDisplayreturn tostring(compareUrl) end return env end ---------------------------------------------------------------------------- -- Auxiliary templates ---------------------------------------------------------------------------- function p.sandboxNotice(args, env) local title = env.title local sandboxTitle = env.sandboxTitle local templateTitle = env.templateTitle if not (title and sandboxTitle and templateTitle and mw.title.equals(title, sandboxTitle)) then return nil end local omargs = {} -- Args for {{ombox}}. -- Get the image wikitext. omargs.image = message('sandboxNoticeImage', 'string') -- Get the text. We start with the opening blurb, which is something like -- "This is the template sandbox for [[Template:Foo]] (diff)." local text = '' local frame = mw.getCurrentFrame() local isPreviewing = frame:preprocess('{{REVISIONID}}') == '' -- True if the page is being previewed. local templateLink = makeWikilink(templateTitle.prefixedText) if isPreviewinglocal compareUrl = env.compareUrl if isPreviewing or not compareUrl then -- 'This is the [[Wikipedia:Template test cases|template sandbox]] page for $1.' text = text .. message('sandboxNoticeBlurb', 'string', {templateLink}) else -- 'This is the [[Wikipedia:Template test cases|template sandbox]] page for $1 ($2).' local comparedisplay = message('sandboxnoticecomparelinkdisplay', 'string') local comparelink = makeurllink(compareurl, comparedisplay)⏎ text = text .. message('sandboxNoticeDiffBlurb', 'string', {templateLink, env.compareLink}) end -- Get the test cases page blurb if the page exists. local testcasesTitle = env.testcasesTitle if testcasesTitle and testcasesTitle.exists then local testcasesLinkDisplay = message('sandboxNoticeTestcasesLinkDisplay', 'string') local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay) text = text .. '<br />' .. message('sandboxNoticeTestcasesBlurb', 'string', {testcasesLink}) (contracted; show full) if sandboxTitle.exists then local sandboxPage = sandboxTitle.prefixedText local sandboxDisplay = message('sandboxLinkDisplay', 'string') local sandboxLink = makeWikilink(sandboxPage, sandboxDisplay) local sandboxEditUrl = sandboxTitle:fullUrl{action = 'edit'} local sandboxEditDisplay = message('sandboxEditLinkDisplay', 'string') local sandboxEditLink = makeUrlLink(sandboxEditUrl, sandboxEditDisplay) local compare Link = env.compareLinkUrl = env.compareUrl local compareLink if compareUrl then local compareDisplay = message('compareLinkDisplay', 'string') compareLink = makeUrlLink(compareUrl, compareDisplay) end sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink) else local sandboxPreload if subjectSpace == 828 then sandboxPreload = message('moduleSandboxPreload', 'string') else sandboxPreload = message('templateSandboxPreload', 'string') (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=51819.
![]() ![]() 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.
|