Module:Shortcut: Difference between revisions
from sandbox
(Implement merger code by Pppery) |
(from sandbox) |
||
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 templateMode = yesno(options.template) | |||
local floatLeft = options.float and options.float:lower() == 'left' | |||
local isCategorized = yesno(options.category) ~= false | local isCategorized = yesno(options.category) ~= false | ||
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 | local templatePath | ||
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 | |||
end | |||
if yesno(options.target) then | |||
listItems[i] = templateMode | |||
and string.format("{{[[%s|%s]]}}", 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} | ||
} | } | ||
if templateMode then | |||
listItems[i] = string.format("{{%s}}", listItems[i]) | |||
end | |||
end | end | ||
end | end | ||
Line 85: | Line 102: | ||
:addClass('module-shortcutboxplain plainlist noprint') | :addClass('module-shortcutboxplain plainlist noprint') | ||
:attr('role', 'note') | :attr('role', 'note') | ||
if floatLeft then | |||
shortcutList:addClass('module-shortcutboxleft') | |||
end | |||
if shortcutHeading then | if shortcutHeading then | ||
shortcutList | shortcutList |