Modul:Redirect hatnote: Unterschied zwischen den Versionen
increment iArg two at a time; better but still buggy
(still wrong, but slightly less wrong?) |
(increment iArg two at a time; better but still buggy) |
||
Zeile 13: | Zeile 13: | ||
function p.redirect(frame) | function p.redirect(frame) | ||
-- Get the args table and work out the maximum arg key. | -- Get the args table and work out the maximum arg key. | ||
--[[ | |||
local origArgs = frame:getParent().args | local origArgs = frame:getParent().args | ||
local args = {} | local args = {} | ||
Zeile 23: | Zeile 25: | ||
if v ~= '' then | if v ~= '' then | ||
args[k] = v | args[k] = v | ||
end | |||
end | |||
--]] | |||
local args = require('Module:Arguments').getArgs(frame) | |||
local maxArg = 0 | |||
for k, v in pairs(args) do | |||
if type(k) == 'number' and k > maxArg then | |||
maxArg = k | |||
end | end | ||
end | end | ||
Zeile 38: | Zeile 49: | ||
-- Create the data table. | -- Create the data table. | ||
local data = {} | local data = {} | ||
local iArg = | local iArg = 0 | ||
local iData = 1 | local iData = 1 | ||
while iArg < maxArg do | while iArg < maxArg do | ||
iArg = iArg + | iArg = iArg + 2 | ||
local useTable = data[iData] or {} | local useTable = data[iData] or {} | ||
local | local use = args[iArg] | ||
local page = args[iArg + 1] | |||
useTable[#useTable + 1] = page | |||
data[iData] = useTable | data[iData] = useTable | ||
if | if use ~= 'and' then | ||
useTable.use = use | |||
iData = iData + 1 | iData = iData + 1 | ||
end | end | ||
mw.logObject(useTable) | |||
end | end | ||