m (1 revision imported)
 
(No difference)

Latest revision as of 16:10, 18 November 2015

Documentation for this module may be created at Module:Infobox/doc

  1. --
  2. -- This module implements {{Infobox}}
  3. --
  4. local p = {}
  5.  
  6. local navbar = require('Module:Navbar')._navbar
  7.  
  8. local args = {}
  9. local origArgs
  10. local root
  11.  
  12. local function union(t1, t2)
  13. -- Returns the union of the values of two tables, as a sequence.
  14. local vals = {}
  15. for k, v in pairs(t1) do
  16. vals[v] = true
  17. end
  18. for k, v in pairs(t2) do
  19. vals[v] = true
  20. end
  21. local ret = {}
  22. for k, v in pairs(vals) do
  23. table.insert(ret, k)
  24. end
  25. return ret
  26. end
  27.  
  28. local function getArgNums(prefix)
  29. -- Returns a table containing the numbers of the arguments that exist
  30. -- for the specified prefix. For example, if the prefix was 'data', and
  31. -- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
  32. local nums = {}
  33. for k, v in pairs(args) do
  34. local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
  35. if num then table.insert(nums, tonumber(num)) end
  36. end
  37. table.sort(nums)
  38. return nums
  39. end
  40.  
  41. local function addRow(rowArgs)
  42. -- Adds a row to the infobox, with either a header cell
  43. -- or a label/data cell combination.
  44. if rowArgs.header then
  45. root
  46. :tag('tr')
  47. :addClass(rowArgs.rowclass)
  48. :cssText(rowArgs.rowstyle)
  49. :attr('id', rowArgs.rowid)
  50. :tag('th')
  51. :attr('colspan', 2)
  52. :attr('id', rowArgs.headerid)
  53. :addClass(rowArgs.class)
  54. :addClass(args.headerclass)
  55. :css('text-align', 'center')
  56. :cssText(args.headerstyle)
  57. :wikitext(rowArgs.header)
  58. elseif rowArgs.data then
  59. local row = root:tag('tr')
  60. row:addClass(rowArgs.rowclass)
  61. row:cssText(rowArgs.rowstyle)
  62. row:attr('id', rowArgs.rowid)
  63. if rowArgs.label then
  64. row
  65. :tag('th')
  66. :attr('scope', 'row')
  67. :attr('id', rowArgs.labelid)
  68. :cssText(args.labelstyle)
  69. :wikitext(rowArgs.label)
  70. :done()
  71. end
  72. local dataCell = row:tag('td')
  73. if not rowArgs.label then
  74. dataCell
  75. :attr('colspan', 2)
  76. :css('text-align', 'center')
  77. end
  78. dataCell
  79. :attr('id', rowArgs.dataid)
  80. :addClass(rowArgs.class)
  81. :cssText(rowArgs.datastyle)
  82. :newline()
  83. :wikitext(rowArgs.data)
  84. end
  85. end
  86.  
  87. local function renderTitle()
  88. if not args.title then return end
  89.  
  90. root
  91. :tag('caption')
  92. :addClass(args.titleclass)
  93. :cssText(args.titlestyle)
  94. :wikitext(args.title)
  95. end
  96.  
  97. local function renderAboveRow()
  98. if not args.above then return end
  99. root
  100. :tag('tr')
  101. :tag('th')
  102. :attr('colspan', 2)
  103. :addClass(args.aboveclass)
  104. :css('text-align', 'center')
  105. :css('font-size', '125%')
  106. :css('font-weight', 'bold')
  107. :cssText(args.abovestyle)
  108. :wikitext(args.above)
  109. end
  110.  
  111. local function renderBelowRow()
  112. if not args.below then return end
  113. root
  114. :tag('tr')
  115. :tag('td')
  116. :attr('colspan', '2')
  117. :addClass(args.belowclass)
  118. :css('text-align', 'center')
  119. :cssText(args.belowstyle)
  120. :newline()
  121. :wikitext(args.below)
  122. end
  123.  
  124. local function renderSubheaders()
  125. if args.subheader then
  126. args.subheader1 = args.subheader
  127. end
  128. if args.subheaderrowclass then
  129. args.subheaderrowclass1 = args.subheaderrowclass
  130. end
  131. local subheadernums = getArgNums('subheader')
  132. for k, num in ipairs(subheadernums) do
  133. addRow({
  134. data = args['subheader' .. tostring(num)],
  135. datastyle = args.subheaderstyle or args['subheaderstyle' .. tostring(num)],
  136. class = args.subheaderclass,
  137. rowclass = args['subheaderrowclass' .. tostring(num)]
  138. })
  139. end
  140. end
  141.  
  142. local function renderImages()
  143. if args.image then
  144. args.image1 = args.image
  145. end
  146. if args.caption then
  147. args.caption1 = args.caption
  148. end
  149. local imagenums = getArgNums('image')
  150. for k, num in ipairs(imagenums) do
  151. local caption = args['caption' .. tostring(num)]
  152. local data = mw.html.create():wikitext(args['image' .. tostring(num)])
  153. if caption then
  154. data
  155. :tag('div')
  156. :cssText(args.captionstyle)
  157. :wikitext(caption)
  158. end
  159. addRow({
  160. data = tostring(data),
  161. datastyle = args.imagestyle,
  162. class = args.imageclass,
  163. rowclass = args['imagerowclass' .. tostring(num)]
  164. })
  165. end
  166. end
  167.  
  168. local function renderRows()
  169. -- Gets the union of the header and data argument numbers,
  170. -- and renders them all in order using addRow.
  171. local rownums = union(getArgNums('header'), getArgNums('data'))
  172. table.sort(rownums)
  173. for k, num in ipairs(rownums) do
  174. addRow({
  175. header = args['header' .. tostring(num)],
  176. label = args['label' .. tostring(num)],
  177. data = args['data' .. tostring(num)],
  178. datastyle = args.datastyle,
  179. class = args['class' .. tostring(num)],
  180. rowclass = args['rowclass' .. tostring(num)],
  181. rowstyle = args['rowstyle' .. tostring(num)],
  182. dataid = args['dataid' .. tostring(num)],
  183. labelid = args['labelid' .. tostring(num)],
  184. headerid = args['headerid' .. tostring(num)],
  185. rowid = args['rowid' .. tostring(num)]
  186. })
  187. end
  188. end
  189.  
  190. local function renderNavBar()
  191. if not args.name then return end
  192. root
  193. :tag('tr')
  194. :tag('td')
  195. :attr('colspan', '2')
  196. :css('text-align', 'right')
  197. :wikitext(navbar{
  198. args.name,
  199. mini = 1,
  200. })
  201. end
  202.  
  203. local function renderItalicTitle()
  204. local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
  205. if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
  206. root:wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
  207. end
  208. end
  209.  
  210. local function renderTrackingCategories()
  211. if args.decat ~= 'yes' then
  212. if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
  213. root:wikitext('[[Category:Articles which use infobox templates with no data rows]]')
  214. end
  215. if args.child == 'yes' and args.title then
  216. root:wikitext('[[Category:Pages which use embedded infobox templates with the title parameter]]')
  217. end
  218. end
  219. end
  220.  
  221. local function _infobox()
  222. -- Specify the overall layout of the infobox, with special settings
  223. -- if the infobox is used as a 'child' inside another infobox.
  224. if args.child ~= 'yes' then
  225. root = mw.html.create('table')
  226. root
  227. :addClass('infobox')
  228. :addClass(args.bodyclass)
  229. if args.subbox == 'yes' then
  230. root
  231. :css('padding', '0')
  232. :css('border', 'none')
  233. :css('margin', '-3px')
  234. :css('width', 'auto')
  235. :css('min-width', '100%')
  236. :css('font-size', '100%')
  237. :css('clear', 'none')
  238. :css('float', 'none')
  239. :css('background-color', 'transparent')
  240. else
  241. root
  242. :css('width', '22em')
  243. end
  244. root
  245. :cssText(args.bodystyle)
  246. renderTitle()
  247. renderAboveRow()
  248. else
  249. root = mw.html.create()
  250. root
  251. :wikitext(args.title)
  252. end
  253.  
  254. renderSubheaders()
  255. renderImages()
  256. renderRows()
  257. renderBelowRow()
  258. renderNavBar()
  259. renderItalicTitle()
  260. renderTrackingCategories()
  261. return tostring(root)
  262. end
  263.  
  264. local function preprocessSingleArg(argName)
  265. -- If the argument exists and isn't blank, add it to the argument table.
  266. -- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
  267. if origArgs[argName] and origArgs[argName] ~= '' then
  268. args[argName] = origArgs[argName]
  269. end
  270. end
  271.  
  272. local function preprocessArgs(prefixTable, step)
  273. -- Assign the parameters with the given prefixes to the args table, in order, in batches
  274. -- of the step size specified. This is to prevent references etc. from appearing in the
  275. -- wrong order. The prefixTable should be an array containing tables, each of which has
  276. -- two possible fields, a "prefix" string and a "depend" table. The function always parses
  277. -- parameters containing the "prefix" string, but only parses parameters in the "depend"
  278. -- table if the prefix parameter is present and non-blank.
  279. if type(prefixTable) ~= 'table' then
  280. error("Non-table value detected for the prefix table", 2)
  281. end
  282. if type(step) ~= 'number' then
  283. error("Invalid step value detected", 2)
  284. end
  285. -- Get arguments without a number suffix, and check for bad input.
  286. for i,v in ipairs(prefixTable) do
  287. if type(v) ~= 'table' or type(v.prefix) ~= "string" or (v.depend and type(v.depend) ~= 'table') then
  288. error('Invalid input detected to preprocessArgs prefix table', 2)
  289. end
  290. preprocessSingleArg(v.prefix)
  291. -- Only parse the depend parameter if the prefix parameter is present and not blank.
  292. if args[v.prefix] and v.depend then
  293. for j, dependValue in ipairs(v.depend) do
  294. if type(dependValue) ~= 'string' then
  295. error('Invalid "depend" parameter value detected in preprocessArgs')
  296. end
  297. preprocessSingleArg(dependValue)
  298. end
  299. end
  300. end
  301.  
  302. -- Get arguments with number suffixes.
  303. local a = 1 -- Counter variable.
  304. local moreArgumentsExist = true
  305. while moreArgumentsExist == true do
  306. moreArgumentsExist = false
  307. for i = a, a + step - 1 do
  308. for j,v in ipairs(prefixTable) do
  309. local prefixArgName = v.prefix .. tostring(i)
  310. if origArgs[prefixArgName] then
  311. moreArgumentsExist = true -- Do another loop if any arguments are found, even blank ones.
  312. preprocessSingleArg(prefixArgName)
  313. end
  314. -- Process the depend table if the prefix argument is present and not blank, or
  315. -- we are processing "prefix1" and "prefix" is present and not blank, and
  316. -- if the depend table is present.
  317. if v.depend and (args[prefixArgName] or (i == 1 and args[v.prefix])) then
  318. for j,dependValue in ipairs(v.depend) do
  319. local dependArgName = dependValue .. tostring(i)
  320. preprocessSingleArg(dependArgName)
  321. end
  322. end
  323. end
  324. end
  325. a = a + step
  326. end
  327. end
  328. function p.infobox(frame)
  329. -- If called via #invoke, use the args passed into the invoking template.
  330. -- Otherwise, for testing purposes, assume args are being passed directly in.
  331. if frame == mw.getCurrentFrame() then
  332. origArgs = frame:getParent().args
  333. else
  334. origArgs = frame
  335. end
  336. -- Parse the data parameters in the same order that the old {{infobox}} did, so that
  337. -- references etc. will display in the expected places. Parameters that depend on
  338. -- another parameter are only processed if that parameter is present, to avoid
  339. -- phantom references appearing in article reference lists.
  340. preprocessSingleArg('child')
  341. preprocessSingleArg('bodyclass')
  342. preprocessSingleArg('subbox')
  343. preprocessSingleArg('bodystyle')
  344. preprocessSingleArg('title')
  345. preprocessSingleArg('titleclass')
  346. preprocessSingleArg('titlestyle')
  347. preprocessSingleArg('above')
  348. preprocessSingleArg('aboveclass')
  349. preprocessSingleArg('abovestyle')
  350. preprocessArgs({
  351. {prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
  352. }, 10)
  353. preprocessSingleArg('subheaderstyle')
  354. preprocessSingleArg('subheaderclass')
  355. preprocessArgs({
  356. {prefix = 'image', depend = {'caption', 'imagerowclass'}}
  357. }, 10)
  358. preprocessSingleArg('captionstyle')
  359. preprocessSingleArg('imagestyle')
  360. preprocessSingleArg('imageclass')
  361. preprocessArgs({
  362. {prefix = 'header'},
  363. {prefix = 'data', depend = {'label'}},
  364. {prefix = 'rowclass'},
  365. {prefix = 'rowstyle'},
  366. {prefix = 'class'},
  367. {prefix = 'dataid'},
  368. {prefix = 'labelid'},
  369. {prefix = 'headerid'},
  370. {prefix = 'rowid'}
  371. }, 50)
  372. preprocessSingleArg('headerclass')
  373. preprocessSingleArg('headerstyle')
  374. preprocessSingleArg('labelstyle')
  375. preprocessSingleArg('datastyle')
  376. preprocessSingleArg('below')
  377. preprocessSingleArg('belowclass')
  378. preprocessSingleArg('belowstyle')
  379. preprocessSingleArg('name')
  380. args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
  381. preprocessSingleArg('decat')
  382. return _infobox()
  383. end
  384. return p

--

-- This module implements

--

local p = {}

local navbar = require('Module:Navbar')._navbar

local args = {} local origArgs local root

local function union(t1, t2)

  1. -- Returns the union of the values of two tables, as a sequence.
  2. local vals = {}
  3. for k, v in pairs(t1) do
  4. vals[v] = true
  5. end
  6. for k, v in pairs(t2) do
  7. vals[v] = true
  8. end
  9. local ret = {}
  10. for k, v in pairs(vals) do
  11. table.insert(ret, k)
  12. end
  13. return ret

end

local function getArgNums(prefix)

  1. -- Returns a table containing the numbers of the arguments that exist
  2. -- for the specified prefix. For example, if the prefix was 'data', and
  3. -- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
  4. local nums = {}
  5. for k, v in pairs(args) do
  6. local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
  7. if num then table.insert(nums, tonumber(num)) end
  8. end
  9. table.sort(nums)
  10. return nums

end

local function addRow(rowArgs)

  1. -- Adds a row to the infobox, with either a header cell
  2. -- or a label/data cell combination.
  3. if rowArgs.header then
  4. root
  5.  :tag('tr')
  6.  :addClass(rowArgs.rowclass)
  7.  :cssText(rowArgs.rowstyle)
  8.  :attr('id', rowArgs.rowid)
  9.  :tag('th')
  10.  :attr('colspan', 2)
  11.  :attr('id', rowArgs.headerid)
  12.  :addClass(rowArgs.class)
  13.  :addClass(args.headerclass)
  14.  :css('text-align', 'center')
  15.  :cssText(args.headerstyle)
  16.  :wikitext(rowArgs.header)
  17. elseif rowArgs.data then
  18. local row = root:tag('tr')
  19. row:addClass(rowArgs.rowclass)
  20. row:cssText(rowArgs.rowstyle)
  21. row:attr('id', rowArgs.rowid)
  22. if rowArgs.label then
  23. row
  24.  :tag('th')
  25.  :attr('scope', 'row')
  26.  :attr('id', rowArgs.labelid)
  27.  :cssText(args.labelstyle)
  28.  :wikitext(rowArgs.label)
  29.  :done()
  30. end
  31. local dataCell = row:tag('td')
  32. if not rowArgs.label then
  33. dataCell
  34.  :attr('colspan', 2)
  35.  :css('text-align', 'center')
  36. end
  37. dataCell
  38.  :attr('id', rowArgs.dataid)
  39.  :addClass(rowArgs.class)
  40.  :cssText(rowArgs.datastyle)
  41.  :newline()
  42.  :wikitext(rowArgs.data)
  43. end

end

local function renderTitle()

  1. if not args.title then return end
  1. root
  2.  :tag('caption')
  3.  :addClass(args.titleclass)
  4.  :cssText(args.titlestyle)
  5.  :wikitext(args.title)

end

local function renderAboveRow()

  1. if not args.above then return end
  2. root
  3.  :tag('tr')
  4.  :tag('th')
  5.  :attr('colspan', 2)
  6.  :addClass(args.aboveclass)
  7.  :css('text-align', 'center')
  8.  :css('font-size', '125%')
  9.  :css('font-weight', 'bold')
  10.  :cssText(args.abovestyle)
  11.  :wikitext(args.above)

end

local function renderBelowRow()

  1. if not args.below then return end
  2. root
  3.  :tag('tr')
  4.  :tag('td')
  5.  :attr('colspan', '2')
  6.  :addClass(args.belowclass)
  7.  :css('text-align', 'center')
  8.  :cssText(args.belowstyle)
  9.  :newline()
  10.  :wikitext(args.below)

end

local function renderSubheaders()

  1. if args.subheader then
  2. args.subheader1 = args.subheader
  3. end
  4. if args.subheaderrowclass then
  5. args.subheaderrowclass1 = args.subheaderrowclass
  6. end
  7. local subheadernums = getArgNums('subheader')
  8. for k, num in ipairs(subheadernums) do
  9. addRow({
  10. data = args['subheader' .. tostring(num)],
  11. datastyle = args.subheaderstyle or args['subheaderstyle' .. tostring(num)],
  12. class = args.subheaderclass,
  13. rowclass = args['subheaderrowclass' .. tostring(num)]
  14. })
  15. end

end

local function renderImages()

  1. if args.image then
  2. args.image1 = args.image
  3. end
  4. if args.caption then
  5. args.caption1 = args.caption
  6. end
  7. local imagenums = getArgNums('image')
  8. for k, num in ipairs(imagenums) do
  9. local caption = args['caption' .. tostring(num)]
  10. local data = mw.html.create():wikitext(args['image' .. tostring(num)])
  11. if caption then
  12. data
  13.  :tag('div')
  14.  :cssText(args.captionstyle)
  15.  :wikitext(caption)
  16. end
  17. addRow({
  18. data = tostring(data),
  19. datastyle = args.imagestyle,
  20. class = args.imageclass,
  21. rowclass = args['imagerowclass' .. tostring(num)]
  22. })
  23. end

end

local function renderRows()

  1. -- Gets the union of the header and data argument numbers,
  2. -- and renders them all in order using addRow.
  3. local rownums = union(getArgNums('header'), getArgNums('data'))
  4. table.sort(rownums)
  5. for k, num in ipairs(rownums) do
  6. addRow({
  7. header = args['header' .. tostring(num)],
  8. label = args['label' .. tostring(num)],
  9. data = args['data' .. tostring(num)],
  10. datastyle = args.datastyle,
  11. class = args['class' .. tostring(num)],
  12. rowclass = args['rowclass' .. tostring(num)],
  13. rowstyle = args['rowstyle' .. tostring(num)],
  14. dataid = args['dataid' .. tostring(num)],
  15. labelid = args['labelid' .. tostring(num)],
  16. headerid = args['headerid' .. tostring(num)],
  17. rowid = args['rowid' .. tostring(num)]
  18. })
  19. end

end

local function renderNavBar()

  1. if not args.name then return end
  2. root
  3.  :tag('tr')
  4.  :tag('td')
  5.  :attr('colspan', '2')
  6.  :css('text-align', 'right')
  7.  :wikitext(navbar{
  8. args.name,
  9. mini = 1,
  10. })

end

local function renderItalicTitle()

  1. local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
  2. if italicTitle == or italicTitle == 'force' or italicTitle == 'yes' then
  3. root:wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
  4. end

end

local function renderTrackingCategories()

  1. if args.decat ~= 'yes' then
  2. if #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
  3. root:wikitext()
  4. end
  5. if args.child == 'yes' and args.title then
  6. root:wikitext()
  7. end
  8. end

end

local function _infobox()

  1. -- Specify the overall layout of the infobox, with special settings
  2. -- if the infobox is used as a 'child' inside another infobox.
  3. if args.child ~= 'yes' then
  4. root = mw.html.create('table')
  5. root
  6.  :addClass('infobox')
  7.  :addClass(args.bodyclass)
  8. if args.subbox == 'yes' then
  9. root
  10.  :css('padding', '0')
  11.  :css('border', 'none')
  12.  :css('margin', '-3px')
  13.  :css('width', 'auto')
  14.  :css('min-width', '100%')
  15.  :css('font-size', '100%')
  16.  :css('clear', 'none')
  17.  :css('float', 'none')
  18.  :css('background-color', 'transparent')
  19. else
  20. root
  21.  :css('width', '22em')
  22. end
  23. root
  24.  :cssText(args.bodystyle)
  25. renderTitle()
  26. renderAboveRow()
  27. else
  28. root = mw.html.create()
  29. root
  30.  :wikitext(args.title)
  31. end
  1. renderSubheaders()
  2. renderImages()
  3. renderRows()
  4. renderBelowRow()
  5. renderNavBar()
  6. renderItalicTitle()
  7. renderTrackingCategories()
  8. return tostring(root)

end

local function preprocessSingleArg(argName)

  1. -- If the argument exists and isn't blank, add it to the argument table.
  2. -- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
  3. if origArgs[argName] and origArgs[argName] ~= then
  4. args[argName] = origArgs[argName]
  5. end

end

local function preprocessArgs(prefixTable, step)

  1. -- Assign the parameters with the given prefixes to the args table, in order, in batches
  2. -- of the step size specified. This is to prevent references etc. from appearing in the
  3. -- wrong order. The prefixTable should be an array containing tables, each of which has
  4. -- two possible fields, a "prefix" string and a "depend" table. The function always parses
  5. -- parameters containing the "prefix" string, but only parses parameters in the "depend"
  6. -- table if the prefix parameter is present and non-blank.
  7. if type(prefixTable) ~= 'table' then
  8. error("Non-table value detected for the prefix table", 2)
  9. end
  10. if type(step) ~= 'number' then
  11. error("Invalid step value detected", 2)
  12. end
  13. -- Get arguments without a number suffix, and check for bad input.
  14. for i,v in ipairs(prefixTable) do
  15. if type(v) ~= 'table' or type(v.prefix) ~= "string" or (v.depend and type(v.depend) ~= 'table') then
  16. error('Invalid input detected to preprocessArgs prefix table', 2)
  17. end
  18. preprocessSingleArg(v.prefix)
  19. -- Only parse the depend parameter if the prefix parameter is present and not blank.
  20. if args[v.prefix] and v.depend then
  21. for j, dependValue in ipairs(v.depend) do
  22. if type(dependValue) ~= 'string' then
  23. error('Invalid "depend" parameter value detected in preprocessArgs')
  24. end
  25. preprocessSingleArg(dependValue)
  26. end
  27. end
  28. end
  1. -- Get arguments with number suffixes.
  2. local a = 1 -- Counter variable.
  3. local moreArgumentsExist = true
  4. while moreArgumentsExist == true do
  5. moreArgumentsExist = false
  6. for i = a, a + step - 1 do
  7. for j,v in ipairs(prefixTable) do
  8. local prefixArgName = v.prefix .. tostring(i)
  9. if origArgs[prefixArgName] then
  10. moreArgumentsExist = true -- Do another loop if any arguments are found, even blank ones.
  11. preprocessSingleArg(prefixArgName)
  12. end
  13. -- Process the depend table if the prefix argument is present and not blank, or
  14. -- we are processing "prefix1" and "prefix" is present and not blank, and
  15. -- if the depend table is present.
  16. if v.depend and (args[prefixArgName] or (i == 1 and args[v.prefix])) then
  17. for j,dependValue in ipairs(v.depend) do
  18. local dependArgName = dependValue .. tostring(i)
  19. preprocessSingleArg(dependArgName)
  20. end
  21. end
  22. end
  23. end
  24. a = a + step
  25. end

end

function p.infobox(frame)

  1. -- If called via #invoke, use the args passed into the invoking template.
  2. -- Otherwise, for testing purposes, assume args are being passed directly in.
  3. if frame == mw.getCurrentFrame() then
  4. origArgs = frame:getParent().args
  5. else
  6. origArgs = frame
  7. end
-- Parse the data parameters in the same order that the old
did, so that
  1. -- references etc. will display in the expected places. Parameters that depend on
  2. -- another parameter are only processed if that parameter is present, to avoid
  3. -- phantom references appearing in article reference lists.
  4. preprocessSingleArg('child')
  5. preprocessSingleArg('bodyclass')
  6. preprocessSingleArg('subbox')
  7. preprocessSingleArg('bodystyle')
  8. preprocessSingleArg('title')
  9. preprocessSingleArg('titleclass')
  10. preprocessSingleArg('titlestyle')
  11. preprocessSingleArg('above')
  12. preprocessSingleArg('aboveclass')
  13. preprocessSingleArg('abovestyle')
  14. preprocessArgs({
  15. {prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
  16. }, 10)
  17. preprocessSingleArg('subheaderstyle')
  18. preprocessSingleArg('subheaderclass')
  19. preprocessArgs({
  20. {prefix = 'image', depend = {'caption', 'imagerowclass'}}
  21. }, 10)
  22. preprocessSingleArg('captionstyle')
  23. preprocessSingleArg('imagestyle')
  24. preprocessSingleArg('imageclass')
  25. preprocessArgs({
  26. {prefix = 'header'},
  27. {prefix = 'data', depend = {'label'}},
  28. {prefix = 'rowclass'},
  29. {prefix = 'rowstyle'},
  30. {prefix = 'class'},
  31. {prefix = 'dataid'},
  32. {prefix = 'labelid'},
  33. {prefix = 'headerid'},
  34. {prefix = 'rowid'}
  35. }, 50)
  36. preprocessSingleArg('headerclass')
  37. preprocessSingleArg('headerstyle')
  38. preprocessSingleArg('labelstyle')
  39. preprocessSingleArg('datastyle')
  40. preprocessSingleArg('below')
  41. preprocessSingleArg('belowclass')
  42. preprocessSingleArg('belowstyle')
  43. preprocessSingleArg('name')
  44. args['italic title'] = origArgs['italic title'] -- different behaviour if blank or absent
  45. preprocessSingleArg('decat')
  46.  
  47. return _infobox()

end

return p