Changes

Jump to navigation Jump to search
1,081 bytes added ,  16:05, 16 December 2015
m
1 revision: family tree template
Line 3: Line 3:  
-- Get required modules.
 
-- Get required modules.
 
local getArgs = require('Module:Arguments').getArgs
 
local getArgs = require('Module:Arguments').getArgs
local htmlBuilder = require('Module:HtmlBuilder')
   
local messageBox = require('Module:Message box')
 
local messageBox = require('Module:Message box')
   Line 128: Line 127:  
--]]
 
--]]
 
local env = p.getEnvironment(args)
 
local env = p.getEnvironment(args)
local root = htmlBuilder.create()
+
local root = mw.html.create()
 
root
 
root
.wikitext(p.protectionTemplate(env))
+
:wikitext(p.protectionTemplate(env))
.wikitext(p.sandboxNotice(args, env))
+
:wikitext(p.sandboxNotice(args, env))
 
-- This div tag is from {{documentation/start box}}, but moving it here
 
-- This div tag is from {{documentation/start box}}, but moving it here
 
-- so that we don't have to worry about unclosed tags.
 
-- so that we don't have to worry about unclosed tags.
.tag('div')
+
:tag('div')
.attr('id', message('main-div-id'))
+
:attr('id', message('main-div-id'))
.addClass(message('main-div-classes'))
+
:addClass(message('main-div-classes'))
.newline()
+
:newline()
.wikitext(p._startBox(args, env))
+
:wikitext(p._startBox(args, env))
.wikitext(p._content(args, env))
+
:wikitext(p._content(args, env))
.tag('div')
+
:tag('div')
.css('clear', 'both') -- So right or left floating items don't stick out of the doc box.
+
:css('clear', 'both') -- So right or left floating items don't stick out of the doc box.
.newline()
+
:newline()
.done()
+
:done()
.done()
+
:done()
.wikitext(p._endBox(args, env))
+
:wikitext(p._endBox(args, env))
.newline()
+
:wikitext(p.addTrackingCategories(env))
.wikitext(p.addTrackingCategories(env))
   
return tostring(root)
 
return tostring(root)
 
end
 
end
Line 170: Line 168:  
--
 
--
 
-- Data includes:
 
-- Data includes:
 +
-- env.protectionLevels - the protection levels table of the title object.
 
-- env.subjectSpace - the number of the title's subject namespace.
 
-- env.subjectSpace - the number of the title's subject namespace.
 
-- env.docSpace - the number of the namespace the title puts its documentation in.
 
-- env.docSpace - the number of the namespace the title puts its documentation in.
Line 269: Line 268:  
--]]
 
--]]
 
return env.templateTitle:subPageTitle(message('print-subpage'))
 
return env.templateTitle:subPageTitle(message('print-subpage'))
 +
end
 +
 +
function envFuncs.protectionLevels()
 +
-- The protection levels table of the title object.
 +
return env.title.protectionLevels
 
end
 
end
   Line 327: Line 331:  
--  
 
--  
 
-- Messages:
 
-- Messages:
-- 'sandbox-notice-image' --> '[[Image:Sandbox.png|50px|alt=|link=]]'
+
-- 'sandbox-notice-image' --> '[[Image:Sandbox.svg|50px|alt=|link=]]'
 
-- 'sandbox-notice-blurb' --> 'This is the $1 for $2.'
 
-- 'sandbox-notice-blurb' --> 'This is the $1 for $2.'
 
-- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).'
 
-- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).'
Line 374: Line 378:  
local testcasesTitle = env.testcasesTitle
 
local testcasesTitle = env.testcasesTitle
 
if testcasesTitle and testcasesTitle.exists then
 
if testcasesTitle and testcasesTitle.exists then
local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display')
+
if testcasesTitle.namespace == mw.site.namespaces.Module.id then
local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay)
+
local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display')
text = text .. '<br />' .. message('sandbox-notice-testcases-blurb', {testcasesLink})
+
local testcasesRunLinkDisplay = message('sandbox-notice-testcases-run-link-display')
 +
local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay)
 +
local testcasesRunLink = makeWikilink(testcasesTitle.talkPageTitle.prefixedText, testcasesRunLinkDisplay)
 +
text = text .. '<br />' .. message('sandbox-notice-testcases-run-blurb', {testcasesLink, testcasesRunLink})
 +
else
 +
local testcasesLinkDisplay = message('sandbox-notice-testcases-link-display')
 +
local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay)
 +
text = text .. '<br />' .. message('sandbox-notice-testcases-blurb', {testcasesLink})
 +
end
 
end
 
end
 
-- Add the sandbox to the sandbox category.
 
-- Add the sandbox to the sandbox category.
 
text = text .. makeCategoryLink(message('sandbox-category'))
 
text = text .. makeCategoryLink(message('sandbox-category'))
 
omargs.text = text
 
omargs.text = text
return messageBox.main('ombox', omargs)
+
local ret = '<div style="clear: both;"></div>'
 +
ret = ret .. messageBox.main('ombox', omargs)
 +
return ret
 
end
 
end
   Line 390: Line 404:  
-- 'protection-template' --> 'pp-template'
 
-- 'protection-template' --> 'pp-template'
 
-- 'protection-template-args' --> {docusage = 'yes'}
 
-- 'protection-template-args' --> {docusage = 'yes'}
 +
local protectionLevels, mProtectionBanner
 
local title = env.title
 
local title = env.title
local protectionTemplate = message('protection-template')
+
if title.namespace ~= 10 and title.namespace ~= 828 then
local namespace = title.namespace
  −
if not (protectionTemplate and (namespace == 10 or namespace == 828)) then
   
-- Don't display the protection template if we are not in the template or module namespaces.
 
-- Don't display the protection template if we are not in the template or module namespaces.
 
return nil
 
return nil
 
end
 
end
local frame = mw.getCurrentFrame()
+
protectionLevels = env.protectionLevels
local function getProtectionLevel(protectionType, page)
+
if not protectionLevels then
-- Gets the protection level for page, or for the current page if page is not specified.
+
return nil
local level = frame:callParserFunction('PROTECTIONLEVEL', protectionType, page)
  −
if level ~= '' then
  −
return level
  −
else
  −
return nil -- The parser function returns the blank string if there is no match.
  −
end
   
end
 
end
local prefixedTitle = title.prefixedText
+
local editProt = protectionLevels.edit and protectionLevels.edit[1]
if getProtectionLevel('move', prefixedTitle) == 'sysop' or getProtectionLevel('edit', prefixedTitle) then
+
local moveProt = protectionLevels.move and protectionLevels.move[1]
-- The page is full-move protected, or full, template, or semi-protected.
+
if editProt then
return frame:expandTemplate{title = protectionTemplate, args = message('protection-template-args', nil, 'table')}
+
-- The page is edit-protected.
 +
mProtectionBanner = require('Module:Protection banner')
 +
local reason = message('protection-reason-edit')
 +
return mProtectionBanner._main{reason, small = true}
 +
elseif moveProt and moveProt ~= 'autoconfirmed' then
 +
-- The page is move-protected but not edit-protected. Exclude move
 +
-- protection with the level "autoconfirmed", as this is equivalent to
 +
-- no move protection at all.
 +
mProtectionBanner = require('Module:Protection banner')
 +
return mProtectionBanner._main{action = 'move', small = true}
 +
else
 +
return nil
 
end
 
end
return nil
   
end
 
end
   Line 539: Line 556:  
--
 
--
 
-- Messages:
 
-- Messages:
-- 'documentation-icon-wikitext' --> '[[File:Template-info.png|50px|link=|alt=Documentation icon]]'
+
-- 'documentation-icon-wikitext' --> '[[File:Test Template Info-Icon - Version (2).svg|50px|link=|alt=Documentation icon]]'
 
-- 'template-namespace-heading' --> 'Template documentation'
 
-- 'template-namespace-heading' --> 'Template documentation'
 
-- 'module-namespace-heading' --> 'Module documentation'
 
-- 'module-namespace-heading' --> 'Module documentation'
Line 599: Line 616:  
-- Renders the start box html.
 
-- Renders the start box html.
 
-- @data - a table of data generated by p.makeStartBoxData.
 
-- @data - a table of data generated by p.makeStartBoxData.
local sbox = htmlBuilder.create('div')
+
local sbox = mw.html.create('div')
 
sbox
 
sbox
.css('padding-bottom', '3px')
+
:css('padding-bottom', '3px')
.css('border-bottom', '1px solid #aaa')
+
:css('border-bottom', '1px solid #aaa')
.css('margin-bottom', '1ex')
+
:css('margin-bottom', '1ex')
.newline()
+
:newline()
.tag('span')
+
:tag('span')
.cssText(data.headingStyleText)
+
:cssText(data.headingStyleText)
.css('font-weight', data.headingFontWeight)
+
:css('font-weight', data.headingFontWeight)
.css('font-size', data.headingFontSize)
+
:css('font-size', data.headingFontSize)
.wikitext(data.heading)
+
:wikitext(data.heading)
 
local links = data.links
 
local links = data.links
 
if links then
 
if links then
sbox.tag('span')
+
sbox:tag('span')
.addClass(data.linksClass)
+
:addClass(data.linksClass)
.attr('id', data.linksId)
+
:attr('id', data.linksId)
.wikitext(links)
+
:wikitext(links)
 
end
 
end
 
return tostring(sbox)
 
return tostring(sbox)
Line 634: Line 651:  
local content = args.content
 
local content = args.content
 
if not content and docTitle and docTitle.exists then
 
if not content and docTitle and docTitle.exists then
local frame = mw.getCurrentFrame()
+
content = args._content or mw.getCurrentFrame():expandTemplate{title = docTitle.prefixedText}
content = frame:expandTemplate{title = docTitle.prefixedText}
   
end
 
end
 
-- The line breaks below are necessary so that "=== Headings ===" at the start and end
 
-- The line breaks below are necessary so that "=== Headings ===" at the start and end
 
-- of docs are interpreted correctly.
 
-- of docs are interpreted correctly.
 
return '\n' .. (content or '') .. '\n'  
 
return '\n' .. (content or '') .. '\n'  
 +
end
 +
 +
p.contentTitle = makeInvokeFunc('_contentTitle')
 +
 +
function p._contentTitle(args, env)
 +
env = env or p.getEnvironment(args)
 +
local docTitle = env.docTitle
 +
if not args.content and docTitle and docTitle.exists then
 +
return docTitle.prefixedText
 +
else
 +
return ''
 +
end
 
end
 
end
   Line 702: Line 730:  
-- Add sandbox and testcases links.
 
-- Add sandbox and testcases links.
 
-- "Editors can experiment in this template's sandbox and testcases pages."
 
-- "Editors can experiment in this template's sandbox and testcases pages."
text = text .. p.makeExperimentBlurb(args, env)
+
text = text .. (p.makeExperimentBlurb(args, env) or '')
 
text = text .. '<br />'
 
text = text .. '<br />'
 
if not args.content and not args[1] then
 
if not args.content and not args[1] then
Line 783: Line 811:  
-- 'mirror-edit-summary' --> 'Create sandbox version of $1'
 
-- 'mirror-edit-summary' --> 'Create sandbox version of $1'
 
-- 'mirror-link-display' --> 'mirror'
 
-- 'mirror-link-display' --> 'mirror'
 +
-- 'mirror-link-preload' --> 'Template:Documentation/mirror'
 
-- 'sandbox-link-display' --> 'sandbox'
 
-- 'sandbox-link-display' --> 'sandbox'
 
-- 'testcases-link-display' --> 'testcases'
 
-- 'testcases-link-display' --> 'testcases'
 
-- 'testcases-edit-link-display'--> 'edit'
 
-- 'testcases-edit-link-display'--> 'edit'
-- 'module-testcases-preload' --> 'Template:Documentation/preload-module-testcases'
   
-- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox'
 
-- 'template-sandbox-preload' --> 'Template:Documentation/preload-sandbox'
 
-- 'testcases-create-link-display' --> 'create'
 
-- 'testcases-create-link-display' --> 'create'
Line 831: Line 859:  
local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay)
 
local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay)
 
local mirrorSummary = message('mirror-edit-summary', {makeWikilink(templatePage)})
 
local mirrorSummary = message('mirror-edit-summary', {makeWikilink(templatePage)})
local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}
+
local mirrorPreload = message('mirror-link-preload')
 +
local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = mirrorPreload, summary = mirrorSummary}
 
local mirrorDisplay = message('mirror-link-display')
 
local mirrorDisplay = message('mirror-link-display')
 
local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay)
 
local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay)

Navigation menu