Jump to content

Module:Infobox ship/data

Permanently protected module
From Wikipedia, the free encyclopedia
--[[--------------------------< W A R N I N G   M E S S A G E S >----------------------------------------------

These styles cannot be moved to Module:Infobox ship/style.css because mw.addWarning() does not understand or apply css

]]

local warn_span_style = 'color:#bf3c2c';
local warn_code_style = 'color: inherit; background: inherit; border: none; padding: inherit;';
local warning_fmt_str = '<span style="%s"><code style="%s">&#123;{[[Template:%s|%s]]}}</code>: unknown parameter: <code style="%s">|%s=%s</code></span>';


--[[--------------------------< E R R O R _ M E S S A G E S >--------------------------------------------------
]]

local error_messages_t = {
	missing_section = '<span class="error">missing <span class="code">|section\'\'n\'\'=</span> parameter in <span class="code">|section%s=</span></span>',		-- %s is |sectionn= (|datan=) enumerator
	positional = '<span class="error">positional parameters not supported</span>',	-- categorized in the unknown parameter category (because in '|{{infobox ship/...}}' the positional param is not known)
	}


--[[--------------------------< C A T E G O R I E S >----------------------------------------------------------
]]

local categories_t = {
	no_image = '[[Category:Ship infoboxes without an image]]',
	unknown = '[[Category:Pages using infobox ship with unknown parameters]]',
	missing_section = '[[Category:Ship infoboxes missing section parameter]]',
	}


--[[--------------------------< I N F O B O X   P A R A M E T E R S >------------------------------------------

These tables hold the names and define the rendering order of the label/data pairs in the associated infoboxen.
Each table is a sequence of sub-sequences where each subsequence holds
	[1] the parameter name
	[2] the rendered label for that parameter's value

]]

local infobox_career_params_t = {												-- table of parameters that are rendered in the same way
	{'name', 'Name'},
	{'namesake', 'Namesake'},
	{'owner', 'Owner'},
	{'operator', 'Operator'},
	{'registry', 'Port of registry'},
	{'route', 'Route'},
	{'ordered', 'Ordered'},
	{'awarded', 'Awarded'},
	{'builder', 'Builder'},
	{'original_cost', 'Cost'},
	{'yard_number', 'Yard number'},
	{'way_number', 'Way number'},
	{'laid_down', 'Laid down'},
	{'launched', 'Launched'},
	{'sponsor', 'Sponsored by'},
	{'christened', 'Christened'},
	{'completed', 'Completed'},
	{'acquired', 'Acquired'},
	{'commissioned', 'Commissioned'},
	{'recommissioned', 'Recommissioned'},
	{'decommissioned', 'Decommissioned'},
	{'maiden_voyage', 'Maiden voyage'},
	{'in_service', 'In service'},
	{'out_of_service', 'Out of service'},
	{'renamed', 'Renamed'},
	{'reclassified', 'Reclassified'},
	{'refit', 'Refit'},
	{'struck', 'Stricken'},
	{'stricken', 'Stricken'},
	{'reinstated', 'Reinstated'},
	{'homeport', 'Homeport'},
	{'identification', 'Identification'},
	{'motto', 'Motto'},
	{'nickname', 'Nickname(s)'},
	{'honours', 'Honours and<br />awards'},										-- uk spelling
	{'honors', 'Honors and<br />awards'},
	{'captured', 'Captured'},
	{'fate', 'Fate'},
	{'status', 'Status'},
	{'notes', 'Notes'},
	{'badge', 'Badge'},
	}

local infobox_characteristics_params_t = {										-- table of parameters that are rendered in the same way
	{'class', 'Class & type'},
	{'type', 'Type'},
	{'tonnage', 'Tonnage'},
	{'displacement', 'Displacement'},
	{'tons_burthen', 'Tons burthen'},
	{'length', 'Length'},
	{'beam', 'Beam'},
	{'height', 'Height'},
	{'draught', 'Draught'},														-- uk spelling
	{'draft', 'Draft'},
	{'depth', 'Depth'},
	{'hold_depth', 'Depth of hold'},
	{'decks', 'Decks'},
	{'deck_clearance', 'Deck clearance'},
	{'ramps', 'Ramps'},
	{'ice_class', 'Ice class'},
	{'power', 'Installed power'},
	{'propulsion', 'Propulsion'},
	{'sail_plan', 'Sail plan'},
	{'speed', 'Speed'},
	{'range', 'Range'},
	{'endurance', 'Endurance'},
	{'test_depth', 'Test depth'},
	{'boats', 'Boats & landing<br />craft carried'},
	{'capacity', 'Capacity'},
	{'troops', 'Troops'},
	{'complement', 'Complement'},
	{'crew', 'Crew'},
	{'time_to_activate', 'Time to activate'},
	{'sensors', 'Sensors &<br />processing systems'},
	{'EW', 'Electronic warfare<br />& decoys'},
	{'armament', 'Armament'},
	{'armour', 'Armour'},														-- uk spelling
	{'armor', 'Armor'},
	{'aircraft', 'Aircraft carried'},
	{'aircraft_facilities', 'Aviation facilities'},
	{'notes', 'Notes'},
	}

local infobox_class_overview_params_t = {										-- table of parameters that are rendered in the same way
	{'name', 'Name'},
	{'builders', 'Builders'},
	{'operators', 'Operators'},
	{'class_before', 'Preceded by'},
	{'class_after', 'Succeeded&nbsp;by'},
	{'subclasses', 'Subclasses'},
	{'cost', 'Cost'},
	{'built_range', 'Built'},
	{'in_service_range', 'In service'},
	{'in_commission_range', 'In commission'},
	{'total_ships_planned', 'Planned'},
	{'total_ships_on_order', 'On order'},
	{'total_ships_building', 'Building'},
	{'total_ships_completed', 'Completed'},
	{'total_ships_cancelled', 'Cancelled'},										-- uk spelling
	{'total_ships_canceled', 'Canceled'},
	{'total_ships_active', 'Active'},
	{'total_ships_laid_up', 'Laid up'},
	{'total_ships_lost', 'Lost'},
	{'total_ships_retired', 'Retired'},
	{'total_ships_scrapped', 'Scrapped'},
	{'total_ships_preserved', 'Preserved'},
	}

local infobox_ship_service_record_params_t = {									-- table of parameters that are rendered in the same way
	{'partof', 'Part of'},
	{'codes', 'Identification codes'},
	{'commanders', 'Commanders'},
	{'operations', 'Operations'},
	{'victories', 'Victories'},
	{'awards', 'Awards'},
	}


--[[--------------------------< K N O W N   P A R A M E T E R   T A B L E S >----------------------------------

These tables for detecting unknown parameters

]]

local known_infobox_ship_params_t = {											-- all parameters known to {{Infox ship}}
	['data#'] = true,															-- these native to infobox ship
	['label#'] = true,
	['section#'] = true,

	display_title = true,														-- these inherited from obsolete {{infobox ship begin}}
	infobox_caption = true,
	sclass = true,
	showerrs = true,
	}

local known_infobox_ship_image_params_t = {										-- all parameters known to {{Infox ship/image}}
	child = true,																-- |child= defaults to 'yes'; set to 'no' for standalone 
	infobox_caption = true,														-- only valid when |child=no (stand-alone mode)
	image = true,
	image_alt = true,
	image_size = true,
	image_caption = true,
	}

local known_infobox_ship_career_params_t = {									-- non-line-item parameters known to {{Infox ship/career}}
	child = true,																-- |child= defaults to 'yes'; set to 'no' for standalone 
	infobox_caption = true,														-- this one only valid when |child=no (stand-alone mode)
	hide_header = true,
	country = true,
	flag = true,
	}
	
local known_infobox_ship_characteristics_params_t = {							-- non-line-item parameters known to {{Infox ship/characteristics}}
	child = true,																-- |child= defaults to 'yes'; set to 'no' for standalone 
	infobox_caption = true,														-- this one only valid when |child=no (stand-alone mode)
	header_caption = true,
	hide_header = true,
	}
	
local known_infobox_ship_class_overview_params_t = {							-- non-line-item parameters known to {{Infox ship/class}}
	child = true,																-- |child= defaults to 'yes'; set to 'no' for standalone 
	infobox_caption = true,														-- this one only valid when |child=no (stand-alone mode)
	hide_header = true,
	}
	
local known_infobox_ship_service_record_params_t = {							-- non-line-item parameters known to {{Infox ship/service record}}
	child = true,																-- |child= defaults to 'yes'; set to 'no' for standalone 
	infobox_caption = true,														-- this one only valid when |child=no (stand-alone mode)
	header_caption = true,
	hide_header = true,
	label = true,																-- deprecated alias of |header_caption=
	}


for _, tables_t in ipairs (
	{																			-- this table maps line-item tables with known parameter tables
	{infobox_career_params_t, known_infobox_ship_career_params_t},
	{infobox_characteristics_params_t, known_infobox_ship_characteristics_params_t},
	{infobox_class_overview_params_t, known_infobox_ship_class_overview_params_t},
	{infobox_ship_service_record_params_t, known_infobox_ship_service_record_params_t},
	}) do																		-- now fill known parameter tables from line-item tables
		for _, line_t in ipairs (tables_t[1]) do								-- <line_t> is sequence of parameter name [1] and displayed label [2]
			tables_t[2][line_t[1]] = true;										-- known-parameters table gets parameter name set to boolean true
		end
end


--[[--------------------------< E X P O R T S >----------------------------------------------------------------
]]

local namespace_number = mw.title.getCurrentTitle().namespace;					-- get article namespace for categorization

return
	{
	cat_this_namespace = (0 == namespace_number) or (118 == namespace_number),	-- only categorize in these namespaces (article, draft)
	stripmarker = '\127[^\127]*UNIQ%-%-%a+%-%x+%-QINU[^\127]*\127',				-- used to supress stripmarkers in preview warning messages
	
	namespace_number = namespace_number,										-- article namespace number
	namespace_name = mw.title.getCurrentTitle().nsText;							-- article namespace name
	
	categories_t = categories_t,
	error_messages_t = error_messages_t,
	
	infobox_career_params_t = infobox_career_params_t,							-- infobox ship line items
	infobox_characteristics_params_t = infobox_characteristics_params_t,
	infobox_class_overview_params_t = infobox_class_overview_params_t,
	infobox_ship_service_record_params_t = infobox_ship_service_record_params_t,
	
	warn_code_style = warn_code_style,											-- for preview warning messages; preview warning messages do not support css
	warning_fmt_str = warning_fmt_str,
	warn_span_style = warn_span_style,

	known_infobox_ship_params_t = known_infobox_ship_params_t,					-- for detecting unknown parameters
	known_infobox_ship_image_params_t = known_infobox_ship_image_params_t,
	known_infobox_ship_career_params_t = known_infobox_ship_career_params_t,
	known_infobox_ship_characteristics_params_t = known_infobox_ship_characteristics_params_t,
	known_infobox_ship_class_overview_params_t = known_infobox_ship_class_overview_params_t,
	known_infobox_ship_service_record_params_t = known_infobox_ship_service_record_params_t
	}