Module:Shortcut: Difference between revisions
m
1 revision imported
en>Centrist16 (Created page with "-- This module implements {{shortcut}}. -- Set constants local CONFIG_MODULE = 'Module:Shortcut/config' -- Load required modules local checkType = require('libraryUtil').che...") |
Vivaporius (talk | contribs) m (1 revision imported) |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 24:
frame = frame or mw.getCurrentFrame()
cfg = cfg or mw.loadData(CONFIG_MODULE)
local
local redirectMode = options.redirect and yesno(options.redirect)
local isCategorized = not options.category or yesno(options.category) ~= false
-- Validate shortcuts
Line 37 ⟶ 39:
local listItems = {}
for i, shortcut in ipairs(shortcuts) do
local templatePath, prefix
listItems[i] = frame:expandTemplate{▼
if templateMode then
title = 'No redirect',▼
-- Namespace detection
args = {shortcut}▼
local titleObj = mw.title.new(shortcut, 10)
}▼
if titleObj.namespace == 10 then
templatePath = titleObj.fullText
else
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
▲ listItems[i] = frame:expandTemplate{
▲ title = 'No redirect',
args = templateMode and {templatePath, shortcut} or {shortcut, shortcut}
▲ }
if templateMode then
listItems[i] = string.format("{{%s%s}}", prefix, listItems[i])
end
end
end
table.insert(listItems, options.msg)
Line 55 ⟶ 77:
local root = mw.html.create()
root:wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Shortcut/styles.css'} })
-- Anchors
local anchorDiv = root
:tag('div')
:addClass('module-shortcutanchordiv')
for i, shortcut in ipairs(shortcuts) do
local anchor = mw.uri.anchorEncode(shortcut)
anchorDiv:tag('span'):attr('id', anchor)
end
-- Shortcut heading
Line 73 ⟶ 92:
local nShortcuts = #shortcuts
if nShortcuts > 0 then
redirectMode and cfg['redirect-heading'] or
cfg['shortcut-heading']
shortcutHeading = frame:preprocess(shortcutHeading)
▲ shortcutHeading = shortcutHeading .. '\n'
end
end
Line 82 ⟶ 103:
local shortcutList = root
:tag('div')
:addClass('
:attr('role', 'note')
if options.float and options.float:lower() == 'left' then
shortcutList:addClass('module-shortcutboxleft')
end
if options.clear and options.clear ~= '' then
end
if shortcutHeading then
shortcutList
:tag('div')
:
:wikitext(shortcutHeading)
end
▲ end
return tostring(root)
end
function p.main(frame)
local args = require('Module:Arguments').getArgs(frame
-- Separate shortcuts from options
|