Module:Citation/CS1: Difference between revisions
sync to sandbox, adds parameter whitelist
m>Dragons flight (sync to sandbox, fixes problem with broken span in association with double "..", also publisher layout for pressrelease mode) |
m>Dragons flight (sync to sandbox, adds parameter whitelist) |
||
Line 3: | Line 3: | ||
message_tail = {}; | message_tail = {}; | ||
} | } | ||
local whitelist = mw.loadData( 'Module:Citation/CS1/Whitelist' ); | |||
-- Checks that parameter name is valid | |||
function validate( name ) | |||
name = tostring( name ); | |||
-- Normal arguments | |||
if whitelist.basic_arguments[ name ] then | |||
return true; | |||
end | |||
-- Arguments with numbers in them | |||
name = name:gsub( "%d+", "#" ); | |||
if whitelist.numbered_arguments[ name ] then | |||
return true; | |||
end | |||
-- Not found, argument not supported. | |||
return false | |||
end | |||
-- Formats a hidden comment for error trapping not intended to be visible to readers | -- Formats a hidden comment for error trapping not intended to be visible to readers | ||
Line 74: | Line 95: | ||
-- Formats a wiki style external link | -- Formats a wiki style external link | ||
function externallinkid( | function externallinkid(options) | ||
local sep = | local sep = options.separator or " " | ||
options.suffix = options.suffix or "" | |||
local url_string = | local url_string = options.id | ||
if | if options.encode == true or options.encode == nil then | ||
url_string = mw.uri.encode( url_string ); | url_string = mw.uri.encode( url_string ); | ||
end | end | ||
return "[[" .. | return "[[" .. options.link .. "|" .. options.label .. "]]" .. sep .. "[" .. | ||
options.prefix .. url_string .. options.suffix .. " " .. nowiki(options.id) .. "]" | |||
end | end | ||
-- Formats a wiki style internal link | -- Formats a wiki style internal link | ||
function internallinkid( | function internallinkid(options) | ||
local sep = | local sep = options.separator or " " | ||
options.suffix = options.suffix or "" | |||
return "[[" .. | return "[[" .. options.link .. "|" .. options.label .. "]]" .. sep .. "[[" .. | ||
options.prefix .. options.id .. options.suffix .. "|" .. nowiki(options.id) .. "]]" | |||
end | end | ||
Line 347: | Line 368: | ||
-- Generates a CITEREF anchor ID. | -- Generates a CITEREF anchor ID. | ||
function anchorid( | function anchorid(options) | ||
local P1 = | local P1 = options[1] or "" | ||
local P2 = | local P2 = options[2] or "" | ||
local P3 = | local P3 = options[3] or "" | ||
local P4 = | local P4 = options[4] or "" | ||
local P5 = | local P5 = options[5] or "" | ||
-- Bugzilla 46608 | -- Bugzilla 46608 | ||
Line 473: | Line 494: | ||
local ArchiveURL = args["archive-url"] or args.archiveurl | local ArchiveURL = args["archive-url"] or args.archiveurl | ||
local URL = args.url or args.URL | local URL = args.url or args.URL | ||
local ChapterURL = args["chapter-url"] or args.chapterurl | local ChapterURL = args["chapter-url"] or args.chapterurl or args["contribution-url"] | ||
local ConferenceURL = args["conference-url"] or args.conferenceurl | local ConferenceURL = args["conference-url"] or args.conferenceurl | ||
local Periodical = args.journal or args.newspaper or args.magazine or args.work | local Periodical = args.journal or args.newspaper or args.magazine or args.work | ||
Line 1,361: | Line 1,382: | ||
for k, v in pairs( pframe.args ) do | for k, v in pairs( pframe.args ) do | ||
if v ~= '' then | if v ~= '' then | ||
if not validate( k ) then | |||
if type( k ) ~= 'string' then | |||
-- Exclude empty numbered parameters | |||
if v:match("%S+") ~= nil then | |||
table.insert( z.message_tail, 'Unnamed parameter containing "' .. v .. '" ignored' ); | |||
end | |||
elseif validate( k:lower() ) then | |||
table.insert( z.message_tail, 'Unknown parameter "' .. k .. '=" ignored (suggest "' .. k:lower() .. '=")' ); | |||
else | |||
table.insert( z.message_tail, 'Unknown parameter "' .. k .. '=" ignored' ); | |||
end | |||
table.insert( z.error_categories, 'Pages with citations using unsupported parameters' ); | |||
end | |||
args[k] = v; | args[k] = v; | ||
elseif k == 'postscript' then | elseif k == 'postscript' then |