打开主菜单

Ballance Wiki β

更改

模块:Infobox

添加94字节2019年6月22日 (六) 00:59
无编辑摘要
--
-- This module implements {{Infobox}}
-- 中文的此模块对比英文维基多解析了overimage, overcaption,
-- overimagerowclass以及header/labal/data*style参数。
--
local p = {}
local origArgs
local root
 
local function notempty( s ) return s and s:match( '%S' ) end
 
local function fixChildBoxes(sval, tt)
if notempty(sval) then
local marker = '<span class=special_infobox_marker>'
local s = sval
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
-- https://en.wikipedia.org/w/index.php?title=Template_talk:Infobox_musical_artist&oldid=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
local function union(t1, t2)
:addClass(args.headerclass)
:css('text-align', 'center')
:cssText(argsrowArgs.headerstyle) :cssText(rowArgs.rowcellstyle) :wikitext(fixChildBoxes(rowArgs.header, 'th'))
elseif rowArgs.data then
local row = root:tag('tr')
:tag('th')
:attr('scope', 'row')
:css('text-align', 'left')
:attr('id', rowArgs.labelid)
:cssText(argsrowArgs.labelstyle) :cssText(rowArgs.rowcellstyle)
:wikitext(rowArgs.label)
:done()
:addClass(rowArgs.class)
:cssText(rowArgs.datastyle)
:cssTextnewline(rowArgs.rowcellstyle) :wikitext(fixChildBoxes(rowArgs.data, 'td'))
end
end
 
local function renderOverImage()
if not args.overimage then return end
 
local row = root:tag('tr')
row:addClass(args.overimagerowclass)
local topImage = row:tag('td')
topImage:attr('colspan', 2)
topImage:addClass(args.imageclass)
topImage:cssText(args.imagestyle)
topImage:css('text-align', 'center')
if args.overcaption and args.captionstyle then
topImage:wikitext(args.overimage .. '<br /><span style=\"' .. args.captionstyle .. '\">' .. args.overcaption .. '</span>')
else
if args.overcaption then
topImage:wikitext(args.overimage .. '<br />' .. args.overcaption)
else
topImage:wikitext(args.overimage)
end
end
end
:addClass(args.titleclass)
:cssText(args.titlestyle)
:wikitext('\'\'\'' .. args.title.. '\'\'\'')
end
:css('font-weight', 'bold')
:cssText(args.abovestyle)
:wikitext(fixChildBoxes(args.above,'th'))
end
:css('text-align', 'center')
:cssText(args.belowstyle)
:newline() :wikitext(fixChildBoxes(args.below,'td'))
end
addRow({
data = args['subheader' .. tostring(num)],
datastyle = args.subheaderstyle, rowcellstyle = or args['subheaderstyle' .. tostring(num)],
class = args.subheaderclass,
rowclass = args['subheaderrowclass' .. tostring(num)]
addRow({
header = args['header' .. tostring(num)],
headerstyle = (args.headerstyle or '') .. (args.headerstyle and ';' or '') .. (args['header' .. tostring(num) .. 'style'] or ''),
label = args['label' .. tostring(num)],
labelstyle = (args.labelstyle or '') .. (args.labelstyle and ';' or '') .. (args['label' .. tostring(num) .. 'style'] or ''),
data = args['data' .. tostring(num)],
datastyle = (args.datastyleor '') .. (args.datastyle and ';' or '') .. (args['data' .. tostring(num) .. 'style'] or ''),
class = args['class' .. tostring(num)],
rowclass = args['rowclass' .. tostring(num)],
rowstyle = args['rowstyle' .. tostring(num)],
rowcellstyle = args['rowcellstyle' .. tostring(num)],
dataid = args['dataid' .. tostring(num)],
labelid = args['labelid' .. tostring(num)],
local function renderTrackingCategories()
if args.decat ~= 'yes' then
if args.child #(getArgNums('data')) == 'yes' then if args0 and mw.title .getCurrentTitle().namespace == 0 then root:wikitext('[[Category:Pages which use embedded infobox templates with the title parameter使用无数据行信息框模板的条目]]') end elseif #(getArgNums(if args.child == 'datayes')) == 0 and mwargs.title.getCurrentTitle().namespace == 0 then root:wikitext('[[Category:Articles which use infobox templates with no data rows使用带有标题参数的嵌入式信息框模板的条目]]')
end
end
root
:addClass((args.subbox ~= 'yes') and 'infobox' or nil)
:addClass(args.bodyclass)
:attr('cellspacing', 3)
:css('border-spacing', '3px')
if args.subbox == 'yes' then
:css('width', 'auto')
:css('min-width', '100%')
:css('font-size', '100%small')
:css('clear', 'none')
:css('float', 'none')
root
:css('width', '22em')
:css('text-align', 'left')
:css('font-size', 'small')
:css('line-height', '1.5em')
end
root
end
renderOverImage()
renderSubheaders()
renderImages()
preprocessSingleArg(dependArgName)
end
end
end
end
a = a + step
end
end
 
function preprocessSpecificStyle(styleTable, step)
-- Assign the parameters *style to the args table
local a = 1 -- Counter variable.
local moreArgumentsExist = true
while moreArgumentsExist == true do
moreArgumentsExist = false
for i = a,a + step - 1 do
for j,v in ipairs(styleTable) do
local styleArgName = v.arg .. tostring(i) .. 'style'
if origArgs[styleArgName] then
moreArgumentsExist = true -- Do another loop if any arguments are found, even blank ones.
preprocessSingleArg(styleArgName)
end
end
preprocessSingleArg('subbox')
preprocessSingleArg('bodystyle')
preprocessSingleArg('overimage')
preprocessSingleArg('overcaption')
preprocessSingleArg('overimagerowclass')
preprocessSingleArg('title')
preprocessSingleArg('titleclass')
{prefix = 'rowclass'},
{prefix = 'rowstyle'},
{prefix = 'rowcellstyle'},
{prefix = 'class'},
{prefix = 'dataid'},
{prefix = 'headerid'},
{prefix = 'rowid'}
}, 5080) preprocessSpecificStyle({ {arg = 'header'}, {arg = 'label'}, {arg = 'data'} }, 80)
preprocessSingleArg('headerclass')
preprocessSingleArg('headerstyle')