Module:Shortcut/sandbox: Difference between revisions

Content deleted Content added
do template function
Tag: Reverted
m move template func.
Tag: Reverted
Line 18:
end
 
function p._main_template(shortcuts, options, frame, cfg)
checkType('_main_template', 1, shortcuts, 'table')
checkType('_main_template', 2, options, 'table', true)
options = options or {}
frame = frame or mw.getCurrentFrame()
cfg = cfg or mw.loadData(CONFIG_MODULE)
local templateMode = yesno(options.template)
local policyHeading = yesno(options.policy)
local isCategorized = yesno(options.category) ~= false
 
Line 34 ⟶ 32:
end
end
 
 
-- Make the list items. These are the shortcuts plus any extra lines such
Line 40 ⟶ 37:
local listItems = {}
for i, shortcut in ipairs(shortcuts) do
if yesno(options['target']) then
local templatePath
listItems[i] = string.format("{{{[[template:%s|%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
listItems[i] = frame:expandTemplate{
title = 'No redirect',
args = templateMode and {templatePath, shortcut} or {shortcut}
}
if templateMode then
listItems[i] = string.format("{{%s}}", listItems[i])
end
end
end
Line 92 ⟶ 74:
local nShortcuts = #shortcuts
if nShortcuts > 0 then
local headingMsg = options['shortcut-heading'] or cfg['shortcut-heading']
if policyHeading
then
headingMsg = options['policy-shortcut-heading'] or cfg['policy-shortcut-heading']
else
headingMsg = options['shortcut-heading'] or cfg['shortcut-heading']
end
if yesno(options.policy)
then
headingMsg = options['policy-shortcut-heading'] or cfg['policy-shortcut-heading']
else
headingMsg = options['shortcut-heading'] or cfg['shortcut-heading']
end
shortcutHeading = message(headingMsg, nShortcuts)
shortcutHeading = frame:preprocess(shortcutHeading)
Line 128 ⟶ 98:
end
 
function p.maintemplate(frame)
local args = require('Module:Arguments').getArgs(frame)
 
Line 155 ⟶ 125:
shortcuts = compressArray(shortcuts)
 
return p._main_template(shortcuts, options, frame)
end
 
function p._template_main(shortcuts, options, frame, cfg)
checkType('_template_main', 1, shortcuts, 'table')
checkType('_template_main', 2, options, 'table', true)
options = options or {}
frame = frame or mw.getCurrentFrame()
cfg = cfg or mw.loadData(CONFIG_MODULE)
local templateMode = yesno(options.template)
local policyHeading = yesno(options.policy)
local isCategorized = yesno(options.category) ~= false
 
Line 172 ⟶ 144:
end
end
 
 
-- Make the list items. These are the shortcuts plus any extra lines such
Line 177 ⟶ 150:
local listItems = {}
for i, shortcut in ipairs(shortcuts) do
local templatePath
if yesno(options['target']) then
if templateMode then
listItems[i] = string.format("{{{[[template:%s|%s]]}}}",shortcut)
-- 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
listItems[i] = frame:expandTemplate{
title = 'No redirect',
args = templateMode and {templatePath, shortcut} or {shortcut}
}
if templateMode then
listItems[i] = string.format("{{%s}}", listItems[i])
end
end
end
Line 214 ⟶ 202:
local nShortcuts = #shortcuts
if nShortcuts > 0 then
local headingMsg = options['shortcut-heading'] or cfg['shortcut-heading']
if policyHeading
then
headingMsg = options['policy-shortcut-heading'] or cfg['policy-shortcut-heading']
else
headingMsg = options['shortcut-heading'] or cfg['shortcut-heading']
end
if yesno(options.policy)
then
headingMsg = options['policy-shortcut-heading'] or cfg['policy-shortcut-heading']
else
headingMsg = options['shortcut-heading'] or cfg['shortcut-heading']
end
shortcutHeading = message(headingMsg, nShortcuts)
shortcutHeading = frame:preprocess(shortcutHeading)
Line 238:
end
 
function p.templatemain(frame)
local args = require('Module:Arguments').getArgs(frame)
 
Line 265:
shortcuts = compressArray(shortcuts)
 
return p._template_main(shortcuts, options, frame)
end