Module:WPSHIPS utilities and Module:WPSHIPS utilities/sandbox: Difference between pages
Appearance
(Difference between pages)
Content deleted Content added
Special:LintErrors/night-mode-unaware-background-color to match https://en.wikipedia.org/w/index.php?title=Module%3AWPMILHIST_Infobox_style&diff=1232708594&oldid=860617822 |
use require('strict') instead of require('Module:No globals') |
||
Line 2: | Line 2: | ||
local get_args = require ('Module:Arguments').getArgs; |
local get_args = require ('Module:Arguments').getArgs; |
||
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css |
local styles = require ('Module:WPMILHIST Infobox style'); -- infobox css |
||
local data = mw.loadData ('Module:WPSHIPS utilities/data'); |
local data = mw.loadData ('Module:WPSHIPS utilities/data/sandbox'); |
||
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization |
local namespace = mw.title.getCurrentTitle().namespace; -- used for categorization |
||
local error_map = { -- [1] is error message; [2] is error category |
|||
['synonymous'] = {'has synonymous parameter', 'Pages using infobox ship with synonymous parameters'}; |
|||
--[[--------------------------< E R R O R _ M A P _ T >-------------------------------------------------------- |
|||
]] |
|||
local error_map_t = { -- [1] is error message; [2] is error category |
|||
synonymous = {'has synonymous parameter', 'Category:Pages using infobox ship with synonymous parameters'}; |
|||
missing = {'missing required parameter: %s', 'Category:WPSHIPS: sclass and sclass2 errors'}, |
|||
format = {'invalid format code: %s. Should be 0–5, or blank', 'Category:WPSHIPS: sclass and sclass2 errors'}, |
|||
missing_name = {'missing name', 'Category:WPSHIPS: Template Ship parameter errors'}, |
|||
missing_dab = {'missing disambiguator', 'Category:WPSHIPS: Template Ship parameter errors'}, |
|||
missing_prefix = {'missing prefix', 'Category:WPSHIPS: Template Ship parameter errors'}, |
|||
invalid_control = {'invalid control parameter: %s', 'Category:WPSHIPS: Template Ship parameter errors'}, |
|||
} |
} |
||
--[[--------------------------< E R R O R _ M S G |
--[[--------------------------< M A K E _ E R R O R _ M S G >-------------------------------------------------- |
||
assembles an error message from message text |
assembles an error message from message text, help link, and error category. |
||
page; categorizes only main and template namespaces. |
|||
<no_cat> disables categorization for those templates that support it; to disable categorization set <no_cat> true |
|||
]] |
]] |
||
local function |
local function make_error_msg (msg, cat, no_cat) |
||
local out = {}; |
local out = {}; |
||
local category; |
local category; |
||
table.insert (out, '<span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); |
table.insert (out, ' <span style=\"font-size: 100%; font-style: normal;\" class=\"error\">Error: '); |
||
table.insert (out, error_map[msg][1]); |
|||
if template then |
|||
table.insert (out, table.concat ({' ([[:Category:', error_map[msg][2], '|help]])'})); |
|||
if link_template_name then |
|||
table.insert (out, table.concat ({'{{[[Template:', template, '|', template, ']]}} '})); |
|||
else |
|||
table.insert (out, table.concat ({'{{', template, '}} '})); -- TODO: get template names for synonymous parameter errors |
|||
end |
|||
end |
|||
table.insert (out, string.format (error_map_t[msg_idx][1], detail)); -- build error message from base + <detail> |
|||
table.insert (out, table.concat ({' ([[:', error_map_t[msg_idx][2], '|help]])'})); -- help text on category pages; TODO: help text on template pages also? |
|||
table.insert (out, '</span>'); |
table.insert (out, '</span>'); |
||
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages) |
if (0 == namespace or 10 == namespace) and not no_cat then -- categorize in article space (and template space to take care of broken usages) |
||
table.insert (out, table.concat ({'[[', |
table.insert (out, table.concat ({'[[Category:', error_map[msg][2], ']]'})); |
||
end |
end |
||
return table.concat (out); |
return table.concat (out); |
||
end |
end |
||
Line 445: | Line 425: | ||
]] |
]] |
||
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole |
local function _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole) |
||
local error_msg = ''; |
local error_msg = ''; |
||
local category = ''; |
local category = ''; |
||
Line 455: | Line 435: | ||
control = control:match ('%d'); -- strip out the hyphen |
control = control:match ('%d'); -- strip out the hyphen |
||
end |
end |
||
-- dispose of error conditions straight away |
-- dispose of error conditions straight away |
||
if not is_set (name) then -- this is the only required parameter |
if not is_set (name) then -- this is the only required parameter |
||
error_msg = |
error_msg = ' missing name'; |
||
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it |
elseif not is_set (dab) and ('1' == control or '3' == control or '5' == control) then -- dab required when control value set to expect it |
||
error_msg = |
error_msg = ' missing disambiguator'; |
||
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it |
elseif not is_set (prefix) and ('5' == control or '6' == control) then -- prefix required when control value set to expect it |
||
error_msg = |
error_msg = ' missing prefix'; |
||
elseif '4' == control then -- displaying only the prefix |
elseif '4' == control then -- displaying only the prefix |
||
error_msg = |
error_msg = 'invalid control parameter: ' .. control; |
||
elseif is_set (control) then |
elseif is_set (control) then |
||
if ('number' ~= type (tonumber (control) |
if ('number' ~= type (tonumber (control))) or (1 > tonumber (control) or 6 < tonumber (control)) then -- control must be a number between 1 through 6 |
||
error_msg = |
error_msg = 'invalid control parameter: ' .. control; |
||
end |
end |
||
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes |
elseif not is_set (prefix) and unlinked_prefix then -- prefix required when |up=yes |
||
error_msg = |
error_msg = ' missing prefix'; |
||
end |
end |
||
if is_set (error_msg) then |
if is_set (error_msg) then |
||
if 0 == mw.title.getCurrentTitle().namespace then -- only categorize pages in article space |
|||
return error_msg; |
|||
category = '[[Category:WPSHIPS: template ship parameter errors]]'; |
|||
end |
|||
return '<span style="font-size:100%" class="error">' .. error_msg .. '</span>' .. category; -- return an error message; don't bother with making a link |
|||
end |
end |
||
local link_name; |
local link_name; |
||
local link = ''; |
local link = '[['; |
||
if is_set (prefix) then |
if is_set (prefix) then |
||
link = prefix .. ' ' .. name; |
link = link .. prefix .. ' ' .. name; -- begin assembling the article name portion of the wikilink |
||
else |
else |
||
link = name; |
link = link .. name; |
||
end |
end |
||
Line 489: | Line 472: | ||
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses |
link = link .. ' (' .. dab .. ')'; -- wrap dab in parentheses |
||
end |
end |
||
local target_object = mw.title.new (link).redirectTarget; -- if <link> points to a redirect |
|||
if target_object then |
|||
link = target_object.fullText; -- get the target title to avoid linking through the redirect |
|||
end |
|||
name = "''" .. name .. "''"; -- name is always italicized so do it now |
name = "''" .. name .. "''"; -- name is always italicized so do it now |
||
Line 510: | Line 488: | ||
if not is_set (control) then -- when control not set: prefix, name, and dab |
if not is_set (control) then -- when control not set: prefix, name, and dab |
||
if unlinked_prefix then -- 'unlinked prefix'? |
|||
if is_set (prefix) then |
|||
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render |
|||
link_name = name .. dab; |
|||
elseif is_set (prefix) then |
|||
link_name = prefix .. ' ' .. name .. dab; |
link_name = prefix .. ' ' .. name .. dab; |
||
else |
else |
||
Line 521: | Line 502: | ||
link_name = name .. dab; |
link_name = name .. dab; |
||
elseif '5' == control then -- prefix and dab |
elseif '5' == control then -- prefix and dab |
||
if unlinked_prefix then -- 'unlinked prefix'? |
|||
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render |
|||
link_name = dab; |
|||
else |
|||
link_name = prefix .. dab; |
link_name = prefix .. dab; |
||
end |
|||
elseif '6' == control then -- prefix and name |
elseif '6' == control then -- prefix and name |
||
if unlinked_prefix then -- 'unlinked prefix'? |
|||
link = prefix .. ' ' .. link; -- yes, modify link so that prefix is not linked in final render |
|||
link_name = name; |
|||
else |
|||
link_name = prefix .. ' ' .. name; |
link_name = prefix .. ' ' .. name; |
||
end |
|||
end |
end |
||
end |
|||
if '5' ~= control and'6' ~= control and is_set (control) then |
|||
unlinked_prefix = false; -- no prefix so don't try to unlink it |
|||
end |
end |
||
if unlinked_whole then |
if unlinked_whole then |
||
return link_name; |
return link_name; |
||
elseif unlinked_prefix and is_set (prefix) then -- when there is a prefix to unlink |
|||
link_name = link_name:gsub ('^.- ', '', 1); -- remove the prefix and nbsp |
|||
return prefix .. ' [[' .. link .. '|' .. link_name .. ']]'; -- add prefix and nbsp to front and done |
|||
else |
else |
||
return |
return link .. '|' .. link_name .. ']]'; |
||
end |
end |
||
end |
end |
||
--[[--------------------------< S H I P >---------------------------------------------------------------------- |
--[[--------------------------< S H I P >---------------------------------------------------------------------- |
||
Line 548: | Line 531: | ||
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc |
This function is the externally accessible entry point for template {{ship}}, {{HMS}}, {{USS}}, etc |
||
{{#invoke:WPSHIPS_utilities|ship| |
{{#invoke:WPSHIPS_utilities/sandbox|ship|{{{1|}}}|{{{2|}}}|{{{3|}}}|{{{4|}}}|link={{{link|}}}|up={{{up|}}}}} |
||
{{#invoke:WPSHIPS_utilities|ship_pre|prefix=<prefix>|_template=<template name>}} |
|||
Parameters in the module frame are: |
|||
there are no module frame parameters |
|||
Parameters in the template frame are: |
|||
{{{1|}}} – prefix (HMS, USS, Japanese submarine, etc) |
|||
{{{2|}}} – ship's name (required) |
|||
{{{3|}}} – disambiguator (year, hull or pennant number, etc) |
|||
{{{4|}}} – format control (1, 2, 3, 5, 6; 4 not allowed) |
|||
|wl= – when set to 'no', rendering is not wikilinked |
|||
|up= – when set to 'yes' prefix (if rendered) is not linked |
|||
]] |
]] |
||
local function ship (frame) -- this version not supported from the template yet |
local function ship (frame) -- this version not supported from the template yet |
||
local prefix = mw.text.trim (frame.args[1] or ''); -- fetch positional parameters into named variables for readability |
|||
local args_t = get_args (frame); |
|||
local name = mw.text.trim (frame.args[2] or ''); -- stripped of leading and trailing whitespace |
|||
local |
local dab = mw.text.trim (frame.args[3] or ''); -- and and set to empty string (is that needed?) |
||
local control = frame.args[4]; |
|||
local name = args_t[2] or ''; -- stripped of leading and trailing whitespace |
|||
local unlinked_prefix = 'yes' == frame.args.up; |
|||
local dab = args_t[3] or ''; -- empty positional parameters are nil so convert nil to empty string |
|||
local |
local unlinked_whole = 'no' == frame.args.link; |
||
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes |
|||
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no |
|||
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes |
|||
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, 'Ship', no_cat); |
|||
end |
|||
--[[--------------------------< S H I P _ P R E F I X _ T E M P L A T E S >------------------------------------ |
|||
This is a possible replacement for the template prefix templates {{USS}}, {{HMS}}, etc. It has better error |
|||
detection and handling. |
|||
This function is the externally accessible entry point for those templates |
|||
{{#invoke:WPSHIPS_utilities|ship_prefix_templates|prefix=<prefix>|template=<template name>}} |
|||
Parameters in the module frame are: |
|||
|_prefix= – (required) _prefix (HMS, USS, Japanese submarine, etc) |
|||
|_template= template name for error messages; optional when |prefix= same as template name |
|||
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole); |
|||
Parameters in the template frame are: |
|||
{{{1|}}} – ship's name (required) |
|||
{{{2|}}} – disambiguator (year, hull or pennant number, etc) |
|||
{{{3|}}} – format control (1, 2, 3, 5, 6; 4 not allowed) |
|||
|wl= – when set to 'no', rendering is not wikilinked |
|||
|up= – when set to 'yes' prefix (if rendered) is not linked |
|||
]] |
|||
local function ship_prefix_templates (frame) -- this version not supported from the templates yet |
|||
local args_t = get_args (frame); |
|||
local prefix = args_t.prefix or ''; -- fetch positional parameters into named variables for readability |
|||
local name = args_t[1] or ''; -- stripped of leading and trailing whitespace |
|||
local dab = args_t[2] or ''; -- empty positional parameters are nil so convert nil to empty string |
|||
local control = args_t[3]; |
|||
local unlinked_prefix = 'yes' == args_t.up; -- make boolean: true when |up=yes |
|||
local unlinked_whole = 'no' == args_t.wl; -- make boolean: true when |wl=no |
|||
local no_cat = 'yes' == args_t['no-tracking']; -- make boolean: true when |no-tracking=yes |
|||
return _ship (prefix, name, dab, control, unlinked_prefix, unlinked_whole, args_t.template_name or prefix, no_cat); |
|||
end |
end |
||
Line 740: | Line 670: | ||
elseif splats == level + 1 then -- number of splats can only increase by one |
elseif splats == level + 1 then -- number of splats can only increase by one |
||
level = splats; -- record the new level |
level = splats; -- record the new level |
||
table.insert (html_table, '<ul style="list-style: |
table.insert (html_table, '<ul style="list-style:none">'); -- add a new sublist |
||
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item |
table.insert (html_table, List_item_otag .. item .. '</li>'); -- and the item |
||
elseif splats < level then -- from three splats to one splat for example |
elseif splats < level then -- from three splats to one splat for example |
||
Line 869: | Line 799: | ||
]] |
]] |
||
local function synonym_check (args_t, uk_param, us_param, error_flag) |
local function synonym_check (args_t, uk_param, us_param)--, error_flag) |
||
if args_t[uk_param] and args_t[us_param] then |
if args_t[uk_param] and args_t[us_param] then |
||
args_t[uk_param] = args_t[uk_param] .. make_error_msg ('synonymous'); -- both are set so append error message with category |
|||
args_t[ |
args_t[us_param] = args_t[us_param] .. make_error_msg ('synonymous', true); -- but append error message without category |
||
args_t[us_param] = args_t[us_param] .. error_msg_make ('synonymous', nil, nil, true); -- but append error message without category |
|||
return true; -- inform the calling function that it needs to emit maint category |
return true; -- inform the calling function that it needs to emit maint category |
||
end |
end |
||
-- return error_flag; -- no match so return unmodified <error_flag> |
|||
end |
end |
||
Line 921: | Line 850: | ||
return table.concat (lines_t); -- make a big string of line items and done |
return table.concat (lines_t); -- make a big string of line items and done |
||
end |
|||
--[[--------------------------< I S _ E M P T Y _ I B O X _ T E M P L A T E >---------------------------------- |
|||
temporary(?) code to add Category:WPSHIPS: articles with empty infobox templates when empty infobox templates |
|||
are encountered. A template is empty when no parameters have assigned values or when the only parameter with an |
|||
assigned value is |Hide header= |
|||
when 'empty', returns the category name; nil else |
|||
]] |
|||
local function is_empty_ibox_template (args_t) |
|||
local i = 0; |
|||
for k, v in pairs (args_t) do |
|||
i = i + 1; |
|||
end |
|||
if ((1 == i) and args_t['Hide header']) or (0 == i) then |
|||
return '[[Category:WPSHIPS: articles with empty infobox templates]]'; |
|||
end |
|||
end |
end |
||
Line 955: | Line 863: | ||
local function infobox_ship_career (frame) |
local function infobox_ship_career (frame) |
||
local args_t = get_args (frame); -- get a table of all parameters in the template call |
local args_t = get_args (frame); -- get a table of all parameters in the template call |
||
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates |
|||
if err_cat then |
|||
return err_cat; -- template is empty so return the category and done |
|||
end |
|||
local html_out_t = {}; -- html table text goes here |
local html_out_t = {}; -- html table text goes here |
||
-- local error_flag = false; -- controls emission of maint category when synonymous parameters are both set |
|||
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set |
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set |
||
-- error_flag = synonym_check (args_t, 'Ship stricken', 'Ship struck', error_flag); -- error if both synonymous parameters set |
|||
-- error_flag = synonym_check (args_t, 'Ship honours', 'Ship honors', error_flag); |
|||
-- error_flag = synonym_check (args_t, 'Ship pennant num', 'Ship hull num', error_flag); |
|||
synonym_check (args_t, 'Ship stricken', 'Ship struck'); -- error if both synonymous parameters set |
|||
synonym_check (args_t, 'Ship honours', 'Ship honors'); |
|||
synonym_check (args_t, 'Ship pennant num', 'Ship hull num'); |
|||
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header |
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header |
||
Line 977: | Line 884: | ||
if args_t['Ship country'] and args_t['Ship flag'] then |
if args_t['Ship country'] and args_t['Ship flag'] then |
||
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE |
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:left;padding-left:2px;vertical-align:middle;font-size:110%;">'); |
||
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag'])); |
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag'])); |
||
table.insert (html_out_t, '<span style="padding-left:1em">'); |
table.insert (html_out_t, '<span style="padding-left:1em">'); |
||
Line 984: | Line 891: | ||
table.insert (html_out_t, '</th></tr>\n'); |
table.insert (html_out_t, '</th></tr>\n'); |
||
elseif args_t['Ship country'] then |
elseif args_t['Ship country'] then |
||
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE |
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;text-align:center;vertical-align:middle;font-size:110%;">'); |
||
table.insert (html_out_t, args_t['Ship country']); |
table.insert (html_out_t, args_t['Ship country']); |
||
table.insert (html_out_t, '</th></tr>\n'); |
table.insert (html_out_t, '</th></tr>\n'); |
||
elseif args_t['Ship flag'] then |
elseif args_t['Ship flag'] then |
||
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE |
table.insert (html_out_t, '<tr><th height="30" colspan="2" style="background-color:#B0C4DE;padding-left:2px;">'); |
||
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag'])); |
table.insert (html_out_t, _infobox_ship_flag (args_t['Ship flag'])); |
||
table.insert (html_out_t, '</th></tr>\n'); |
table.insert (html_out_t, '</th></tr>\n'); |
||
Line 1,011: | Line 918: | ||
local function infobox_ship_characteristics (frame) |
local function infobox_ship_characteristics (frame) |
||
local args_t = get_args (frame); -- get a table of all parameters in the template call |
local args_t = get_args (frame); -- get a table of all parameters in the template call |
||
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates |
|||
if err_cat then |
|||
return err_cat; -- template is empty so return the category and done |
|||
end |
|||
local html_out_t = {}; -- html table text goes here |
local html_out_t = {}; -- html table text goes here |
||
-- local error_flag = false; -- controls emission of maint category when synonymous parameters are both set |
|||
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set |
args_t['Hide header'] = args_t['Hide header'] and args_t['Hide header']:lower(); -- set to lowercase if set |
||
-- error_flag = synonym_check (args_t, 'Ship armour', 'Ship armor', error_flag); -- error if both synonymous parameters set |
|||
-- error_flag = synonym_check (args_t, 'Ship draught', 'Ship draft', error_flag); |
|||
synonym_check (args_t, 'Ship armour', 'Ship armor'); -- error if both synonymous parameters set |
|||
synonym_check (args_t, 'Ship draught', 'Ship draft'); |
|||
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header |
if 'yes' ~= args_t['Hide header'] then -- |Hide header=yes then no header |
||
Line 1,053: | Line 957: | ||
local function infobox_ship_class_overview (frame) |
local function infobox_ship_class_overview (frame) |
||
local args_t = get_args (frame); -- get a table of all parameters in the template call |
local args_t = get_args (frame); -- get a table of all parameters in the template call |
||
local err_cat = is_empty_ibox_template (args_t); -- look for and identify empty templates |
|||
if err_cat then |
|||
return err_cat; -- template is empty so return the category and done |
|||
end |
|||
local html_out_t = {}; -- html table text goes here |
local html_out_t = {}; -- html table text goes here |
||
Line 1,098: | Line 996: | ||
local args_t = get_args (frame); -- get a table of all parameters in the invoke |
local args_t = get_args (frame); -- get a table of all parameters in the invoke |
||
local year, volume, scan; |
local year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts |
||
if args_t[1] then -- this to avoid script errors when args_t[1] missing |
|||
year, volume, scan = args_t[1]:match ('(%d%d)(%l)(%d%d%d%d)%.[Pp][Dd][Ff]'); -- get the various parts |
|||
end |
|||
if not year then return nil end -- nil when no match so we're done |
if not year then return nil end -- nil when no match so we're done |
||
year = tonumber (year); |
year = tonumber (year); |
||
Line 1,177: | Line 1,072: | ||
args_t[1]); -- append <filename> onto the end, and done |
args_t[1]); -- append <filename> onto the end, and done |
||
end |
end |
||
end |
|||
--[[--------------------------< S C L A S S >------------------------------------------------------------------ |
|||
implements {{sclass}} and {{sclass2}} |
|||
{{#invoke:WPSHIPS utilities|sclass}} |
|||
]] |
|||
local function sclass (frame) |
|||
local args_t = get_args (frame); |
|||
local parent = frame:getParent(); |
|||
local template = parent:getTitle():gsub ('^Template:', ''):lower(); -- get the name of the template that called this module (includes namespace so strip that) |
|||
local class_name = args_t[1]; -- names to make it easier to understand |
|||
local ship_type = args_t[2]; |
|||
local format = args_t[3]; |
|||
local ship_type_dab = args_t[4]; |
|||
local class_name_dab = args_t[5]; |
|||
local no_cat = 'yes' == args_t['no-cat']; -- make a boolean |
|||
if not class_name then -- when omitted, abandon with error message |
|||
return error_msg_make ('missing', template, 'class name', no_cat); |
|||
end |
|||
if not ship_type then -- when omitted, abandon with error message |
|||
return error_msg_make ('missing', template, 'ship type', no_cat); |
|||
end |
|||
if format then |
|||
if tonumber (format) then -- if <format> has a value that is a number |
|||
format = tonumber (format); -- make it a number for comparisons |
|||
if 5 < format then -- is <format> outside of allowed range |
|||
return error_msg_make ('format', template, format, no_cat); |
|||
end |
|||
else -- <format> could not be converted to a number |
|||
return error_msg_make ('format', template, format, no_cat); |
|||
end |
|||
end |
|||
local out_t = {}; -- output goes here |
|||
table.insert (out_t, '[['); -- open the wikilink |
|||
table.insert (out_t, class_name); -- build the wikilink to the class article |
|||
table.insert (out_t, '-class '); |
|||
table.insert (out_t, ship_type); -- add ship type |
|||
if class_name_dab then -- when class article is disambiguated |
|||
table.insert (out_t, ' ('); -- add the disambiguator |
|||
table.insert (out_t, class_name_dab); |
|||
table.insert (out_t, ')'); |
|||
end |
|||
table.insert (out_t, '|'); |
|||
if 'sclass' == template:gsub ('/sandbox', '') then -- strip '/sandbox' if present; class named for a member of the class |
|||
table.insert (out_t, '\'\''); -- class name is italicized |
|||
table.insert (out_t, class_name); |
|||
table.insert (out_t, '\'\''); |
|||
else |
|||
table.insert (out_t, class_name); -- class name is a common attribute; plain text |
|||
end |
|||
if not format or (3 == format) then -- when format is omitted, same as format #3 |
|||
table.insert (out_t, '-class]] [['); -- open ship-type wikilink |
|||
if ship_type_dab then -- when ship-type article is disambiguated |
|||
table.insert (out_t, ship_type); -- add ship type |
|||
table.insert (out_t, ' ('); -- and the disambiguator |
|||
table.insert (out_t, ship_type_dab); |
|||
table.insert (out_t, ')|'); -- dab is not displayed so insert a pipe and |
|||
end |
|||
table.insert (out_t, ship_type); -- add ship type |
|||
table.insert (out_t, ']]'); -- close ship-type wikilink |
|||
end |
|||
if 0 == format then -- no separate ship-type wikilink |
|||
table.insert (out_t, '-class]]'); |
|||
end |
|||
if 1 == format then -- no separate ship-type wikilink |
|||
table.insert (out_t, '-class '); |
|||
table.insert (out_t, ship_type); |
|||
table.insert (out_t, ']]'); |
|||
end |
|||
if 2 == format then -- ship-type is not wikilinked |
|||
table.insert (out_t, '-class]] '); |
|||
table.insert (out_t, ship_type); |
|||
end |
|||
if 4 == format then -- noun form; no ship type |
|||
table.insert (out_t, ' class]]'); |
|||
end |
|||
if 5 == format then -- class name only; no '-class' annotation |
|||
table.insert (out_t, ']]'); |
|||
end |
|||
return table.concat (out_t); |
|||
end |
end |
||
Line 1,289: | Line 1,087: | ||
is_plimsoll_filename = is_plimsoll_filename, |
is_plimsoll_filename = is_plimsoll_filename, |
||
navsource = navsource, |
navsource = navsource, |
||
sclass = sclass, |
|||
set_plimsoll_subtitle = set_plimsoll_subtitle, |
set_plimsoll_subtitle = set_plimsoll_subtitle, |
||
set_plimsoll_date = set_plimsoll_date, |
set_plimsoll_date = set_plimsoll_date, |
||
set_plimsoll_url = set_plimsoll_url, |
set_plimsoll_url = set_plimsoll_url, |
||
ship = ship, -- experiment |
ship = ship, -- experiment |
||
ship_prefix_templates = ship_prefix_templates, -- experiment |
|||
ship_name_format = ship_name_format, |
ship_name_format = ship_name_format, |
||
unbulleted_list = unbulleted_list, |
unbulleted_list = unbulleted_list, |