Jump to content

Module:Shortcut: Difference between revisions

m
1 revision imported
m (1 revision imported)
m (1 revision imported)
(One intermediate revision by one other user not shown)
Line 24: Line 24:
frame = frame or mw.getCurrentFrame()
frame = frame or mw.getCurrentFrame()
cfg = cfg or mw.loadData(CONFIG_MODULE)
cfg = cfg or mw.loadData(CONFIG_MODULE)
local isCategorized = yesno(options.category) ~= false
local templateMode = options.template and yesno(options.template)
local redirectMode = options.redirect and yesno(options.redirect)
local isCategorized = not options.category or yesno(options.category) ~= false


-- Validate shortcuts
-- Validate shortcuts
Line 37: Line 39:
local listItems = {}
local listItems = {}
for i, shortcut in ipairs(shortcuts) do
for i, shortcut in ipairs(shortcuts) do
if yesno(options['target']) then
local templatePath, prefix
listItems[i] = string.format("[[%s]]",shortcut)
if templateMode then
-- Namespace detection
local titleObj = mw.title.new(shortcut, 10)
if titleObj.namespace == 10 then
templatePath = titleObj.fullText
else
templatePath = shortcut
end
prefix = options['pre' .. i] or options.pre or ''
end
if options.target and yesno(options.target) then
listItems[i] = templateMode
and string.format("{{%s[[%s|%s]]}}", prefix, templatePath, shortcut)
or string.format("[[%s]]", shortcut)
else
else
listItems[i] = frame:expandTemplate{
listItems[i] = frame:expandTemplate{
title = 'No redirect',
title = 'No redirect',
args = {shortcut}
args = templateMode and {templatePath, shortcut} or {shortcut, shortcut}
}
}
if templateMode then
listItems[i] = string.format("{{%s%s}}", prefix, listItems[i])
end
end
end
end
end
Line 74: Line 92:
local nShortcuts = #shortcuts
local nShortcuts = #shortcuts
if nShortcuts > 0 then
if nShortcuts > 0 then
local headingMsg = options['shortcut-heading'] or cfg['shortcut-heading']
local headingMsg = options['shortcut-heading'] or
redirectMode and cfg['redirect-heading'] or
cfg['shortcut-heading']
shortcutHeading = message(headingMsg, nShortcuts)
shortcutHeading = message(headingMsg, nShortcuts)
shortcutHeading = frame:preprocess(shortcutHeading)
shortcutHeading = frame:preprocess(shortcutHeading)
Line 85: Line 105:
:addClass('module-shortcutboxplain plainlist noprint')
:addClass('module-shortcutboxplain plainlist noprint')
:attr('role', 'note')
:attr('role', 'note')
if options.float and options.float:lower() == 'left' then
shortcutList:addClass('module-shortcutboxleft')
end
if options.clear and options.clear ~= '' then
shortcutList:css('clear', options.clear)
end
if shortcutHeading then
if shortcutHeading then
shortcutList
shortcutList