← Older revision
Revision as of 17:19, 9 June 2014
Line 20:
Line 20:
-- Generate the displayed information
-- Generate the displayed information
local display = {}
local display = {}
−
--
table.insert(display, show_breadcrumbs(info))
+
table.insert(display, show_breadcrumbs(info))
−
--
table.insert(display, show_description(info))
+
table.insert(display, show_description(info))
−
--
table.insert(display, show_TOC(info))
+
table.insert(display, show_TOC(info))
return show_categories(info) .. table.concat(display, "\n\n")
return show_categories(info) .. table.concat(display, "\n\n")
Line 101:
Line 101:
function show_breadcrumbs(info)
function show_breadcrumbs(info)
if not info.code then
if not info.code then
−
return
nil
+
return
""
end
end
local lang = require("Module:languages").getByCode(info.code) or error("The language code \"" .. info.code .. "\" is not valid.")
local lang = require("Module:languages").getByCode(info.code) or error("The language code \"" .. info.code .. "\" is not valid.")
−
local codename = lang:getCanonicalName()
local steps = {}
local steps = {}
Line 111:
Line 110:
local current = info.label
local current = info.label
−
while
true
do
+
while
current ~= ""
do
−
if
current:find
("
^Category:
"
)
then
+
local
parent = get_item
(
{code = info.code, label = current, sc =
""
,
template = info.template}, "parent1")
−
-- If the parent begins with "Category:" it's not a label name but a raw category.
+
−
-- We can't determine its
parent
if it's not a label, so show it and then break the
"
chain
"
here.
+
if
parent
~=
""
then
−
table.insert(steps,
1,
"»
[[:" .. current:gsub
(
"
{
{{codename}}}",
codename)
.
.
"|"
..
current:gsub("{{{codename}}}"
,
codename):gsub("^Category:"
,
"")
.
.
"
]]
")
+
local
parent_name
=
get_item
({
code
=
info
.
code,
label
=
parent
,
sc = info.sc
,
template =
info
.
template},
"
basic
")
−
break
+
local parent_display = get_item({code = info.code, label = parent, sc = info.sc, template = info.template}, "display_name")
+
table.insert(steps, 1, "» [[:Category:" .. parent_name .. "|" .. mw.getContentLanguage():ucfirst(parent_display) .. "]]")
else
else
−
table.insert(steps,
1,
"»
[[:Category:"
..
mw
.
getContentLanguage():ucfirst(codename
..
"
"
..
info.data.labels[current].full_name) ..
"
|
"
..
mw.getContentLanguage():ucfirst(
info.
data.labels[current].full_name) ..
"
]]
")
+
local
parentbyname
=
get_item({code
=
info
.
code,
label
=
current,
sc
=
""
,
template =
info.
template},
"
parentbyname1
")
−
--
Does
this label have a parent, so that we can continue the
"
chain
"
?
+
if
parentbyname
~=
""
then
−
--
If not
,
stop
here
.
+
table.insert(steps,
1
,
"» [[:Category:"
.
. parentbyname .. "]]")
−
if not info.data.labels[current].parents or not info.data.labels[current].parents[1] then
−
break
end
end
−
−
-- Move up the "chain" by one level.
−
current = info.data.labels[current].parents[1]
end
end
+
+
-- Move up the "chain" by one level.
+
current = parent
end
end