Content added Content deleted
mNo edit summary |
(test using new infobox) |
||
Line 3: | Line 3: | ||
------------------------ |
------------------------ |
||
local getArgs = require('Module:Arguments').getArgs |
local getArgs = require('Module:Arguments').getArgs |
||
local |
local InfoboxBuilder = require('Module:InfoboxBuilder new') |
||
local |
local QueryBuilder = require('Module:QueryBuilder') |
||
local |
local utils = require('Module:Utilities') |
||
local |
local icons = require('Module:Icons')._main |
||
local cargo = mw.ext.cargo |
|||
local p = {} |
local p = {} |
||
local categories = "" |
local categories = "" |
||
local function splitStringWithDelim(delim) |
|||
return function(str) |
|||
if str == nil then |
|||
return nil |
|||
⚫ | |||
⚫ | |||
local list = mw.text.split(str, delim) |
|||
for i=1,#list do |
|||
list[i] = mw.text.trim(list[i]) |
|||
end |
|||
return list |
|||
end |
|||
end |
|||
local function formatList(list) |
|||
if #list < 2 then |
|||
return list[1] |
|||
end |
|||
⚫ | |||
local ul = mw.html.create('ul') |
|||
for i=1,#list do |
|||
ul:tag('li') |
|||
:wikitext(list[i]) |
|||
end |
|||
return tostring(ul) |
|||
end |
|||
local function formatImage(image_name) |
local function formatImage(image_name) |
||
Line 30: | Line 61: | ||
local function formatSongs(song_ids) |
local function formatSongs(song_ids) |
||
local |
local qb = QueryBuilder.new() |
||
qb |
|||
local queryArr = {} |
|||
:setTables('Songs') |
|||
for i,v in ipairs(idsArr) do |
|||
:setFields([[ |
|||
table.insert(queryArr, 'song_id = ' .. v) |
|||
_pageName, |
|||
⚫ | |||
song_name, |
|||
]]) |
|||
:setGroupBy('_pageName') |
|||
:addWhereList('song_id', '=', song_ids, ',', 'OR') |
|||
local results = qb:query() |
|||
local fields = 'song_name, _pageName' |
|||
local args = { |
|||
where = table.concat(queryArr, " OR ") |
|||
} |
|||
local results = cargo.query( tables, fields, args ) |
|||
if #results > 0 then |
if #results > 0 then |
||
Line 56: | Line 86: | ||
end |
end |
||
return |
return formatList(resArr) |
||
end |
end |
||
return nil |
return nil |
||
end |
|||
local function formatStampId(id) |
|||
end |
|||
local function formatTitleId(id) |
|||
end |
end |
||
Line 65: | Line 103: | ||
function p.main(frame) |
function p.main(frame) |
||
local args = getArgs(frame) |
local args = getArgs(frame) |
||
local infobox = |
local infobox = InfoboxBuilder.new() |
||
infobox:setName('Infobox virtual live') |
infobox:setName('Infobox virtual live') |
||
:setWidth("330px") |
|||
:setParams{ |
:setParams{ |
||
{ name = 'vlive id' }, |
{ name = 'vlive id' }, |
||
{ name = 'vlive name', default = mw.title.getCurrentTitle().text }, |
{ name = 'vlive name', default = mw.title.getCurrentTitle().text }, |
||
{ name = 'image', |
{ name = 'image', dFunc = formatImage }, |
||
{ name = 'japanese' }, |
{ name = 'japanese' }, |
||
{ name = 'romaji' }, |
{ name = 'romaji' }, |
||
{ name = 'from' }, |
{ name = 'from' }, |
||
{ name = 'until' }, |
{ name = 'until' }, |
||
{ name = 'characters', |
{ name = 'characters', dFunc = formatCharacters }, |
||
{ name = 'song ids', |
{ name = 'song ids', dFunc = formatSongs }, |
||
{ name = 'stamp', |
{ name = 'stamp', dFunc = formatRewardImage }, |
||
{ name = 'title', |
{ name = 'title', dFunc = formatRewardImage }, |
||
} |
} |
||
:setArgs(args) |
:setArgs(args) |
||
:processArgs() |
|||
infobox |
infobox |
||
Line 91: | Line 129: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Japanese' |
{ tag = 'th', content = 'Japanese' }, |
||
{ tag = 'argtd', content = 'japanese' |
{ tag = 'argtd', content = 'japanese' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'japanese' } } |
{ hideIfEmpty = { 'japanese' } } |
||
Line 98: | Line 136: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Romaji' |
{ tag = 'th', content = 'Romaji' }, |
||
{ tag = 'argtd', content = 'romaji' |
{ tag = 'argtd', content = 'romaji' } |
||
}, |
}, |
||
{ hideIfEmpty = { 'romaji' } } |
{ hideIfEmpty = { 'romaji' } } |
||
Line 106: | Line 144: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'From' |
{ tag = 'th', content = 'From' }, |
||
{ tag = 'argtd', content = 'from' |
{ tag = 'argtd', content = 'from' } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Until' |
{ tag = 'th', content = 'Until' }, |
||
{ tag = 'argtd', content = 'until' |
{ tag = 'argtd', content = 'until' } |
||
} |
} |
||
) |
) |
||
Line 119: | Line 157: | ||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Featured Characters ' |
{ tag = 'th', content = 'Featured Characters ' }, |
||
{ tag = 'argtd', content = 'characters' |
{ tag = 'argtd', content = 'characters' } |
||
} |
} |
||
) |
) |
||
:addRow( |
:addRow( |
||
{ |
{ |
||
{ tag = 'th', content = 'Featured Songs' |
{ tag = 'th', content = 'Featured Songs' }, |
||
{ tag = 'argtd', content = 'song ids' |
{ tag = 'argtd', content = 'song ids' } |
||
} |
} |
||
) |
) |
||
Line 150: | Line 188: | ||
) |
) |
||
⚫ | |||
if mw.title.getCurrentTitle().namespace == 0 then |
if mw.title.getCurrentTitle().namespace == 0 then |
||
categories = "[[Category:Virtual lives]]" .. |
categories = "[[Category:Virtual lives]]" .. infobox:getCategories() |
||
⚫ | |||
local procArgs = infobox:getArgs('processed') |
|||
local rawArgs = infobox:getArgs('raw') |
|||
end |
end |
||
Revision as of 05:10, 27 March 2022
This module depends on the following other modules: |
This module uses the following Cargo tables: |
To generate {{Infobox virtual live}}, invoke using the main function.
--------------------------
-- Module for [[Template:Infobox virtual live]]
------------------------
local getArgs = require('Module:Arguments').getArgs
local InfoboxBuilder = require('Module:InfoboxBuilder new')
local QueryBuilder = require('Module:QueryBuilder')
local utils = require('Module:Utilities')
local icons = require('Module:Icons')._main
local cargo = mw.ext.cargo
local p = {}
local categories = ""
local function splitStringWithDelim(delim)
return function(str)
if str == nil then
return nil
end
local list = mw.text.split(str, delim)
for i=1,#list do
list[i] = mw.text.trim(list[i])
end
return list
end
end
local function formatList(list)
if #list < 2 then
return list[1]
end
local ul = mw.html.create('ul')
for i=1,#list do
ul:tag('li')
:wikitext(list[i])
end
return tostring(ul)
end
local function formatImage(image_name)
return string.format("[[File:%s|250px]]", image_name)
end
local function formatRewardImage(image_name)
return string.format("[[File:%s|150px]]", image_name)
end
local function formatCharacters(characters)
local characterArr = utils.split(characters, ',')
local resArr = {}
for i,v in ipairs(characterArr) do
table.insert(resArr, icons({ v, size = '30px' }))
end
return table.concat(resArr, " ")
end
local function formatSongs(song_ids)
local qb = QueryBuilder.new()
qb
:setTables('Songs')
:setFields([[
_pageName,
song_name,
]])
:setGroupBy('_pageName')
:addWhereList('song_id', '=', song_ids, ',', 'OR')
local results = qb:query()
if #results > 0 then
local resArr = {}
for i,v in ipairs(results) do
table.insert(
resArr,
string.format(
'[[%s|%s]]',
v._pageName,
v.song_name
)
)
end
return formatList(resArr)
end
return nil
end
local function formatStampId(id)
end
local function formatTitleId(id)
end
function p.main(frame)
local args = getArgs(frame)
local infobox = InfoboxBuilder.new()
infobox:setName('Infobox virtual live')
:setParams{
{ name = 'vlive id' },
{ name = 'vlive name', default = mw.title.getCurrentTitle().text },
{ name = 'image', dFunc = formatImage },
{ name = 'japanese' },
{ name = 'romaji' },
{ name = 'from' },
{ name = 'until' },
{ name = 'characters', dFunc = formatCharacters },
{ name = 'song ids', dFunc = formatSongs },
{ name = 'stamp', dFunc = formatRewardImage },
{ name = 'title', dFunc = formatRewardImage },
}
:setArgs(args)
:processArgs()
infobox
:addHeader({ tag = 'argth', content = 'vlive name' })
:addImage({
{ tag = 'argtd', content = 'image' },
})
:addRow(
{
{ tag = 'th', content = 'Japanese' },
{ tag = 'argtd', content = 'japanese' }
},
{ hideIfEmpty = { 'japanese' } }
)
:addRow(
{
{ tag = 'th', content = 'Romaji' },
{ tag = 'argtd', content = 'romaji' }
},
{ hideIfEmpty = { 'romaji' } }
)
:addHeader({ tag = 'th', content = 'Availability Period' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'From' },
{ tag = 'argtd', content = 'from' }
}
)
:addRow(
{
{ tag = 'th', content = 'Until' },
{ tag = 'argtd', content = 'until' }
}
)
:addHeader({ tag = 'th', content = 'Virtual Live Information' }, { subheader = true })
:addRow(
{
{ tag = 'th', content = 'Featured Characters ' },
{ tag = 'argtd', content = 'characters' }
}
)
:addRow(
{
{ tag = 'th', content = 'Featured Songs' },
{ tag = 'argtd', content = 'song ids' }
}
)
:addHeader(
{ tag = 'th', content = 'Reward Stamp' },
{ hideIfEmpty = { 'stamp' }, subheader = true }
)
:addImage(
{
{ tag = 'argtd', content = 'stamp' },
},
{ hideIfEmpty = { 'stamp' } }
)
:addHeader(
{ tag = 'th', content = 'Reward Title' },
{ hideIfEmpty = { 'title' }, subheader = true }
)
:addImage(
{
{ tag = 'argtd', content = 'title' },
},
{ hideIfEmpty = { 'title' } }
)
if mw.title.getCurrentTitle().namespace == 0 then
categories = "[[Category:Virtual lives]]" .. infobox:getCategories()
end
return infobox:tostring() .. categories
end
return p