Module:Infobox album: Difference between revisions
MusikAnimal (talk | contribs) (Created page with "local p = {} local types = { ['ep'] = { color = 'lightsalmon', link = 'EP', category = 'EPs', respect_casing = true }, ['studio'] = { color = '...") |
MusikAnimal (talk | contribs) No edit summary |
||
(29 intermediate revisions by the same user not shown) | |||
Line 12: | Line 12: | ||
link = '[[:Category:Studio albums|Studio album]]', | link = '[[:Category:Studio albums|Studio album]]', | ||
category = 'Studio albums' | category = 'Studio albums' | ||
}, | |||
['recording'] = { | |||
color = 'peachpuff', | |||
link = 'Recording', | |||
category = '' | |||
}, | }, | ||
['demo'] = { | ['demo'] = { | ||
color = 'khaki', | color = 'khaki', | ||
link = '[[:Category:Demo albums|Demo album]]', | link = '[[:Category:Demo albums|Demo album]]', | ||
category = ' | category = 'Demo albums' | ||
}, | }, | ||
['live'] = { | ['live'] = { | ||
Line 45: | Line 50: | ||
['soundtrack'] = { | ['soundtrack'] = { | ||
color = 'gainsboro', | color = 'gainsboro', | ||
link = '[[:Category:Soundtrack albums|Soundtrack | link = '[[:Category:Soundtrack albums|Soundtrack]]', | ||
category = 'Soundtrack albums' | category = 'Soundtrack albums' | ||
}, | }, | ||
Line 55: | Line 60: | ||
['video'] = { | ['video'] = { | ||
color = ' #99CCFF', | color = ' #99CCFF', | ||
link = '[[:Category: | link = '[[:Category:Video releases|Video release]]', | ||
category = ' | category = 'Video releases' | ||
}, | |||
['promo'] = { | |||
color = 'peachpuff', | |||
link = '[[:Category:Promotional releases|Promotional release]]', | |||
category = 'Promotional releases' | |||
}, | |||
['promotional'] = { | |||
color = 'peachpuff', | |||
link = '[[:Category:Promotional releases|Promotional release]]', | |||
category = 'Promotional releases' | |||
}, | }, | ||
['tribute'] = { | ['tribute'] = { | ||
Line 68: | Line 83: | ||
category = 'Bootleg albums' | category = 'Bootleg albums' | ||
} | } | ||
} | |||
local artists = { | |||
['The Smashing Pumpkins'] = true, | |||
['Billy Corgan'] = true, | |||
['Zwan'] = true, | |||
['James Iha'] = true, | |||
['Jimmy Chamberlin Complex'] = true, | |||
['The Marked'] = true, | |||
['Various artists'] = true | |||
} | } | ||
Line 77: | Line 102: | ||
function p.color( frame ) | function p.color( frame ) | ||
local given = mw.text.split(frame.args[1], "%s*,%s*") | local given = mw.text.split(frame.args[1], "%s*,%s*") | ||
return types[given[1]].color | if given[1] ~= nil and types[given[1]] ~= nil then | ||
return types[given[1]].color | |||
end | |||
end | end | ||
Line 83: | Line 110: | ||
local given = mw.text.split(frame.args[1], "%s*,%s*") | local given = mw.text.split(frame.args[1], "%s*,%s*") | ||
local artist = frame.args[2] | local artist = frame.args[2] | ||
local is_tribute = string.find(frame.args[1], "tribute") | |||
if artists[artist] == nil and not(is_tribute) then | |||
return '[[Category:Side projects]]' | |||
end | |||
local cats = '' | local cats = '[[Category:Albums]]' | ||
for _, v in ipairs( | |||
if not(is_tribute) then | |||
cats = cats .. '[[Category:' .. artist .. ' albums]]' | |||
end | |||
if artist == 'The Marked' then | |||
return cats | |||
end | |||
for _, v in ipairs(given) do | |||
local data = types[v] | local data = types[v] | ||
cats = cats .. '[[Category:' .. data.category .. ']]' | if data.category ~= '' then | ||
cats = cats .. '[[Category:' .. data.category .. ']]' | |||
if data.respect_casing then | end | ||
if artist ~= 'Various artists' and not(is_tribute) then | |||
if data.respect_casing then | |||
cats = cats .. '[[Category:' .. artist .. ' ' .. data.category .. ']]' | |||
else | |||
cats = cats .. '[[Category:' .. artist .. ' ' .. data.category:lower() .. ']]' | |||
end | |||
end | |||
end | |||
return cats | |||
end | |||
function p._studio_sessions(album) | |||
local cargo = mw.ext.cargo | |||
local results = cargo.query( | |||
'studio_sessions, albums', | |||
'studio_sessions._pageName=page', | |||
{ | |||
where = 'albums.name = "' .. album .. '"', | |||
join = 'studio_sessions.album HOLDS albums.name', | |||
orderBy = 'date_from ASC', | |||
groupBy = 'studio_sessions._pageName' | |||
} | |||
) | |||
if 0 == #results or (1 == #results and results[1]['page'] == nil) then | |||
return '' | |||
elseif 1 == #results then | |||
return '[[' .. results[1]['page'] .. ']]' | |||
end | |||
local root = mw.html.create() | |||
local ulRoot = root:tag('ul') | |||
:addClass('studio-sessions') | |||
local sessions = {} | |||
for r = 1, #results do | |||
local page = results[r]['page'] | |||
if page ~= nil and page ~= '' then | |||
ulRoot:tag('li') | |||
:wikitext('[[' .. page .. ']]') | |||
end | end | ||
end | end | ||
return tostring(root) | |||
end | |||
function p.studio_sessions(frame) | |||
local album = frame.args[1] | |||
return p._studio_sessions(album) | |||
end | end | ||
return p | return p |
Latest revision as of 05:40, 20 November 2023
Documentation for this module may be created at Module:Infobox album/doc
local p = {}
local types = {
['ep'] = {
color = 'lightsalmon',
link = '[[:Category:EPs|EP]]',
category = 'EPs',
respect_casing = true
},
['studio'] = {
color = 'lightsteelblue',
link = '[[:Category:Studio albums|Studio album]]',
category = 'Studio albums'
},
['recording'] = {
color = 'peachpuff',
link = 'Recording',
category = ''
},
['demo'] = {
color = 'khaki',
link = '[[:Category:Demo albums|Demo album]]',
category = 'Demo albums'
},
['live'] = {
color = 'burlywood',
link = '[[:Category:Live albums|Live album]]',
category = 'Live albums'
},
['greatest hits'] = {
color = 'darkseagreen',
link = '[[:Category:Compilation albums|Compilation album]]',
category = 'Compilation albums'
},
['box set'] = {
color = 'darkseagreen',
link = '[[:Category:Box sets|Box set]]',
category = 'Box sets'
},
['compilation'] = {
color = 'darkseagreen',
link = '[[:Category:Compilation albums|Compilation album]]',
category = 'Compilation albums'
},
['remix'] = {
color = 'peachpuff',
link = '[[:Category:Remix album|Remix album]]',
category = 'Category:Remix albums'
},
['soundtrack'] = {
color = 'gainsboro',
link = '[[:Category:Soundtrack albums|Soundtrack]]',
category = 'Soundtrack albums'
},
['film score'] = {
color = 'gainsboro',
link = '[[:Category:Soundtrack albums|Soundtrack album]]',
category = 'Soundtrack albums'
},
['video'] = {
color = ' #99CCFF',
link = '[[:Category:Video releases|Video release]]',
category = 'Video releases'
},
['promo'] = {
color = 'peachpuff',
link = '[[:Category:Promotional releases|Promotional release]]',
category = 'Promotional releases'
},
['promotional'] = {
color = 'peachpuff',
link = '[[:Category:Promotional releases|Promotional release]]',
category = 'Promotional releases'
},
['tribute'] = {
color = 'peachpuff',
link = '[[:Category:Tribute albums|Tribute album]]',
category = 'Tribute albums'
},
['bootleg'] = {
color = ' #E6E8FA',
link = '[[:Category:Bootleg albums|Bootleg]]',
category = 'Bootleg albums'
}
}
local artists = {
['The Smashing Pumpkins'] = true,
['Billy Corgan'] = true,
['Zwan'] = true,
['James Iha'] = true,
['Jimmy Chamberlin Complex'] = true,
['The Marked'] = true,
['Various artists'] = true
}
function p.link( frame )
local given = mw.text.split(frame.args[1], "%s*,%s*")
return types[given[1]].link
end
function p.color( frame )
local given = mw.text.split(frame.args[1], "%s*,%s*")
if given[1] ~= nil and types[given[1]] ~= nil then
return types[given[1]].color
end
end
function p.categories( frame )
local given = mw.text.split(frame.args[1], "%s*,%s*")
local artist = frame.args[2]
local is_tribute = string.find(frame.args[1], "tribute")
if artists[artist] == nil and not(is_tribute) then
return '[[Category:Side projects]]'
end
local cats = '[[Category:Albums]]'
if not(is_tribute) then
cats = cats .. '[[Category:' .. artist .. ' albums]]'
end
if artist == 'The Marked' then
return cats
end
for _, v in ipairs(given) do
local data = types[v]
if data.category ~= '' then
cats = cats .. '[[Category:' .. data.category .. ']]'
end
if artist ~= 'Various artists' and not(is_tribute) then
if data.respect_casing then
cats = cats .. '[[Category:' .. artist .. ' ' .. data.category .. ']]'
else
cats = cats .. '[[Category:' .. artist .. ' ' .. data.category:lower() .. ']]'
end
end
end
return cats
end
function p._studio_sessions(album)
local cargo = mw.ext.cargo
local results = cargo.query(
'studio_sessions, albums',
'studio_sessions._pageName=page',
{
where = 'albums.name = "' .. album .. '"',
join = 'studio_sessions.album HOLDS albums.name',
orderBy = 'date_from ASC',
groupBy = 'studio_sessions._pageName'
}
)
if 0 == #results or (1 == #results and results[1]['page'] == nil) then
return ''
elseif 1 == #results then
return '[[' .. results[1]['page'] .. ']]'
end
local root = mw.html.create()
local ulRoot = root:tag('ul')
:addClass('studio-sessions')
local sessions = {}
for r = 1, #results do
local page = results[r]['page']
if page ~= nil and page ~= '' then
ulRoot:tag('li')
:wikitext('[[' .. page .. ']]')
end
end
return tostring(root)
end
function p.studio_sessions(frame)
local album = frame.args[1]
return p._studio_sessions(album)
end
return p