Halo Esports Wiki

We are currently performing extensive maintenance to this wiki and as a result there will likely be errors. Please be patient while we work to fix all problems.

READ MORE

Halo Esports Wiki
[checked revision][checked revision]
m (Protected "Module:FormUtil": Syncing content across wikis ([Edit=Allow only administrators] (indefinite)))
m (Syncing content across wikis)
Line 9: Line 9:
 
end
 
end
 
 
partialurl = string.format('https://lol.gamepedia.com/Special:RunQuery/%s?%s',
+
partialurl = string.format('%s/Special:RunQuery/%s?%s',
  +
mw.site.server,
 
form,
 
form,
 
string.gsub(table.concat(tbl,'&'),' ','%%20')
 
string.gsub(table.concat(tbl,'&'),' ','%%20')
Line 28: Line 29:
 
end
 
end
 
 
partialurl = string.format('https://lol.gamepedia.com/Special:RunQuery/%s?%s',
+
partialurl = string.format('%s/Special:RunQuery/%s?%s',
  +
mw.site.server,
 
form,
 
form,
 
string.gsub(table.concat(tbl,'&'),' ','%%20')
 
string.gsub(table.concat(tbl,'&'),' ','%%20')

Revision as of 18:25, 17 August 2018

To edit the documentation or categories for this module, click here.


-- FormUtil
local forms = {}

-- if you have an ordered list of fields and an ordered list of values
function forms.makeBaseQueryURL(form, template, fields, values)
	local tbl = {}
	for k, v in ipairs(fields) do
		tbl[#tbl+1] = template .. '%5B' .. v .. '%5D=' .. values[k]
	end
	
	partialurl = string.format('%s/Special:RunQuery/%s?%s',
		mw.site.server,
		form,
		string.gsub(table.concat(tbl,'&'),' ','%%20')
		)
		
	url = partialurl .. '&pfRunQueryFormName=' .. form
		
	return { full = url, partial = partialurl }
end

-- if you don't care about order and just want to make a query from all args
function forms.makeBaseQueryURLFromArgs(form, template, args)
	local tbl = {}
	for k, v in pairs(args) do
		if v ~= 'No' then
			tbl[#tbl+1] = template .. '%5B' .. k .. '%5D=' .. v
		end
	end
	
	partialurl = string.format('%s/Special:RunQuery/%s?%s',
		mw.site.server,
		form,
		string.gsub(table.concat(tbl,'&'),' ','%%20')
		)
		
	url = partialurl .. '&pfRunQueryFormName=' .. form
		
	return { full = url, partial = partialurl }
end

-- if you have a partial query and an ordered list of fields and values to add to it at the end (this requires 2 separate lists of what to add)
function forms.addToQueryURL(form, template, oldquery, newfields, newvalues)
	
	local tbl = {}
	for k, v in ipairs(newfields) do
		tbl[#tbl+1] = template .. '%5B' .. v .. '%5D=' .. newvalues[k]
	end
	
	partialurl = oldquery .. '&' .. string.gsub(table.concat(tbl,'&'),' ','%%20')
		
	url = partialurl .. '&pfRunQueryFormName=' .. form
		
	return { full = url, partial = partialurl }
	
	
end

return forms