Module:Shortcut: Difference between revisions

From Test Wiki
69 bytes added ,  15 December 2014
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
if nShortcuts < 1 then
for i, shortcut in ipairs(shortcuts) do
return nil
if type(shortcut) ~= 'string' or #shortcut < 1 then
else
error(string.format(
for i, shortcut in ipairs(shortcuts) do
'shortcut #%d was invalid (shortcuts must be strings of ' ..
if type(shortcut) ~= 'string' or #shortcut < 1 then
'at least one character in length)'
error(string.format(
), 2)
'shortcut #%d was invalid (shortcuts must be strings of ' ..
'at least one character in length)'
), 2)
end
end
end
end
end
Line 82: Line 83:


-- Error category
-- Error category
do
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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.