Difference between revisions of "Module:Sandbox/Ahecht/Cite DNV"
< Module:Sandbox | Ahecht
Jump to navigation
Jump to search
blackwiki>Ahecht (bug fix) |
m (15 revisions imported) |
||
| (8 intermediate revisions by 2 users not shown) | |||
| Line 14: | Line 14: | ||
url, vesselid = string.match(string.lower(args['url'] or ''),'//exchange.dnv.com/exchange/main.aspx?(.*)vesselid=(g?%d%d%d%d%d%d?)') | url, vesselid = string.match(string.lower(args['url'] or ''),'//exchange.dnv.com/exchange/main.aspx?(.*)vesselid=(g?%d%d%d%d%d%d?)') | ||
| − | vesselid = (vesselid or string.lower((args['id'] or args['ID']) or args['vesselid'] | + | vesselid = (vesselid or string.lower(((args['id'] or args['ID']) or args['vesselid']) or '') ) |
if vesselid == '' then | if vesselid == '' then | ||
success=false | success=false | ||
| Line 20: | Line 20: | ||
vesselid = string.upper(vesselid) | vesselid = string.upper(vesselid) | ||
register = "GL" | register = "GL" | ||
| − | elseif vesselid > 99999 then | + | elseif tonumber(vesselid) > 99999 then |
vesselid = "G"..vesselid | vesselid = "G"..vesselid | ||
register = "GL" | register = "GL" | ||
end | end | ||
| − | shipname = ((string.match(args['title'],'\'\'(.-)\'\'') or args['title']) or (args['shipname'] or args['name'])) or '' | + | shipname = ((string.match((args['title'] or ''),'\'\'(.-)\'\'') or args['title']) or (args['shipname'] or args['name'])) or '' |
if shipname == '' then success=false end | if shipname == '' then success=false end | ||
if success then | if success then | ||
| − | return '{{cite ship register|register='..register..'|id='..vesselid..'|shipname='..shipname..'|accessdate='..((args['accessdate'] or args['access-date']) or '')..'}' | + | return '{{cite ship register |register='..register..' |id='..vesselid..' |shipname='..shipname..' |accessdate='..((args['accessdate'] or args['access-date']) or '')..' }}' |
| − | + | else | |
| − | + | outstr = args['url'] and '{{cite web' or '{{cite DNV' | |
| + | |||
for k, v in pairs(origArgs) do | for k, v in pairs(origArgs) do | ||
| − | outstr = outstr..'|'..k..'='..v | + | outstr = outstr..' | '..k..'='..v |
end | end | ||
| − | + | ||
| − | + | outstr = outstr..'}}'..(args['url'] and '' or htmlerror{'Error in [[Template:Cite DNV]]: Invalid parameters.'}) | |
| − | + | ||
| + | return outstr | ||
end | end | ||
Latest revision as of 09:14, 27 September 2020
Documentation for this module may be created at Module:Sandbox/Ahecht/Cite DNV/doc
local p = {}
local htmlerror = require('Module:Error').error
function p.citednv(frame)
local origArgs = frame:getParent().args
local args = {}
local success=true
local register="DNV"
local outstr = ""
for k, v in pairs(origArgs) do
args[k] = v
end
url, vesselid = string.match(string.lower(args['url'] or ''),'//exchange.dnv.com/exchange/main.aspx?(.*)vesselid=(g?%d%d%d%d%d%d?)')
vesselid = (vesselid or string.lower(((args['id'] or args['ID']) or args['vesselid']) or '') )
if vesselid == '' then
success=false
elseif not tonumber(vesselid) then
vesselid = string.upper(vesselid)
register = "GL"
elseif tonumber(vesselid) > 99999 then
vesselid = "G"..vesselid
register = "GL"
end
shipname = ((string.match((args['title'] or ''),'\'\'(.-)\'\'') or args['title']) or (args['shipname'] or args['name'])) or ''
if shipname == '' then success=false end
if success then
return '{{cite ship register |register='..register..' |id='..vesselid..' |shipname='..shipname..' |accessdate='..((args['accessdate'] or args['access-date']) or '')..' }}'
else
outstr = args['url'] and '{{cite web' or '{{cite DNV'
for k, v in pairs(origArgs) do
outstr = outstr..' | '..k..'='..v
end
outstr = outstr..'}}'..(args['url'] and '' or htmlerror{'Error in [[Template:Cite DNV]]: Invalid parameters.'})
return outstr
end
end
return p