[checked revision] | [checked revision] |
m (Syncing content across wikis) |
m (Syncing content across wikis from Call of Duty Esports Wiki, if something seems broken as a result let me know) |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
+ | local util_args = require("Module:ArgsUtil") |
||
− | -- FormUtil |
||
+ | local util_table = require('Module:TableUtil') |
||
⚫ | |||
+ | local util_text = require("Module:TextUtil") |
||
+ | local util_vars = require('Module:VarsUtil') |
||
+ | local i18n = require('Module:i18nUtil') |
||
⚫ | |||
− | -- if you have an ordered list of fields and an ordered list of values |
||
⚫ | |||
− | function forms.makeBaseQueryURL(form, template, fields, values) |
||
⚫ | |||
⚫ | |||
− | tbl[#tbl+1] = template .. '%5B' .. v .. '%5D=' .. values[k] |
||
⚫ | |||
⚫ | |||
− | 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 } |
||
⚫ | |||
+ | function p.fullURL(formInfo, args) |
||
− | -- 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 = {} |
local tbl = {} |
||
for k, v in pairs(args) do |
for k, v in pairs(args) do |
||
− | if v ~= 'No' then |
+ | if v and v ~= 'No' then |
− | tbl[#tbl+1] = |
+ | tbl[#tbl+1] = ('%s%%5B%s%%5D=%s'):format(formInfo.template, k, tostring(v)) |
end |
end |
||
end |
end |
||
+ | local form_args = h.escape(table.concat(tbl,'&')) |
||
⚫ | |||
− | + | return ('%s/Special:RunQuery/%s?%s&pfRunQueryFormName=%s'):format( |
|
mw.site.server, |
mw.site.server, |
||
− | form, |
+ | formInfo.form, |
+ | form_args, |
||
− | string.gsub(table.concat(tbl,'&'),' ','%%20') |
||
+ | formInfo.form |
||
− | ) |
||
⚫ | |||
− | |||
− | url = partialurl .. '&pfRunQueryFormName=' .. form |
||
− | |||
− | return { full = url, partial = partialurl } |
||
end |
end |
||
+ | function p.permalink(output, args, formInfo) |
||
− | -- 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) |
||
+ | output:wikitext(i18n.print('Permalink'), p.fullURL(formInfo, args)) |
||
− | function forms.addToQueryURL(form, template, oldquery, newfields, newvalues) |
||
+ | output:wikitext('<br>') |
||
⚫ | |||
+ | output:wikitext(i18n.print('TemplateArgs')) |
||
+ | output:tag('div') |
||
+ | :css('display', 'inline-block') |
||
+ | :wikitext(mw.text.tag{ |
||
+ | name = 'code', |
||
+ | content = h.templateArgs(formInfo, args) |
||
+ | }) |
||
⚫ | |||
+ | |||
+ | function h.escape(str) |
||
+ | local lookup = { |
||
+ | [' '] = '%%20', |
||
+ | ['"'] = '%%22', |
||
+ | ['>'] = '%%3E', |
||
+ | ['<'] = '%%3C', |
||
+ | ['+'] = '%%2B', |
||
⚫ | |||
⚫ | |||
+ | str = str:gsub(k, v) |
||
⚫ | |||
+ | return str |
||
+ | end |
||
+ | |||
+ | function h.templateArgs(formInfo, args) |
||
+ | local formInfo = util_table.guaranteeTable(formInfo) |
||
local tbl = {} |
local tbl = {} |
||
− | for k, v in |
+ | for k, v in pairs(args) do |
− | tbl[#tbl+1] = |
+ | tbl[#tbl+1] = '|' .. k .. '=' .. v |
end |
end |
||
+ | return mw.text.nowiki(('{{%s%s}}'):format(formInfo.template, util_table.concat(tbl, ''))) |
||
− | |||
+ | end |
||
− | partialurl = oldquery .. '&' .. string.gsub(table.concat(tbl,'&'),' ','%%20') |
||
+ | |||
− | |||
+ | function p.printLog(output) |
||
− | url = partialurl .. '&pfRunQueryFormName=' .. form |
||
+ | local log = util_vars.getVar('log') |
||
− | |||
+ | if not log then return end |
||
− | return { full = url, partial = partialurl } |
||
+ | output:tag('br') |
||
− | |||
+ | output:wikitext(log) |
||
− | |||
+ | end |
||
+ | |||
+ | function p.makeIntroSentence(formInfo, args, formArgs) |
||
+ | if not util_args.castAsBool(args.showformlink) then return '' end |
||
+ | return util_text.extLink( |
||
+ | p.fullURL(formInfo, formArgs), |
||
+ | i18n.print('introSentence') |
||
⚫ | |||
+ | end |
||
+ | |||
+ | function p.makeTableCellFilterLink(formInfo, formArgs, class) |
||
+ | local output = mw.html.create('span') |
||
+ | :addClass('table-cell-filter-link') |
||
+ | :addClass(class) |
||
+ | :wikitext(util_text.extLink(p.fullURL(formInfo, formArgs), ' ')) |
||
+ | return tostring(output) |
||
end |
end |
||
− | return |
+ | return p |
Latest revision as of 16:42, 31 August 2021
To edit the documentation or categories for this module, click here.
local util_args = require("Module:ArgsUtil")
local util_table = require('Module:TableUtil')
local util_text = require("Module:TextUtil")
local util_vars = require('Module:VarsUtil')
local i18n = require('Module:i18nUtil')
local p = {}
local h = {}
function p.fullURL(formInfo, args)
local tbl = {}
for k, v in pairs(args) do
if v and v ~= 'No' then
tbl[#tbl+1] = ('%s%%5B%s%%5D=%s'):format(formInfo.template, k, tostring(v))
end
end
local form_args = h.escape(table.concat(tbl,'&'))
return ('%s/Special:RunQuery/%s?%s&pfRunQueryFormName=%s'):format(
mw.site.server,
formInfo.form,
form_args,
formInfo.form
)
end
function p.permalink(output, args, formInfo)
output:wikitext(i18n.print('Permalink'), p.fullURL(formInfo, args))
output:wikitext('<br>')
output:wikitext(i18n.print('TemplateArgs'))
output:tag('div')
:css('display', 'inline-block')
:wikitext(mw.text.tag{
name = 'code',
content = h.templateArgs(formInfo, args)
})
end
function h.escape(str)
local lookup = {
[' '] = '%%20',
['"'] = '%%22',
['>'] = '%%3E',
['<'] = '%%3C',
['+'] = '%%2B',
}
for k, v in pairs(lookup) do
str = str:gsub(k, v)
end
return str
end
function h.templateArgs(formInfo, args)
local formInfo = util_table.guaranteeTable(formInfo)
local tbl = {}
for k, v in pairs(args) do
tbl[#tbl+1] = '|' .. k .. '=' .. v
end
return mw.text.nowiki(('{{%s%s}}'):format(formInfo.template, util_table.concat(tbl, '')))
end
function p.printLog(output)
local log = util_vars.getVar('log')
if not log then return end
output:tag('br')
output:wikitext(log)
end
function p.makeIntroSentence(formInfo, args, formArgs)
if not util_args.castAsBool(args.showformlink) then return '' end
return util_text.extLink(
p.fullURL(formInfo, formArgs),
i18n.print('introSentence')
)
end
function p.makeTableCellFilterLink(formInfo, formArgs, class)
local output = mw.html.create('span')
:addClass('table-cell-filter-link')
:addClass(class)
:wikitext(util_text.extLink(p.fullURL(formInfo, formArgs), ' '))
return tostring(output)
end
return p