mNo edit summary |
mNo edit summary |
||
Line 28: | Line 28: | ||
local whereStr = '' | local whereStr = '' | ||
local tables = 'Locations' | if args.type then whereStr = whereStr .. 'Locations.type HOLDS "' .. args.type .. '"' end | ||
local fields = '_pageName' | if args.country then | ||
local countries = mw.text.split(args.country, ',') | |||
if whereStr ~= '' then whereStr = whereStr .. ' AND ' end | |||
whereStr = whereStr .. '(' | |||
for i = 1, #countries do | |||
if i > 1 then whereStr = whereStr .. ' OR ' end | |||
whereStr = whereStr .. 'Locations.country="' .. countries[i] .. '"' | |||
end | |||
whereStr = whereStr .. ')' | |||
end | |||
if args.name then whereStr = whereStr .. (whereStr ~= '' and ' AND ' or '') .. 'Locations._pageName LIKE "%' .. args.name .. '%"' end | |||
local tables = 'Locations, _pageData' | |||
local fields = 'Locations._pageName=_pageName, Locations.franchise=franchise, Locations.country=country, Locations.city=city, Locations.type=type' | |||
local cargoArgs = { | local cargoArgs = { | ||
join = 'Locations._pageName = _pageData._pageName', | |||
where = whereStr, | where = whereStr, | ||
limit = 20, | |||
orderBy = "_pageData._modificationDate DESC", | |||
} | } | ||
local results = cargo.query(tables, fields, cargoArgs) | local results = cargo.query(tables, fields, cargoArgs) | ||
Revision as of 14:56, 26 March 2024
Documentation for this module may be created at Module:Locations/Full list/doc
local getArgs = require('Module:Arguments').getArgs
local cargo = mw.ext.cargo
local limit = 100000
local LocationsList = {}
function LocationsList.main(frame)
local args = getArgs(frame)
local results = query( args)
if #results > 0 then
local container = mw.html.create('div'):attr('id', 'locations-search-container')
local ul = mw.html.create('ul')
for r = 1, #results do
ul:node(mw.html.create('li'):node('[[' .. results[r]._pageName .. ']]'))
end
container:node(ul)
return container
end
end
function query(args)
local whereStr = ''
if args.type then whereStr = whereStr .. 'Locations.type HOLDS "' .. args.type .. '"' end
if args.country then
local countries = mw.text.split(args.country, ',')
if whereStr ~= '' then whereStr = whereStr .. ' AND ' end
whereStr = whereStr .. '('
for i = 1, #countries do
if i > 1 then whereStr = whereStr .. ' OR ' end
whereStr = whereStr .. 'Locations.country="' .. countries[i] .. '"'
end
whereStr = whereStr .. ')'
end
if args.name then whereStr = whereStr .. (whereStr ~= '' and ' AND ' or '') .. 'Locations._pageName LIKE "%' .. args.name .. '%"' end
local tables = 'Locations, _pageData'
local fields = 'Locations._pageName=_pageName, Locations.franchise=franchise, Locations.country=country, Locations.city=city, Locations.type=type'
local cargoArgs = {
join = 'Locations._pageName = _pageData._pageName',
where = whereStr,
limit = 20,
orderBy = "_pageData._modificationDate DESC",
}
local results = cargo.query(tables, fields, cargoArgs)
return results
end
return LocationsList