Module:Documentation: Difference between revisions
m
update code comment according to Special:Diff/989669779
(+پارامتر فارسی «محتوا») |
m (update code comment according to Special:Diff/989669779) |
||
Line 1: | Line 1: | ||
-- This module implements {{documentation}}. | -- This module implements {{documentation}}. | ||
Line 33: | Line 32: | ||
expectType = expectType or 'string' | expectType = expectType or 'string' | ||
if type(msg) ~= expectType then | if type(msg) ~= expectType then | ||
error(' | error('message: type error in message cfg.' .. cfgKey .. ' (' .. expectType .. ' expected, got ' .. type(msg) .. ')', 2) | ||
end | end | ||
if not valArray then | if not valArray then | ||
Line 41: | Line 40: | ||
local function getMessageVal(match) | local function getMessageVal(match) | ||
match = tonumber(match) | match = tonumber(match) | ||
return valArray[match] or error('message: no value found for key $' .. match .. ' in message cfg.' .. cfgKey, 4) | |||
return valArray[match] or error(' | |||
end | end | ||
return ugsub(msg, '$([1- | return ugsub(msg, '$([1-9][0-9]*)', getMessageVal) | ||
end | end | ||
Line 98: | Line 96: | ||
valueFunc = function (key, value) | valueFunc = function (key, value) | ||
if type(value) == 'string' then | if type(value) == 'string' then | ||
value = | value = value:match('^%s*(.-)%s*$') -- Remove whitespace. | ||
if key == 'heading' or value ~= '' then | if key == 'heading' or value ~= '' then | ||
return value | return value | ||
Line 118: | Line 116: | ||
function p.nonexistent(frame) | function p.nonexistent(frame) | ||
if mw.title.getCurrentTitle().subpageText == ' | if mw.title.getCurrentTitle().subpageText == 'testcases' then | ||
return frame:expandTemplate{title = ' | return frame:expandTemplate{title = 'module test cases notice'} | ||
else | else | ||
return p.main(frame) | return p.main(frame) | ||
Line 141: | Line 139: | ||
-- 'documentation-container' | -- 'documentation-container' | ||
:addClass(message('container')) | :addClass(message('container')) | ||
:attr('role', 'complementary') | |||
:attr('aria-labelledby', args.heading ~= '' and 'documentation-heading' or nil) | |||
:attr('aria-label', args.heading == '' and 'Documentation' or nil) | |||
:newline() | :newline() | ||
:tag('div') | :tag('div') | ||
Line 313: | Line 314: | ||
if templateTitle.exists and sandboxTitle.exists then | if templateTitle.exists and sandboxTitle.exists then | ||
local compareUrl = mw.uri.fullUrl( | local compareUrl = mw.uri.fullUrl( | ||
' | 'Special:ComparePages', | ||
{ page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText} | { page1 = templateTitle.prefixedText, page2 = sandboxTitle.prefixedText} | ||
) | ) | ||
Line 348: | Line 349: | ||
-- | -- | ||
-- Messages: | -- Messages: | ||
-- 'sandbox-notice-image' --> '[[ | -- 'sandbox-notice-image' --> '[[File:Sandbox.svg|50px|alt=|link=]]' | ||
-- 'sandbox-notice-blurb' --> 'This is the $1 for $2.' | -- 'sandbox-notice-blurb' --> 'This is the $1 for $2.' | ||
-- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).' | -- 'sandbox-notice-diff-blurb' --> 'This is the $1 for $2 ($3).' | ||
Line 461: | Line 462: | ||
env = env or p.getEnvironment(args) | env = env or p.getEnvironment(args) | ||
local links | local links | ||
local content = args.content | local content = args.content | ||
if not content or args[1] then | if not content or args[1] then | ||
-- No need to include the links if the documentation is on the template page itself. | -- No need to include the links if the documentation is on the template page itself. | ||
Line 490: | Line 491: | ||
-- 'history-link-display' --> 'history' | -- 'history-link-display' --> 'history' | ||
-- 'purge-link-display' --> 'purge' | -- 'purge-link-display' --> 'purge' | ||
-- 'module-preload' --> 'Template:Documentation/preload-module-doc' | -- 'module-preload' --> 'Template:Documentation/preload-module-doc' | ||
-- 'docpage-preload' --> 'Template:Documentation/preload' | -- 'docpage-preload' --> 'Template:Documentation/preload' | ||
Line 516: | Line 516: | ||
local preload = args.preload | local preload = args.preload | ||
if not preload then | if not preload then | ||
if | if subjectSpace == 828 then -- Module namespace | ||
preload = message('module-preload') | preload = message('module-preload') | ||
else | else | ||
Line 632: | Line 630: | ||
:tag('span') | :tag('span') | ||
:addClass(data.headingClass) | :addClass(data.headingClass) | ||
:attr('id', 'documentation-heading') | |||
:cssText(data.headingStyleText) | :cssText(data.headingStyleText) | ||
:wikitext(data.heading) | :wikitext(data.heading) | ||
Line 656: | Line 655: | ||
env = env or p.getEnvironment(args) | env = env or p.getEnvironment(args) | ||
local docTitle = env.docTitle | local docTitle = env.docTitle | ||
local content = args.content | local content = args.content | ||
if not content and docTitle and docTitle.exists then | if not content and docTitle and docTitle.exists then | ||
content = args._content or mw.getCurrentFrame():expandTemplate{title = docTitle.prefixedText} | content = args._content or mw.getCurrentFrame():expandTemplate{title = docTitle.prefixedText} | ||
Line 670: | Line 669: | ||
env = env or p.getEnvironment(args) | env = env or p.getEnvironment(args) | ||
local docTitle = env.docTitle | local docTitle = env.docTitle | ||
if not | if not args.content and docTitle and docTitle.exists then | ||
return docTitle.prefixedText | return docTitle.prefixedText | ||
else | else | ||
Line 725: | Line 724: | ||
-- "Editors can experiment in this template's sandbox and testcases pages." | -- "Editors can experiment in this template's sandbox and testcases pages." | ||
text = text .. (p.makeExperimentBlurb(args, env) or '') .. '<br />' | text = text .. (p.makeExperimentBlurb(args, env) or '') .. '<br />' | ||
if not | if not args.content and not args[1] then | ||
-- "Please add categories to the /doc subpage." | -- "Please add categories to the /doc subpage." | ||
-- Don't show this message with inline docs or with an explicitly specified doc page, | -- Don't show this message with inline docs or with an explicitly specified doc page, | ||
Line 944: | Line 943: | ||
end | end | ||
local subpagesLink = makeWikilink( | local subpagesLink = makeWikilink( | ||
' | 'Special:PrefixIndex/' .. templateTitle.prefixedText .. '/', | ||
message('subpages-link-display', {pagetype}) | message('subpages-link-display', {pagetype}) | ||
) | ) |