Modifica di Modulo:Citation/CS1/Utilities
Vai alla navigazione
Vai alla ricerca
Questa modifica può essere annullata. Controlla le differenze mostrate sotto fra le due versioni per essere certo che il contenuto corrisponda a quanto desiderato, e quindi pubblicare le modifiche per completare la procedura di annullamento.
Versione attuale | Il tuo testo | ||
Riga 1: | Riga 1: | ||
local z = { | local z = { | ||
error_categories = {}; -- for categorizing citations that contain errors | |||
error_ids = {}; | |||
message_tail = {}; | |||
maintenance_cats = {}; -- for categorizing citations that aren't erroneous per se, but could use a little work | |||
properties_cats = {}; -- for categorizing citations based on certain properties, language of source for instance | |||
}; | }; | ||
Riga 13: | Riga 13: | ||
local cfg; -- table of tables imported from selected Module:Citation/CS1/Configuration | local cfg; -- table of tables imported from selected Module:Citation/CS1/Configuration | ||
--[[--------------------------< H A S _ A C C E P T _ A S _ W R I T T E N >------------------------------------ | |||
When <str> is wholly wrapped in accept-as-written markup, return <str> without markup and true; return <str> and false else | |||
with allow_empty = false, <str> must have at least one character inside the markup | |||
with allow_empty = true, <str> the markup frame can be empty like (()) to distinguish an empty template parameter from the specific condition "has no applicable value" in citation-context. | |||
After further evaluation the two cases might be merged at a later stage, but should be kept separated for now. | |||
]] | |||
local function has_accept_as_written (str, allow_empty) | |||
local count; | |||
if true == allow_empty then | |||
str, count = str:gsub ('^%(%((.*)%)%)$', '%1'); -- allows (()) to be an empty set | |||
else | |||
str, count = str:gsub ('^%(%((.+)%)%)$', '%1'); | |||
end | |||
return str, 0 ~= count; | |||
end | |||
Riga 42: | Riga 64: | ||
end | end | ||
return false; | return false; | ||
end | end | ||
Riga 74: | Riga 69: | ||
--[[--------------------------< S U B S T I T U T E >---------------------------------------------------------- | --[[--------------------------< S U B S T I T U T E >---------------------------------------------------------- | ||
Populates numbered arguments in a message string using an argument table | Populates numbered arguments in a message string using an argument table. | ||
]] | ]] | ||
Riga 86: | Riga 80: | ||
--[[--------------------------< E R R O R _ C O M M E N T >---------------------------------------------------- | --[[--------------------------< E R R O R _ C O M M E N T >---------------------------------------------------- | ||
Wraps error messages with CSS markup according to the state of hidden | Wraps error messages with CSS markup according to the state of hidden. | ||
]] | ]] | ||
Riga 93: | Riga 86: | ||
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 | end | ||
Riga 177: | Riga 110: | ||
--[[--------------------------< S E T _ M E S S A G E >---------------------------------------------------------- | --[[--------------------------< S E T _ M E S S A G E >---------------------------------------------------------- | ||
Sets an error message | Sets an error condition and returns the appropriate error message. The actual placement of the error message in the output is | ||
the responsibility of the calling function. | |||
TODO: change z.error_categories and z.maintenance_cats to have the form cat_name = true; to avoid dups without having to have an extra cat | |||
TODO: change z. | |||
]] | ]] | ||
local added_maint_cats = {} -- list of maintenance categories that have been added to z.maintenance_cats; TODO: figure out how to delete this table | |||
local added_maint_cats = {} -- list of maintenance categories that have been added to z. | |||
local function set_message (error_id, arguments, raw, prefix, suffix) | local function set_message (error_id, arguments, raw, prefix, suffix) | ||
Riga 208: | Riga 129: | ||
elseif is_set (error_state.category) then | elseif is_set (error_state.category) then | ||
if error_state.message then -- when error_state.message defined, this is an error message | if error_state.message then -- when error_state.message defined, this is an error message | ||
table.insert (z. | table.insert (z.error_categories, error_state.category); | ||
else | else | ||
if not added_maint_cats[error_id] then | if not added_maint_cats[error_id] then | ||
added_maint_cats[error_id] = true; -- note that we've added this category | added_maint_cats[error_id] = true; -- note that we've added this category | ||
table.insert (z. | table.insert (z.maintenance_cats, substitute (error_state.category, arguments)); -- make cat name then add to table | ||
end | end | ||
return; -- because no message, nothing more to do | return; -- because no message, nothing more to do | ||
Riga 235: | Riga 156: | ||
}); | }); | ||
z. | z.error_ids[error_id] = true; | ||
if z. | if z.error_ids['err_citation_missing_title'] and -- if missing-title error already noted | ||
in_array (error_id, {'err_bare_url_missing_title', 'err_trans_missing_title'}) then -- and this error is one of these | in_array (error_id, {'err_bare_url_missing_title', 'err_trans_missing_title'}) then -- and this error is one of these | ||
return '', false; -- don't bother because one flavor of missing title is sufficient | return '', false; -- don't bother because one flavor of missing title is sufficient | ||
Riga 243: | Riga 164: | ||
message = table.concat ({prefix, message, suffix}); | message = table.concat ({prefix, message, suffix}); | ||
if | if raw == true then | ||
return message, error_state.hidden; | return message, error_state.hidden; | ||
end | end | ||
return error_comment (message, error_state.hidden); | |||
end | end | ||
Riga 280: | Riga 199: | ||
end | end | ||
if is_set (args[alias]) then | if is_set (args[alias]) then -- alias is in the template's argument list | ||
if value ~= nil and selected ~= alias then -- if we have already selected one of the aliases | if value ~= nil and selected ~= alias then -- if we have already selected one of the aliases | ||
local skip; | local skip; | ||
Riga 303: | Riga 222: | ||
--[[--------------------------< A D D _ M A I N T _ C A T >------------------------------------------------------ | --[[--------------------------< A D D _ M A I N T _ C A T >------------------------------------------------------ | ||
Adds a category to z. | Adds a category to z.maintenance_cats using names from the configuration file with additional text if any. | ||
To prevent duplication, the added_maint_cats table lists the categories by key that have been added to z. | To prevent duplication, the added_maint_cats table lists the categories by key that have been added to z.maintenance_cats. | ||
]] | ]] | ||
Riga 311: | Riga 230: | ||
if not added_maint_cats [key] then | if not added_maint_cats [key] then | ||
added_maint_cats [key] = true; -- note that we've added this category | added_maint_cats [key] = true; -- note that we've added this category | ||
table.insert (z. | table.insert (z.maintenance_cats, substitute (cfg.maint_cats [key], arguments)); -- make name then add to table | ||
end | end | ||
end | end | ||
Riga 318: | Riga 237: | ||
--[[--------------------------< A D D _ P R O P _ C A T >-------------------------------------------------------- | --[[--------------------------< A D D _ P R O P _ C A T >-------------------------------------------------------- | ||
Adds a category to z. | Adds a category to z.properties_cats using names from the configuration file with additional text if any. | ||
foreign_lang_source and foreign_lang_source_2 keys have a language code appended to them so that multiple languages | foreign_lang_source and foreign_lang_source_2 keys have a language code appended to them so that multiple languages | ||
Riga 327: | Riga 246: | ||
]] | ]] | ||
local added_prop_cats = {}; -- list of property categories that have been added to z. | local added_prop_cats = {}; -- list of property categories that have been added to z.properties_cats | ||
local function add_prop_cat (key, arguments | local function add_prop_cat (key, arguments) | ||
if not added_prop_cats [key] then | |||
added_prop_cats [key] = true; -- note that we've added this category | |||
if not added_prop_cats [ | key = key:gsub ('(foreign_lang_source_?2?)%a%a%a?[%a%-]*', '%1'); -- strip lang code from keyname | ||
added_prop_cats [ | table.insert (z.properties_cats, substitute (cfg.prop_cats [key], arguments)); -- make name then add to table | ||
table.insert (z. | |||
end | end | ||
end | end | ||
Riga 356: | Riga 273: | ||
if str:sub (-1, -1) == "'" then str = str .. "<span></span>"; end | if str:sub (-1, -1) == "'" then str = str .. "<span></span>"; end | ||
return str:gsub ('\n', ' '); | -- Remove newlines as they break italics. | ||
return str:gsub ('\n', ' '); | |||
end | end | ||
Riga 447: | Riga 366: | ||
end | end | ||
table.insert (error_list, wrap_style ('parameter', selected)); | table.insert (error_list, wrap_style ('parameter', selected)); | ||
set_message (error_condition, {make_sep_list (#error_list, error_list)}); | table.insert (z.message_tail, {set_message (error_condition, {make_sep_list (#error_list, error_list)}, true)}); | ||
end | end | ||
Riga 532: | Riga 451: | ||
while true do | while true do | ||
if argument:find ("'''''", 1, true) then -- bold italic (5) | if argument:find ("'''''", 1, true) then -- bold italic (5) | ||
argument, flag = argument:gsub ("%'%'%'%'%'", ""); | argument, flag = argument:gsub ("%'%'%'%'%'", ""); -- remove all instances of it | ||
elseif argument:find ("''''", 1, true) then | elseif argument:find ("''''", 1, true) then -- italic start and end without content (4) | ||
argument, flag=argument:gsub ("%'%'%'%'", ""); | argument, flag=argument:gsub ("%'%'%'%'", ""); | ||
elseif argument:find ("'''", 1, true) then | elseif argument:find ("'''", 1, true) then -- bold (3) | ||
argument, flag=argument:gsub ("%'%'%'", ""); | argument, flag=argument:gsub ("%'%'%'", ""); | ||
elseif argument:find ("''", 1, true) then -- italic (2) | elseif argument:find ("''", 1, true) then -- italic (2) | ||
Riga 568: | Riga 487: | ||
error_comment = error_comment, | error_comment = error_comment, | ||
has_accept_as_written = has_accept_as_written, | has_accept_as_written = has_accept_as_written, | ||
in_array = in_array, | in_array = in_array, | ||
is_set = is_set, | is_set = is_set, |