Module:Citation/CS1/Utilities: Difference between revisions
m>Redrose64 (this kind of markup is no longer allowed, and puts pages in Category:Pages using invalid self-closed HTML tags) |
m>Trappist the monk (synch from sandbox;) |
||
| Line 13: | Line 13: | ||
]] | ]] | ||
local cfg; -- table of tables imported from | local cfg; -- table of tables imported from selected Module:Citation/CS1/Configuration | ||
| Line 19: | Line 19: | ||
Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string. | Returns true if argument is set; false otherwise. Argument is 'set' when it exists (not nil) or when it is not an empty string. | ||
]] | ]] | ||
local function is_set( var ) | local function is_set( var ) | ||
return not (var == nil or var == ''); | return not (var == nil or var == ''); | ||
| Line 62: | Line 62: | ||
]] | ]] | ||
local function error_comment( content, hidden ) | local function error_comment( content, hidden ) | ||
return substitute( hidden and cfg.presentation['hidden-error'] or cfg.presentation['visible-error'], content ); | return substitute( hidden and cfg.presentation['hidden-error'] or cfg.presentation['visible-error'], content ); | ||
end | |||
--[=[-------------------------< M A K E _ W I K I L I N K >---------------------------------------------------- | |||
Makes a wikilink; when bot link and display text is provided, returns a wikilink in the form [[L|D]]; if only | |||
link is provided, returns a wikilink in the form [[L]]; if neither are provided or link is omitted, returns an | |||
empty string. | |||
]=] | |||
local function make_wikilink (link, display) | |||
if is_set (link) then | |||
if is_set (display) then | |||
return table.concat ({'[[', link, '|', display, ']]'}); | |||
else | |||
return table.concat ({'[[', link, ']]'}); | |||
end | |||
else | |||
return ''; | |||
end | |||
end | end | ||
| Line 73: | Line 95: | ||
]] | ]] | ||
local function set_error( error_id, arguments, raw, prefix, suffix ) | local function set_error( error_id, arguments, raw, prefix, suffix ) | ||
local error_state = cfg.error_conditions[ error_id ]; | local error_state = cfg.error_conditions[ error_id ]; | ||
| Line 80: | Line 103: | ||
if error_state == nil then | if error_state == nil then | ||
error( cfg.messages['undefined_error'] ); | error( cfg.messages['undefined_error'] ); -- because missing error handler in Module:Citation/CS1/Configuration | ||
elseif is_set( error_state.category ) then | elseif is_set( error_state.category ) then | ||
table.insert( z.error_categories, error_state.category ); | table.insert( z.error_categories, error_state.category ); | ||
| Line 86: | Line 109: | ||
local message = substitute( error_state.message, arguments ); | local message = substitute( error_state.message, arguments ); | ||
message = message .. " ([[" .. cfg.messages['help page link'] .. | message = table.concat ( | ||
{ | |||
message, | |||
' (', | |||
make_wikilink ( | |||
table.concat ( | |||
{ | |||
cfg.messages['help page link'], | |||
'#', | |||
error_state.anchor | |||
}), | |||
cfg.messages['help page label']), | |||
')' | |||
}); | |||
-- message = table.concat ({message, ' (', substitute (cfg.presentation['wikilink'], | |||
-- {cfg.messages['help page link'] .. '#' .. error_state.anchor, cfg.messages['help page label']}), ')'}); | |||
-- message = message .. " ([[" .. cfg.messages['help page link'] .. | |||
-- "#" .. error_state.anchor .. "|" .. | |||
-- cfg.messages['help page label'] .. "]])"; | |||
z.error_ids[ error_id ] = true; | z.error_ids[ error_id ] = true; | ||
| Line 266: | Line 306: | ||