Module:For related page: Difference between revisions
Appearance
Content deleted Content added
MusikAnimal (talk | contribs) m Protected "Module:For related page": High-risk template or module; match protection with associated template ([Edit=Require autoconfirmed or confirmed access] (indefinite)) |
Allow specifying multiple pages |
||
Line 7: | Line 7: | ||
{parentOnly = true} |
{parentOnly = true} |
||
) |
) |
||
local |
local forargs = {frame.args.what} |
||
if args[1] then |
if args[1] and (args[1] or '' ~= '') then |
||
for i, v in ipairs(args) do |
|||
if (v or '' ~= '') then table.insert(forargs, args[i]) end |
|||
end |
|||
else |
else |
||
local target |
|||
local title = mw.title.getCurrentTitle().text |
local title = mw.title.getCurrentTitle().text |
||
local titles = { |
local titles = { |
||
Line 27: | Line 30: | ||
if target then break end |
if target then break end |
||
end |
end |
||
table.insert(forargs, target or string.format(forms[1], title)) |
|||
end |
end |
||
return mFor._For( |
return mFor._For(forargs) |
||
end |
end |
||
return p |
return p |
Latest revision as of 21:27, 30 December 2024
Implements {{for outline}} and {{for timeline}}.
local mFor = require('Module:For')
local mArguments = require('Module:Arguments')
local p = {}
function p.forFoo (frame)
local args = mArguments.getArgs(frame,
{parentOnly = true}
)
local forargs = {frame.args.what}
if args[1] and (args[1] or '' ~= '') then
for i, v in ipairs(args) do
if (v or '' ~= '') then table.insert(forargs, args[i]) end
end
else
local target
local title = mw.title.getCurrentTitle().text
local titles = {
mw.ustring.lower(mw.ustring.sub(title, 1, 1)) .. mw.ustring.sub(title, 2),
title
}
local forms = frame.args
for k, v in ipairs(forms) do
for i, j in pairs(titles) do
local lookup = string.format(v, j)
if mw.title.new(lookup, 0).exists then
target = lookup
break
end
end
if target then break end
end
table.insert(forargs, target or string.format(forms[1], title))
end
return mFor._For(forargs)
end
return p