模块:BusLineData
此模块的文档可以在模块:BusLineData/doc创建
脚本错误:Lua错误:无法创建进程:proc_open不可用。请检查PHP的指令配置“disable_functions”。
local z = {}
function t(a)
if a == nil then
return ''
else
return a
end
end
function fb(a, b) --a首选
if a == nil or a == '' then
return b
else
return a
end
end
function z.stop_detail(frame)
wt = {}
local route = frame.args[1]
local direction = frame.args[2]
local data_title = mw.title.new(
'Template:BusStopData.json'
)
local data_content = data_title:getContent()
local data = mw.text.jsonDecode(data_content)
local stops = require('Module:BusLineData/' .. route)[direction]
for i, item in ipairs(stops) do
-- Line-end
if type(item) == "string" then
stop_data = data[item]
j = {}
j[1] = item
elseif type(item) == "table" then
stop_data = data[item[1]]
j = item
else
j = {ec = '3'}
stop_data = {0}
end
j['notes'] = {}
-- Stop-end
if stop_data == nil then
j['ec'] = '0 无站点数据'
stop_data = {0}
end
if type(stop_data[1]) == "table" then
if j[2] == nil then
j['ec'] = '1 需要指定站位'
else
stop_data = stop_data[j[2]]
if stop_data == nil then
j['ec'] = '2 未找到指定的站位'
end
end
end
-- Name
if j['ec'] == '3' then
table.insert(wt, '<tr><td>' .. i .. frame:preprocess('<td colspan="5"> [[Template:BusLineData#error|<span style="color:#f00">错误:0x3 不可接受的站点输入</span>]]'))
elseif j['ec'] ~= nil then
j['name'] = fb( j['name_custom'], j[1] )
table.insert(wt, '<tr><td>' .. i .. '<td>' .. frame:preprocess(t(j['name']) .. '<td colspan="4">[[Template:BusLineData#error|<span style="color:#f00">错误:0x' .. j['ec'] .. '</span>]]'))
else
j['name'] = fb( j['name_custom'], j[1] )
-- Road
-- Administration
-- Transfer
j['transfer'] = frame:preprocess( t(stop_data['transfer']):gsub( '}}%s*{{BRT|', '}}<br/>{{BRT|'):gsub( '}}%s*{{AMTR|', '}}<br/>{{AMTR|'):gsub( '}}%s*{{CR|', '}}<br/>{{CR|'))
-- Note(s)
if stop_data['single'] == 1 then
j['notes'] = {'单向车站'}
end
table.insert(j['notes'], j['note'])
j['note'] = fb( j['note_custom'], table.concat( j['notes'], ","))
-- End
table.insert(wt, '<tr><td>' .. i .. '<td>' .. frame:preprocess(t(j['name'])) .. '<td>' .. t(stop_data['road']) .. '<td>' .. t(stop_data['admin']) .. '<td>' .. j['transfer'] .. '<td>' .. j['note'] )
end
end
return '<table class="wikitable"><tr><th>站序<th>站名<th>道路<th>行政区<th>换乘站点<th>备注' .. table.concat(wt) .. '</table>'
end
function z.stop_inline(frame)
wt = {}
local route = frame.args[1]
local direction = frame.args[2]
local data = require('Module:BusLineData/' .. route)[direction]
for i, item in ipairs(data) do
if type(item) == "string" then
stop = item
elseif type(item) == "table" then
stop = item[1]
else
stop = '<span style="color:#f00">错误:0x3</span>'
end
table.insert(wt, (frame:preprocess( t(stop):gsub( '<br%s?/?>', '') )))
end
return table.concat( wt, '、' ) .. '。'
end
function z.stop_count(frame)
wt = {}
local route = frame.args[1]
local direction = frame.args[2]
local data = require('Module:BusLineData/' .. route)[direction]
return #data
end
return z