Modul:Redirect hatnote: Unterschied zwischen den Versionen

(Added hack to categorize pages using odd edge-case behaviour)
(Updated with sandbox/testcases-tested behaviour that changes defaulting and adds tracking for a different wierd behaviour)
Zeile 86: Zeile 86:
-- phrase "For cats, see [[Felines]]".)
-- phrase "For cats, see [[Felines]]".)
-- Returns a string, or nil if no use was specified.
-- Returns a string, or nil if no use was specified.
-- The isFirst parameter is used to apply special formatting for the first
-- The isFirst parameter is legacy, but partly maintained for its effect of
-- table in the data array. If isFirst is specified, the redirect parameter
-- cancelling empty use items.
useTable = useTable or {}
useTable = useTable or {}
local use
local use
Zeile 95: Zeile 95:
return nil
return nil
elseif tonumber(useTable.use) == 1 then
elseif tonumber(useTable.use) == 1 then
use = 'other uses'
--This is really strange behaviour, so it gets a category hack to see if it's actually being used.
use = 'other uses[[Category:Hatnote templates using unusual parameters]]'
else
else
use = useTable.use
use = useTable.use
end
end
local pages = useTable.pages or {}
local pages = useTable.pages or {}
if isFirst then
redirect = redirect[1] or error(
redirect = redirect[1] or error(
'no redirect was supplied',
'isFirst was set in formatUseTable, but no redirect was supplied',
2
2
)
)
pages[1] = pages[1] or redirect .. ' (disambiguation)'
pages[1] = pages[1] or redirect .. ' (disambiguation)'
else
--pages[1] = pages[1] or useTable.use .. ' (disambiguation)'
--Terrible but temporary hack switches above line to below if to test prevalence of this behaviour:
if not pages[1] then
pages[1] = useTable.use .. ' (disambiguation)'
use = use .. '[[Category:Hatnote templates using unusual parameters]]'
end
end
pages = mHatnote.formatPages(unpack(pages))
pages = mHatnote.formatPages(unpack(pages))
pages = mw.text.listToText(pages)
pages = mw.text.listToText(pages)
Zeile 146: Zeile 138:
if data[1] and data[1].use and data[1].use ~= 'other uses' then
if data[1] and data[1].use and data[1].use ~= 'other uses' then
for i = 2, #data do
for i = 2, #data do
text[#text + 1] = formatUseTable(data[i] or {}, false)
text[#text + 1] = formatUseTable(data[i] or {}, false, redirect)
end
end
end
end