Module:Shortcut/sandbox: Difference between revisions

Content deleted Content added
Tag: Reverted
Whatback11 (talk | contribs)
No edit summary
 
(31 intermediate revisions by 4 users not shown)
Line 24:
frame = frame or mw.getCurrentFrame()
cfg = cfg or mw.loadData(CONFIG_MODULE)
local isCategorizedtemplateMode = options.template and yesno(options.categorytemplate) ~= false
local redirectMode = options.redirect and yesno(options.redirect)
local isCategorized = not options.category or yesno(options.category) ~= false
 
-- Validate shortcuts
Line 31 ⟶ 33:
error(message(cfg['invalid-shortcut-error'], i), 2)
end
end
 
-- Template mode, an opt-out option in the Template namespace and an opt-in
-- one in others.
local templateMode = yesno(options.template)
if templateMode == nil then
templateMode = mw.title.getCurrentTitle().namespace == 10
end
 
Line 44 ⟶ 39:
local listItems = {}
for i, shortcut in ipairs(shortcuts) do
local templatePath, prefix
if yesno(options.target) then
if templateMode == nil then
-- Namespace detection
local titleObj = mw.title.new(shortcut, 10)
if titleObj.namespace == 10 then
templatePath = titleObj.fullText
else
ortemplatePath = {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("TM:{{%s[[%s:%s|%s]]}}", mw.site.namespaces[10].nameprefix, shortcuttemplatePath, shortcut)
or string.format("[[%s]]", shortcut)
else
listItems[i] = frame:expandTemplate{
title = 'No redirect',
args = templateMode and {templatePath, shortcut} or {shortcut, shortcut}
and {string.format("%s:%s", mw.site.namespaces[10].name, shortcut), shortcut}
or {shortcut}
}
if templateMode then
listItems[i] = string.format("TM:{{%s%s}}", prefix, listItems[i])
end
end
Line 73 ⟶ 77:
 
local root = mw.html.create()
root:wikitext(frame:extensionTag{ name = 'templatestyles', args = { src = 'Module:Shortcut/styles.css'} })
-- Anchors
local anchorDiv = root
Line 88 ⟶ 92:
local nShortcuts = #shortcuts
if nShortcuts > 0 then
local headingMsg = options['shortcut-heading'] or cfg['shortcut-heading']
redirectMode and cfg['redirect-heading'] or
cfg['shortcut-heading']
shortcutHeading = message(headingMsg, nShortcuts)
shortcutHeading = frame:preprocess(shortcutHeading)
Line 97 ⟶ 103:
local shortcutList = root
:tag('div')
:addClass('module-shortcutboxplain plainlist noprint')
: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
shortcutList
Line 105 ⟶ 117:
:wikitext(shortcutHeading)
end
local list = shortcutList:tag('ul')
forlocal i,ubl item= in ipairsrequire('Module:List').unbulleted(listItems) do
list:tag('li') shortcutList:wikitext(itemubl)
end
return tostring(root)
end