Module:Shortcut: Difference between revisions
allow output if no shortcuts are set but msg is present
(fix error message) |
(allow output if no shortcuts are set but msg is present) |
||
Line 16: | Line 16: | ||
cfg = cfg or mw.loadData(CONFIG_MODULE) | cfg = cfg or mw.loadData(CONFIG_MODULE) | ||
local nShortcuts = #shortcuts | local nShortcuts = #shortcuts | ||
-- Check that we have something to display | |||
if nShortcuts < 1 and not options.msg then | |||
return nil | |||
end | |||
-- Validate shortcuts | -- Validate shortcuts | ||
for i, shortcut in ipairs(shortcuts) do | |||
if type(shortcut) ~= 'string' or #shortcut < 1 then | |||
error(string.format( | |||
'shortcut #%d was invalid (shortcuts must be strings of ' .. | |||
'at least one character in length)' | |||
), 2) | |||
end | end | ||
end | end | ||
Line 82: | Line 83: | ||
-- Error category | -- Error category | ||
if shortcuts[1] then | |||
local title = mw.title.new(shortcuts[1]) | local title = mw.title.new(shortcuts[1]) | ||
if not title or not title.exists then | if not title or not title.exists then |