3,726
edits
MusikAnimal (talk | contribs) No edit summary |
MusikAnimal (talk | contribs) No edit summary |
||
(40 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
local p = {} | local p = {} | ||
local cargo = mw.ext.cargo | local cargo = mw.ext.cargo | ||
local multi_song = false | |||
local function get_keys(t) | local function get_keys(t) | ||
Line 102: | Line 103: | ||
if full ~= '' and full ~= nil then | if full ~= '' and full ~= nil then | ||
after_sql = ' AND tease = 0 AND abandoned = 0 AND prerecorded = 0' | after_sql = ' AND tease = 0 AND abandoned = 0 AND soundcheck = 0 AND prerecorded = 0' | ||
end | end | ||
Line 230: | Line 231: | ||
local artist = frame.args[3] | local artist = frame.args[3] | ||
return p._main(song, longest, artist) | return p._main(song, longest, artist) | ||
end | |||
local function normalize_song_option(value) | |||
if value:sub(1, 7) == 'Include' then | |||
return 1 | |||
end | |||
return 0 | |||
end | end | ||
Line 242: | Line 250: | ||
'shows.venue=venue', | 'shows.venue=venue', | ||
'shows.venue_wikitext=venue_wikitext', | 'shows.venue_wikitext=venue_wikitext', | ||
"shows.venue_type=venue_type", | |||
'shows.location=location', | 'shows.location=location', | ||
'shows.festival=festival', | 'shows.festival=festival', | ||
'shows.notes=notes', | |||
"IF(live_show_photos._pageName IS NULL AND shows.poster IS NULL, NULL, '1')=photos", | "IF(live_show_photos._pageName IS NULL AND shows.poster IS NULL, NULL, '1')=photos", | ||
"IF(live_show_videos._pageName IS NULL, NULL, '1')=video", | "IF(live_show_videos._pageName IS NULL, NULL, '1')=video", | ||
Line 260: | Line 263: | ||
['live_show_photos._pageName'] = 'live_show_videos._pageName' | ['live_show_photos._pageName'] = 'live_show_videos._pageName' | ||
} | } | ||
local groups = {'shows._pageName'} | |||
-- live_songs options | -- live_songs options | ||
if options['songs'] then | if options['songs'] then | ||
local songs = mw.text.split(options['songs'], ';', true) | local songs = mw.text.split(options['songs'], ';', true) | ||
multi_song = #songs > 1 | |||
local songWheres = {} | local songWheres = {} | ||
for r = 1, #songs do | for r = 1, #songs do | ||
Line 270: | Line 275: | ||
table.insert(wheres, "(" .. table.concat(songWheres, ' OR ') .. ")") | table.insert(wheres, "(" .. table.concat(songWheres, ' OR ') .. ")") | ||
end | end | ||
if options['acoustic'] then | if multi_song or (options['songs'] and options['grouping'] == 'Group by song') then | ||
table.insert(wheres, "live_songs.acoustic = | table.insert(groups, "live_songs._ID") | ||
end | |||
if options['songs'] then | |||
table.insert(fields, "live_songs.name=song") | |||
table.insert(fields, "live_songs.acoustic=acoustic") | |||
table.insert(fields, "live_songs.piano=piano") | |||
table.insert(fields, "live_songs.tease=tease") | |||
table.insert(fields, "live_songs.abandoned=abandoned") | |||
table.insert(fields, "live_songs.length=length") | |||
table.insert(fields, "live_songs.vip=vip") | |||
table.insert(fields, "live_songs.soundcheck=soundcheck") | |||
end | |||
if options['acoustic'] and options['acoustic'] ~= 'All' then | |||
table.insert(wheres, "live_songs.acoustic = " .. normalize_song_option(options['acoustic'])) | |||
end | |||
if options['piano'] and options['piano'] ~= 'All' then | |||
table.insert(wheres, "live_songs.piano = " .. normalize_song_option(options['piano'])) | |||
end | |||
if options['soundcheck'] and options['soundcheck'] ~= 'All' then | |||
table.insert(wheres, "live_songs.soundcheck = " .. normalize_song_option(options['soundcheck'])) | |||
end | end | ||
if options[' | if options['prerecorded'] and options['prerecorded'] ~= 'All' then | ||
table.insert(wheres, "live_songs. | table.insert(wheres, "live_songs.prerecorded = " .. normalize_song_option(options['prerecorded'])) | ||
end | end | ||
if options[' | if options['vip'] and options['vip'] ~= 'All' then | ||
table.insert(wheres, "live_songs. | table.insert(wheres, "live_songs.vip = " .. normalize_song_option(options['vip'])) | ||
end | end | ||
if options[' | if options['tease'] and options['tease'] ~= 'All' then | ||
table.insert(wheres, "live_songs. | table.insert(wheres, "live_songs.tease = " .. normalize_song_option(options['tease'])) | ||
end | end | ||
if options[' | if options['abandoned'] and options['abandoned'] ~= 'All' then | ||
table.insert(wheres, "live_songs. | table.insert(wheres, "live_songs.abandoned = " .. normalize_song_option(options['abandoned'])) | ||
end | end | ||
if options['cover_artist'] then | if options['cover_artist'] and options['cover_artist'] ~= 'No' then | ||
table.insert(wheres, "live_songs.cover = \"" .. options['cover_artist'] .. "\"") | table.insert(wheres, "live_songs.cover = \"" .. options['cover_artist'] .. "\"") | ||
end | |||
if options['length'] and options['length'] ~= 'No' then | |||
local secs = require('Module:Live song')._time_to_seconds(options['length']) | |||
table.insert(wheres, "live_songs.seconds >= " .. secs) | |||
end | end | ||
Line 305: | Line 333: | ||
local bandsWheres = {} | local bandsWheres = {} | ||
for r = 1, #bands do | for r = 1, #bands do | ||
table.insert(bandsWheres, "shows.bands HOLDS \"" .. | table.insert(bandsWheres, "shows.bands HOLDS \"" .. bands[r] .. "\"") | ||
end | end | ||
table.insert(wheres, "(" .. table.concat(bandsWheres, ' OR ') .. ")") | table.insert(wheres, "(" .. table.concat(bandsWheres, ' OR ') .. ")") | ||
end | end | ||
if options['country'] then | if options['country'] then | ||
table.insert( | table.insert(wheres, "country = \"" .. options['country'] .. "\"") | ||
end | end | ||
if options['venue'] then | if options['venue'] then | ||
table.insert( | table.insert(wheres, "venue = \"" .. options['venue'] .. "\"") | ||
end | |||
if options['venue_type'] then | |||
table.insert(wheres, "venue_type = \"" .. options['venue_type'] .. "\"") | |||
end | end | ||
if options['tour'] then | if options['tour'] then | ||
table.insert( | table.insert(wheres, "tour = \"" .. options['tour'] .. "\"") | ||
end | end | ||
if options['date_after'] then | if options['date_after'] then | ||
table.insert( | table.insert(wheres, "shows.date >= \"" .. options['date_after'] .. "\"") | ||
end | end | ||
if options['date_before'] then | if options['date_before'] then | ||
table.insert( | table.insert(wheres, "shows.date <= \"" .. options['date_before'] .. "\"") | ||
end | end | ||
Line 330: | Line 361: | ||
end | end | ||
local offset = options['offset'] or 0 | |||
local results = cargo.query( | local results = cargo.query( | ||
table.concat(tables, ','), | table.concat(tables, ','), | ||
Line 335: | Line 368: | ||
{ | { | ||
where = table.concat(wheres, ' AND '), | where = table.concat(wheres, ' AND '), | ||
join = table.concat(joins2, ',') | join = table.concat(joins2, ','), | ||
offset = offset, | |||
groupBy = table.concat(groups, ','), | |||
orderBy = 'shows.date ASC', | |||
limit = 5000 | |||
} | } | ||
) | ) | ||
Line 345: | Line 382: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local results = p._query(args) | local results = p._query(args) | ||
local root = mw.html.create('div') | local root = mw.html.create('div'):addClass('search-results') | ||
local title = 'Results' | local title = 'Results' | ||
root:tag('h3'):wikitext(title) | root:tag('h3'):wikitext(title) | ||
root:tag(' | -- TODO: maybe give more fitting title, at least mention song(s) names | ||
local lang = mw.getContentLanguage() | |||
local totals_div = root:tag('div'):addClass('search-results--totals') | |||
:wikitext(#results .. ' ' .. lang:plural(#results, 'result', 'results')) | |||
local get_row = require('Module:Live show row')._main | local get_row = require('Module:Live show row')._main | ||
local list = root:tag('ul') | local list = root:tag('ul') | ||
local artists = {} | |||
local teases = 0 | |||
local abandoned = 0 | |||
local acoustic = 0 | |||
local piano = 0 | |||
local soundcheck = 0 | |||
for r = 1, #results do | for r = 1, #results do | ||
local result = results[r] | local result = results[r] | ||
if multi_song then | |||
result['multi_song'] = '1' | |||
end | |||
local success, row_node = pcall(get_row, result) | |||
if success == false then | |||
error('Too many results! Try narrowing your search criteria') | |||
else | |||
list:node(row_node) | |||
end | |||
-- For counts | |||
artists[result['artist']] = true | |||
if result['tease'] == '1' then | |||
teases = teases + 1 | |||
end | |||
if result['abandoned'] == '1' then | |||
abandoned = abandoned + 1 | |||
end | |||
if result['acoustic'] == '1' then | |||
acoustic = acoustic + 1 | |||
end | |||
if result['piano'] == '1' then | |||
piano = piano + 1 | |||
end | |||
if result['soundcheck'] == '1' then | |||
soundcheck = soundcheck + 1 | |||
end | |||
end | |||
totals_info = {} | |||
local num_artists = #get_keys(artists) | |||
if num_artists > 1 then | |||
table.insert(totals_info, num_artists .. ' artists') | |||
end | |||
if acoustic > 0 then | |||
table.insert(totals_info, acoustic .. ' acoustic') | |||
end | |||
if piano > 0 then | |||
table.insert(totals_info, piano .. ' piano') | |||
end | |||
if teases > 0 then | |||
table.insert(totals_info, teases .. ' ' .. lang:plural(teases, 'tease', 'teases')) | |||
end | |||
if abandoned > 0 then | |||
table.insert(totals_info, abandoned .. ' abandoned') | |||
end | |||
if soundcheck > 0 then | |||
table.insert(totals_info, soundcheck .. ' soundcheck') | |||
end | |||
if #totals_info > 0 then | |||
totals_div:wikitext(' (' .. table.concat(totals_info, ', ') .. ')') | |||
end | end | ||