模組:CNBUS/sandbox

![]() | 这是Module:CNBUS(差异)的沙盒。 |
![]() | 此模块使用Lua语言: |
本模块是实现一系列交通相关模板功能的基础模块,支持管理各城市公共汽车系统的数据资料,目前主要用于生成一个显示公交线路资料的表格。
子模块一览
目前,各公交系统均使用独立的模板,并依赖本模块子页面的相关资料。下表为本模块已建立的子模块。您也可以仿照后文所述的格式新建子模块(技术上不限于中国大陆城市,但港澳地区巴士路线是否迁移入本模块体系尚待接洽),并将其添加至下表。欢迎各位对已有资料进行定期维护更新。
相互引用情况
位置
|
被引用系统 | |||||||||
---|---|---|---|---|---|---|---|---|---|---|
肇庆 | 珠海 | 江门 | 中山 | 佛山 | 广州 | 东莞 | 惠州 | 深圳 | ||
系统 | 肇庆 | 不適用 | ZQ/foshan | |||||||
珠海 | 不適用 | ZH/jiangmen | ZH/data | |||||||
江门 | JM/zhuhai | 不適用 | JM/zhongshan | JM/foshan | ||||||
中山 | ZS/zhuhai | ZS/data | 不適用 | ZS/foshan | ||||||
佛山 | FS/zhaoqing | FS/data | FS/data | 不適用 | FS/guangzhou | |||||
广州 | GZ/foshan | 不適用 | GZ/dongguan | |||||||
东莞 | DG/guangzhou | 不適用 | DG/huizhou | DG/shenzhen | ||||||
惠州 | HZ/dongguan | 不適用 | HZ/shenzhen | |||||||
深圳 | SZ/zhongshan | SZ/dongguan | SZ/huizhou | 不適用 |
位置
|
被引用系统 | |||
---|---|---|---|---|
汕头 | 潮州 | 揭阳 | ||
系统 | 汕头 | 不適用 | ST/jieyang | |
潮州 | CZ/shantou | 不適用 | CZ/jieyang | |
揭阳 | JY/shantou | 不適用 |
接口一览
直接调用接口的模板的参数表(传入)和其调用接口时显式指定的参数表(传出)都会被识别,两者优先级参见Module:Arguments。由本模块导出的模板可能还提供了其他别名。
参数 | 说明 | 列表 | 折叠列表 | 运营商颜色 | 线路名称 | 别名与注释 |
---|---|---|---|---|---|---|
{{{1}}} {{{2}}} … | 线路代码列表 | 需要 | 需要 | 不適用 | 单个 | |
{{{city}}} | 城市代码 | 需要 | 需要 | 需要 | 需要 | 各城市模板默认填写 |
{{{area}}} | 区域代码 | 需要 | 需要 | 不適用 | 需要 | 部分模板提供{{{loc}}}别名 |
{{{operator}}} | 运营商代码 | 不適用 | 不適用 | 需要 | 不適用 | {{{company}}} 区别于{{{operators}}} |
{{{start}}} | 是否开始表格 输出 <table> 开标签及表头
|
可选 | 可选 | 不適用 | 不適用 | 默认为真 |
{{{end}}} | 是否结束表格 输出 </table>
|
可选 | 可选 | 不適用 | 不適用 | 默认为真 |
{{{header}}} | 表格标题 | 可选 | 可选 | 不適用 | 不適用 | {{{info}}} {{{station}}} 依赖于{{{start}}} |
{{{type}}} | 列表样式 | 可选 | 不適用 | 不適用 | 不適用 | BRT :覆盖{{{fare}}}{{{operators}}}{{{vehicles}}}值
|
{{{time}}} | 是否显示时间 | 可选 | 不適用 | 不適用 | 不適用 | |
{{{fare}}} | 是否显示票价 | 可选 | 不適用 | 不適用 | 不適用 | 默认为真 |
{{{operators}}} | 是否显示运营商 | 可选 | 不適用 | 不適用 | 不適用 | 默认为真 区别于{{{operator}}} |
{{{vehicles}}} | 是否显示车型 | 可选 | 不適用 | 不適用 | 不適用 | |
{{{image}}} | 是否显示图片 | 可选 | 不適用 | 不適用 | 不適用 |
list
通过输入一个或多个线路编号以生成包含这些线路资料的表格。目前支持起讫点、线路方向、营运公司(分公司)、票价、运营时间、车辆图片、线路配车、BRT站台信息、备注等信息。
{{#invoke:CNBUS |list |city=#包含系统 }}
编号 | 线路及运营时间 | 收费 | 运营商 | 备注 | |||
---|---|---|---|---|---|---|---|
1 | 芳村花园南门 6:00–22:30 | ⇆ | 东山(署前路) 6:00–22:30 | 2元 | 一汽一分 |
或者,线路也可以使用单个模式匹配表达式(必须以^
开头)指定,用例参见重庆公交线路列表 (中心城区)。常用的代码匹配方式如:
^T
:所有T开头的线路;^%d%d%D*$
:所有两位数的线路(允许非数字后缀,不允许更多数字);^1%d%d%D*$
:1开头三位数的线路(允许非数字后缀,不允许更多数字)。
注意,输出的线路将按照线路代码以字符串排序,这意味着2
会排在10
的后面;此情形下建议配合{{{start}}}{{{end}}}将不同位数代码分拆多个表格显示。
collapsibleList
类似list,但只会生成一个的简化版的表格。目前仅支持起讫点和线路方向。
{{#invoke:CNBUS |collapsibleList |city=#包含系统 }}
行经巴士路线一览 | ||||
---|---|---|---|---|
编号 | 路线 | 备注 | ||
番1 | 祈福新邨 | ⇆ | 傍雁路临时公交总站 |
color
属于辅助功能,可输出代表线路运营商的颜色代号。list
已集成该功能。
lineName
展示简短行内链接。如{{惠州巴士路线极简列表|1}}
:公交路线:1
数据格式
本模块约定将数据存储在子模块中。
城市总表模块
在将本模块引入公交系统前,首先需要建立一个子模块作为该系统的数据模块。请将该子模块命名为Module:CNBUS/<城市代码>
,其基本框架为:
local xx = {
areas = { },
operators = { }
}
xx.areas['xx'] = {
name = "<区域名>",
page = "<线路列表条目名>",
source = "Module:CNBUS/XX/data", -- 对应模块
aliases = { "XX", "理塘", "default" } --
}
xx.operators['bus'] = {
color = "red",
aliases = { "Bus", "公交集团" }
}
xx.operators['transport'] = {
color = "silver",
aliases = { "交运集团" }
}
return xx
区域表
每个子模块可包含一个或多个子区域,可分别存放城区、郊区、外市路线的资料。在本模块设置各区域资料的例子如下:
gz.areas['guangzhou'] = {
name = "广州",
page = "广州巴士路线列表",
source = "Module:CNBUS/GZ/data",
aliases = { "Guangzhou", "GZ", "gz", "广州", "廣州", "default" }
}
gz.areas['nansha'] = {
name = "南沙",
page = "南沙巴士路线列表",
source = "Module:CNBUS/GZ/nansha",
aliases = { "Nansha", "NS", "ns", "南沙" }
}
gz.areas['foshan'] = {
name = "佛山",
page = "佛山巴士路线列表",
source = "Module:CNBUS/GZ/foshan",
aliases = { "Foshan", "FS", "fs", "佛山" }
}
其中,source
的值为子区域各线路的详细资料;page
和name
用于设置list和collapsibleList的标题中指向列表条目的内部链接([[page|name]]
,如[[广州巴士路线列表|广州]]
);aliases
则包含了该子区域的别名,由area
参数调用。
本例中共有3个区域,分别为“guangzhou
”、“nansha
”和“foshan
”。在未提供area
参数的值,或area
参数的值为“guangzhou
”、“Guangzhou
”、“GZ
”、“gz
”、“广州
”、“廣州
”时,则选择区域“guangzhou
”。“nansha
”和“foshan
”同理。
运营商表
在本模块设置各运营商颜色的例子如下:
xx.operators['bus1'] = {
color = "orange", -- 颜色
aliases = { "一汽一分", "一汽二分" } -- 别名。键值本身(此处为bus1)不需要包含其中
}
xx.operators['bus3'] = {
color = "#fff600",
aliases = { "三汽一分", "三汽二分" }
}
xx.operators['other'] = {
color = "white",
}
xx.operators['multi'] = {
color = "black",
}
在本例中,一汽和三汽公司的代码分别为bus1
和bus3
,则运营商为“一汽一分”和“一汽二分”的代表色为“orange”(橙色),“三汽一分”和“三汽二分”的代表色为“#fff600”(近似于黄色)。此外,还需要设置“other
”和“multi
”,分别代表模块中未列出的运营商(显示为白色)和多个异组运营商(显示为黑色)。
线路表模块
此后,便是为各个区域添加具体的线路(line)资料。请在该子模块下再新建一个二级子模块,并命名为“Module:CNBUS/<城市代码>/<区域代码>
”,其基本框架如下:
local p = {
-- 常规线路
['1'] = { name = "线路名", mark = "线路名标注", fare = "票价", operators = "运营商", vehicles = { "配车1", "..." }, note = "备注", image = "[[File:示例.jpg|128px]]",
{ { "左起讫点", time = "发车时间" }, { "方向箭头", mark = "方向标注" }, { "右起讫点", time = "发车时间" } }, --[[区间1]]
{ { "左起讫点", time = "发车时间" }, { "方向箭头", mark = "方向标注" }, { "右起讫点", time = "发车时间" } }, --[[区间2]]
{ --[[…]] }, --[[任意数量区间]] },
-- BRT线路
['B1'] = { name = "线路名", mark = "线路名标注", fare = "票价" --[[BRT样式下不可见]], operator = "运营商", note = "备注", image = "[[File:图片.jpg|x128px]]", brt = { { "驶入BRT通道车站", "经停BRT车站数", "驶出BRT通道车站" --[[右向]] }, { "驶出BRT通道车站", "经停BRT车站数", "驶入BRT通道车站" --[[左向车站定义位置相反]] } }
{ { "左起讫点", time = "发车时间" }, { "→" --[[完整列表BRT样式下由brt字段自动确定;单向线路需要为其他情况填写]], mark = "方向标注" }, { "右起讫点", time = "发车时间" } }, },
-- 停办线路
['114'] = { name = "线路名", mark = "线路名标注", status = { -1, date = "日期" } },
-- 暂时停运线路
['514'] = { name = "线路名", mark = "线路名标注", status = { 0, date = "日期" } },
}
-- 导入其他模块的线路资料。请注意,引用的线路代码不能是重定向
p._external = {
['Module:CNBUS/XX/data'] = {
['1'] = '1',
['114'] = { '514', override = { name = '114' } }, -- 支持覆写部分属性
},
['Module:CNBUS/YY/data'] = {
['2'] = '2',
},
}
-- 定义线路编号重定向
p._map = {
['01'] = '1',
['BRT1'] = 'B1',
}
return p
- 线路代码
['line']
是区分简体/繁体和英文大写/小写的,因此在使用时不可混用,建议统一同城市下各子系统的简繁和大小写规则。其他参数内容不受限制。 - 如需在名词中使用连字符,请使用“-”而非“-”或“-”等。为使用方便,连字暨减号
-
(U+002D
)在线路名称、时间、票价和备注中,与数字字母相邻时将被替换为半宽连接号–
(U+2013
),其余情形下将被替换为全宽连接号—
(U+2014
)。 name
必填,<区间>[1][1]
、<区间>[2][1]
、<区间>[3][1]
、fare
、operator
和note
参数建议填写(<区间>
相关补全规则见#区间子表)。operators
和vehicles
既可以是字符串,也可以是数组(显示时分行)。数组表示的operators
会直接被视为多运营商。- 若需要显示BRT信息,则右向
<BRT>[1][1]
<BRT>[1][2]
<BRT>[1][3]
和左向<BRT>[2][1]
<BRT>[2][2]
<BRT>[2][3]
参数需要至少填入一组。右向为空时需要显式置nil
方能填写左向数据;若实际存在但缺少相关资料,则应将对应方向置为空表{ }
。 - 各参数值可以加入内部链接及换行符<br />,但来源引用<ref>和各类模板是无法使用的。
区间子表
为使用简便,一部分置空的值会使用邻近的值进行取代。补全的顺序遵循区间定义的顺序,区间内部则依次为左、右、方向。首个区间(route)和后继区间的回落规则有所不同。
对于每条线路的首个区间:
- 左起讫点保持原样(as-is),除表不存在(
nil
或未定义)时转化为空表; - 右起讫点若无效(表不存在;表首位的字符串不存在或长度为0),复制左起讫点的名称,附属属性保持原样;
- 方向若无效(表不存在;表首位的字符串不存在或长度为0),左右起讫点(回落补全后)若相等则视作逆时针循环线,否则视为往返线,附属属性保持原样。
{ },
-- 等价于
{ { }, { "↺" }, { } },
{ { "火车站" }, { mark = "直" }, { "机场" } },
-- 等价于
{ { "火车站" }, { "⇆", mark = "直" }, { "机场" } },
{ { "火车站", time = "10:00" }, nil, { time = "20:00" } },
-- 等价于
{ { "火车站", time = "10:00" }, { "↺" }, { "火车站", time = "20:00" } },
对于后继区间:
- 左右起讫点若表不存在,则复制上一区间对应起讫点的所有属性;若表首位的字符串(名称)不存在或长度为0,则只复制上一区间对应起讫点的名称,附属属性保持原样;
- 方向的行为与首个区间相同。
-- 假定补全后的上一区间
{ { "火车站", time = "10:00" }, { "⇆", mark = "快" }, { "机场", time = "20:00" } },
{ },
-- 等价于
{ { "火车站", time = "10:00" }, { "⇆" }, { "机场", time = "20:00" } },
{ nil, { mark = "直" }, { "" } },
-- 等价于
{ { "火车站", time = "10:00" }, { "⇆", mark = "直" }, { "机场" } },
用例
- 时间、BRT资料及线路导入:Module:CNBUS/GZ/data
- 图片:Module:CNBUS/SZ/data
- 配车:Module:CNBUS/HZ/data
常见错误
在条目中使用引用了本模块的模板后,可能会提示以下错误:
错误提示 | 错误原因 | 解决方法 | ||||
---|---|---|---|---|---|---|
错误 | Module:CNBUS不存在“XXX”的公交系统数据 | Module:CNBUS/XXX不存在 | 检查模板中 city=<城市代码> 的<城市代码>是否填写错误
| |||
错误 | “city”参数为空,请输入城市代码 | 模板未填入 city 的值
|
填写模板中 city=<城市代码> 的<城市代码>
| |||
错误 | Module:CNBUS/XXX中未包含“yyy”的资料模块 | Module:CNBUS/XXX/yyy不存在 | 检查模板中 loc=<子系统代码> 的<子系统代码>是否填写错误
| |||
错误 | 资料模块Module:CNBUS/XXX/yyy出现错误,请前往检查 | Module:CNBUS/XXX/yyy出现错误 | 大多为资料模块导入其他模块时输入错误(本说明文档示例中的“导入其他模块的线路资料”部分),请仔细检查资料模块中该部分代码是否有误。如无法定位错误,可借助编辑框下方的“调试控制台”寻找出错行数。不知道怎么用?最简单的方法是输入 print(p) 后回车,如提示“Lua错误”,即可找到出错的变量及其位置。
| |||
无输入 | 请输入线路编号 | 使用模板时填入线路编号,或去除多余的“|” | ||||
295 | 数据模块Module:CNBUS/XXX/yyy出现错误 | Module:CNBUS/XXX/yyy没有结尾 | 在相应模块添加return line 或return xxxbusline
| |||
308 | 模块Module:CNBUS/XXX/zzz引用的数据模块Module:CNBUS/XXX/yyy出现错误 | |||||
1234 | 本线已于0202年1月1日停办,请移除 | 使用模板时删除该线路 | ||||
5678 | 本线自0202年1月1日起暂停服务 | 使用模板时视情况删除或保留该线路 | ||||
9012 | 本线并非BRT线路 | 线路缺少 brt_b 参数
|
如该线路并非BRT线路,使用模板时请勿选择 style=BRT 样式;如该线路的确为BRT线路,请补充完整该线路在BRT通道的行驶信息,否则使用模板时请勿选择 style=BRT 样式。
|
备注
本模块的相关功能以先前广州巴士路线列表的样式排版设计。模块前身为{{廣州巴士路線}};为优化页面加载速度和方便在不同系统间调用资料,模板于2019年中进行模块化改版(Module:GZBUS);为方便各模块的维护管理,2020年5月再将原先各模块合并于此。
遇线路调整需要修改模块数据时,请留意调整所根据的来源性质(不是要求将来源写入模块中,这样做反而可能导致代码兼容问题),依据近期WP:RSN共识,巴士档案站(buspedia.top)通常不可靠,请勿单纯根据该网站盲目修改。
如您在使用本模块时遇到问题或有任何建议,欢迎在模块讨论页中提出。
-- 声明模块本体
local p = {
NO_DATA = '(暂缺)',
DEFAULT_SPACE = ' ',
}
-- 导入城市数据
local function _loadSystemData(city)
local system_data = nil
local err_text = nil
if city ~= nil and city ~= "" then
local state
state, ro_system_data = pcall(mw.loadData, "Module:CNBUS/"..city)
if state then
system_data = setmetatable( {}, { __index = ro_system_data }); -- 转换为可读写的table
system_data.locName = {}
for i1, t1 in pairs(system_data.location) do
for _, k1 in pairs(t1) do
system_data.locName[k1] = t1[1]
end
end
system_data.compName = {}
for i2, t2 in pairs(system_data.company) do
for _, k2 in pairs(t2) do
system_data.compName[k2] = t2[1]
end
end
else
err_text = mw.ustring.format('[\[Module:CNBUS]\]不存在“%s”的公交系统数据', city)
end
else
err_text = mw.ustring.format('“city”参数为空,请输入城市代码')
end
return system_data, err_text
end
local function _isEmpty(var)
if var == '' then var = nil end
return not var
end
-- 导入路线数据
local function _loadLineData(datapath)
local city_data = nil
local err_text = nil
local state
state, city_data = pcall(mw.loadData, datapath)
if not state then
err_text = mw.ustring.format("资料模块[\[%s]\]出现错误,请前往检查", datapath)
end
return city_data, err_text
end
-- {{巴士公司色块}}
function p._internalColorbox(compname, city)
local sys = _loadSystemData(city) -- 加载系统数据
str = compname
len = #str
if sys.compName[compname] then
box_output = string.format('width=1%% bgcolor=%s', sys.colors[sys.compName[compname]])
elseif len > 18 or compname == "multi" then -- 公司名超过六个字为联营
box_output = string.format('width=1%% bgcolor=%s', sys.colors['multi'])
else
box_output = string.format('width=1%% bgcolor=%s', sys.colors['other'])
end
return box_output
end
-- 仅输出颜色
function p._internalColor(compname, city)
local sys = _loadSystemData(city) -- 加载系统数据
str = compname
len = #str
if sys.compName[compname] then
color = sys.colors[sys.compName[compname]]
elseif len > 18 or compname == "multi" then -- 公司名超过六个字为联营
color = sys.colors['multi']
else
color = sys.colors['other']
end
return color
end
-- 处理起讫点中出现的跨粤文维基百科的链接模板({{tsl|zh-yue|...}})
function p._internalTsllink(name)
if _isEmpty(name) then
str = p.DEFAULT_SPACE
else
str = name --[[
if string.find(name, "tsl") then
start = string.find(name, "{")
en3 = string.find(name, "}", start)
en1 = string.find(name, "|", start+13)
arg1 = string.sub(name, start+13, en1-1)
en2 = string.find(name, "|", en1+1)
arg2 = string.sub(name, en1+1, en2-1)
arg3 = string.sub(name, en2+1, en3-1)
no1 = string.sub(name, 0, start-1)
fi1 = string.find(name, "{", en2+1)
if fi1 == nil then -- 只引用一次tsl
no2 = string.sub(name, en3+2, string.len(name))
str = no1..mw.getCurrentFrame():expandTemplate{title = "ly", args = {arg2, arg1, arg3}}..no2
else -- 引用两次tsl
start1 = string.find(name, "{", en3)
no2 = string.sub(name, en3+2, start1-1)
en4 = string.find(name, "|", start1+13)
arg4 = string.sub(name, start1+13, en4-1)
en5 = string.find(name, "|", en4+1)
arg5 = string.sub(name, en4+1, en5-1)
en6 = string.find(name, "}", start1)
arg6 = string.sub(name, en5+1, en6-1)
no3 = string.sub(name, en6+2, string.len(name))
str = no1..mw.getCurrentFrame():expandTemplate{title = "ly", args = {arg2, arg1, arg3}}..no2..mw.getCurrentFrame():expandTemplate{title = "ly", args = {arg5, arg4, arg6}}..no3
end
end ]]
end
return str
end
-- 生成一条路线的一列表格内容
function p._internalList(no, style, city, loc, time, vehicle, image)
local sys, err_text = _loadSystemData(city) -- 加载系统数据
if not err_text and sys.locName[loc] then
sysloc = sys.locName[loc] -- sysloc为拼音
loc = sys.titlename[sysloc] -- loc为简体
d, err_text = _loadLineData(sys.data[sysloc]) -- 加载线路数据
elseif not err_text then
err_text = mw.ustring.format("[\[Module:CNBUS/%s]\]中未包含“%s”的资料模块", city, loc)
end
table_output = mw.html.create('tr')
if err_text then
no = "错误"
elseif _isEmpty(no) then
no = "无输入"
err_text = mw.ustring.format("请输入线路[\[%s巴士路线列表|编号]\]", loc)
elseif not d[no] then
err_text = mw.ustring.format("[\[%s]\]中未包含这条[\[%s巴士路线列表|%s]\]的线路", sys.data[sysloc], loc, loc)
elseif d[no].note and mw.ustring.match(d[no].note, "已停[办辦]") then
if _isEmpty(d[no].suspend) then
err_text = "本线已停办,请移除"
else
err_text = mw.ustring.format("本线自%s起停办,请移除", d[no].suspend)
end
no = d[no].code
elseif d[no].note and (d[no].note == "暂停服务" or d[no].note == "暫停服務") then
if _isEmpty(d[no].suspend) then
err_text = "本线已暂停服务"
else
err_text = mw.ustring.format("本线自%s起暂停服务", d[no].suspend)
end
no = d[no].code
else
data_color = p._internalColor(d[no].company, city) -- 获取颜色
data_ep1 = d[no].endpoint1 or ""
data_ep2 = d[no].endpoint2 or data_ep1
--[[ p._internalTsllink(d[no].endpoint1) -- 处理起讫点1可能出现的{{tsl|zh-yue}}
if _isEmpty(d[no].endpoint2) then
data_ep2 = data_ep1
else
data_ep2 = p._internalTsllink(d[no].endpoint2) -- 处理起讫点2可能出现的{{tsl|zh-yue}}
end]]
if _isEmpty(d[no].endpoint3) then -- 部分双向高峰快线:去程终点和返程起点不同
data_ep3 = nil -- 处理起讫点3可能出现的{{tsl|zh-yue}}
else
data_ep3 = p._internalTsllink(d[no].endpoint3)
end
if time == "yes" then
--if time and mw.ustring.match(time, "[Yy][Ee][Ss]") then
if not _isEmpty(d[no].time1) then data_ep1 = data_ep1..[[<br>]]..d[no].time1 end
if not _isEmpty(d[no].time2) then data_ep2 = data_ep2..[[<br>]]..d[no].time2 end
if not _isEmpty(d[no].time3) and data_ep3 then data_ep3 = data_ep3..[[<br>]]..d[no].time3 end
end
if _isEmpty(d[no].direction) then
if _isEmpty(d[no].endpoint2) then
data_direction = "↺"
else
data_direction = "⇆"
end
elseif not _isEmpty(d[no].direction1) then -- 部分线路的第二个方向
if data_ep3 then -- 部分线路去程终点和返程起点不同
data_direction = d[no].direction..'<hr>'..d[no].direction1
data_ep2 = data_ep2..'<hr>'..data_ep3
else
data_direction = d[no].direction..'<br>'..d[no].direction1
end
else
data_direction = d[no].direction
end
data_note = d[no].note or ""
-- BRT样式(广州、中山)
if style == "BRT" and _isEmpty(d[no].brt_b) then -- 不是BRT路线
err_text = "本线并非[\[快速公交系统|BRT线路]\]"
elseif style == "BRT" and not _isEmpty(d[no].brt_b) then -- BRT样式:单向路线(一列,广州)
data_brt_b_in = p._internalTsllink(d[no].brt_b_in)
data_brt_b_out = p._internalTsllink(d[no].brt_b_out)
if not _isEmpty(d[no].brt_a) then
data_brt_a_in = p._internalTsllink(d[no].brt_a_in)
data_brt_a_out = p._internalTsllink(d[no].brt_a_out)
data_brtin = data_brt_a_in..'<hr>'..data_brt_b_in
data_brtout = data_brt_a_out..'<hr>'..data_brt_b_out
data_brtno = d[no].brt_a..'<hr>'..d[no].brt_b
data_direction = "→<hr>←"
else
data_brtin = data_brt_b_in
data_brtout = data_brt_b_out
data_brtno = d[no].brt_b
end
data_company = d[no].company or ""
if not _isEmpty(d[no].brt_info) then
if not _isEmpty(data_note) then
data_note = data_note..[[;]]..d[no].brt_info
else
data_note = data_note..d[no].brt_info
end
end
table_output
:tag('td')
:attr('width', '1%')
:attr('bgcolor', data_color)
:done()
:tag('td')
:tag('b')
:wikitext(d[no].code)
:done()
:done()
:tag('td')
:attr('align', 'right')
:wikitext(data_ep1)
:done()
:tag('td')
:wikitext(data_direction)
:done()
:tag('td')
:attr('align', 'left')
:wikitext(data_ep2)
:done()
:tag('td')
:wikitext(data_brtin)
:done()
:tag('td')
:wikitext(data_brtout)
:done()
:tag('td')
:wikitext(data_brtno)
:done()
:tag('td')
:wikitext(data_company)
-- 非BRT样式
else
table_output
:tag('td')
:attr('width', '1%')
:attr('bgcolor', data_color)
:done()
:tag('td')
:tag('b')
:wikitext(d[no].code)
:done()
:done()
:tag('td')
:attr('align', 'right')
:wikitext(data_ep1)
:done()
:tag('td')
:attr('nowrap', 'true')
:wikitext(data_direction)
:done()
:tag('td')
:attr('align', 'left')
:wikitext(data_ep2)
:done()
if style ~= "nofa" and style ~= "nocofa" then
data_fare = d[no].fare or ""
table_output
:tag('td')
:wikitext(data_fare)
end
if style ~= "noco" and style ~= "nocofa" then -- 不显示公司栏(noco、nocofa)
data_company = d[no].company or ""
table_output
:tag('td')
:wikitext(data_company)
end
if vehicle == "yes" then -- 配车信息(惠州)
data_vehicle = d[no].vehicle or ""
table_output
:tag('td')
:wikitext(data_vehicle)
end
end
if image == "yes" and not _isEmpty(d[no].image) then
if not _isEmpty(d[no].note) then
data_note = data_note..'<br>'..d[no].image
else
data_note = d[no].image
end
end
table_output
:tag('td')
:attr('align', 'left')
:wikitext(data_note)
:allDone()
:newline()
end
if err_text then -- 输出错误信息
table_output
:tag('td')
:attr('width', '1%')
:done()
:tag('td')
:tag('b')
:wikitext(mw.ustring.format("%s", no))
:done()
:done()
:tag('td')
:attr('colspan', 3)
:wikitext(mw.ustring.format("%s", err_text))
:allDone()
:newline()
end
return table_output
end
-- 列表模板
function p.list(frame)
local bb = frame.args
local ret = p._internalList(bb.code, bb.format, bb.city, bb.loc, bb.time, bb.vehicle, bb.image)
return ret
end
-- 生成一条路线的一列简单表格内容
function p._internalSimpList(no, city, loc)
local sys = _loadSystemData(city) -- 加载系统数据
local sysloc = sys.locName[loc] -- sysloc为拼音
local loc = sys.titlename[sysloc] -- loc为简体
local path = sys.data
local d = _loadLineData(sysloc, path) -- 加载路线数据
if not d[no] then
err_text = mw.ustring.format("(错误:%s中未包含这条[\[%s巴士路线列表|%s]\]的线路)", sys.data[sysloc], loc, loc)
elseif mw.ustring.match(d[no].note, "已停[办辦]") then
if _isEmpty(d[no].suspend) then
err_text = "(本线已停办,请移除)"
else
err_text = mw.ustring.format("(本线自%s起停办,请移除)", d[no].suspend)
end
no = d[no].code
elseif mw.ustring.match(d[no].note, "[暂暫]停服[务務]") then
if _isEmpty(d[no].suspend) then
err_text = "(本线已暂停服务)"
else
err_text = mw.ustring.format("(本线自%s起暂停服务)", d[no].suspend)
end
no = d[no].code
else
data_ep1 = p._internalTsllink(d[no].endpoint1) -- 处理起讫点1可能出现的{{tsl|zh-yue}}
if _isEmpty(d[no].endpoint2) then
data_ep2 = data_ep1 -- 未填入endpoint2默认为循环线
else
data_ep2 = p._internalTsllink(d[no].endpoint2) -- 处理起讫点2可能出现的{{tsl|zh-yue}}
end
if _isEmpty(d[no].direction) then -- 部分线路省略了方向
if _isEmpty(d[no].endpoint2) then -- 未填入endpoint2默认为循环线
data_direction = "↺"
else
data_direction = "⇆"
end
elseif not _isEmpty(d[no].direction1) then -- 部分线路的第二个方向
if not _isEmpty(d[no].endpoint3) then -- 部分线路去程终点和返程起点不同
data_direction = d[no].direction..'<hr>'..d[no].direction1
data_ep2 = data_ep2..'<hr>'..p._internalTsllink(d[no].endpoint3) -- 处理起讫点3可能出现的{{tsl|zh-yue}}
else
data_direction = d[no].direction..'<br>'..d[no].direction1
end
else
data_direction = d[no].direction
end
data_note = d[no].note or ""
end
local table_output = mw.html.create()
if err_text then
table_output
:tag('tr')
:tag('td')
:attr('align', 'center')
:tag('b')
:wikitext(mw.ustring.format("%s", no))
:done()
:done()
:tag('td')
:attr('colspan', 3)
:attr('align', 'center')
:tag('i')
:wikitext(mw.ustring.format("%s", err_text))
else
table_output
:tag('tr')
:tag('td')
:attr('align', 'right')
:tag('b')
:wikitext(mw.ustring.format("%s", d[no].code))
:done()
:done()
:tag('td')
:attr('align', 'right')
:wikitext(data_ep1)
:done()
:tag('td')
:attr('align', center)
:attr('nowrap', 'true')
:wikitext(data_direction)
:done()
:tag('td')
:attr('align', 'left')
:wikitext(data_ep2)
:done()
:tag('td')
:attr('align', 'left')
:wikitext(data_note)
end
return table_output
end
-- 简单列表模板
function p.simplelist(frame)
local ss = frame.args
local ret = p._internalSimpList(ss.code, ss.city, ss.loc)
return ret
end
-- 输出线路单项资料(惠州)
function p._internalCode(no, city, loc)
local sys = _loadSystemData(city) -- 加载系统数据
local sysloc = sys.locName[loc] -- sysloc为拼音
local loc = sys.titlename[sysloc] -- loc为简体
local path = sys.data
local d = _loadLineData(sysloc, path) -- 加载路线数据
if not d[no] then
out = string.format("(错误:%s中无%s线)", sys.data[sysloc], no)
elseif mw.ustring.match(d[no].note, "已停[办辦]") then
out = string.format("(错误:%s已停办,请移除)", d[no].code)
elseif mw.ustring.match(d[no].note, "[暂暫]停服[务務]") then
out = string.format("(错误:%s暂停服务)", d[no].code)
else
out = d[no].code or no
end
return out
end
-- 极简列表模板(惠州)
function p.code(frame)
local ss = frame.args
local ret = p._internalCode(ss.code, ss.city, ss.loc)
return ret
end
-- 生成表格表头
function p._internalTitle(style, city, loc, vehicle, time, image)
local sys = _loadSystemData(city) -- 加载系统数据
local sysloc = sys.locName[loc] -- sysloc为拼音
local titleloc = sys.titlename[sysloc] or loc -- loc为简体
local listname = nil --sys.listname[sysloc] or nil
local link_list
if not _isEmpty(listname) then
link_list = listname
else
if city == "ZZ" or city == "SU" or city == "BJ" or city == "CW" or city == "LYG" then
link_list = mw.ustring.format('%s公交线路列表', titleloc)
elseif city == "CQ" then
link_list = mw.ustring.format('重庆公交线路列表 (%s)', titleloc)
elseif city == "XA" then
link_list = mw.ustring.format('%s市公交线路表', titleloc)
elseif city == "ST" or city == "CZ" or city == "JY" then
link_list = mw.ustring.format('%s公交路线列表', titleloc)
elseif titleloc == "惠州" then
link_list = '惠州公共交通线路表'
else
link_list = mw.ustring.format('%s巴士路线列表', titleloc)
end
end
if mw.ustring.match(time, "[Yy][Ee][Ys]") then
title_route = "线路及运营时间"
else
title_route = "线路"
end
if mw.ustring.match(image, "[Yy][Ee][Ys]") then
title_note = "图片及备注"
else
title_note = "备注"
end
local t = mw.html.create()
if mw.ustring.match(style, "[Bb][Rr][Tt]") then
t
:tag('th')
:attr('colspan', 2)
:attr('width', '8.5%')
:wikitext(mw.ustring.format('[\[%s|编号]\]',link_list))
:done()
:tag('th')
:attr('colspan', 3)
:attr('width', '25%')
:wikitext(title_route)
:done()
:tag('th')
:attr('width', '10.6%')
:wikitext('驶入BRT通道')
:done()
:tag('th')
:attr('width', '10.6%')
:wikitext('驶出BRT通道')
:done()
:tag('th')
:attr('width', '8.5%')
:wikitext('BRT通道停靠站数')
:done()
:tag('th')
:attr('width', '14.9%')
:wikitext('运营商')
:done()
:tag('th')
:attr('width', '21.3%')
:wikitext(title_note)
elseif mw.ustring.match(vehicle, "[Yy][Ee][Ys]") then -- 显示运力(vehicle = yes)
if style == "noco" then -- 不显示公司栏(noco)
t = '!colspan="2" width="12%"|[['..link_list..'|编号]]!!colspan="3"|'..title_route..'!!width="8%"|收费!!width="19%"|运力!!width="19%"|'..title_note..'\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="20%"| || ||width="20%"| ||colspan="3"| '
elseif style == "nofa" then -- 不显示票价栏(nofa)
t = '!colspan="2" width="12%"|[['..link_list..'|编号]]!!colspan="3"|'..title_route..'!!width="8%"|运营商!!width="19%"|运力!!width="19%"|'..title_note..'\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="20%"| || ||width="20%"| ||colspan="3"| '
elseif style == "nocofa" then -- 不显示公司和票价栏(nocofa)
t = '!colspan="2" width="13%"|[['..link_list..'|编号]]!!colspan="3"|'..title_route..'!!width="21%"|运力!!width="20%"|'..title_note..'\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="22%"| || ||width="22%"| ||colspan="2"| '
else -- 显示公司和票价栏(默认)
t = '!colspan="2" width="10%"|[['..link_list..'|编号]]!!colspan="3"|'..title_route..'!!width="8%"|收费!!width="8%"|运营商!!width="18%"|运力!!width="18%"|'..title_note..'\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="18%"| || ||width="18%"| ||colspan="4"| '
end
else -- 不显示运力
t
:tag('th')
:attr('colspan', 2)
:attr('width', width_code)
:wikitext(mw.ustring.format('[\[%s|编号]\]', link_list))
:tag('th')
:attr('colspan', 3)
:attr('width', width_route)
:wikitext(title_route)
:tag('th')
:attr('width', width_col1)
:wikitext(title_col1)
--if style ~= "nocofa" then 未完成
-- width_col2
t
:tag('th')
:attr('width', width_col2)
:wikitext(title_col2)
if style then
t
:tag('th')
:attr('width', width_col3)
:wikitext(title_note)
end
if style == "noco" then -- 不显示公司栏(noco)
t = '!colspan="2" width="14%"|[['..link_list..'|编号]]!!colspan="3"|'..title_route..'!!width="10%"|收费!!width="22%"|'..title_note..'\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="25%"| || ||width="25%"| ||colspan="2"| '
elseif style == "nofa" then -- 不显示票价栏(nofa)
t = '!colspan="2" width="14%"|[['..link_list..'|编号]]!!colspan="3"|'..title_route..'!!width="11%"|运营商!!width="21%"|'..title_note..'\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="25%"| || ||width="25%"| ||colspan="2"| '
elseif style == "nocofa" then -- 不显示公司和票价栏(nocofa)
t = '!colspan="2" width="16%"|[['..link_list..'|编号]]!!colspan="3"|'..title_route..'!!width="24%"|'..title_note..'\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="28%"| || ||width="28%"| || '
else -- 显示公司和票价栏(默认)
t = '!colspan="2" width="12%"|[['..link_list..'|编号]]!!colspan="3"|'..title_route..'!!width="8%"|收费!!width="10%"|运营商!!width="20%"|'..title_note..'\n|-style="background:#EAECF0" height=0\n|colspan="2"| ||width="23%"| || ||width="23%"| ||colspan="3"| '
end
end
return t
end
-- Title模板
function p.title(frame)
local tt = frame.args
local ret = p._internalTitle(tt.format, tt.city, tt.loc, tt.vehicle, tt.time, tt.image)
return ret
end
-- 色块模板
function p.colorbox(frame)
local cc = frame.args
local ret = p._internalColorbox(cc.company, cc.city)
return ret
end
-- 颜色模板(新)
function p.color(frame)
local cc = frame.args
local ret = p._internalColor(cc.company, cc.city)
return ret
end
return p