Module:Infobox: Difference between revisions
No edit summary Tag: Reverted |
No edit summary Tags: Manual revert Reverted |
||
| Line 43: | Line 43: | ||
end | end | ||
end | end | ||
end | |||
end | |||
local function fixChildBoxes(sval, tt) | |||
local function notempty( s ) return s and s:match( '%S' ) end | |||
if notempty(sval) then | |||
local marker = '<span class=special_infobox_marker>' | |||
local s = sval | |||
-- start moving templatestyles and categories inside of table rows | |||
local slast = '' | |||
while slast ~= s do | |||
slast = s | |||
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*%]%])', '%2%1') | |||
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)', '%2%1') | |||
end | |||
-- end moving templatestyles and categories inside of table rows | |||
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1') | |||
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker) | |||
if s:match(marker) then | |||
s = mw.ustring.gsub(s, marker .. '%s*' .. marker, '') | |||
s = mw.ustring.gsub(s, '([\r\n]|-[^\r\n]*[\r\n])%s*' .. marker, '%1') | |||
s = mw.ustring.gsub(s, marker .. '%s*([\r\n]|-)', '%1') | |||
s = mw.ustring.gsub(s, '(</[Cc][Aa][Pp][Tt][Ii][Oo][Nn]%s*>%s*)' .. marker, '%1') | |||
s = mw.ustring.gsub(s, '(<%s*[Tt][Aa][Bb][Ll][Ee][^<>]*>%s*)' .. marker, '%1') | |||
s = mw.ustring.gsub(s, '^(%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1') | |||
s = mw.ustring.gsub(s, '([\r\n]%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1') | |||
s = mw.ustring.gsub(s, marker .. '(%s*</[Tt][Aa][Bb][Ll][Ee]%s*>)', '%1') | |||
s = mw.ustring.gsub(s, marker .. '(%s*\n|%})', '%1') | |||
end | |||
if s:match(marker) then | |||
local subcells = mw.text.split(s, marker) | |||
s = '' | |||
for k = 1, #subcells do | |||
if k == 1 then | |||
s = s .. subcells[k] .. '</' .. tt .. '></tr>' | |||
elseif k == #subcells then | |||
local rowstyle = ' style="display:none"' | |||
if notempty(subcells[k]) then rowstyle = '' end | |||
s = s .. '<tr' .. rowstyle ..'><' .. tt .. ' colspan=2>\n' .. | |||
subcells[k] | |||
elseif notempty(subcells[k]) then | |||
if (k % 2) == 0 then | |||
s = s .. subcells[k] | |||
else | |||
s = s .. '<tr><' .. tt .. ' colspan=2>\n' .. | |||
subcells[k] .. '</' .. tt .. '></tr>' | |||
end | |||
end | |||
end | |||
end | |||
-- the next two lines add a newline at the end of lists for the PHP parser | |||
-- [[Special:Diff/849054481]] | |||
-- remove when [[:phab:T191516]] is fixed or OBE | |||
s = mw.ustring.gsub(s, '([\r\n][%*#;:][^\r\n]*)$', '%1\n') | |||
s = mw.ustring.gsub(s, '^([%*#;:][^\r\n]*)$', '%1\n') | |||
s = mw.ustring.gsub(s, '^([%*#;:])', '\n%1') | |||
s = mw.ustring.gsub(s, '^(%{%|)', '\n%1') | |||
return s | |||
else | |||
return sval | |||
end | end | ||
end | end | ||
| Line 50: | Line 111: | ||
root = tostring(root) | root = tostring(root) | ||
if has_rows == false then | if has_rows == false then | ||
root = mw.ustring.gsub(root, '<table[^<>]*>%s*< | root = mw.ustring.gsub(root, '<table[^<>]*>%s*</table>', '') | ||
end | end | ||
end | end | ||
| Line 140: | Line 201: | ||
else | else | ||
table.insert(empty_row_categories, rowArgs.data or '') | table.insert(empty_row_categories, rowArgs.data or '') | ||
end | end | ||
end | end | ||
| Line 432: | Line 431: | ||
-- Render tracking categories. args.decat == turns off tracking categories. | -- Render tracking categories. args.decat == turns off tracking categories. | ||
local function renderTrackingCategories() | local function renderTrackingCategories() | ||
if yesno(args.decat) then return end | |||
if | |||
if args.child == 'yes' then | if args.child == 'yes' then | ||
if args.title then | if args.title then | ||
| Line 549: | Line 547: | ||
structure_infobox_common() | structure_infobox_common() | ||
return loadTemplateStyles() .. | return loadTemplateStyles() .. root | ||
end | end | ||