Module:Documentation: Difference between revisions

Jump to navigation Jump to search
m>Mr. Stradivarius
finish i18n for the startBox function
m>Mr. Stradivarius
i18n of link names in the endBox function
Line 21: Line 21:
cfg.contentArg = 'content' -- Passes documentation content directly from the {{documentation}} invocation.
cfg.contentArg = 'content' -- Passes documentation content directly from the {{documentation}} invocation.
cfg.linkBoxArg = 'link box' -- Specifies a custom link box (end box) or prevents it from being generated.
cfg.linkBoxArg = 'link box' -- Specifies a custom link box (end box) or prevents it from being generated.
-- Argument values
-- The following are argument values that are checked by the module.
cfg.linkBoxOff = 'off' -- The value to send to cfg.linkBoxArg to turn the link box off.


-- Software settings
-- Software settings
Line 26: Line 31:
-- defined in commons.css or the names of templates.
-- defined in commons.css or the names of templates.


cfg.docSubpage = 'doc' -- The name of the subpage typically used for documentation pages.
cfg.sandboxSubpage = 'sandbox' -- The name of the template subpage typically used for sandboxes.
cfg.testcasesSubpage = 'testcases' -- The name of the template subpage typically used for test cases.
cfg.mainDivId = 'template-documentation' -- The "id" attribute of the main HTML "div" tag.
cfg.mainDivId = 'template-documentation' -- The "id" attribute of the main HTML "div" tag.
cfg.mainDivClasses = 'template-documentation iezoomfix' -- The CSS classes added to the main HTML "div" tag.
cfg.mainDivClasses = 'template-documentation iezoomfix' -- The CSS classes added to the main HTML "div" tag.
cfg.sandboxSubpage = 'sandbox' -- The name of the template subpage typically used for sandboxes.
cfg.sandboxNoticeTemplate = 'template sandbox notice' -- The name of the template to display at the top of sandbox pages.
cfg.sandboxNoticeTemplate = 'template sandbox notice' -- The name of the template to display at the top of sandbox pages.
cfg.sandboxNoticeLivepageParam = 1 -- The parameter of the sandbox notice template to send the cfg.livepageArg to.
cfg.sandboxNoticeLivepageParam = 1 -- The parameter of the sandbox notice template to send the cfg.livepageArg to.
cfg.protectionTemplate = 'pp-template' -- The name of the template that displays the protection icon (a padlock on enwiki).
cfg.protectionTemplate = 'pp-template' -- The name of the template that displays the protection icon (a padlock on enwiki).
cfg.protectionTemplateArgs = {docusage = 'yes'} -- Any arguments to send to the protection template.
cfg.protectionTemplateArgs = {docusage = 'yes'} -- Any arguments to send to the protection template.
cfg.docSubpage = 'doc' -- The name of the subpage typically used for documentation pages.
cfg.startBoxLinkclasses = 'mw-editsection plainlinks' -- The CSS classes used for the [view][edit][history] or [create] links in the start box.
cfg.startBoxLinkclasses = 'mw-editsection plainlinks' -- The CSS classes used for the [view][edit][history] or [create] links in the start box.
cfg.startBoxLinkId = 'doc_editlinks' -- The HTML "id" attribute for the links in the start box.
cfg.startBoxLinkId = 'doc_editlinks' -- The HTML "id" attribute for the links in the start box.
cfg.fileDocpagePreload = 'Template:Documentation/preload-filespace' -- A preload file for documentation page in the file namespace.
cfg.fileDocpagePreload = 'Template:Documentation/preload-filespace' -- A preload file for documentation page in the file namespace.
cfg.docpagePreload = 'Template:Documentation/preload-filespace' -- A preload file for template documentation pages in all namespaces.
cfg.docpagePreload = 'Template:Documentation/preload-filespace' -- A preload file for template documentation pages in all namespaces.
-- Settings for the {{fmbox}} template.
cfg.fmboxIdParam = 'id' -- The name of the "id" parameter of {{fmbox}}.
cfg.fmboxId = 'documentation-meta-data' -- The id sent to the "id" parameter of the {{fmbox}} template.
cfg.fmboxImageParam = 'image' -- The name of the "image" parameter of {{fmbox}}.
cfg.fmboxImageNone = 'none' -- The value to suppress image output from the "image" parameter of {{fmbox}}.
cfg.fmboxStyleParam = 'style' -- The name of the "style" parameter of {{fmbox}}.
cfg.fmboxStyle = 'background-color: #ecfcf4' -- The value sent to the style parameter of {{fmbox}}.
cfg.fmboxTextstyleParam = 'textstyle' -- The name of the "textstyle" parameter of {{fmbox}}.
cfg.fmboxTextstyle = 'font-style: italic;' -- The value send to the "textstyle parameter of {{fmbox}}.


-- Display settings
-- Display settings
Line 48: Line 65:
cfg.createLinkDisplay = 'create' -- The text to display for "create" links.
cfg.createLinkDisplay = 'create' -- The text to display for "create" links.
cfg.sandboxLinkDisplay = 'sandbox' -- The text to display for "sandbox" links.
cfg.sandboxLinkDisplay = 'sandbox' -- The text to display for "sandbox" links.
cfg.sandboxEditLinkDisplay = 'edit' -- The text to display for sandbox "edit" links.
cfg.sandboxCreateLinkDisplay = 'create' -- The text to display for sandbox "create" links.
cfg.compareLinkDisplay = 'diff' -- The text to display for "compare" links.
cfg.mirrorLinkDisplay = 'mirror' -- The text to display for "mirror" links.
cfg.testcasesLinkDisplay = 'testcases' -- The text to display for "testcases" links.
cfg.testcasesEditLinkDisplay = 'edit' -- The text to display for test cases "edit" links.
cfg.testcasesCreateLinkDisplay = 'create' -- The text to display for test cases "create" links.
cfg.documentationIconWikitext = '[[File:Template-info.png|50px|link=|alt=Documentation icon]]' -- The wikitext for the icon shown at the top of the template.
cfg.documentationIconWikitext = '[[File:Template-info.png|50px|link=|alt=Documentation icon]]' -- The wikitext for the icon shown at the top of the template.
cfg.templateNamespaceHeading = 'Template documentation' -- The heading shown in the template namespace.
cfg.templateNamespaceHeading = 'Template documentation' -- The heading shown in the template namespace.
Line 327: Line 351:
local docnameFed = args[1] and true
local docnameFed = args[1] and true
local sandbox = docpageRoot .. '/' .. cfg.sandboxSubpage
local sandbox = docpageRoot .. '/' .. cfg.sandboxSubpage
local testcases = docpageRoot .. '/testcases'
local testcases = docpageRoot .. '/' .. cfg.testcasesSubpage
templatePage = currentTitle.nsText .. ':' .. templatePage
templatePage = currentTitle.nsText .. ':' .. templatePage


Line 334: Line 358:
-- First, check whether we should output the end box at all. Add the end box by default if the documentation
-- 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.
-- exists or if we are in the user, module or template namespaces.
if linkBox == 'off' or not (docExist or subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10) then
if linkBox == cfg.linkBoxOff or not (docExist or subjectSpace == 2 or subjectSpace == 828 or subjectSpace == 10) then
return nil
return nil
end
end
Line 340: Line 364:
-- Assemble the arguments for {{fmbox}}.
-- Assemble the arguments for {{fmbox}}.
local fmargs = {}
local fmargs = {}
fmargs.id = 'documentation-meta-data'
fmargs[cfg.fmboxIdParam] = cfg.fmboxId -- Sets fmargs.id = 'documentation-meta-data'
fmargs.image = 'none'
fmargs[cfg.fmboxImageParam] = cfg.fmboxImageNone -- Sets fmargs.image = 'none'
fmargs.style = 'background-color: #ecfcf4'
fmargs[cfg.fmboxStyleParam] = cfg.fmboxStyle -- Sets fmargs.style = 'background-color: #ecfcf4'
fmargs.textstyle = 'font-style: italic;'
fmargs[cfg.fmboxTextstyleParam] = cfg.fmboxTextstyle -- Sets fmargs.textstyle = 'font-style: italic;'


-- Assemble the fmbox text field.
-- Assemble the fmbox text field.
Line 354: Line 378:
-- /doc exists; link to it.
-- /doc exists; link to it.
local docLink = makeWikilink(docpage)
local docLink = makeWikilink(docpage)
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, 'edit')
local editLink = makeUrlLink(docTitle:fullUrl{action = 'edit'}, cfg.editLinkDisplay)
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, 'history')
local historyLink = makeUrlLink(docTitle:fullUrl{action = 'history'}, cfg.historyLinkDisplay)
text = text .. 'The above [[Wikipedia:Template documentation|documentation]] is [[Wikipedia:Transclusion|transcluded]] from '
text = text .. 'The above [[Wikipedia:Template documentation|documentation]] is [[Wikipedia:Transclusion|transcluded]] from '
.. docLink .. '. ' .. makeToolbar(editLink, historyLink) .. '<br />'
.. docLink .. '. ' .. makeToolbar(editLink, historyLink) .. '<br />'
elseif subjectSpace == 828 then
elseif subjectSpace == 828 then
-- /doc does not exist; ask to create it.
-- /doc does not exist; ask to create it.
local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = 'Template:Documentation/preload-module-doc'}, 'create')
local createLink = makeUrlLink(docTitle:fullUrl{action = 'edit', preload = 'Template:Documentation/preload-module-doc'}, cfg.createLinkDisplay)
text = text .. 'You might want to ' .. createLink .. ' a documentation page for this [[Wikipedia:Lua|Scribunto module]].<br />'
text = text .. 'You might want to ' .. createLink .. ' a documentation page for this [[Wikipedia:Lua|Scribunto module]].<br />'
end
end
Line 371: Line 395:
if sandboxTitle.exists then
if sandboxTitle.exists then
local sandboxLink = makeWikilink(sandbox, cfg.sandboxLinkDisplay)
local sandboxLink = makeWikilink(sandbox, cfg.sandboxLinkDisplay)
local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, 'edit')
local sandboxEditLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit'}, cfg.sandboxEditLinkDisplay)
local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, 'diff')
local compareLink = makeUrlLink(mw.title.new('Special:ComparePages'):fullUrl{page1 = templatePage, page2 = sandbox}, cfg.compareLinkDisplay)
text = text .. sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink)
text = text .. sandboxLink .. ' ' .. makeToolbar(sandboxEditLink, compareLink)
else
else
local sandboxPreload = 'Template:Documentation/preload-' .. (subjectSpace == 828 and 'module-' or '') .. 'sandbox'
local sandboxPreload = 'Template:Documentation/preload-' .. (subjectSpace == 828 and 'module-' or '') .. 'sandbox'
local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, 'create')
local sandboxCreateLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = sandboxPreload}, cfg.sandboxCreateLinkDisplay)
local mirrorSummary = 'Create sandbox version of ' .. makeWikilink(templatePage)
local mirrorSummary = 'Create sandbox version of ' .. makeWikilink(templatePage)
local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, 'mirror')
local mirrorLink = makeUrlLink(sandboxTitle:fullUrl{action = 'edit', preload = templatePage, summary = mirrorSummary}, cfg.mirrorLinkDisplay)
text = text .. cfg.sandboxLinkDisplay .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
text = text .. cfg.sandboxLinkDisplay .. ' ' .. makeToolbar(sandboxCreateLink, mirrorLink)
end
end
Line 384: Line 408:
local testcaseTitle = mw.title.new(testcases)
local testcaseTitle = mw.title.new(testcases)
if testcaseTitle.exists then
if testcaseTitle.exists then
local testcasesLink = makeWikilink(testcases, 'testcases')
local testcasesLink = makeWikilink(testcases, cfg.testcasesLinkDisplay)
local testcasesEditLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit'}, 'edit')
local testcasesEditLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit'}, cfg.testcasesEditLinkDisplay)
text = text .. testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
text = text .. testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
else
else
local testcasesPreload = 'Template:Documentation/preload-' .. (subjectSpace == 828 and 'module-' or '') .. 'testcases'
local testcasesPreload = 'Template:Documentation/preload-' .. (subjectSpace == 828 and 'module-' or '') .. 'testcases'
local testcasesCreateLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit', preload = testcasesPreload}, 'create')
local testcasesCreateLink = makeUrlLink(testcaseTitle:fullUrl{action = 'edit', preload = testcasesPreload}, cfg.testcasesCreateLinkDisplay)
text = text .. 'testcases ' .. makeToolbar(testcasesCreateLink)
text = text .. cfg.testcasesLinkDisplay .. ' ' .. makeToolbar(testcasesCreateLink)
end
end
text = text .. ' pages. <br />'
text = text .. ' pages. <br />'
Line 429: Line 453:
local ret = ''
local ret = ''
local subpage = currentTitle.subpageText
local subpage = currentTitle.subpageText
if subpage == cfg.docSubpage or subpage == 'testcases' then
if subpage == cfg.docSubpage or subpage == cfg.testcasesSubpage then
local sort = (currentTitle.namespace == 0 and 'Main:' or '') .. currentTitle.prefixedText -- Sort on namespace.
local sort = (currentTitle.namespace == 0 and 'Main:' or '') .. currentTitle.prefixedText -- Sort on namespace.
ret = ret .. makeWikilink('Category:Wikipedia pages with strange ((documentation)) usage', sort)
ret = ret .. makeWikilink('Category:Wikipedia pages with strange ((documentation)) usage', sort)
Line 450: Line 474:
-- Determines the template page. No namespace or interwiki prefixes are included.
-- Determines the template page. No namespace or interwiki prefixes are included.
local subpage = currentTitle.subpageText
local subpage = currentTitle.subpageText
if subpage == cfg.sandboxSubpage or subpage == 'testcases' then
if subpage == cfg.sandboxSubpage or subpage == cfg.testcasesSubpage then
return currentTitle.baseText
return currentTitle.baseText
else
else