Jump to content

Module:Naval Vessel Register URL/doc: Difference between revisions

From Wikipedia, the free encyclopedia
Content deleted Content added
module's been in use for a month
update;
Line 1: Line 1:
{{ml|NVR|sandbox=NVR/sandbox}}
{{Module rating |release <!-- Values: pre-alpha • alpha • beta • release • protected -- If a rating not needed/relevant, delete this template call -->}}
<!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) -->
<!-- Please place categories where indicated at the bottom of this page and interwikis at Wikidata (see [[Wikipedia:Wikidata]]) -->
__NOTOC__
__NOTOC__
== Summary ==
== Summary ==
This module generates links to ships in the Naval Vessel Register (nvr.navy.mil) database. Intended to be used by:
This module generates links to ships in the Naval Vessel Register (nvr.navy.mil) database. Intended to be used by:
*{{tl|NVR url}}
*{{tlx|NVR url}}
*{{tl|NVR SC url}}
*{{tlx|NVR SC url}}


NVR have adopted a file naming convention based on a ship's [[hull classification symbol]] with an appended underscore and some number of digits. The extra digits do not seem to follow an identifiable pattern so the former rules-based system used here no longer works.
The table of URL transformations used by this module can be found at [[Module:NVR/rules]].

To get round the 'new' file format, this version of the module adopts a brute-force mechanism by using a local database that maps a ship's hull classification symbol to its associated NVR file name. The database is two large Lua tables maintained at [[Module:NVR/data]].


== Using this module from templates ==
== Using this module from templates ==
Line 14: Line 14:
=== MakeShipLink ===
=== MakeShipLink ===


This function returns a link to a ship in the Naval Vessel Register.
This function returns a link to a ship's page at the Naval Vessel Register website.


Usage:
Usage:
Line 21: Line 21:


Parameters:
Parameters:
: '''1''' or '''id''' — The 'file name' portion of the url path (typically the ship's hull designation) without the .HTM/.HTML extension.
: '''1''' or '''id''' — the ship's case-insensitive hull classification symbol in one of five forms:
:#SSBN-659 – the preferred format because it matches the format for hull classification symbols generally used for US Navy ships throughout Wikipedia
:#SSBN 659
:#SSBN659
:#SSBN_659
:#SSBN_659_1635 – the NVR file name format as of September 2017
::There are exceptions. There are three ships listed at the NVR website that do not have hull classification symbols. These are: {{USS|Constitution}}, {{USS|Maine|ACR-1|6}}, and {{USS|Texas|1892|6}}. For these three ships, use the ship's name for this parameter. The code word OLDIRON, previously used to identify ''Constitution'' is no longer supported.
: '''2''' or '''title''' — A title or label for the link.
: '''2''' or '''title''' — A title or label for the link.
Examples:
Examples:
: <code><nowiki>{{#invoke:NVR|MakeShipLink|DDG_1000}}</nowiki></code> produces {{#invoke:NVR|MakeShipLink|DDG_1000}}
: <code><nowiki>{{#invoke:NVR|MakeShipLink|DDG_1000}}</nowiki></code> produces {{#invoke:NVR|MakeShipLink|DDG_1000}}
: <code><nowiki>{{#invoke:NVR|MakeShipLink|OLDIRON}}</nowiki></code> produces {{#invoke:NVR|MakeShipLink|OLDIRON}}
: <code><nowiki>{{#invoke:NVR|MakeShipLink|constitution}}</nowiki></code> produces {{#invoke:NVR|MakeShipLink|constitution}}
: <code><nowiki>{{#invoke:NVR|MakeShipLink|OLDIRON|USS ''Constitution''}}</nowiki></code> produces {{#invoke:NVR|MakeShipLink|OLDIRON|USS ''Constitution''}}
: <code><nowiki>{{#invoke:NVR|MakeShipLink|maine|USS ''Maine''}}</nowiki></code> produces {{#invoke:NVR|MakeShipLink|maine|USS ''Maine''}}


=== MakeServiceCraftLink ===
=== MakeServiceCraftLink ===
Line 38: Line 44:


Parameters:
Parameters:
: '''1''' or '''id''' — The 'file name' portion of the url path (typically the craft's hull designation) without the .HTM/.HTML extension.
: '''2''' or '''title''' — A title or label for the link.
Example:
: <code><nowiki>{{#invoke:NVR|MakeServiceCraftLink|AFDB1_1}}</nowiki></code> produces {{#invoke:NVR|MakeServiceCraftLink|AFDB1_1}}

== Using this module from Lua code ==

In order to use the functions in this module from another Lua module you first have to import this module.
Example:
: <code>local nvr = require('Module:NVR')</code>

=== _MakeShipLink ===

This function returns a link to a ship in the Naval Vessel Register.

Usage:
: <code><nowiki>link_string = nvr._MakeShipLink(nvrid, title)</nowiki></code>

Parameters:
Parameters:
: '''nvrid''' — The 'file name' portion of the url path (typically the ship's hull designation) without the .HTM/.HTML extension, as a string.
: '''1''' or '''id''' the ship's case-insensitive hull classification symbol in one of five forms:
:#YTB-760 – the preferred format because it matches the format for hull classification symbols generally used for US Navy ships throughout Wikipedia
: '''title''' — Title for link, set to <code><nowiki>''</nowiki></code> for a bare link without a title.
:#YTB 760

:#YTB760
:#YTB_760
:#YTB_760_5292 – the NVR file name format as of September 2017
::There are exceptions. NVR has separate pages for some single and some multiple sections of some floating drydocks. For these, this module adopts a convention similarly used by NVR where each section is distinguished by a letter designator; that letter must be appended to the hull classification symbol used in this parameter; see the examples
: '''2''' or '''title''' — A title or label for the link.
Examples:
Examples:
: <code><nowiki>link_string = nvr._MakeShipLink('DDG_1000', '')</nowiki></code>
: <code><nowiki>{{#invoke:NVR|MakeServiceCraftLink|AFDB-7F}}</nowiki></code> produces {{#invoke:NVR|MakeServiceCraftLink|AFDB7F}}
: <code><nowiki>link_string = nvr._MakeShipLink('OLDIRON', '')</nowiki></code>
: <code><nowiki>{{#invoke:NVR|MakeServiceCraftLink|ytb-760}}</nowiki></code> produces {{#invoke:NVR|MakeServiceCraftLink|ytb-760|''Natick''}}

=== _MakeServiceCraftLink ===

This function returns a link to a service craft in the Naval Vessel Register.

Usage:
: <code><nowiki>link_string = nvr._MakeServiceCraftLink(nvrid, title)</nowiki></code>

Parameters:
: '''nvrid''' — The 'file name' portion of the url path (typically the craft's hull designation) without the .HTM/.HTML extension, as a string.
: '''title''' — Title for link, set to <code><nowiki>''</nowiki></code> for a bare link without a title.

Example:
: <code><nowiki>link_string = nvr._MakeServiceCraftLink('AFDB1_1', '')</nowiki></code>

==See Also==
* [[Module:NVR/rules]]
* [[Template:NVR url]]
* [[Template:NVR SC url]]

Revision as of 10:37, 5 September 2017


Summary

This module generates links to ships in the Naval Vessel Register (nvr.navy.mil) database. Intended to be used by:

NVR have adopted a file naming convention based on a ship's hull classification symbol with an appended underscore and some number of digits. The extra digits do not seem to follow an identifiable pattern so the former rules-based system used here no longer works.

To get round the 'new' file format, this version of the module adopts a brute-force mechanism by using a local database that maps a ship's hull classification symbol to its associated NVR file name. The database is two large Lua tables maintained at Module:NVR/data.

Using this module from templates

This function returns a link to a ship's page at the Naval Vessel Register website.

Usage:

{{#invoke:NVR|MakeShipLink|id=|title=}}
{{#invoke:NVR|MakeShipLink}} — uses the calling template's parameters

Parameters:

1 or id — the ship's case-insensitive hull classification symbol in one of five forms:
  1. SSBN-659 – the preferred format because it matches the format for hull classification symbols generally used for US Navy ships throughout Wikipedia
  2. SSBN 659
  3. SSBN659
  4. SSBN_659
  5. SSBN_659_1635 – the NVR file name format as of September 2017
There are exceptions. There are three ships listed at the NVR website that do not have hull classification symbols. These are: USS Constitution, USS Maine, and USS Texas. For these three ships, use the ship's name for this parameter. The code word OLDIRON, previously used to identify Constitution is no longer supported.
2 or title — A title or label for the link.

Examples:

{{#invoke:NVR|MakeShipLink|DDG_1000}} produces Script error: No such module "NVR".
{{#invoke:NVR|MakeShipLink|constitution}} produces Script error: No such module "NVR".
{{#invoke:NVR|MakeShipLink|maine|USS ''Maine''}} produces Script error: No such module "NVR".

This function returns a link to a service craft in the Naval Vessel Register.

Usage:

{{#invoke:NVR|MakeServiceCraftLink|id=|title=}}
{{#invoke:NVR|MakeServiceCraftLink}} — uses the calling template's parameters

Parameters: Parameters:

1 or id — the ship's case-insensitive hull classification symbol in one of five forms:
  1. YTB-760 – the preferred format because it matches the format for hull classification symbols generally used for US Navy ships throughout Wikipedia
  2. YTB 760
  3. YTB760
  4. YTB_760
  5. YTB_760_5292 – the NVR file name format as of September 2017
There are exceptions. NVR has separate pages for some single and some multiple sections of some floating drydocks. For these, this module adopts a convention similarly used by NVR where each section is distinguished by a letter designator; that letter must be appended to the hull classification symbol used in this parameter; see the examples
2 or title — A title or label for the link.

Examples:

{{#invoke:NVR|MakeServiceCraftLink|AFDB-7F}} produces Script error: No such module "NVR".
{{#invoke:NVR|MakeServiceCraftLink|ytb-760}} produces Script error: No such module "NVR".