Content added Content deleted
No edit summary |
mNo edit summary |
||
(8 intermediate revisions by the same user not shown) | |||
Line 5: | Line 5: | ||
local p = {} |
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 pageName then |
|||
return string.format( |
|||
'[[%s|Chapter %s: %s]]', |
|||
pageName, |
|||
chapter or '?', |
|||
chapterName or '?' |
|||
) |
|||
end |
|||
return nil |
|||
end |
|||
local function formatCharacters(characters) |
local function formatCharacters(characters) |
||
local charArr = utils.splitWithDelim(';')(characters) |
local charArr = utils.splitWithDelim(';')(characters) |
||
local icon_tbl = {} |
|||
⚫ | |||
⚫ | |||
if charArr then |
|||
⚫ | |||
⚫ | |||
⚫ | |||
if _icon then |
|||
table.insert(icon_tbl, _icon) |
|||
end |
|||
end |
|||
end |
end |
||
return table. |
return table.concat(icon_tbl, ' ') |
||
end |
end |
||
Line 29: | Line 56: | ||
_pageName, |
_pageName, |
||
english, |
english, |
||
japanese, |
|||
characters |
characters |
||
]]) |
]]) |
||
:addWhere('event_id', '=', |
:addWhere('event_id', '=', eventId) |
||
local results = qb:query() |
local results = qb:query() |
||
Line 37: | Line 65: | ||
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 |
||
root:tag('tr') |
root:tag('tr') |
||
:tag('td') |
:tag('td') |
||
:wikitext(row.image) |
:wikitext(formatImage(row.image)) |
||
:done() |
:done() |
||
:tag('td') |
:tag('td') |
||
:wikitext( |
:wikitext(formatChapter( |
||
row.chapter, |
|||
row._pageName, |
|||
row.english or row.japanese |
|||
)) |
|||
:done() |
:done() |
||
:tag('td') |
:tag('td') |
Latest revision as of 23:35, 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 pageName then
return string.format(
'[[%s|Chapter %s: %s]]',
pageName,
chapter or '?',
chapterName or '?'
)
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,
japanese,
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 or row.japanese
))
:done()
:tag('td')
:wikitext(formatCharacters(row.characters))
:done()
end
return tostring(root)
end
return p