Module:Documentation: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
check existence of all cfg messages - this should help avoid hard-to-track-down bugs and silent failures if translators make a coding mistake
(set the proper error level for formatMessage, although it looks like it doesn't work because of the upvalues)
(check existence of all cfg messages - this should help avoid hard-to-track-down bugs and silent failures if translators make a coding mistake)
Line 32:
--]]
checkType('formatMessage', 1, cfgKey, 'string')
checkType('formatMessage', 2, valArray, 'table', true)
local msg = cfg[cfgKey] or error('formatMessage: no message found for cfg key "' .. cfgKey .. '"', 2)
if msg == nil then
error('formatMessage: no message found for cfg key "' .. cfgKey .. '"', 2)
end
if not valArray then
return msg
end
 
local function getMessageVal(match)
Line 79 ⟶ 85:
local function makeInvokeFunc(funcName)
return function (frame)
local headingArg = cfg.formatMessage('headingArg')
local args = getArgs(frame, {
valueFunc = function (key, value)
Line 112 ⟶ 118:
-- so that we don't have to worry about unclosed tags.
.tag('div')
.attr('id', cfg.formatMessage('mainDivId'))
.addClass(cfg.formatMessage('mainDivClasses'))
.wikitext(p._startBox(args))
.wikitext(p._content(args))
Line 126 ⟶ 132:
 
function p.sandboxNotice(args)
local sandboxNoticeTemplate = cfg.formatMessage('sandboxNoticeTemplate')
if not (sandboxNoticeTemplate and currentTitle.subpageText == cfg.formatMessage('sandboxSubpage')) then
return nil
end
Line 136 ⟶ 142:
.css('clear', 'both')
.done()
.wikitext(frame:expandTemplate{title = sandboxNoticeTemplate, args = {[cfg.formatMessage('sandboxNoticeLivepageParam')] = args[cfg.formatMessage('livepageArg')]}})
return tostring(notice)
end
 
function p.protectionTemplate()
local protectionTemplate = cfg.formatMessage('protectionTemplate')
if not (protectionTemplate and currentTitle.namespace == 10) then
-- Don't display the protection template if we are not in the template namespace.
Line 158 ⟶ 164:
if getProtectionLevel('move') == 'sysop' or getProtectionLevel('edit') then
-- The page is full-move protected, or full, template, or semi-protected.
return frame:expandTemplate{title = protectionTemplate, args = cfg.formatMessage('protectionTemplateArgs')}
end
return nil
Line 167 ⟶ 173:
function p._startBox(args)
-- Arg processing from {{documentation}}.
local preload = args[cfg.formatMessage('preloadArg')] -- Allow custom preloads.
local heading = args[cfg.formatMessage('headingArg')] -- Blank values are not removed.
local headingStyle = args[cfg.formatMessage('headingStyleArg')]
local content = args[cfg.formatMessage('contentArg')]
local docspace = p.docspace()
local docname = args[1] -- Other docname, if fed.
Line 182 ⟶ 188:
local namespace = docspace or currentTitle.nsText
local pagename = templatePage or currentTitle.text
docpage = namespace .. ':' .. pagename .. '/' .. cfg.formatMessage('docSubpage')
end
local docTitle = mw.title.new(docpage)
Line 218 ⟶ 224:
hspan.wikitext(heading)
elseif subjectSpace == 10 then -- Template namespace
hspan.wikitext(cfg.formatMessage('documentationIconWikitext') .. ' ' .. cfg.formatMessage('templateNamespaceHeading'))
elseif subjectSpace == 828 then -- Module namespace
hspan.wikitext(cfg.formatMessage('documentationIconWikitext') .. ' ' .. cfg.formatMessage('moduleNamespaceHeading'))
elseif subjectSpace == 6 then -- File namespace
hspan.wikitext(cfg.formatMessage('fileNamespaceHeading'))
else
hspan.wikitext(cfg.formatMessage('otherNamespaceHeading'))
end
 
Line 233 ⟶ 239:
local lspan = sbox.tag('span') -- lspan is short for "link span".
lspan
.addClass(cfg.formatMessage('startBoxLinkclasses'))
.attr('id', cfg.formatMessage('startBoxLinkId'))
if docExist then
local viewLink = makeWikilink(docpage, cfg.formatMessage('viewLinkDisplay'))
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, cfg.formatMessage('editLinkDisplay'))
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, cfg.formatMessage('historyLinkDisplay'))
local purgeLink = makeUrlLink(currentTitle:fullUrl{action = 'purge'}, cfg.formatMessage('purgeLinkDisplay'))
local text = '[%s] [%s] [%s] [%s]'
text = text:gsub('%[', '[') -- Replace square brackets with HTML entities.
Line 247 ⟶ 253:
if not preload then
if subjectSpace == 6 then -- File namespace
preload = cfg.formatMessage('fileDocpagePreload')
else
preload = cfg.formatMessage('docpagePreload')
end
end
lspan.wikitext(makeUrlLink(docTitle:fullUrl{action = 'edit', preload = preload}, cfg.formatMessage('createLinkDisplay')))
end
end
Line 262 ⟶ 268:
 
function p._content(args)
local content = args[cfg.formatMessage('contentArg')]
if not content then
local docpage = args[1]
Line 269 ⟶ 275:
content = frame:preprocess('{{ ' .. docpage .. ' }}')
else
docpage = p.docspace() .. ':' .. p.templatePage() .. '/' .. cfg.formatMessage('docSubpage')
if mw.title.new(docpage).exists then
local frame = mw.getCurrentFrame()
Line 285 ⟶ 291:
function p._endBox(args)
-- Argument processing in {{documentation}}.
local content = args[cfg.formatMessage('contentArg')]
local linkBox = args[cfg.formatMessage('linkBoxArg')] -- So "link box=off" works.
local docspace = p.docspace()
local docname = args[1] -- Other docname, if fed.
Line 297 ⟶ 303:
docpage = docname
else
docpage = docpageRoot .. '/' .. cfg.formatMessage('docSubpage')
end
local docTitle = mw.title.new(docpage)
local docExist = docTitle.exists
local docnameFed = args[1] and true
local sandbox = docpageRoot .. '/' .. cfg.formatMessage('sandboxSubpage')
local testcases = docpageRoot .. '/' .. cfg.formatMessage('testcasesSubpage')
templatePage = currentTitle.nsText .. ':' .. templatePage
 
Line 310 ⟶ 316:
-- First, check whether we should output the end box at all. Add the end box by default if the documentation
-- exists or if we are in the user, module or template namespaces.
if linkBox == cfg.formatMessage('linkBoxOff') or not (docExist or subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10) then
return nil
end
Line 316 ⟶ 322:
-- Assemble the arguments for {{fmbox}}.
local fmargs = {}
fmargs[cfg.formatMessage('fmboxIdParam')] = cfg.formatMessage('fmboxId') -- Sets fmargs.id = 'documentation-meta-data'
fmargs[cfg.formatMessage('fmboxImageParam')] = cfg.formatMessage('fmboxImageNone') -- Sets fmargs.image = 'none'
fmargs[cfg.formatMessage('fmboxStyleParam')] = cfg.formatMessage('fmboxStyle') -- Sets fmargs.style = 'background-color: #ecfcf4'
fmargs[cfg.formatMessage('fmboxTextstyleParam')] = cfg.formatMessage('fmboxTextstyle') -- Sets fmargs.textstyle = 'font-style: italic;'
 
-- Assemble the fmbox text field.
Line 330 ⟶ 336:
-- /doc exists; link to it.
local docLink = makeWikilink(docpage)
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, cfg.formatMessage('editLinkDisplay'))
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, cfg.formatMessage('historyLinkDisplay'))
text = text .. formatMessage('transcludedFromBlurb', {docLink}) .. ' ' .. makeToolbar(editLink, historyLink) .. '<br />'
elseif subjectSpace == 828 then
-- /doc does not exist; ask to create it.
local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = cfg.formatMessage('modulePreload')}, cfg.formatMessage('createLinkDisplay'))
text = text .. formatMessage('createModuleDocBlurb', {createLink}) .. '<br />'
end
Line 342 ⟶ 348:
-- We are in the user, module or template namespaces.
local sandboxLinks, testcasesLinks
local pagePossessive = subjectSpace == 828 and cfg.formatMessage('modulePossessive') or cfg.formatMessage('templatePossessive')
local sandboxTitle = mw.title.new(sandbox)
if sandboxTitle.exists then
local sandboxLink = makeWikilink(sandbox, cfg.formatMessage('sandboxLinkDisplay'))
local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, cfg.formatMessage('sandboxEditLinkDisplay'))
local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, cfg.formatMessage('compareLinkDisplay'))
sandboxLinks = sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink)
else
local sandboxPreload = subjectSpace == 828 and cfg.formatMessage('moduleSandboxPreload') or cfg.formatMessage('templateSandboxPreload')
local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, cfg.formatMessage('sandboxCreateLinkDisplay'))
local mirrorSummary = formatMessage('mirrorEditSummary', {makeWikilink(templatePage)})
local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, cfg.formatMessage('mirrorLinkDisplay'))
sandboxLinks = cfg.formatMessage('sandboxLinkDisplay') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
end
local testcaseTitle = mw.title.new(testcases)
if testcaseTitle.exists then
local testcasesLink = makeWikilink(testcases, cfg.formatMessage('testcasesLinkDisplay'))
local testcasesEditLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit'}, cfg.formatMessage('testcasesEditLinkDisplay'))
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
else
local testcasesPreload = subjectSpace == 828 and cfg.formatMessage('moduleTestcasesPreload') or cfg.formatMessage('templateTestcasesPreload')
local testcasesCreateLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit', preload = testcasesPreload}, cfg.formatMessage('testcasesCreateLinkDisplay'))
testcasesLinks = cfg.formatMessage('testcasesLinkDisplay') .. ' ' .. makeToolbar(testcasesCreateLink)
end
text = text .. formatMessage('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
local docPathLink = makeWikilink(docpage, cfg.formatMessage('docLinkDisplay'))
text = text .. formatMessage('addCategoriesBlurb', {docPathLink})
end
Line 376 ⟶ 382:
local pagetype
if subjectSpace == 10 then
pagetype = cfg.formatMessage('templatePagetype')
elseif subjectSpace == 828 then
pagetype = cfg.formatMessage('modulePagetype')
else
pagetype = cfg.formatMessage('defaultPagetype')
end
text = text .. ' ' .. makeWikilink('Special:PrefixIndex/' .. templatePage .. '/', formatMessage('subpagesLinkDisplay', {pagetype}))
end
-- Show the "print" link if it exists.
local printPage = templatePage .. '/' .. cfg.formatMessage('printSubpage')
local printTitle = mw.title.new(printPage)
if printTitle.exists then
local printLink = makeWikilink(printPage, cfg.formatMessage('printLinkDisplay'))
text = text .. '<br />' .. formatMessage('printBlurb', {printLink})
.. (cfg.formatMessage('displayPrintCategory') and makeCategoryLink(cfg.formatMessage('printCategory')) or '')
end
end
Line 404 ⟶ 410:
local ret = ''
local subpage = currentTitle.subpageText
if cfg.formatMessage('displayStrangeUsageCategory') and (subpage == cfg.formatMessage('docSubpage') or subpage == cfg.formatMessage('testcasesSubpage')) then
local sort = (currentTitle.namespace == 0 and cfg.formatMessage('strangeUsageCategoryMainspaceSort') or '') .. currentTitle.prefixedText -- Sort on namespace.
ret = ret .. makeCategoryLink(cfg.formatMessage('strangeUsageCategory'), sort)
end
return ret
Line 425 ⟶ 431:
-- Determines the template page. No namespace or interwiki prefixes are included.
local subpage = currentTitle.subpageText
if subpage == cfg.formatMessage('sandboxSubpage') or subpage == cfg.formatMessage('testcasesSubpage') then
return currentTitle.baseText
else
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu