正在編輯「模組:Infobox」
跳至導覽
跳至搜尋
此編輯可以被還原。 請檢查以下比較表,確認您是否要還原,然後發布以下變更以完成編輯還原。
最新修訂 | 您的文字 | ||
行 4: | 行 4: | ||
-- overimagerowclass以及header/labal/data*style參數。 |
-- overimagerowclass以及header/labal/data*style參數。 |
||
-- |
-- |
||
⚫ | |||
local p = {} |
local p = {} |
||
local |
local HtmlBuilder = require('Module:HtmlBuilder') |
||
local args = {} |
local args = {} |
||
行 13: | 行 13: | ||
local root |
local root |
||
function union(t1, t2) |
|||
-- Returns the union of the values of two tables, as a sequence. |
-- Returns the union of the values of two tables, as a sequence. |
||
local vals = {} |
local vals = {} |
||
for k, |
for k,v in pairs(t1) do |
||
vals[v] = true |
vals[v] = true |
||
end |
end |
||
for k, |
for k,v in pairs(t2) do |
||
vals[v] = true |
vals[v] = true |
||
end |
end |
||
local ret = {} |
local ret = {} |
||
for k, |
for k,v in pairs(vals) do |
||
table.insert(ret, k) |
table.insert(ret, k) |
||
end |
end |
||
行 34: | 行 34: | ||
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}. |
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}. |
||
local nums = {} |
local nums = {} |
||
for k, |
for k,v in pairs(args) do |
||
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$') |
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$') |
||
if num then table.insert(nums, tonumber(num)) end |
if num then table.insert(nums, tonumber(num)) end |
||
行 47: | 行 47: | ||
if rowArgs.header then |
if rowArgs.header then |
||
root |
root |
||
.tag('tr') |
|||
.addClass(rowArgs.rowclass) |
|||
.tag('th') |
|||
.attr('colspan', 2) |
|||
.addClass(rowArgs.class) |
|||
.css('text-align', 'center') |
|||
.cssText(rowArgs.headerstyle) |
|||
.wikitext(rowArgs.header) |
|||
⚫ | |||
⚫ | |||
:cssText(rowArgs.headerstyle) |
|||
:wikitext(rowArgs.header) |
|||
elseif rowArgs.data then |
elseif rowArgs.data then |
||
local row = root |
local row = root.tag('tr') |
||
row |
row.addClass(rowArgs.rowclass) |
||
row:cssText(rowArgs.rowstyle) |
|||
row:attr('id', rowArgs.rowid) |
|||
if rowArgs.label then |
if rowArgs.label then |
||
row |
row |
||
.tag('th') |
|||
.attr('scope', 'row') |
|||
.css('text-align', 'left') |
|||
.cssText(rowArgs.labelstyle) |
|||
.wikitext(rowArgs.label) |
|||
.done() |
|||
:done() |
|||
end |
end |
||
local dataCell = row |
local dataCell = row.tag('td') |
||
if not rowArgs.label then |
if not rowArgs.label then |
||
dataCell |
dataCell |
||
.attr('colspan', 2) |
|||
.css('text-align', 'center') |
|||
end |
end |
||
dataCell |
dataCell |
||
.addClass(rowArgs.class) |
|||
.cssText(rowArgs.datastyle) |
|||
.newline() |
|||
.wikitext(rowArgs.data) |
|||
:wikitext(rowArgs.data) |
|||
end |
end |
||
end |
end |
||
行 93: | 行 85: | ||
if not args.overimage then return end |
if not args.overimage then return end |
||
local row = root |
local row = root.tag('tr') |
||
row.addClass(args.overimagerowclass) |
|||
local topImage = row.tag('td') |
|||
topImage.attr('colspan', 2) |
|||
topImage.addClass(args.class) |
|||
topImage.cssText(args.datastyle) |
|||
topImage.css('text-align', 'center') |
|||
if args.overcaption then |
|||
topImage.wikitext(args.overimage .. '<br><span style=\"' .. args.captionstyle .. '\">' .. args.overcaption .. '</span>') |
|||
else |
|||
⚫ | |||
if args.overcaption then |
|||
end |
|||
topImage:wikitext(args.overimage .. '<br />' .. args.overcaption) |
|||
else |
|||
⚫ | |||
end |
|||
end |
|||
end |
end |
||
local function renderTitle() |
local function renderTitle() |
||
if not args.title then return end |
if not args.title then return end |
||
⚫ | |||
root |
root |
||
.tag('caption') |
|||
.addClass(args.titleclass) |
|||
.cssText(args.titlestyle) |
|||
.wikitext('\'\'\'' .. args.title .. '\'\'\'') |
|||
end |
end |
||
local function renderAboveRow() |
local function renderAboveRow() |
||
if not args.above then return end |
if not args.above then return end |
||
⚫ | |||
root |
root |
||
.tag('tr') |
|||
.tag('th') |
|||
.attr('colspan', 2) |
|||
.addClass(args.aboveclass) |
|||
.css('text-align', 'center') |
|||
.css('font-size', '125%') |
|||
.css('font-weight', 'bold') |
|||
.cssText(args.abovestyle) |
|||
.wikitext(args.above) |
|||
end |
end |
||
local function renderBelowRow() |
local function renderBelowRow() |
||
if not args.below then return end |
if not args.below then return end |
||
root |
root |
||
.tag('tr') |
|||
.tag('td') |
|||
.attr('colspan', '2') |
|||
.addClass(args.belowclass) |
|||
.css('text-align', 'center') |
|||
.cssText(args.belowstyle) |
|||
.newline() |
|||
.wikitext(args.below) |
|||
end |
end |
||
行 158: | 行 146: | ||
end |
end |
||
local subheadernums = getArgNums('subheader') |
local subheadernums = getArgNums('subheader') |
||
for k, |
for k,num in ipairs(subheadernums) do |
||
addRow({ |
addRow({ |
||
data = args['subheader' .. tostring(num)], |
data = args['subheader' .. tostring(num)], |
||
行 176: | 行 164: | ||
end |
end |
||
local imagenums = getArgNums('image') |
local imagenums = getArgNums('image') |
||
for k, |
for k,num in ipairs(imagenums) do |
||
local caption = args['caption' .. tostring(num)] |
local caption = args['caption' .. tostring(num)] |
||
local data = |
local data = HtmlBuilder.create().wikitext(args['image' .. tostring(num)]) |
||
if caption then |
if caption then |
||
data |
data |
||
.tag('br', {selfClosing = true}) |
|||
.done() |
|||
.tag('div') |
|||
⚫ | |||
⚫ | |||
end |
end |
||
addRow({ |
addRow({ |
||
行 199: | 行 189: | ||
local rownums = union(getArgNums('header'), getArgNums('data')) |
local rownums = union(getArgNums('header'), getArgNums('data')) |
||
table.sort(rownums) |
table.sort(rownums) |
||
for k, |
for k,num in ipairs(rownums) do |
||
addRow({ |
addRow({ |
||
header = args['header' .. tostring(num)], |
header = args['header' .. tostring(num)], |
||
headerstyle = (args.headerstyle or '') .. ';' .. (args['header' .. tostring(num) .. 'style'] or ''), |
|||
label = args['label' .. tostring(num)], |
label = args['label' .. tostring(num)], |
||
labelstyle = (args.labelstyle or '') .. ';' .. (args['label' .. tostring(num) .. 'style'] or ''), |
|||
data = args['data' .. tostring(num)], |
data = args['data' .. tostring(num)], |
||
datastyle = (args.datastyle or '') .. |
datastyle = (args.datastyle or '') .. ';' .. (args['data' .. tostring(num) .. 'style'] or ''), |
||
class = args['class' .. tostring(num)], |
class = args['class' .. tostring(num)], |
||
rowclass = args['rowclass' .. tostring(num)] |
rowclass = args['rowclass' .. tostring(num)] |
||
rowstyle = args['rowstyle' .. tostring(num)], |
|||
dataid = args['dataid' .. tostring(num)], |
|||
labelid = args['labelid' .. tostring(num)], |
|||
headerid = args['headerid' .. tostring(num)], |
|||
rowid = args['rowid' .. tostring(num)] |
|||
}) |
}) |
||
end |
end |
||
行 220: | 行 205: | ||
local function renderNavBar() |
local function renderNavBar() |
||
if not args.name then return end |
if not args.name then return end |
||
⚫ | |||
root |
root |
||
.tag('tr') |
|||
.tag('td') |
|||
.attr('colspan', '2') |
|||
.css('text-align', 'right') |
|||
.wikitext(mw.getCurrentFrame():expandTemplate({ |
|||
title = 'navbar', |
|||
mini = 1 |
args = { args.name, mini = 1 } |
||
}) |
})) |
||
end |
end |
||
行 235: | 行 220: | ||
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 |
root.wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'})) |
||
end |
end |
||
end |
end |
||
行 242: | 行 227: | ||
if args.decat ~= 'yes' then |
if args.decat ~= 'yes' then |
||
if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then |
if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then |
||
root |
root.wikitext('[[Category:使用無數據行信息框模板的條目]]') |
||
end |
end |
||
if args.child == 'yes' and args.title then |
if args.child == 'yes' and args.title then |
||
root |
root.wikitext('[[Category:使用帶有標題參數的嵌入式信息框模板的條目]]') |
||
end |
end |
||
end |
end |
||
行 254: | 行 239: | ||
-- if the infobox is used as a 'child' inside another infobox. |
-- if the infobox is used as a 'child' inside another infobox. |
||
if args.child ~= 'yes' then |
if args.child ~= 'yes' then |
||
root = |
root = HtmlBuilder.create('table') |
||
root |
root |
||
.addClass('infobox') |
|||
.addClass(args.bodyclass) |
|||
.attr('cellspacing', 3) |
|||
.css('border-spacing', '3px') |
|||
if args.subbox == 'yes' then |
if args.subbox == 'yes' then |
||
root |
root |
||
.css('padding', '0') |
|||
.css('border', 'none') |
|||
.css('margin', '-3px') |
|||
.css('width', 'auto') |
|||
.css('min-width', '100%') |
|||
.css('font-size', 'small') |
|||
.css('clear', 'none') |
|||
.css('float', 'none') |
|||
.css('background-color', 'transparent') |
|||
else |
else |
||
root |
root |
||
.css('width', '22em') |
|||
.css('text-align', 'left') |
|||
.css('font-size', 'small') |
|||
.css('line-height', '1.5em') |
|||
end |
end |
||
root |
root |
||
.cssText(args.bodystyle) |
|||
renderTitle() |
renderTitle() |
||
renderAboveRow() |
renderAboveRow() |
||
else |
else |
||
root = |
root = HtmlBuilder.create() |
||
root |
root |
||
.wikitext(args.title) |
|||
end |
end |
||
renderOverImage() |
|||
renderSubheaders() |
renderSubheaders() |
||
renderImages() |
renderImages() |
||
行 300: | 行 285: | ||
renderItalicTitle() |
renderItalicTitle() |
||
renderTrackingCategories() |
renderTrackingCategories() |
||
return tostring(root) |
return tostring(root) |
||
end |
end |
||
行 325: | 行 310: | ||
error("Invalid step value detected", 2) |
error("Invalid step value detected", 2) |
||
end |
end |
||
-- Get arguments without a number suffix, and check for bad input. |
-- Get arguments without a number suffix, and check for bad input. |
||
for i,v in ipairs(prefixTable) do |
for i,v in ipairs(prefixTable) do |
||
行 334: | 行 319: | ||
-- Only parse the depend parameter if the prefix parameter is present and not blank. |
-- Only parse the depend parameter if the prefix parameter is present and not blank. |
||
if args[v.prefix] and v.depend then |
if args[v.prefix] and v.depend then |
||
for j, |
for j,dependValue in ipairs(v.depend) do |
||
if type(dependValue) ~= 'string' then |
if type(dependValue) ~= 'string' then |
||
error('Invalid "depend" parameter value detected in preprocessArgs') |
error('Invalid "depend" parameter value detected in preprocessArgs') |
||
行 388: | 行 373: | ||
end |
end |
||
end |
end |
||
⚫ | |||
function p.infobox(frame) |
function p.infobox(frame) |
||
-- If called via #invoke, use the args passed into the invoking template. |
-- If called via #invoke, use the args passed into the invoking template. |
||
行 397: | 行 382: | ||
origArgs = frame |
origArgs = frame |
||
end |
end |
||
-- Parse the data parameters in the same order that the old {{infobox}} did, so that |
-- Parse the data parameters in the same order that the old {{infobox}} did, so that |
||
-- references etc. will display in the expected places. Parameters that depend on |
-- references etc. will display in the expected places. Parameters that depend on |
||
行 415: | 行 400: | ||
preprocessSingleArg('aboveclass') |
preprocessSingleArg('aboveclass') |
||
preprocessSingleArg('abovestyle') |
preprocessSingleArg('abovestyle') |
||
⚫ | |||
preprocessArgs({ |
preprocessArgs({ |
||
{prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}} |
{prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}} |
||
行 430: | 行 416: | ||
{prefix = 'data', depend = {'label'}}, |
{prefix = 'data', depend = {'label'}}, |
||
{prefix = 'rowclass'}, |
{prefix = 'rowclass'}, |
||
{prefix = ' |
{prefix = 'class'} |
||
{prefix = 'class'}, |
|||
{prefix = 'dataid'}, |
|||
{prefix = 'labelid'}, |
|||
{prefix = 'headerid'}, |
|||
{prefix = 'rowid'} |
|||
}, 80) |
}, 80) |
||
preprocessSpecificStyle({ |
preprocessSpecificStyle({ |
||
行 442: | 行 423: | ||
{arg = 'data'} |
{arg = 'data'} |
||
}, 80) |
}, 80) |
||
⚫ | |||
preprocessSingleArg('headerstyle') |
preprocessSingleArg('headerstyle') |
||
preprocessSingleArg('labelstyle') |
preprocessSingleArg('labelstyle') |
||
行 452: | 行 432: | ||
args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent |
args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent |
||
preprocessSingleArg('decat') |
preprocessSingleArg('decat') |
||
⚫ | |||
return _infobox() |
return _infobox() |
||
end |
end |
||
return p |
return p |