Difference between revisions of "Module:Documentation"

1,199 bytes added ,  07:20, 16 January 2014
convert the sandbox notice code to Lua
>Mr. Stradivarius
(move diff link to the env table)
>Mr. Stradivarius
(convert the sandbox notice code to Lua)
Line 295: Line 295:


function p.sandboxNotice(args, env)
function p.sandboxNotice(args, env)
local sandboxNoticeTemplate = message('sandboxNoticeTemplate', 'string')
local title = env.title
if not (sandboxNoticeTemplate and env.title.subpageText == message('sandboxSubpage', 'string')) then
local sandboxTitle = env.sandboxTitle
local templateTitle = env.templateTitle
if not (title and sandboxTitle and templateTitle and mw.title.equals(title, sandboxTitle)) then
return nil
return nil
end
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 frame = mw.getCurrentFrame()
local notice = htmlBuilder.create()
local isPreviewing = frame:callParserFunction('REVISIONID') == '' -- True if the page is being previewed.
notice
local templateLink = makeWikilink(templateTitle.prefixedText)
.tag('div')
if isPreviewing then
.css('clear', 'both')
-- 'This is the [[Wikipedia:Template test cases|template sandbox]] page for $1.'
.done()
text = text .. message('sandboxNoticeBlurb', 'string', {templateLink})
.wikitext(frame:expandTemplate{title = sandboxNoticeTemplate, args = {[message('sandboxNoticeLivepageParam')] = args.livepage}})
else
return tostring(notice)
-- 'This is the [[Wikipedia:Template test cases|template sandbox]] page for $1 ($2).'
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 .. ' ' .. message('sandboxNoticeTestcasesBlurb', 'string', {testcasesLink})
end
-- Add the page to [[Category:Template sandboxes]].
text = text .. makeCategoryLink(message('sandboxCategory', 'string'))
omargs.text = text
return messageBox.main('ombox', omargs)
end
end


Anonymous user