Этот модуль зависит от следующих других модулей: |
Описание[]
Модуль для реализации всех запросов Cargo.
Список реализованных в настоящее время шаблонов[]
Вышеприведенная документация извлекается из Модуль:Queries/doc.
Редакторы могут экспериментировать в sandbox этого модуля и в testcases страницах.
Подстраницы этого модуля.
Редакторы могут экспериментировать в sandbox этого модуля и в testcases страницах.
Подстраницы этого модуля.
local getArgs = require('Module:Arguments').getArgs
local m_util = require('Module:Util')
local xtable = require('Module:Table')
local f_item_link = require('Module:Item link').item_link
local m_cargo = require('Module:Cargo')
local p = {}
local shared = {}
local data = {}
-- ----------------------------------------------------------------------------
-- i18n
-- ----------------------------------------------------------------------------
local i18n = {
errors = {
missing_item_class = 'item_class argument must be specified',
wrong_length = '%s has the wrong number of delimited inputs.'
},
}
-- ----------------------------------------------------------------------------
-- Section shared functions
-- ----------------------------------------------------------------------------
-- ----------------------------------------------------------------------------
-- Section specific templates
-- ----------------------------------------------------------------------------
function p.item_class_icon(frame)
--[[
Displays a icon for a item class.
Examples
--------
=p.item_class_icon{item_class='Daggers'}
=p.items_class_icon{item_class='Daggers, Claws'}
]]
-- Get template arguments.
local tpl_args = getArgs(frame, {
parentFirst = true
})
frame = m_util.misc.get_frame(frame)
-- Set initial values:
tpl_args.item_class = tpl_args.item_class or tpl_args[1]
tpl_args.size = tpl_args.size or '32x32'
tpl_args.link = tpl_args.link or tpl_args.item_class
if tpl_args.item_class == nil then
error(i18n.errors.missing_item_class)
end
local ic = {}
for i,v in ipairs(m_util.string.split(tpl_args.item_class, ', ')) do
ic[i] = string.format('"%s"', v)
ic[v] = i
end
for k,v in pairs(tpl_args) do
tpl_args[k] = m_util.string.split(tpl_args[k], ', ')
if #tpl_args[k] == 1 then
for i,_ in ipairs(ic) do
tpl_args[k][i] = tpl_args[k][1]
end
elseif #tpl_args[k] > 1 and #tpl_args[k] ~= #ic then
return error(string.format(i18n.errors.wrong_length, k))
end
end
local results = m_cargo.query(
{'items'},
{'items.inventory_icon', 'items.class'},
{
where=string.format('items.class IN (%s)', table.concat(ic, ', ')),
groupBy='items.class',
orderBy='items.class',
limit=#tpl_args.item_class,
}
)
local out = {}
for i,v in ipairs(results) do
local o = ic[v['items.class']]
out[#out+1] = string.format(
'[[%s|%spx|link=%s]]',
v['items.inventory_icon'],
tpl_args.size[o],
tpl_args.link[o]
)
end
return table.concat(out, ' ')
end
function p.test(frame)
-- Args
tpl_args = getArgs(frame, {
parentFirst = true
})
frame = m_util.misc.get_frame(frame)
local tquery = {}
-- selectors
tquery[#tquery+1] = '[[-Has subobject::<q>[[Concept:Spawnable named prefix mods]] [[Has mod domain::1]]</q>]]'
tquery[#tquery+1] = '[[Has tag::+]]'
tquery[#tquery+1] = '[[Has spawn weight::>>0]]'
tquery[#tquery+1] = '?Has tag'
-- extra
tquery.limit = 5000 -- server-side limit, hope it's enough
local c = os.clock()
local results = m_util.smw.query(tquery, frame)
tags = {}
for _, row in ipairs(results) do
local page, _ = string.gsub(row[1], '#_[%x]+', '')
if tags[page] == nil then
tags[page] = {}
end
table.insert(tags[page], row['Has tag'])
end
mw.log('Total ' .. (os.clock() - c))
mw.logObject(#results)
end
return p