Changes

Module:Documentation

142 bytes added, 01:39, 20 January 2014
use hyphens for message names rather than camelCase, in line with MediaWiki
-- message are substituted with values from the table keys [1], [2] etc.
-- For example, if the message cfg.fooMessage had the value 'Foo $2 bar $1.',
-- message('fooMessagefoo-message', {'baz', 'qux'}) would return "Foo qux bar baz."
--]]
local msg = cfg[cfgKey]
-- so that we don't have to worry about unclosed tags.
.tag('div')
.attr('id', message('mainDivIdmain-div-id')) .addClass(message('mainDivClassesmain-div-classes'))
.newline()
.wikitext(p._startBox(args, env))
title = mw.title.new(titleArg)
if not title then
error(message('titleArgErrortitle-arg-error', {titleArg}))
end
else
local title = env.title
local subpage = title.subpageText
if subpage == message('sandboxSubpagesandbox-subpage') or subpage == message('testcasesSubpagetestcases-subpage') then
return title.basePageTitle
else
docpage = docname
else
docpage = env.docpageRoot .. '/' .. message('docSubpagedoc-subpage')
end
return mw.title.new(docpage)
function envFuncs.sandboxTitle()
-- Title object for the /sandbox subpage.
return mw.title.new(env.docpageRoot .. '/' .. message('sandboxSubpagesandbox-subpage'))
end
function envFuncs.testcasesTitle()
-- Title object for the /testcases subpage.
return mw.title.new(env.docpageRoot .. '/' .. message('testcasesSubpagetestcases-subpage'))
end
function envFuncs.printTitle()
-- Title object for the /Print subpage.
return env.templateTitle:subPageTitle(message('printSubpageprint-subpage'))
end
local omargs = {} -- Args for {{ombox}}.
-- Get the image wikitext.
omargs.image = message('sandboxNoticeImagesandbox-notice-image')
-- Get the text. We start with the opening blurb, which is something like
-- "This is the template sandbox for [[Template:Foo]] (diff)."
if isPreviewing or not compareUrl then
-- 'This is the [[Wikipedia:Template test cases|template sandbox]] page for $1.'
text = text .. message('sandboxNoticeBlurbsandbox-notice-blurb', {templateLink})
else
-- 'This is the [[Wikipedia:Template test cases|template sandbox]] page for $1 ($2).'
local compareDisplay = message('sandboxNoticeCompareLinkDisplaysandbox-notice-compare-link-display')
local compareLink = makeUrlLink(compareUrl, compareDisplay)
text = text .. message('sandboxNoticeDiffBlurbsandbox-notice-diff-blurb', {templateLink, 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('sandboxNoticeTestcasesLinkDisplaysandbox-notice-testcases-link-display')
local testcasesLink = makeWikilink(testcasesTitle.prefixedText, testcasesLinkDisplay)
text = text .. '<br />' .. message('sandboxNoticeTestcasesBlurbsandbox-notice-testcases-blurb', {testcasesLink})
end
-- Add the page to [[Category:Template sandboxes]].
text = text .. makeCategoryLink(message('sandboxCategorysandbox-category'))
omargs.text = text
return messageBox.main('ombox', omargs)
function p.protectionTemplate(env)
local title = env.title
local protectionTemplate = message('protectionTemplateprotection-template')
if not (protectionTemplate and title.namespace == 10) then
-- Don't display the protection template if we are not in the template namespace.
if getProtectionLevel('move', prefixedTitle) == 'sysop' or getProtectionLevel('edit', prefixedTitle) then
-- The page is full-move protected, or full, template, or semi-protected.
return frame:expandTemplate{title = protectionTemplate, args = message('protectionTemplateArgsprotection-template-args', nil, 'table')}
end
return nil
data.docTitle = docTitle
-- View, display, edit, and purge links if /doc exists.
data.viewLinkDisplay = message('viewLinkDisplayview-link-display') data.editLinkDisplay = message('editLinkDisplayedit-link-display') data.historyLinkDisplay = message('historyLinkDisplayhistory-link-display') data.purgeLinkDisplay = message('purgeLinkDisplaypurge-link-display')
-- Create link if /doc doesn't exist.
local preload = args.preload
if not preload then
if env.subjectSpace == 6 then -- File namespace
preload = message('fileDocpagePreloadfile-docpage-preload')
else
preload = message('docpagePreloaddocpage-preload')
end
end
data.preload = preload
data.createLinkDisplay = message('createLinkDisplaycreate-link-display')
return data
end
data.heading = heading
elseif subjectSpace == 10 then -- Template namespace
data.heading = message('documentationIconWikitextdocumentation-icon-wikitext') .. ' ' .. message('templateNamespaceHeadingtemplate-namespace-heading')
elseif subjectSpace == 828 then -- Module namespace
data.heading = message('documentationIconWikitextdocumentation-icon-wikitext') .. ' ' .. message('moduleNamespaceHeadingmodule-namespace-heading')
elseif subjectSpace == 6 then -- File namespace
data.heading = message('fileNamespaceHeadingfile-namespace-heading')
else
data.heading = message('otherNamespacesHeadingother-namespaces-heading')
end
-- [view][edit][history][purge] or [create] links.
if links then
data.linksClass = message('startBoxLinkclassesstart-box-linkclasses') data.linksId = message('startBoxLinkIdstart-box-link-id')
data.links = links
end
-- Assemble the arguments for {{fmbox}}.
local fmargs = {}
fmargs.id = message('fmboxIdfmbox-id') -- Sets 'documentation-meta-data' fmargs.image = message('fmboxImageNonefmbox-image-none') -- Sets 'none' fmargs.style = message('fmboxStylefmbox-style') -- Sets 'background-color: #ecfcf4' fmargs.textstyle = message('fmboxTextstylefmbox-textstyle') -- 'font-style: italic;'
-- Assemble the fmbox text field.
local ret
if printTitle.exists then
local printLink = makeWikilink(printTitle.prefixedText, message('printLinkDisplayprint-link-display')) ret = message('printBlurbprint-blurb', {printLink}) local displayPrintCategory = message('displayPrintCategorydisplay-print-category', nil, 'boolean')
if displayPrintCategory then
ret = ret .. makeCategoryLink(message('printCategoryprint-category'))
end
end
local pagetype
if subjectSpace == 10 then
pagetype = message('templatePagetypetemplate-pagetype')
elseif subjectSpace == 828 then
pagetype = message('modulePagetypemodule-pagetype')
else
pagetype = message('defaultPagetypedefault-pagetype')
end
return makeWikilink(
'Special:PrefixIndex/' .. templateTitle.prefixedText .. '/',
message('subpagesLinkDisplaysubpages-link-display', {pagetype})
)
end
end
-- Make the blurb.
local docPathLink = makeWikilink(docTitle.prefixedText, message('docLinkDisplaydoc-link-display')) return message('addCategoriesBlurbadd-categories-blurb', {docPathLink})
end
local docLink = makeWikilink(docTitle.prefixedText)
local editUrl = docTitle:fullUrl{action = 'edit'}
local editDisplay = message('editLinkDisplayedit-link-display')
local editLink = makeUrlLink(editUrl, editDisplay)
local historyUrl = docTitle:fullUrl{action = 'history'}
local historyDisplay = message('historyLinkDisplayhistory-link-display')
local historyLink = makeUrlLink(historyUrl, historyDisplay)
ret = message('transcludedFromBlurbtranscluded-from-blurb', {docLink})
.. ' '
.. makeToolbar(editLink, historyLink)
elseif env.subjectSpace == 828 then
-- /doc does not exist; ask to create it.
local createUrl = docTitle:fullUrl{action = 'edit', preload = message('modulePreloadmodule-preload')} local createDisplay = message('createLinkDisplaycreate-link-display')
local createLink = makeUrlLink(createUrl, createDisplay)
ret = message('createModuleDocBlurbcreate-module-doc-blurb', {createLink})
.. '<br />'
end
if sandboxTitle.exists then
local sandboxPage = sandboxTitle.prefixedText
local sandboxDisplay = message('sandboxLinkDisplaysandbox-link-display')
local sandboxLink = makeWikilink(sandboxPage, sandboxDisplay)
local sandboxEditUrl = sandboxTitle:fullUrl{action = 'edit'}
local sandboxEditDisplay = message('sandboxEditLinkDisplaysandbox-edit-link-display')
local sandboxEditLink = makeUrlLink(sandboxEditUrl, sandboxEditDisplay)
local compareUrl = env.compareUrl
local compareLink
if compareUrl then
local compareDisplay = message('compareLinkDisplaycompare-link-display')
compareLink = makeUrlLink(compareUrl, compareDisplay)
end
local sandboxPreload
if subjectSpace == 828 then
sandboxPreload = message('moduleSandboxPreloadmodule-sandbox-preload')
else
sandboxPreload = message('templateSandboxPreloadtemplate-sandbox-preload')
end
local sandboxCreateUrl = sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}
local sandboxCreateDisplay = message('sandboxCreateLinkDisplaysandbox-create-link-display')
local sandboxCreateLink = makeUrlLink(sandboxCreateUrl, sandboxCreateDisplay)
local mirrorSummary = message('mirrorEditSummarymirror-edit-summary', {makeWikilink(templatePage)})
local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}
local mirrorDisplay = message('mirrorLinkDisplaymirror-link-display')
local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay)
sandboxLinks = message('sandboxLinkDisplaysandbox-link-display') .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
end
if testcasesTitle.exists then
local testcasesPage = testcasesTitle.prefixedText
local testcasesDisplay = message('testcasesLinkDisplaytestcases-link-display')
local testcasesLink = makeWikilink(testcasesPage, testcasesDisplay)
local testcasesEditUrl = testcasesTitle:fullUrl{action = 'edit'}
local testcasesEditDisplay = message('testcasesEditLinkDisplaytestcases-edit-link-display')
local testcasesEditLink = makeUrlLink(testcasesEditUrl, testcasesEditDisplay)
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
local testcasesPreload
if subjectSpace == 828 then
testcasesPreload = message('moduleTestcasesPreloadmodule-testcases-preload')
else
testcasesPreload = message('templateTestcasesPreloadtemplate-testcases-preload')
end
local testcasesCreateUrl = testcasesTitle:fullUrl{action = 'edit', preload = testcasesPreload}
local testcasesCreateDisplay = message('testcasesCreateLinkDisplaytestcases-create-link-display')
local testcasesCreateLink = makeUrlLink(testcasesCreateUrl, testcasesCreateDisplay)
testcasesLinks = message('testcasesLinkDisplaytestcases-link-display') .. ' ' .. makeToolbar(testcasesCreateLink)
end
local messageName
local ret = ''
local subpage = title.subpageText
if message('displayStrangeUsageCategorydisplay-strange-usage-category', nil, 'boolean') and (subpage == message('docSubpagedoc-subpage') or subpage == message('testcasesSubpagetestcases-subpage')) then local sort = (title.namespace == 0 and message('strangeUsageCategoryMainspaceSortstrange-usage-category-mainspace-sort') or '') .. title.prefixedText -- Sort on namespace. ret = ret .. makeCategoryLink(message('strangeUsageCategorystrange-usage-category'), sort)
end
return ret
Anonymous user