Changes

Module:Documentation

1,530 bytes removed, 19:04, 14 January 2014
finish splitting the _startBox function into smaller functions
function p._startBox(args, env)
local title = env.title local subjectSpace = env.subjectSpace  -- Arg processing from {{documentation}}. local preload = argsGenerate [view][edit][history][message('preloadArg', 'string')purge] -- Allow custom preloads. local heading = argsor [message('headingArg', 'string')create] -- Blank values are not removedlinks. local headingStyle = args[message('headingStyleArg', 'string')]links
local content = args[message('contentArg', 'string')]
local docspace = env.docspaceif not content then local docname = args[1] -- Other docname, No need to include the links if fedthe documentation is on the template page itself. local templatePage linksData = p.makeStartBoxLinksData(args, env) links = p.templatePagerenderStartBoxLinks(linksData) end -- Arg processing from {{documentation/Generate the start box2}}box html. local docpagedata = p.makeStartBoxData(args, env, links) if docname type(data) == 'table' then docpage return p.renderStartBox(data) elseif type(data) = docname= 'string' then -- data is an error message. return data
else
local namespace = docspace or title.nsText local pagename = templatePage or title.text docpage = namespace .. ':' .. pagename .. '/' .. message('docSubpage', 'string') end local docTitle = mw.title.new(docpage) local docExist = docTitle.exists -- Output from {{documentation/start box}}.  -- First, check the User specified no heading parameter. if heading == '' then -- Heading is defined but blank, so do nothing.
return nil
end
 
-- Build the start box div.
local sbox = htmlBuilder.create('div')
sbox
.css('padding-bottom', '3px')
.css('border-bottom', '1px solid #aaa')
.css('margin-bottom', '1ex')
.newline()
 
-- Make the heading.
local hspan = sbox.tag('span')
if headingStyle then
hspan.cssText(headingStyle)
elseif subjectSpace == 10 then
-- We are in the template or template talk namespaces.
hspan
.css('font-weight', 'bold')
.css('font-size', '125%')
else
hspan.css('font-size', '150%')
end
if heading then
-- "heading" has data.
hspan.wikitext(heading)
elseif subjectSpace == 10 then -- Template namespace
hspan.wikitext(message('documentationIconWikitext', 'string') .. ' ' .. message('templateNamespaceHeading', 'string'))
elseif subjectSpace == 828 then -- Module namespace
hspan.wikitext(message('documentationIconWikitext', 'string') .. ' ' .. message('moduleNamespaceHeading', 'string'))
elseif subjectSpace == 6 then -- File namespace
hspan.wikitext(message('fileNamespaceHeading', 'string'))
else
hspan.wikitext(message('otherNamespacesHeading', 'string'))
end
 
-- Add the [view][edit][history][purge] or [create] links.
-- Check for the content parameter first, as we don't need the links if the documentation
-- content is being entered directly onto the template page.
if not content then
local lspan = sbox.tag('span') -- lspan is short for "link span".
lspan
.addClass(message('startBoxLinkclasses', 'string'))
.attr('id', message('startBoxLinkId', 'string'))
if docExist then
local viewLink = makeWikilink(docpage, message('viewLinkDisplay', 'string'))
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, message('editLinkDisplay', 'string'))
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, message('historyLinkDisplay', 'string'))
local purgeLink = makeUrlLink(title:fullUrl{action = 'purge'}, message('purgeLinkDisplay', 'string'))
local text = '[%s] [%s] [%s] [%s]'
text = text:gsub('%[', '[') -- Replace square brackets with HTML entities.
text = text:gsub('%]', ']')
lspan.wikitext(mw.ustring.format(text, viewLink, editLink, historyLink, purgeLink))
else
if not preload then
if subjectSpace == 6 then -- File namespace
preload = message('fileDocpagePreload', 'string')
else
preload = message('docpagePreload', 'string')
end
end
lspan.wikitext(makeUrlLink(docTitle:fullUrl{action = 'edit', preload = preload}, message('createLinkDisplay', 'string')))
end
end
 
return tostring(sbox)
end
ret = mw.ustring.format(ret, viewLink, editLink, historyLink, purgeLink)
else
lspan.wikitext(ret = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = data.preload}, data.createLinkDisplay) endend function p.makeStartBoxData(args, env, links) local subjectSpace = env.subjectSpace local data = {} -- Heading local heading = args[message('headingArg', 'string')] -- Blank values are not removed. if heading == '' then -- Don't display the start box if the heading arg is defined but blank. return nil
end
if heading then
data.heading = heading
elseif subjectSpace == 10 then -- Template namespace
data.heading = message('documentationIconWikitext', 'string') .. ' ' .. message('templateNamespaceHeading', 'string')
elseif subjectSpace == 828 then -- Module namespace
data.heading = message('documentationIconWikitext', 'string') .. ' ' .. message('moduleNamespaceHeading', 'string')
elseif subjectSpace == 6 then -- File namespace
data.heading = message('fileNamespaceHeading', 'string')
else
data.heading = message('otherNamespacesHeading', 'string')
end
-- Heading CSS
local headingStyle = args[message('headingStyleArg', 'string')]
if headingStyle then
data.headingStyleText = headingStyle
elseif subjectSpace == 10 then
-- We are in the template or template talk namespaces.
data.headingFontWeight = 'bold'
data.headingFontSize = '125%'
else
data.headingFontSize = '150%'
end
-- [view][edit][history][purge] or [create] links.
if links then
data.linksClass = message('startBoxLinkclasses', 'string')
data.linksId = message('startBoxLinkId', 'string')
data.links = links
end
return data
end
.css('font-size', data.headingFontSize)
.wikitext(data.heading)
if local links = data.showLinks links if links then
sbox.tag('span')
.addClass(data.linksClass)
.attr('id', data.linksId)
.wikitext(data.links)
end
return tostring(sbox)
Anonymous user