Anonymous user
Module:Documentation: Difference between revisions
From The FunKey Wiki
Undo revision 4731418 by Shirayuki (talk): templates on mediawiki.org use page language, not UI language, and it’s perfectly okay that way
(Remove all print subpage related code as they are being deleted (and non-functional)) |
|||
Line 3:
-- Get required modules.
local getArgs = require('Module:Arguments').getArgs
local messageBox = require('Module:Message box')
-- Get the config table.
local cfg = mw.loadData('Module:Documentation/config')
local i18n = mw.loadData('Module:Documentation/i18n')
local p = {}
Line 32 ⟶ 33:
expectType = expectType or 'string'
if type(msg) ~= expectType then
error(require('
end
if not valArray then
Line 40 ⟶ 41:
local function getMessageVal(match)
match = tonumber(match)
return valArray[match] or error(require('
end
return ret
end
Line 80 ⟶ 82:
ret[#ret + 1] = select(i, ...)
end
return '<small style="font-style: normal;">(' .. table.concat(ret, ' | ') .. ')</small>'
end
Line 112:
----------------------------------------------------------------------------
-- Load TemplateStyles
----------------------------------------------------------------------------
local parent = frame.getParent(frame)
local output = p._main(parent.args)
return frame:extensionTag{ name='templatestyles', args = { src= message('templatestyles-scr') } } .. output
end
----------------------------------------------------------------------------
-- Main function
----------------------------------------------------------------------------
function p._main(args)
Line 129:
-- This function defines logic flow for the module.
-- @args - table of arguments passed by the user
--
-- Messages:
-- 'main-div-id' --> 'template-documentation'
-- 'main-div-classes' --> 'template-documentation iezoomfix'
--]]
local env = p.getEnvironment(args)
local root = mw.html.create()
root
:wikitext(p.protectionTemplate(env))
:wikitext(p.sandboxNotice(args, env))
-- This div tag is from {{documentation/start box}}, but moving it here
-- so that we don't have to worry about unclosed tags.
:tag('div')
:attr('id', message('main-div-id'))
:addClass(message('
:wikitext(p._startBox(args, env))
:wikitext(p._content(args, env))
:done()
:wikitext(p._endBox(args, env))
:wikitext(p.addTrackingCategories(env))
return tostring(root)
end
Line 167 ⟶ 158:
function p.getEnvironment(args)
--[[
-- Returns a table with information about the environment, including title objects and other namespace- or
--
-- @args - table of arguments passed by the user
--
Line 177 ⟶ 168:
-- env.sandboxTitle - the /sandbox subpage.
-- env.testcasesTitle - the /testcases subpage.
-- env.printTitle - the print version of the template, located at the /Print subpage.
--
-- Data includes:
Line 270 ⟶ 262:
--]]
return mw.title.new(env.docpageBase .. '/' .. message('testcases-subpage'))
end
function envFuncs.printTitle()
--[[
-- Title object for the /Print subpage.
-- Messages:
-- 'print-subpage' --> 'Print'
--]]
return env.templateTitle:subPageTitle(message('print-subpage'))
end
Line 283 ⟶ 284:
function envFuncs.docSpace()
-- The documentation namespace number. For most namespaces this is the same as the
--
--
local subjectSpace = env.subjectSpace
if subjectSpace == 0 or subjectSpace == 6 or subjectSpace == 8 or subjectSpace == 14 then
Line 312:
local compareUrl = mw.uri.fullUrl(
'Special:ComparePages',
{
)
return tostring(compareUrl)
Line 326:
-- Auxiliary templates
----------------------------------------------------------------------------
function p.sandboxNotice(args, env)
Line 349 ⟶ 337:
-- 'sandbox-notice-blurb' --> 'This is the $1 for $2.'
-- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).'
-- 'sandbox-notice-pagetype-template' --> '[[w:Wikipedia:Template test cases|template sandbox]] page'
-- 'sandbox-notice-pagetype-module' --> '[[w:Wikipedia:Template test cases|module sandbox]] page'
-- 'sandbox-notice-pagetype-other' --> 'sandbox page'
-- 'sandbox-notice-compare-link-display' --> 'diff'
Line 361 ⟶ 349:
local templateTitle = env.templateTitle
local subjectSpace = env.subjectSpace
if not (subjectSpace and title and sandboxTitle and templateTitle and mw.title.equals(title, sandboxTitle)) then
return nil
end
Line 371 ⟶ 358:
-- "This is the template sandbox for [[Template:Foo]] (diff)."
local text = ''
local frame = mw.getCurrentFrame()
local isPreviewing = frame:preprocess('{{REVISIONID}}') == '' -- True if the page is being previewed.
local pagetype
if subjectSpace == 10 then
Line 381 ⟶ 370:
local templateLink = makeWikilink(templateTitle.prefixedText)
local compareUrl = env.compareUrl
if isPreviewing or not compareUrl then
text = text .. message('sandbox-notice-blurb', {pagetype, templateLink})
else
local compareDisplay = message('sandbox-notice-compare-link-display')
local compareLink = makeUrlLink(compareUrl, compareDisplay)
text = text .. message('sandbox-notice-diff-blurb', {pagetype, templateLink, compareLink})
end
-- Get the test cases page blurb if the page exists. This is something like
Line 405 ⟶ 394:
end
-- Add the sandbox to the sandbox category.
omargs.text = text
omargs.class = message('sandbox-class')
return ret
end
Line 418 ⟶ 408:
-- 'protection-template' --> 'pp-template'
-- 'protection-template-args' --> {docusage = 'yes'}
local
local protectionLevels
local protectionTemplate = message('protection-template')
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.
return nil
end
protectionLevels = env.protectionLevels
if not protectionLevels then
return nil
end
local
local
if moveLevels and moveLevels[1] == 'sysop' or editLevels and editLevels[1] then
-- The page is
local frame = mw.getCurrentFrame()
else
return nil
Line 460 ⟶ 450:
local links
local content = args.content
if not content
-- No need to include the links if the documentation is on the template page itself.
local linksData = p.makeStartBoxLinksData(args, env)
Line 507 ⟶ 497:
data.docTitle = docTitle
-- View, display, edit, and purge links if /doc exists.
data.viewLinkDisplay =
data.editLinkDisplay =
data.historyLinkDisplay =
data.purgeLinkDisplay =
-- Create link if /doc doesn't exist.
local preload = args.preload
Line 523 ⟶ 513:
end
data.preload = preload
data.createLinkDisplay =
return data
end
Line 568 ⟶ 558:
--
-- Messages:
-- 'documentation-icon-wikitext' --> '[[File:Test Template Info-Icon - Version (2).svg|50px|link=|alt=Documentation icon]]'
-- 'template-namespace-heading' --> 'Template documentation'
-- 'module-namespace-heading' --> 'Module documentation'
-- 'file-namespace-heading' --> 'Summary'
-- 'other-namespaces-heading' --> 'Documentation'
-- 'start-box-linkclasses' --> 'mw-editsection-like plainlinks'
-- 'start-box-link-id' --> 'doc_editlinks'
-- 'testcases-create-link-display' --> 'create'
--]=]
Line 592 ⟶ 584:
data.heading = heading
elseif subjectSpace == 10 then -- Template namespace
data.heading =
elseif subjectSpace == 828 then -- Module namespace
data.heading =
elseif subjectSpace == 6 then -- File namespace
data.heading =
else
data.heading =
end
-- Data for the [view][edit][history][purge] or [create] links.
if links then
data.linksClass = message('start-box-linkclasses')
data.
data.links = links
end
Line 625 ⟶ 608:
local sbox = mw.html.create('div')
sbox
:addClass(message('header-div-class'))
:tag('div')
:addClass(message('heading-div-class'))
:wikitext(data.heading)
local links = data.links
if links then
sbox
:
:
:attr('id', data.linksId)
:wikitext(links)
end
return tostring(sbox)
Line 656 ⟶ 637:
local content = args.content
if not content and docTitle and docTitle.exists then
content = args._content or mw.getCurrentFrame():expandTemplate{title = docTitle
end
-- The line breaks below are necessary so that "=== Headings ===" at the start and end
-- of docs are interpreted correctly.
local cbox = mw.html.create('div')
cbox
:addClass(message('content-div-class'))
:wikitext('\n' .. (content or '') .. '\n')
return tostring(cbox)
end
Line 686 ⟶ 671:
-- @args - a table of arguments passed by the user
-- @env - environment table containing title objects, etc., generated with p.getEnvironment
--]=]
Line 712 ⟶ 696:
end
-- Assemble the
local text = ''
if linkBox then
Line 722 ⟶ 706:
-- Add sandbox and testcases links.
-- "Editors can experiment in this template's sandbox and testcases pages."
text = text .. (p.makeExperimentBlurb(args, env) or '')
text = text .. '<br />'
if not args.content and not args[1] then
-- "Please add categories to the /doc subpage."
Line 730 ⟶ 715:
end
text = text .. ' ' .. (p.makeSubpagesBlurb(args, env) or '') --"Subpages of this template"
local printBlurb = p.makePrintBlurb(args, env) -- Two-line blurb about print versions of templates.
if printBlurb then
text = text .. '<br />' .. printBlurb
end
end
end
local
ebox
:addClass(message('footer-div-class'))
:wikitext(text)
return tostring(ebox)
end
Line 755 ⟶ 739:
-- 'history-link-display' --> 'history'
-- 'transcluded-from-blurb' -->
-- 'The above [[w:Wikipedia:Template documentation|documentation]]
-- is [[
-- 'module-preload' --> 'Template:Documentation/preload-module-doc'
-- 'create-link-display' --> 'create'
-- 'create-module-doc-blurb' -->
-- 'You might want to $1 a documentation page for this [[w:Wikipedia:Lua|Scribunto module]].'
--]=]
local docTitle = env.docTitle
if not docTitle or args.content then
return nil
end
Line 771 ⟶ 755:
local docLink = makeWikilink(docTitle.prefixedText)
local editUrl = docTitle:fullUrl{action = 'edit'}
local editDisplay =
local editLink = makeUrlLink(editUrl, editDisplay)
local historyUrl = docTitle:fullUrl{action = 'history'}
local historyDisplay =
local historyLink = makeUrlLink(historyUrl, historyDisplay)
ret = message('transcluded-from-blurb', {docLink})
Line 783 ⟶ 767:
-- /doc does not exist; ask to create it.
local createUrl = docTitle:fullUrl{action = 'edit', preload = message('module-preload')}
local createDisplay =
local createLink = makeUrlLink(createUrl, createDisplay)
ret = message('create-module-doc-blurb', {createLink})
Line 856 ⟶ 840:
local mirrorPreload = message('mirror-link-preload')
local mirrorUrl = sandboxTitle:fullUrl{action = 'edit', preload = mirrorPreload, summary = mirrorSummary}
local mirrorDisplay = message('mirror-link-display')
local mirrorLink = makeUrlLink(mirrorUrl, mirrorDisplay)
Line 870 ⟶ 851:
local testcasesEditDisplay = message('testcases-edit-link-display')
local testcasesEditLink = makeUrlLink(testcasesEditUrl, testcasesEditDisplay)
testcasesLinks = testcasesLink .. ' ' .. makeToolbar(testcasesEditLink)
else
local testcasesPreload
Line 946 ⟶ 920:
)
return message('subpages-blurb', {subpagesLink})
end
function p.makePrintBlurb(args, env)
--[=[
-- Generates the blurb displayed when there is a print version of the template available.
-- @args - a table of arguments passed by the user
-- @env - environment table containing title objects, etc., generated with p.getEnvironment
--
-- Messages:
-- 'print-link-display' --> '/Print'
-- 'print-blurb' --> 'A [[Help:Books/for experts#Improving the book layout|print version]]'
-- .. ' of this template exists at $1.'
-- .. ' If you make a change to this template, please update the print version as well.'
-- 'display-print-category' --> true
-- 'print-category' --> 'Templates with print versions'
--]=]
local printTitle = env.printTitle
if not printTitle then
return nil
end
local ret
if printTitle.exists then
local printLink = makeWikilink(printTitle.prefixedText, message('print-link-display'))
ret = message('print-blurb', {printLink})
local displayPrintCategory = message('display-print-category', nil, 'boolean')
if displayPrintCategory then
ret = ret .. makeCategoryLink(message('print-category'))
end
end
return ret
end
|