Module:Event story chapters: Difference between revisions

From Sekaipedia
Content added Content deleted
mNo edit summary
mNo edit summary
 
(6 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)
Line 10: Line 31:
local icon_tbl = {}
local icon_tbl = {}


for _,v in ipairs(charArr) do
if charArr then
for _,v in ipairs(charArr) do
local _icon = cicon({ v, size = '45px' })
if _icon then
local _icon = cicon({ v, size = '45px' })
table.insert(icon_tbl, _icon)
if _icon then
table.insert(icon_tbl, _icon)
end
end
end
end
end
Line 33: Line 56:
_pageName,
_pageName,
english,
english,
japanese,
characters
characters
]])
]])
:addWhere('event_id', '=', event_id)
:addWhere('event_id', '=', eventId)


local results = qb:query()
local results = qb:query()
Line 41: 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(row.chapter)
:wikitext(formatChapter(
:wikitext(row._pageName)
row.chapter,
:wikitext(row.english)
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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.