Difference between revisions of "Module:Documentation"
Jump to navigation
Jump to search
comment tweaks
>Mr. Stradivarius (don't use title error message) |
>Mr. Stradivarius (comment tweaks) |
||
Line 119: | Line 119: | ||
function p._main(args) | function p._main(args) | ||
--[[ | |||
-- 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 env = p.getEnvironment(args) | ||
local root = htmlBuilder.create() | local root = htmlBuilder.create() | ||
Line 151: | Line 159: | ||
-- Returns a table with information about the environment, including title objects and other namespace- or | -- Returns a table with information about the environment, including title objects and other namespace- or | ||
-- path-related data. | -- path-related data. | ||
-- @args - table of arguments passed by the user | |||
-- | -- | ||
-- Title objects include: | -- Title objects include: | ||
Line 202: | Line 211: | ||
function envFuncs.templateTitle() | function envFuncs.templateTitle() | ||
--[[ | |||
-- The template (or module, etc.) title object. | -- The template (or module, etc.) title object. | ||
-- Messages: | |||
-- 'sandbox-subpage' --> 'sandbox' | |||
-- 'testcases-subpage' --> 'testcases' | |||
--]] | |||
local title = env.title | local title = env.title | ||
local subpage = title.subpageText | local subpage = title.subpageText | ||
Line 213: | Line 227: | ||
function envFuncs.docTitle() | function envFuncs.docTitle() | ||
--[[ | |||
-- Title object of the /doc subpage. | -- Title object of the /doc subpage. | ||
-- Messages: | |||
-- 'doc-subpage' --> 'doc' | |||
--]] | |||
local title = env.title | local title = env.title | ||
local docname = args[1] -- User-specified doc page. | local docname = args[1] -- User-specified doc page. | ||
Line 226: | Line 244: | ||
function envFuncs.sandboxTitle() | function envFuncs.sandboxTitle() | ||
--[[ | |||
-- Title object for the /sandbox subpage. | -- Title object for the /sandbox subpage. | ||
-- Messages: | |||
-- 'sandbox-subpage' --> 'sandbox' | |||
--]] | |||
return mw.title.new(env.docpageRoot .. '/' .. message('sandbox-subpage')) | return mw.title.new(env.docpageRoot .. '/' .. message('sandbox-subpage')) | ||
end | end | ||
function envFuncs.testcasesTitle() | function envFuncs.testcasesTitle() | ||
--[[ | |||
-- Title object for the /testcases subpage. | -- Title object for the /testcases subpage. | ||
-- Messages: | |||
-- 'testcases-subpage' --> 'testcases' | |||
--]] | |||
return mw.title.new(env.docpageRoot .. '/' .. message('testcases-subpage')) | return mw.title.new(env.docpageRoot .. '/' .. message('testcases-subpage')) | ||
end | end | ||
function envFuncs.printTitle() | function envFuncs.printTitle() | ||
--[[ | |||
-- Title object for the /Print subpage. | -- Title object for the /Print subpage. | ||
-- Messages: | |||
-- 'print-subpage' --> 'Print' | |||
--]] | |||
return env.templateTitle:subPageTitle(message('print-subpage')) | return env.templateTitle:subPageTitle(message('print-subpage')) | ||
end | end | ||
Line 286: | Line 316: | ||
function p.sandboxNotice(args, env) | function p.sandboxNotice(args, env) | ||
--[=[ | |||
-- Generates a sandbox notice for display above sandbox pages. | |||
-- @args - a table of arguments passed by the user | |||
-- @env - environment table containing title objects, etc., generated with p.getEnvironment | |||
-- | |||
-- Messages: | |||
-- 'sandbox-notice-image' --> '[[Image:Sandbox.png|50px|alt=|link=]]' | |||
-- 'sandbox-notice-blurb' --> 'This is the [[Wikipedia:Template test cases|template sandbox]] page for $1.' | |||
-- 'sandbox-notice-diff-blurb' --> 'This is the [[Wikipedia:Template test cases|template sandbox]] page for $1 ($2).' | |||
-- 'sandbox-notice-compare-link-display' --> 'diff' | |||
-- 'sandbox-notice-testcases-blurb' --> 'See also the companion subpage for $1.' | |||
-- 'sandbox-notice-testcases-link-display' --> 'test cases' | |||
-- 'sandbox-category' --> 'Template sandboxes' | |||
--]=] | |||
local title = env.title | local title = env.title | ||
local sandboxTitle = env.sandboxTitle | local sandboxTitle = env.sandboxTitle | ||
Line 292: | Line 336: | ||
return nil | return nil | ||
end | end | ||
-- Build the table of arguments to pass to {{ombox}}. We need just two fields, "image" and "text". | |||
local omargs = {} | |||
omargs.image = message('sandbox-notice-image') | omargs.image = message('sandbox-notice-image') | ||
-- Get the text. We start with the opening blurb, which is something like | -- Get the text. We start with the opening blurb, which is something like | ||
Line 303: | Line 347: | ||
local compareUrl = env.compareUrl | local compareUrl = env.compareUrl | ||
if isPreviewing or not compareUrl then | if isPreviewing or not compareUrl then | ||
text = text .. message('sandbox-notice-blurb', {templateLink}) | text = text .. message('sandbox-notice-blurb', {templateLink}) | ||
else | else | ||
local compareDisplay = message('sandbox-notice-compare-link-display') | local compareDisplay = message('sandbox-notice-compare-link-display') | ||
local compareLink = makeUrlLink(compareUrl, compareDisplay) | local compareLink = makeUrlLink(compareUrl, compareDisplay) | ||
text = text .. message('sandbox-notice-diff-blurb', {templateLink, compareLink}) | text = text .. message('sandbox-notice-diff-blurb', {templateLink, compareLink}) | ||
end | end | ||
-- Get the test cases page blurb if the page exists. | -- Get the test cases page blurb if the page exists. This is something like | ||
-- "See also the companion subpage for [[Template:Foo/testcases|test cases]]." | |||
local testcasesTitle = env.testcasesTitle | local testcasesTitle = env.testcasesTitle | ||
if testcasesTitle and testcasesTitle.exists then | if testcasesTitle and testcasesTitle.exists then | ||
Line 318: | Line 361: | ||
text = text .. '<br />' .. message('sandbox-notice-testcases-blurb', {testcasesLink}) | text = text .. '<br />' .. message('sandbox-notice-testcases-blurb', {testcasesLink}) | ||
end | end | ||
-- Add the | -- 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 |