Module:Infobox ship: Difference between revisions

Content deleted Content added
create;
 
No edit summary
 
(8 intermediate revisions by 2 users not shown)
Line 1:
require('Module:No globalsstrict');
 
local utilities = require ('Module:WPSHIPS_utilities');
Line 11:
local data = mw.loadData ('Module:Infobox_ship/data');
 
local namenamespace = mw.title.getCurrentTitle().textnamespace;
local has_unknown_params = false;
 
--[[--------------------------< L I N E _ I T E M S >-----------------------------------------------------------------------------
Line 16 ⟶ 18:
spin through <params_t> sequence. Get parameter name and matching infobox label. Look in <args_t> for parameter name. When parameter
name has a value, add infobox label and parameter value to the infobox table <infobox_ship_t>. <i> identifies where label and data
enumberatorsenumerators begin.
 
]]
Line 26 ⟶ 28:
infobox_ship_t['data' .. i] = unbulleted_list (args_t[v[1]]); -- and add the parameter value as data
i = i + 1; -- bump the enumerator
end
end
end
 
 
--[[--------------------------< U N K N O W N _ P A R A M S _C H E C K >---------------------------------------
 
check parameters supplyed in <template> against known parameters for that template. Emit preview warning when
a parameter is unknown.
 
]]
 
local function unknown_params_check (args_t, known_params_t, template)
for k, v in pairs (args_t) do
local param = k:gsub ('%d+$', '#'); -- for enumerated parameters, replace enumerator with '#'
if not known_params_t[param] then -- add warning message when <param> is not known for <template>
mw.addWarning (string.format (data.warning_fmt_str, data.warn_span_style, data.warn_code_style, template, template, data.warn_code_style, k, v));
has_unknown_params = (0 == namespace); -- add unknown params category when infobox is rendered; mainspace only
end
end
Line 38 ⟶ 58:
 
local function infobox_ship_begin (args_t, infobox_ship_t, frame)
local name = mw.title.getCurrentTitle().text;
 
infobox_ship_t['bodystyle'] = data.styles_t.mainbox;
if args_t.infobox_caption then
local name = mw.title.getCurrentTitle().text;
if 'yes' == args_t.infobox_caption then -- format article title as infobox caption
infobox_ship_t.title = ship_name_format ({name=name, adj='off', showerrs=args_t.showerrs, sclass=args_t.sclass});
Line 52 ⟶ 73:
end
 
if args_t.display_title and ('none' ~= args_t.display_title) then -- any value but 'none'
if 'ital' == args_t.display_title then -- use {{italic title}} template
infobox_ship_t.title = infobox_ship_t.title .. frame:expandTemplate ({title='italic title'});
else elseif ('none' ~= args_t.display_title) then -- any value but 'none' use value in |display_title= for {{DISPLAYTITLE}} magic word
infobox_ship_t.title = infobox_ship_t.title .. frame:preprocess ('{{DISPLAYTITLE:' .. args_t.display_title .. '}}');
end
else -- |display_title= empty or omitted, use article title
infobox_ship_t.title = infobox_ship_t.title .. frame:preprocess ('{{DISPLAYTITLE:' .. ship_name_format ({name=name, sclass=args_t.sclass}) .. '}}');
end
end
Line 72 ⟶ 95:
local function infobox_ship_image (frame)
local args_t = get_args (frame);
 
if not args_t.image then
return; -- if no image specified, abandon
end
local infobox_ship_t = {
child = args_t.child or 'yes'; -- default to child
Line 77 ⟶ 105:
caption1 = args_t.image_caption;
}
 
unknown_params_check (args_t, data.known_infobox_ship_image_params_t, 'Infobox ship/image');
 
return frame:expandTemplate ({title='Infobox', args = infobox_ship_t}); -- return a rendering of this infobox
Line 132 ⟶ 162:
 
line_items (args_t, data.infobox_career_params_t, infobox_ship_t, i, frame); -- go do all of the other infobox parameters
unknown_params_check (args_t, data.known_infobox_ship_career_params_t, 'Infobox ship/career');
 
return frame:expandTemplate ({title='Infobox', args = infobox_ship_t}); -- return a rendering of this infobox
Line 170 ⟶ 201:
 
line_items (args_t, data.infobox_characteristics_params_t, infobox_ship_t, i, frame); -- go do all of the other infobox parameters
unknown_params_check (args_t, data.known_infobox_ship_characteristics_params_t, 'Infobox ship/characteristics');
 
return frame:expandTemplate ({title='Infobox', args = infobox_ship_t}); -- return a rendering of this infobox
Line 198 ⟶ 230:
i = i + 1; -- bump the enumerator
end
 
synonym_check (args_t, 'total_ships_cancelled', 'total_ships_canceled', nil); -- error if both synonymous parameters set
 
line_items (args_t, data.infobox_class_overview_params_t, infobox_ship_t, i, frame); -- go do all of the other infobox parameters
unknown_params_check (args_t, data.known_infobox_ship_class_overview_params_t, 'Infobox ship/class');
 
return frame:expandTemplate ({title='Infobox', args = infobox_ship_t}); -- return a rendering of this infobox
Line 231 ⟶ 266:
 
line_items (args_t, data.infobox_ship_service_record_params_t, infobox_ship_t, i, frame); -- go do all of the other infobox parameters
unknown_params_check (args_t, data.known_infobox_ship_service_record_params_t, 'Infobox ship/service record');
 
return frame:expandTemplate ({title='Infobox', args = infobox_ship_t}); -- return a rendering of this infobox
Line 258 ⟶ 294:
 
end
unknown_params_check (args_t, data.known_infobox_ship_params_t, 'Infobox ship');
 
return frame:expandTemplate ({title='Infobox', args = infobox_ship_t}) .. (has_unknown_params and '[[Category:Pages using infobox ship with unknown parameters]]' or '');
end