More actions
(initial) |
m (adds order_by parameter to p.Files) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
limit = frame.args['limit'] or 100 | limit = frame.args['limit'] or 100 | ||
character = frame.args[1] or '' | |||
character = string.gsub(character, "'", '') | |||
link_parts = { | link_parts = { | ||
'tables=Files,BBRadio_Cuts', | 'tables=Files,BBRadio_Cuts', | ||
'fields=Files._pageName, Files.Caption', | 'fields=Files._pageName, Files.Caption', | ||
'where=Files.Characters HOLDS "' .. html_escape( | 'where=Files.Characters HOLDS "' .. html_escape(character) .. '" AND BBRadio_Cuts.Season="' .. frame.args[2] .. '"', | ||
'join_on=Files._pageName=BBRadio_Cuts._pageName', | 'join_on=Files._pageName=BBRadio_Cuts._pageName', | ||
'order_by=_pageName', | 'order_by=_pageName', | ||
'format=gallery', | |||
'offset=0', | |||
'limit=' .. limit, | |||
'default=', | |||
'intro=' .. intro, | |||
'show bytes=0', | |||
'show dimensions=0', | |||
'show filename=0', | |||
'caption field=Caption', | |||
'image width=250' | |||
} | |||
link = html_escape(concatvalues(link_parts,"&")) | |||
parts = { | |||
'https://blazblue.wiki/index.php\?title=Special:ViewData&', | |||
link | |||
} | |||
final_link = concatvalues(parts,"") | |||
return final_link | |||
end | |||
function p.Files( frame ) | |||
intro = frame.args['intro'] or '' | |||
intro = html_escape(intro) | |||
limit = frame.args['limit'] or 100 | |||
character = frame.args['character'] or '' | |||
character = string.gsub(character, "'", '') | |||
cameo = frame.args['cameo'] or '' | |||
cameo = string.gsub(cameo, "'", '') | |||
order_by = frame.args['order'] or 'Date DESC' | |||
-- build where clause | |||
where_clause_parts = { | |||
(function() if not (frame.args['character'] == "" or frame.args['character'] == nil ) then | |||
return 'Files.Characters HOLDS "' .. character .. '"' else return "" end end)(), | |||
(function() if not (frame.args['cameo'] == "" or frame.args['cameo'] == nil ) then | |||
return 'Files.Cameos HOLDS "' .. cameo .. '"' else return "" end end)(), | |||
(function() if not (frame.args['location'] == "" or frame.args['location'] == nil ) then | |||
return 'Files.Locations HOLDS "' .. frame.args['location'] .. '"' else return "" end end)(), | |||
(function() if not (frame.args['weapon'] == "" or frame.args['weapon'] == nil ) then | |||
return 'Files.Weapons HOLDS "' .. frame.args['weapon'] .. '"' else return "" end end)(), | |||
(function() if not (frame.args['artist'] == "" or frame.args['artist'] == nil ) then | |||
return 'Files.Artists HOLDS "' .. frame.args['artist'] .. '"' else return "" end end)(), | |||
(function() if not (frame.args['section'] == "" or frame.args['section'] == nil ) then | |||
return 'Files.Gallery_Sections HOLDS "' .. frame.args['section'] .. '"' else return "" end end)(), | |||
(function() if not (frame.args['source'] == "" or frame.args['source'] == nil ) then | |||
return 'Files.Source HOLDS "' .. frame.args['source'] .. '"' else return "" end end)() | |||
} | |||
where_clause = concatvalues(where_clause_parts, " AND ") | |||
-- build url arguments | |||
link_parts = { | |||
'tables=Files', | |||
'fields=_pageName, Caption, Date', | |||
'where=' .. where_clause, | |||
'order_by=' .. order_by, | |||
'format=gallery', | 'format=gallery', | ||
'offset=0', | 'offset=0', | ||
Line 36: | Line 99: | ||
-- concat all the strings in table s together with the given delimiter | -- concat all the strings in table s together with the given delimiter | ||
-- skips blank entries (where value v = "") | |||
function concatvalues(s,delimiter) | function concatvalues(s,delimiter) | ||
local t = { } | local t = { } | ||
for k,v in ipairs(s) do | for k,v in ipairs(s) do | ||
if not (v == '') then | |||
t[#t+1] = tostring(v) | |||
end | |||
end | end | ||
return table.concat(t,delimiter) | return table.concat(t,delimiter) |
Latest revision as of 04:09, 10 September 2019
Please go to Module:ViewData URL/doc to edit the documentation.
To be used with Template:Gallery Section (BBRadio) or Template:Gallery Section (Cargo)
Motivation
This module builds a URL to Special:ViewData to fix some undesirable behavior in the link that's generated by default:
- The first batch of results are excluded. We want to display all results, even ones that have already been returned.
- The results per page are limited to whatever was initially set as the limit, unless the limit was 0, in which case Special:ViewData shows 100 results per page. We want to be able to manually set this limit.
Usage
To create a link for Template: Gallery Section (BBRadio):
{{#invoke:ViewData URL|BBRadio|character|season |intro=<h3>BlazBlue Radio D</h3> |limit=100 }}
To create a link for Template:Gallery Section (Cargo):
{{#invoke:ViewData URL|Files |character= |cameo= |location= |weapon= |source= |section= |artist= |limit= |widths= |intro= |limit=100 |order_by=Date DESC }}
local p = {}
local cargo = mw.ext.cargo
function p.BBRadio( frame )
intro = frame.args['intro'] or ''
intro = html_escape(intro)
limit = frame.args['limit'] or 100
character = frame.args[1] or ''
character = string.gsub(character, "'", '')
link_parts = {
'tables=Files,BBRadio_Cuts',
'fields=Files._pageName, Files.Caption',
'where=Files.Characters HOLDS "' .. html_escape(character) .. '" AND BBRadio_Cuts.Season="' .. frame.args[2] .. '"',
'join_on=Files._pageName=BBRadio_Cuts._pageName',
'order_by=_pageName',
'format=gallery',
'offset=0',
'limit=' .. limit,
'default=',
'intro=' .. intro,
'show bytes=0',
'show dimensions=0',
'show filename=0',
'caption field=Caption',
'image width=250'
}
link = html_escape(concatvalues(link_parts,"&"))
parts = {
'https://blazblue.wiki/index.php\?title=Special:ViewData&',
link
}
final_link = concatvalues(parts,"")
return final_link
end
function p.Files( frame )
intro = frame.args['intro'] or ''
intro = html_escape(intro)
limit = frame.args['limit'] or 100
character = frame.args['character'] or ''
character = string.gsub(character, "'", '')
cameo = frame.args['cameo'] or ''
cameo = string.gsub(cameo, "'", '')
order_by = frame.args['order'] or 'Date DESC'
-- build where clause
where_clause_parts = {
(function() if not (frame.args['character'] == "" or frame.args['character'] == nil ) then
return 'Files.Characters HOLDS "' .. character .. '"' else return "" end end)(),
(function() if not (frame.args['cameo'] == "" or frame.args['cameo'] == nil ) then
return 'Files.Cameos HOLDS "' .. cameo .. '"' else return "" end end)(),
(function() if not (frame.args['location'] == "" or frame.args['location'] == nil ) then
return 'Files.Locations HOLDS "' .. frame.args['location'] .. '"' else return "" end end)(),
(function() if not (frame.args['weapon'] == "" or frame.args['weapon'] == nil ) then
return 'Files.Weapons HOLDS "' .. frame.args['weapon'] .. '"' else return "" end end)(),
(function() if not (frame.args['artist'] == "" or frame.args['artist'] == nil ) then
return 'Files.Artists HOLDS "' .. frame.args['artist'] .. '"' else return "" end end)(),
(function() if not (frame.args['section'] == "" or frame.args['section'] == nil ) then
return 'Files.Gallery_Sections HOLDS "' .. frame.args['section'] .. '"' else return "" end end)(),
(function() if not (frame.args['source'] == "" or frame.args['source'] == nil ) then
return 'Files.Source HOLDS "' .. frame.args['source'] .. '"' else return "" end end)()
}
where_clause = concatvalues(where_clause_parts, " AND ")
-- build url arguments
link_parts = {
'tables=Files',
'fields=_pageName, Caption, Date',
'where=' .. where_clause,
'order_by=' .. order_by,
'format=gallery',
'offset=0',
'limit=' .. limit,
'default=',
'intro=' .. intro,
'show bytes=0',
'show dimensions=0',
'show filename=0',
'caption field=Caption',
'image width=250'
}
link = html_escape(concatvalues(link_parts,"&"))
parts = {
'https://blazblue.wiki/index.php\?title=Special:ViewData&',
link
}
final_link = concatvalues(parts,"")
return final_link
end
-- concat all the strings in table s together with the given delimiter
-- skips blank entries (where value v = "")
function concatvalues(s,delimiter)
local t = { }
for k,v in ipairs(s) do
if not (v == '') then
t[#t+1] = tostring(v)
end
end
return table.concat(t,delimiter)
end
function html_escape(s)
return (string.gsub(s, "[<>\"'/ ,]", {
["<"] = "%3C",
[">"] = "%3E",
['"'] = "%22",
["'"] = "%27",
["/"] = "%2F",
[" "] = "+",
[","] = "%2C"
}))
end
return p