Module:Shortcut: Difference between revisions

Content added Content deleted
Enwikipedia>Mr. Stradivarius
(fix error message)
Enwikipedia>Mr. Stradivarius
(allow output if no shortcuts are set but msg is present)
Line 17: Line 17:
local nShortcuts = #shortcuts
local nShortcuts = #shortcuts


-- Check that we have something to display
-- Validate shortcuts
if nShortcuts < 1 then
if nShortcuts < 1 and not options.msg then
return nil
return nil
end
else

for i, shortcut in ipairs(shortcuts) do
-- Validate shortcuts
if type(shortcut) ~= 'string' or #shortcut < 1 then
for i, shortcut in ipairs(shortcuts) do
error(string.format(
'shortcut #%d was invalid (shortcuts must be strings of ' ..
if type(shortcut) ~= 'string' or #shortcut < 1 then
error(string.format(
'at least one character in length)'
'shortcut #%d was invalid (shortcuts must be strings of ' ..
), 2)
'at least one character in length)'
end
), 2)
end
end
end
end
Line 82: Line 83:


-- Error category
-- Error category
if shortcuts[1] then
do
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