Module:Infobox: Difference between revisions

2,542 bytes added ,  21:29, 27 December 2022
merge hlist here
(Created page with "local p = {} local args = {} local origArgs = {} local root local empty_row_categories = {} local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[...")
 
en>Izno
(merge hlist here)
Line 5: Line 5:
local empty_row_categories = {}
local empty_row_categories = {}
local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]'
local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]'
local has_rows = false
local lists = {
plainlist_t = {
patterns = {
'^plainlist$',
'%splainlist$',
'^plainlist%s',
'%splainlist%s'
},
found = false,
styles = 'Plainlist/styles.css'
},
hlist_t = {
patterns = {
'^hlist$',
'%shlist$',
'^hlist%s',
'%shlist%s'
},
found = false,
styles = 'Hlist/styles.css'
}
}
local function has_list_class(args_to_check)
for _, list in pairs(lists) do
if not list.found then
for _, arg in pairs(args_to_check) do
for _, pattern in ipairs(list.patterns) do
if mw.ustring.find(arg or '', pattern) then
list.found = true
break
end
end
if list.found then break end
end
end
end
end


local function fixChildBoxes(sval, tt)
local function fixChildBoxes(sval, tt)
Line 12: Line 51:
local marker = '<span class=special_infobox_marker>'
local marker = '<span class=special_infobox_marker>'
local s = sval
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, '(<%s*[Tt][Rr])', marker .. '%1')
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
Line 56: Line 103:
else
else
return sval
return sval
end
end
-- Cleans empty tables
local function cleanInfobox()
root = tostring(root)
if has_rows == false then
root = mw.ustring.gsub(root, '<table[^<>]*>%s*</table>', '')
end
end
end
end
Line 94: Line 149:
if rowArgs.header and rowArgs.header ~= '_BLANK_' then
if rowArgs.header and rowArgs.header ~= '_BLANK_' then
has_rows = true
has_list_class({ rowArgs.rowclass, rowArgs.class, args.headerclass })
root
root
:tag('tr')
:tag('tr')
Line 109: Line 167:
if rowArgs.data then
if rowArgs.data then
root:wikitext(
root:wikitext(
'[[Category:Pages which use infobox templates with ignored data cells]]'
'[[Category:Pages using infobox templates with ignored data cells]]'
)
)
end
end
elseif rowArgs.data and rowArgs.data:gsub(
elseif rowArgs.data and rowArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
category_in_empty_row_pattern, ''
has_rows = true
):match('^%S') then
has_list_class({ rowArgs.rowclass, rowArgs.class })
local row = root:tag('tr')
local row = root:tag('tr')
row:addClass(rowArgs.rowclass)
row:addClass(rowArgs.rowclass)
Line 147: Line 206:
if not args.title then return end
if not args.title then return end


has_rows = true
has_list_class({args.titleclass})
root
root
:tag('caption')
:tag('caption')
Line 154: Line 216:
:cssText(args.titlestyle)
:cssText(args.titlestyle)
:wikitext(args.title)
:wikitext(args.title)
end
end


Line 159: Line 222:
if not args.above then return end
if not args.above then return end


has_rows = true
has_list_class({ args.aboveclass })
root
root
:tag('tr')
:tag('tr')
Line 173: Line 239:
if not args.below then return end
if not args.below then return end


has_rows = true
has_list_class({ args.belowclass })
root
root
:tag('tr')
:tag('tr')
Line 187: Line 256:
if subheaderArgs.data and
if subheaderArgs.data and
subheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
subheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
has_rows = true
has_list_class({ subheaderArgs.rowclass, subheaderArgs.class })
local row = root:tag('tr')
local row = root:tag('tr')
row:addClass(subheaderArgs.rowclass)
row:addClass(subheaderArgs.rowclass)
Line 227: Line 299:
if imageArgs.data and
if imageArgs.data and
imageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
imageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
has_rows = true
has_list_class({ imageArgs.rowclass, imageArgs.class })
local row = root:tag('tr')
local row = root:tag('tr')
Line 324: Line 399:
if not args.name then return end
if not args.name then return end


has_rows = true
root
root
:tag('tr')
:tag('tr')
Line 338: Line 414:
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
root:wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
root:wikitext(require('Module:Italic title')._main({}))
end
end
end
end
Line 358: Line 434:
if args.title then
if args.title then
root:wikitext(
root:wikitext(
'[[Category:Pages which use embedded infobox templates with the title parameter]]'
'[[Category:Pages using embedded infobox templates with the title parameter]]'
)
)
end
end
elseif #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
elseif #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
root:wikitext('[[Category:Articles which use infobox templates with no data rows]]')
root:wikitext('[[Category:Articles using infobox templates with no data rows]]')
end
end
end
end
Line 369: Line 445:
Loads the templatestyles for the infobox.
Loads the templatestyles for the infobox.


TODO: load base templatestyles here rather than in MediaWiki:Common.css
TODO: FINISH loading base templatestyles here rather than in
We aren't doing it here yet because there are 4-5000 pages with 'raw' infobox
MediaWiki:Common.css. There are 4-5000 pages with 'raw' infobox tables.
tables. See [[Mediawiki_talk:Common.css/to_do#Infobox]] and/or come help :).
See [[Mediawiki_talk:Common.css/to_do#Infobox]] and/or come help :).
When we do this we should clean up the inline CSS below too.
When we do this we should clean up the inline CSS below too.
Will have to do some bizarre conversion category like with sidebar.
Will have to do some bizarre conversion category like with sidebar.
 
]=]
]=]
local function loadTemplateStyles()
local function loadTemplateStyles()
local frame = mw.getCurrentFrame()
local frame = mw.getCurrentFrame()
-- See function description
local hlist_templatestyles = ''
-- local base_templatestyles = frame:extensionTag{
if lists.hlist_t.found then
-- name = 'templatestyles', args = { src = cfg.i18n.templatestyles }
hlist_templatestyles = frame:extensionTag{
-- }
name = 'templatestyles', args = { src = lists.hlist_t.styles }
}
end
local plainlist_templatestyles = ''
if lists.plainlist_t.found then
plainlist_templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = lists.plainlist_t.styles }
}
end
-- See function description
local base_templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = 'Module:Infobox/styles.css' }
}
local templatestyles = ''
local templatestyles = ''
if args['templatestyles'] then templatestyles = frame:extensionTag{
if args['templatestyles'] then
templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = args['templatestyles'] }
name = 'templatestyles', args = { src = args['templatestyles'] }
}
}
Line 391: Line 482:
local child_templatestyles = ''
local child_templatestyles = ''
if args['child templatestyles'] then child_templatestyles = frame:extensionTag{
if args['child templatestyles'] then
child_templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = args['child templatestyles'] }
name = 'templatestyles', args = { src = args['child templatestyles'] }
}
}
Line 397: Line 489:
local grandchild_templatestyles = ''
local grandchild_templatestyles = ''
if args['grandchild templatestyles'] then grandchild_templatestyles = frame:extensionTag{
if args['grandchild templatestyles'] then
grandchild_templatestyles = frame:extensionTag{
name = 'templatestyles', args = { src = args['grandchild templatestyles'] }
name = 'templatestyles', args = { src = args['grandchild templatestyles'] }
}
}
end
end
 
return table.concat({
return table.concat({
-- base_templatestyles, -- see function description
-- hlist -> plainlist -> base is best-effort to preserve old Common.css ordering.
-- this ordering is not a guarantee because the rows of interest invoking
-- each class may not be on a specific page
hlist_templatestyles,
plainlist_templatestyles,
base_templatestyles,
templatestyles,
templatestyles,
child_templatestyles,
child_templatestyles,
grandchild_templatestyles
grandchild_templatestyles
})
})
end
 
-- common functions between the child and non child cases
local function structure_infobox_common()
renderSubheaders()
renderImages()
preprocessRows()
renderRows()
renderBelowRow()
renderNavBar()
renderItalicTitle()
renderEmptyRowCategories()
renderTrackingCategories()
cleanInfobox()
end
end


Line 422: Line 533:
-- @deprecated next; target .infobox-<name>
-- @deprecated next; target .infobox-<name>
:cssText(args.bodystyle)
:cssText(args.bodystyle)
has_list_class({ args.bodyclass })


renderTitle()
renderTitle()
Line 431: Line 544:
:wikitext(args.title)
:wikitext(args.title)
end
end
 
structure_infobox_common()
renderSubheaders()
renderImages()
return loadTemplateStyles() .. root
preprocessRows()
renderRows()
renderBelowRow()
renderNavBar()
renderItalicTitle()
renderEmptyRowCategories()
renderTrackingCategories()
 
return loadTemplateStyles() .. tostring(root)
end
end


Anonymous user