Änderungen

Wechseln zu: Navigation, Suche

Modul:Recipes

1.359 Bytes hinzugefügt, vor 8 Monaten
sync :: en revid:969111::
------- l10n info --------------
local l10n_info = mw.loadData('Module:Recipes/l10n')
 
local l10n_auto_translate_eicons_pagename = {
['zh'] = true,
}
 
 
------- The following is not related to l10n. --------------
end
 
local itemLink = (function(name, args)
local argscache = args or {}
return item_linkfunction(currentFramename, args)
args[1] = name
local args = args or {}
args[2] = currentFrame:expandTemplate{ title = 'tr', args = {name, lang=lang} }
local key = name.."|"
args['eicons'] = l10n_auto_translate_eicons_pagename[lang]
for k, v in pairs(args) do
args['small'] = 'y'
key = key..k..'='..tostring(v)..'|'
args['lang'] = lang or 'en'
end
args['nolink'] = args['nolink'] and 'y' or nil
if station_countcache[key] then
return item_link(currentFrame, args)
return cache[key]
end
else
args[1] = name
args[2] = currentFrame:expandTemplate{ title = 'tr', args = {name, lang=lang} }
args['small'] = 'y'
args['lang'] = lang or 'en'
args['nolink'] = args['nolink'] and 'y' or nil
cache[key] = item_link(currentFrame, args)
return cache[key]
end
end
end)()
 
-- credit: http://richard.warburton.it
end
 
local tableRow = function(str, row, current_station, station_count, rows_count, showResultId, withStation, needCate, needLink, needGroup, current_result, result_count, current_result_ext, result_ext_count, template, stationGroup)
local str_w = '' -- before result col
local str_x = '' -- between result and ingredients cols
if withStation then
local station = row['station']
if stationGroup then
if current_station == station then -- is same group ??
station_count = station_count + 1
else
--new group:
-- rowspan value for prev group, if needed.
station_count if =station_count 1then
str = str:gsub("xxxrowspanxxx", tostring(station_count))
end
-- begin this group
current_station = station
station_count = 1
local station_index = getArg('station-index-'..station)
-- station before:
if extCols_stationBefore then
for _, v in ipairs(extCols_stationBefore) do
if station_index then
str = str .. '<td class="station '..v..'" rowspan="xxxrowspanxxx">' .. (getArg(station_index .. '-row-' .. v) or '') .. '</td>'
else
str = str .. '<td class="station '..v..'" rowspan="xxxrowspanxxx"></td>'
end
end
end
str = str .. '<td class="station" rowspan="xxxrowspanxxx">'.. stationCell(station) ..'</td>'
-- station after:
if extCols_stationAfter then
for _, v in ipairs(extCols_stationAfter) do
if station_index then
str = str .. '<td class="station '..v..'" rowspan="xxxrowspanxxx">' .. (getArg(station_index .. '-row-' .. v) or '') .. '</td>'
else
str = str .. '<td class="station '..v..'" rowspan="xxxrowspanxxx"></td>'
end
end
end
end
else
if current_station == station then -- is same group ??
--new group:
station_count = station_count + 1
-- rowspan value for prev group, if needed.
else
if station_count then
current_station = station
str = str:gsub("xxxrowspanxxx", tostring(station_count))
station_count = 1
end
-- begin this group
current_station = station
station_count = 1
local station_index = getArg('station-index-'..station)
-- station before:
for _, v in ipairs(extCols_stationBefore) do
if station_index then
str = str .. '<td class="station '..v..'" rowspan="xxxrowspanxxx">' .. (getArg(station_index .. '-row-' .. v) or '') .. '</td>'
else
str = str .. '<td class="station '..v..'" rowspan="xxxrowspanxxx"></td>'
end
end
end
str = str .. '<td class="station" rowspan="xxxrowspanxxx">'.. stationCell(station) ..'</td>'
-- station after:
if extCols_stationAfter then
for _, v in ipairs(extCols_stationAfter) do
if station_index then
str = str .. '<td class="station '..v..'" rowspan="xxxrowspanxxx">' .. (getArg(station_index .. '-row-' .. v) or '') .. '</td>'
else
str = str .. '<td class="station '..v..'" rowspan="xxxrowspanxxx"></td>'
end
end
 
 
local tableBody = function(result, showResultId, withStation, needGroup, needCate, needLink, rootpagename, title, expectedrows, template, stationGroup)
local str = tableStart(title, withStation)
-- top ext rows:
rows_count = rows_count + 1
-- table row:
str, current_station, station_count, current_result, result_count, current_result_ext, result_ext_count = tableRow(str, row, current_station, station_count, rows_count, showResultId, withStation, needCate, needLink, needGroup, current_result, result_count, current_result_ext, result_ext_count, template, stationGroup)
-- cate:
if needCate then
end
-- rowspan value for last station group and result group
if withStation and station_count and stationGroup then
str = str:gsub("xxxrowspanxxx", tostring(station_count))
end
local str = ''
for station, _ in pairs(cateCache) do
str = str .. '[[Category:'..(cate[station] or frame:expandTemplate{ title = 'tr', args = {station, lang=lang, link='y'}})..']]'
end
if str ~= '' then
limit = 2000,
})
return tableBody(result, showResultId, false, needGroup, needCate, needLink, rootpagename, _title, _expectedrows, getArg('resulttemplate'), false)
else
-- with station
local stationGroup = true
if (getArg('stationgrouping') or 'y'):sub(1,1) == 'n' then
stationGroup = false
end
-- query
local result = mw.ext.cargo.query('Recipes', 'result, resultid, resultimage, resulttext, amount, version, station, args', {
limit = 2000,
})
return tableBody(result, showResultId, true, needGroup, needCate, needLink, rootpagename, _title, _expectedrows, getArg('resulttemplate'), stationGroup)
end
end -- p.query
3.577

Bearbeitungen