Module:Shortcut: Difference between revisions
From Test Wiki
Content deleted Content added
from sandbox |
m 1 revision imported Tags: Mobile edit Mobile web edit |
||
| (5 intermediate revisions by 5 users 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 templateMode = yesno(options.template) |
local templateMode = options.template and yesno(options.template) |
||
local |
local redirectMode = options.redirect and yesno(options.redirect) |
||
local isCategorized = yesno(options.category) ~= false |
local isCategorized = not options.category or yesno(options.category) ~= false |
||
-- Validate shortcuts |
-- Validate shortcuts |
||
| Line 39: | Line 39: | ||
local listItems = {} |
local listItems = {} |
||
for i, shortcut in ipairs(shortcuts) do |
for i, shortcut in ipairs(shortcuts) do |
||
local templatePath |
local templatePath, prefix |
||
if templateMode then |
if templateMode then |
||
-- Namespace detection |
-- Namespace detection |
||
| Line 48: | Line 48: | ||
templatePath = shortcut |
templatePath = shortcut |
||
end |
end |
||
prefix = options['pre' .. i] or options.pre or '' |
|||
end |
end |
||
if yesno(options.target) then |
if options.target and yesno(options.target) then |
||
listItems[i] = templateMode |
listItems[i] = templateMode |
||
and string.format("{{[[%s|%s]]}}", templatePath, shortcut) |
and string.format("{{%s[[%s|%s]]}}", prefix, templatePath, shortcut) |
||
or string.format("[[%s]]", shortcut) |
or string.format("[[%s]]", shortcut) |
||
else |
else |
||
listItems[i] = frame:expandTemplate{ |
listItems[i] = frame:expandTemplate{ |
||
title = 'No redirect', |
title = 'No redirect', |
||
args = templateMode and {templatePath, shortcut} or {shortcut} |
args = templateMode and {templatePath, shortcut} or {shortcut, shortcut} |
||
} |
} |
||
if templateMode then |
if templateMode then |
||
listItems[i] = string.format("{{%s}}", listItems[i]) |
listItems[i] = string.format("{{%s%s}}", prefix, listItems[i]) |
||
end |
end |
||
end |
end |
||
| Line 76: | Line 77: | ||
local root = mw.html.create() |
local root = mw.html.create() |
||
root:wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Shortcut/styles.css'} }) |
root:wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Shortcut/styles.css'} }) |
||
-- Anchors |
-- Anchors |
||
local anchorDiv = root |
local anchorDiv = root |
||
| Line 91: | Line 92: | ||
local nShortcuts = #shortcuts |
local nShortcuts = #shortcuts |
||
if nShortcuts > 0 then |
if nShortcuts > 0 then |
||
local headingMsg = options['shortcut-heading'] or |
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 100: | Line 103: | ||
local shortcutList = root |
local shortcutList = root |
||
:tag('div') |
:tag('div') |
||
:addClass('module-shortcutboxplain |
:addClass('module-shortcutboxplain noprint') |
||
:attr('role', 'note') |
:attr('role', 'note') |
||
if options.float and options.float:lower() == 'left' then |
|||
if floatLeft then |
|||
shortcutList:addClass('module-shortcutboxleft') |
shortcutList:addClass('module-shortcutboxleft') |
||
| ⚫ | |||
if options.clear and options.clear ~= '' then |
|||
shortcutList:css('clear', options.clear) |
|||
end |
end |
||
if shortcutHeading then |
if shortcutHeading then |
||
| Line 111: | Line 117: | ||
:wikitext(shortcutHeading) |
:wikitext(shortcutHeading) |
||
end |
end |
||
local list = shortcutList:tag('ul') |
|||
local ubl = require('Module:List').unbulleted(listItems) |
|||
shortcutList:wikitext(ubl) |
|||
| ⚫ | |||
return tostring(root) |
return tostring(root) |
||
end |
end |
||