<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ANaval_Vessel_Register_URL</id>
	<title>Module:Naval Vessel Register URL - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://mywikibiz.com/index.php?action=history&amp;feed=atom&amp;title=Module%3ANaval_Vessel_Register_URL"/>
	<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Naval_Vessel_Register_URL&amp;action=history"/>
	<updated>2026-06-19T12:47:13Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.35.3</generator>
	<entry>
		<id>https://mywikibiz.com/index.php?title=Module:Naval_Vessel_Register_URL&amp;diff=478777&amp;oldid=prev</id>
		<title>Zoran: Pywikibot 6.4.0</title>
		<link rel="alternate" type="text/html" href="https://mywikibiz.com/index.php?title=Module:Naval_Vessel_Register_URL&amp;diff=478777&amp;oldid=prev"/>
		<updated>2021-07-16T05:03:56Z</updated>

		<summary type="html">&lt;p&gt;Pywikibot 6.4.0&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[[  &lt;br /&gt;
 &lt;br /&gt;
This module generates links to ships in the Naval Vessel Register (nvr.navy.mil) database.  &lt;br /&gt;
It is used by Template:Naval Vessel Register URL and Template:Naval Vessel Register service craft URL&lt;br /&gt;
 &lt;br /&gt;
Please do not modify this code without applying the changes first at Module:Naval Vessel Register URL/sandbox and testing &lt;br /&gt;
at Module:Naval Vessel Register URL/sandbox/testcases and Module talk:Naval Vessel Register URL/sandbox/testcases.&lt;br /&gt;
 &lt;br /&gt;
Authors and maintainers:&lt;br /&gt;
* User:RP88&lt;br /&gt;
 &lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
require('Module:No globals')&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; F O R W A R D   D E C L A R A T I O N S &amp;gt;--------------------------------------&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local ships_data = {};&lt;br /&gt;
local srv_craft_data = {};&lt;br /&gt;
&lt;br /&gt;
local data = mw.loadData ('Module:Naval Vessel Register URL/data');&lt;br /&gt;
	ships_data = data.nvr_ships_id;&lt;br /&gt;
	srv_craft_data = data.nvr_srv_craft_id;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; M A K E _ E R R O R _ M E S S A G E &amp;gt;------------------------------------------&lt;br /&gt;
&lt;br /&gt;
General purpose error message function to render error messages and categorization&lt;br /&gt;
&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
local function make_error_message (output, prefix, item, suffix, srv_craft)&lt;br /&gt;
	local category = '';														-- for concatenation&lt;br /&gt;
	&lt;br /&gt;
	if 0 == mw.title.getCurrentTitle().namespace then							-- article namespace&lt;br /&gt;
		category = '[[Category:WPSHIPS:Template_errors]]';						-- categorize only from article namespace&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	table.insert (output, '&amp;lt;span style=&amp;quot;font-size:100%&amp;quot; class=&amp;quot;error&amp;quot;&amp;gt;')&lt;br /&gt;
	table.insert (output, prefix);&lt;br /&gt;
	table.insert (output, item);&lt;br /&gt;
	table.insert (output, suffix);&lt;br /&gt;
	if srv_craft then&lt;br /&gt;
		table.insert (output, ' ([[Template:Naval Vessel Register service craft URL#Error messages|help]])&amp;lt;/span&amp;gt;');&lt;br /&gt;
	else&lt;br /&gt;
		table.insert (output, ' ([[Template:Naval Vessel Register url#Error messages|help]])&amp;lt;/span&amp;gt;');&lt;br /&gt;
	end&lt;br /&gt;
	table.insert (output, category);&lt;br /&gt;
	return&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; M A K E _ S H I P _ L I N K &amp;gt;--------------------------------------------------&lt;br /&gt;
&lt;br /&gt;
This function returns a link to a ship in the Naval Vessel Register.&lt;br /&gt;
 &lt;br /&gt;
Usage:&lt;br /&gt;
{{#invoke:Naval Vessel Register URL|MakeShipLink|1=|title=}}&lt;br /&gt;
{{#invoke:Naval Vessel Register URL|MakeShipLink}} - uses the caller's parameters&lt;br /&gt;
 &lt;br /&gt;
Parameters&lt;br /&gt;
    1, id: The ship's hull classification symbol&lt;br /&gt;
    2, title: A title or label for the link.&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
function p.MakeShipLink (frame)&lt;br /&gt;
	local args = frame.args														-- if no argument provided, check parent template/module args&lt;br /&gt;
	local output = {};&lt;br /&gt;
&lt;br /&gt;
	if (args[1]==nil) and (args[&amp;quot;id&amp;quot;]==nil) then&lt;br /&gt;
		args = frame:getParent().args;&lt;br /&gt;
		if (args[1]==nil) and (args[&amp;quot;id&amp;quot;]==nil) then&lt;br /&gt;
			make_error_message (output, 'required parameter missing', '', '');&lt;br /&gt;
			return table.concat (output);&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local hull = args[&amp;quot;id&amp;quot;] or args[1] or '';&lt;br /&gt;
	local hull_designator;														-- for use with |name= parameter rendering&lt;br /&gt;
	local hull_prefix;&lt;br /&gt;
	local title = args[&amp;quot;title&amp;quot;] or args[2] or '';&lt;br /&gt;
	&lt;br /&gt;
	if '' == title then															-- to prevent external links that look like this: [1]&lt;br /&gt;
		title = nil;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	hull = mw.text.trim (hull):upper();											-- make sure that there is no leading/trailing whitespace and uppercase&lt;br /&gt;
																				-- standardize so that we can recognize as many formats as possible&lt;br /&gt;
	hull_designator = hull:match ('^T%-') or '';								-- if there is a 'T-' prefix to the prefix, save a copy of it; empty string for concatenation else&lt;br /&gt;
--error (hull_designator)&lt;br /&gt;
	hull = hull:gsub ('^T%-', '');												-- if hull classification symbol is T-XX-NNN, remove the 'T-'&lt;br /&gt;
	hull = hull:gsub ('(%a+)_(%d+)_%d+', '%1-%2');								-- if template has 'new' url identifier format (SSBN_659_1635); as of March 2019 this form not used at NVR&lt;br /&gt;
	hull = hull:gsub ('(%a+)[_ ]?(%d+)', '%1-%2');								-- if template has SSBN 659 or SSBN_659 or SSBN659 format&lt;br /&gt;
	hull_designator = hull_designator .. hull;									-- copy for use with |name= parameter&lt;br /&gt;
&lt;br /&gt;
	if hull:match ('(%a+)%-%d+') then											-- most common case&lt;br /&gt;
		hull_prefix = hull:match ('(%a+)[%-_]?%d+');&lt;br /&gt;
	elseif hull:match ('[%a+ %(%)]+%-%d+') then									-- special one-off case for AFSB (I)-15&lt;br /&gt;
		hull_prefix = hull:match ('([%a+ %(%)]+)%-%d+')&lt;br /&gt;
	elseif hull:match ('^CONSTITUTION$') or hull:match ('^MAINE$') or hull:match ('^TEXAS$') then	-- Constitution, Maine, and Texas&lt;br /&gt;
		hull_prefix = hull;														-- do not have hull classification symbols; use their names&lt;br /&gt;
	else&lt;br /&gt;
		make_error_message (output, 'malformed hull classification symbol: ', hull, '');&lt;br /&gt;
		return table.concat (output);&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if not ships_data[hull_prefix] then											-- is there a group for the hull number?&lt;br /&gt;
		make_error_message (output, 'unable to find group: [\'', hull_prefix, '\'] in [[Module:Naval Vessel Register URL/data]] nvr_ships_id');&lt;br /&gt;
		return table.concat (output);&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if not ships_data[hull_prefix][hull] then									-- is there a hull number&lt;br /&gt;
		make_error_message (output, 'unable to find hull classification symbol: [\'', hull, '\'] in [[Module:Naval Vessel Register URL/data]] nvr_ships_id');&lt;br /&gt;
		return table.concat (output);&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local nvr_id = ships_data[hull_prefix][hull][1];							-- try to fetch nvr id&lt;br /&gt;
	if not title and (args['name'] and '' ~= args['name']) then&lt;br /&gt;
		title = ships_data[hull_prefix][hull][2];&lt;br /&gt;
		if not title or '' == title then&lt;br /&gt;
			title = nil;														-- ensure&lt;br /&gt;
		elseif 'no name' == title:lower() then									-- new construction capital ships, and many service craft&lt;br /&gt;
			title = title .. ' (' .. hull_designator .. ')';&lt;br /&gt;
		elseif 'nh' == args['name'] then										-- special keyword to render name and hull designator&lt;br /&gt;
			title = '\'\'' .. ships_data[hull_prefix][hull][2] .. '\'\' (' .. hull_designator .. ')';&lt;br /&gt;
		else&lt;br /&gt;
			title = '\'\'' .. ships_data[hull_prefix][hull][2] .. '\'\'';		-- just the name&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if (nil ~= nvr_id) and ('' ~= nvr_id) then									-- there appears to be an identifier, so use it&lt;br /&gt;
		if title then															-- if there is a title then make an external link from it&lt;br /&gt;
			table.insert (output, '[');											-- opening bracket&lt;br /&gt;
		end&lt;br /&gt;
		table.insert (output, 'http://www.nvr.navy.mil/SHIPDETAILS/SHIPSDETAIL_');	-- create the url&lt;br /&gt;
		table.insert (output, nvr_id);&lt;br /&gt;
		table.insert (output, '.HTML');&lt;br /&gt;
		if title then&lt;br /&gt;
			table.insert (output, ' ');											-- required space&lt;br /&gt;
			table.insert (output, title);										-- title&lt;br /&gt;
			table.insert (output, ']');											-- and closing bracket&lt;br /&gt;
		end&lt;br /&gt;
		&lt;br /&gt;
	else																		-- no identifier&lt;br /&gt;
		make_error_message (output, 'no identifier for hull classification symbol: [\'', hull, '\'] in [[Module:Naval Vessel Register URL/data]] nvr_ships_id');&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return table.concat (output);												-- and done&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--[[--------------------------&amp;lt; M A K E _ S E R V I C E _ C R A F T _ L I N K &amp;gt;--------------------------------&lt;br /&gt;
&lt;br /&gt;
This function returns a link to a service craft in the Naval Vessel Register.&lt;br /&gt;
 &lt;br /&gt;
Usage:&lt;br /&gt;
{{#invoke:Naval Vessel Register URL|MakeServiceCraftLink|1=|title=}}&lt;br /&gt;
{{#invoke:Naval Vessel Register URL|MakeServiceCraftLink}} - uses the caller's parameters&lt;br /&gt;
 &lt;br /&gt;
Parameters&lt;br /&gt;
    1, id: The 'file name' portion of the url path (typically the craft's hull designation) without the .HTM/.HTML extension. &lt;br /&gt;
    2, title: A title or label for the link.&lt;br /&gt;
]]&lt;br /&gt;
&lt;br /&gt;
function p.MakeServiceCraftLink( frame )&lt;br /&gt;
	-- if no argument provided than check parent template/module args&lt;br /&gt;
	local args = frame.args&lt;br /&gt;
	local output = {};&lt;br /&gt;
&lt;br /&gt;
	if (args[1]==nil) and (args[&amp;quot;id&amp;quot;]==nil) then&lt;br /&gt;
		args = frame:getParent().args;&lt;br /&gt;
		if (args[1]==nil) and (args[&amp;quot;id&amp;quot;]==nil) then&lt;br /&gt;
			make_error_message (output, 'required parameter missing', '', '', true);&lt;br /&gt;
			return table.concat (output);&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	local hull = args[&amp;quot;id&amp;quot;] or args[1] or '';&lt;br /&gt;
	local hull_prefix;&lt;br /&gt;
	local title = args[&amp;quot;title&amp;quot;] or args[2] or '';&lt;br /&gt;
	&lt;br /&gt;
	if '' == title then															-- to prevent external links that look like this: [1]&lt;br /&gt;
		title = nil;&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	hull = mw.text.trim (hull):upper();											-- make sure that there is no leading/trailing whitespace and uppercase&lt;br /&gt;
																				-- standardize so that we can recognize as many formats as possible&lt;br /&gt;
	hull = hull:gsub ('(%a+)_(%d+)_%d+', '%1-%2');								-- if template has 'new' url identifier format (YT_807_4629)&lt;br /&gt;
	hull = hull:gsub ('(%a+)[_ ]?(%d+)', '%1-%2');								-- if template has YT 807 or YT_807 or YT807 format&lt;br /&gt;
&lt;br /&gt;
	if hull:match ('(%a+)%-%d+') then											-- most common case&lt;br /&gt;
		hull_prefix = hull:match ('(%a+)%-%d+');&lt;br /&gt;
	elseif hull:match ('(%a+)%-%d+%a') then										-- special cases for the various sections of floating dry docks;&lt;br /&gt;
		hull_prefix = hull:match ('(%a+)%-%d+%a');								-- each section has a single letter designator: AFDB-7F&lt;br /&gt;
	else&lt;br /&gt;
		make_error_message (output, 'malformed hull classification symbol: ', hull, '', true);&lt;br /&gt;
		return table.concat (output);&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	if not srv_craft_data[hull_prefix] then										-- is there a group for the hull number?&lt;br /&gt;
		make_error_message (output, 'unable to find group: [\'', hull_prefix, '\'] in [[Module:Naval Vessel Register URL/data]] nvr_srv_craft_id', true);&lt;br /&gt;
		return table.concat (output);&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	if not srv_craft_data[hull_prefix][hull] then								-- is there a hull number&lt;br /&gt;
		make_error_message (output, 'unable to find hull classification symbol: [\'', hull, '\'] in [[Module:Naval Vessel Register URL/data]] nvr_srv_craft_id', true);&lt;br /&gt;
		return table.concat (output);&lt;br /&gt;
	end&lt;br /&gt;
&lt;br /&gt;
	local nvr_id = srv_craft_data[hull_prefix][hull][1];						-- try to fetch nvr id&lt;br /&gt;
&lt;br /&gt;
	if (nil ~= nvr_id) and ('' ~= nvr_id) then									-- there appears to be an identifier, so use it&lt;br /&gt;
		if title then&lt;br /&gt;
			table.insert (output, '[');&lt;br /&gt;
		end&lt;br /&gt;
		table.insert (output, 'http://www.nvr.navy.mil/SHIPDETAILS/SHIPSDETAIL_');&lt;br /&gt;
		table.insert (output, nvr_id);&lt;br /&gt;
		table.insert (output, '.HTML');&lt;br /&gt;
		if title then&lt;br /&gt;
			table.insert (output, ' ');&lt;br /&gt;
			table.insert (output, title);&lt;br /&gt;
			table.insert (output, ']');&lt;br /&gt;
		end&lt;br /&gt;
	else																		-- no identifier&lt;br /&gt;
		make_error_message (output, 'no identifier for hull classification symbol: [\'', hull, '\'] in [[Module:Naval Vessel Register URL/data]] nvr_srv_craft_id', true);&lt;br /&gt;
	end&lt;br /&gt;
	&lt;br /&gt;
	return table.concat (output);&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Zoran</name></author>
	</entry>
</feed>