Content added Content deleted
(more formatting) |
(add headers) |
||
Line 59: | Line 59: | ||
local root = mw.html.create('table') |
local root = mw.html.create('table') |
||
:addClass('wikitable') |
:addClass('wikitable') |
||
root:tag('tr') |
|||
:tag('th') |
|||
:wikitext('Image') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Chapter') |
|||
:done() |
|||
:tag('th') |
|||
:wikitext('Featured characters') |
|||
:done() |
|||
for _,row in ipairs(results) do |
for _,row in ipairs(results) do |
Revision as of 08:53, 16 April 2022
Documentation for this module may be created at Module:Event story chapters/doc
local getArgs = require('Module:Arguments').getArgs
local QueryBuilder = require('Module:QueryBuilder')
local utils = require('Module:Utilities')
local cicon = require('Module:Character icon')._main
local p = {}
local function formatImage(image)
if image then
return string.format('[[File:%s|125px]]', image)
end
return nil
end
local function formatChapter(chapter, pageName, chapterName)
if chapter and pageName and chapterName then
return string.format('[[%s|%s: %s]]', pageName, chapter, chapterName)
end
return nil
end
local function formatCharacters(characters)
local charArr = utils.splitWithDelim(';')(characters)
local icon_tbl = {}
if charArr then
for _,v in ipairs(charArr) do
local _icon = cicon({ v, size = '45px' })
if _icon then
table.insert(icon_tbl, _icon)
end
end
end
return table.concat(icon_tbl, ' ')
end
function p.main(frame)
local args = getArgs(frame)
local eventId = args['event id']
local qb = QueryBuilder.new()
qb
:setTables('event_story_chapters')
:setFields([[
image,
chapter,
_pageName,
english,
characters
]])
:addWhere('event_id', '=', eventId)
local results = qb:query()
local root = mw.html.create('table')
:addClass('wikitable')
root:tag('tr')
:tag('th')
:wikitext('Image')
:done()
:tag('th')
:wikitext('Chapter')
:done()
:tag('th')
:wikitext('Featured characters')
:done()
for _,row in ipairs(results) do
root:tag('tr')
:tag('td')
:wikitext(formatImage(row.image))
:done()
:tag('td')
:wikitext(formatChapter(
row.chapter,
row._pageName,
row.english
))
:done()
:tag('td')
:wikitext(formatCharacters(row.characters))
:done()
end
return tostring(root)
end
return p