Module:Convert: Difference between revisions
Jump to navigation
Jump to search
Content added Content deleted
(extra Wikidata fix I meant to do: when using "frequency" or "wavelength", any output unit also specified in the convert is ignored) |
(update from sandbox per Template talk:Convert#Module version 18) |
||
Line 259: | Line 259: | ||
end |
end |
||
local function wanted_category( |
local function wanted_category(catkey, catsort, want_warning) |
||
-- Return |
-- Return message category if it is wanted in current namespace, |
||
-- otherwise return ''. |
|||
-- This is so tracking categories only include pages that need correction. |
|||
local cat |
|||
local title = mw.title.getCurrentTitle() |
local title = mw.title.getCurrentTitle() |
||
if title then |
if title then |
||
Line 268: | Line 269: | ||
for _, v in ipairs(split(config.nscat or nsdefault, ',')) do |
for _, v in ipairs(split(config.nscat or nsdefault, ',')) do |
||
if namespace == tonumber(v) then |
if namespace == tonumber(v) then |
||
cat = text_code.all_categories[want_warning and 'warning' or catkey] |
|||
⚫ | |||
if catsort and catsort ~= '' and cat:sub(-2) == ']]' then |
|||
cat = cat:sub(1, -3) .. '|' .. mw.text.nowiki(usub(catsort, 1, 20)) .. ']]' |
|||
⚫ | |||
break |
|||
end |
end |
||
end |
end |
||
end |
end |
||
⚫ | |||
end |
end |
||
local function message(parms, mcode) |
local function message(parms, mcode, is_warning) |
||
-- Return wikitext for an error message, including category if specified |
-- Return wikitext for an error message, including category if specified |
||
-- for the message type. |
-- for the message type. |
||
Line 341: | Line 347: | ||
return success and (revid == '') |
return success and (revid == '') |
||
end |
end |
||
local want_warning = is_warning and |
|||
not config.warnings and -- show unobtrusive warnings if config.warnings not configured |
|||
not msg.nowarn -- but use msg settings, not standard warning, if specified |
|||
local title = string.gsub(msg[1] or 'Missing message', '$%d+', parts) |
local title = string.gsub(msg[1] or 'Missing message', '$%d+', parts) |
||
local text = msg[2] or 'Missing message' |
local text = want_warning and '*' or msg[2] or 'Missing message' |
||
local cat = wanted_category( |
local cat = wanted_category(msg[3], mcode[2], want_warning) |
||
local anchor = msg[4] or '' |
local anchor = msg[4] or '' |
||
local fmtkey = ispreview() and 'cvt_format_preview' or |
local fmtkey = ispreview() and 'cvt_format_preview' or |
||
(want_warning and 'cvt_format2' or msg.format or 'cvt_format') |
|||
local fmt = text_code.all_messages[fmtkey] or 'convert: bug' |
local fmt = text_code.all_messages[fmtkey] or 'convert: bug' |
||
return subparm(fmt, title:gsub('"', '"'), text, cat, anchor) |
return subparm(fmt, title:gsub('"', '"'), text, cat, anchor) |
||
Line 354: | Line 364: | ||
function add_warning(parms, level, key, text1, text2) -- for forward declaration above |
function add_warning(parms, level, key, text1, text2) -- for forward declaration above |
||
-- If enabled, add a warning that will be displayed after the convert result. |
-- If enabled, add a warning that will be displayed after the convert result. |
||
-- A higher level is more verbose: more kinds of warnings are displayed. |
|||
-- To reduce output noise, only the first warning is displayed. |
-- To reduce output noise, only the first warning is displayed. |
||
if config.warnings or |
if level <= (tonumber(config.warnings) or 1) then |
||
if |
if parms.warnings == nil then |
||
parms.warnings = message(parms, { key, text1, text2 }, true) |
|||
parms.warnings = message(parms, { key, text1, text2 }) |
|||
⚫ | |||
end |
end |
||
end |
end |
||
Line 380: | Line 389: | ||
success, speller = pcall(get_speller, spell_module) |
success, speller = pcall(get_speller, spell_module) |
||
if not success or type(speller) ~= 'function' then |
if not success or type(speller) ~= 'function' then |
||
add_warning(parms, 1, 'cvt_no_spell') |
add_warning(parms, 1, 'cvt_no_spell', 'spell') |
||
return nil |
return nil |
||
end |
end |
||
Line 1,782: | Line 1,791: | ||
en_value = number |
en_value = number |
||
else |
else |
||
add_warning(parms, 1, (en_name == 'frac' and 'cvt_bad_frac' or 'cvt_bad_sigfig'), loc_value) |
add_warning(parms, 1, (en_name == 'frac' and 'cvt_bad_frac' or 'cvt_bad_sigfig'), loc_name .. '=' .. loc_value) |
||
end |
end |
||
end |
end |