local export = {}
local m_languages = require("Module:languages")
local title = mw.title.getCurrentTitle()
local rsplit = mw.text.split
local function makeUrl(queryType, target)
if title and title.fullUrl then
if target then
if queryType then
local query = { = target}
return title:fullUrl(query, "https")
else
return title:fullUrl(nil, "https")
end
end
end
end
local function link(queryType, target, display, lang_code, script_code)
local url = makeUrl(queryType, target)
if url then
local ext_link = ""
ext_link = mw.html.create("span"):wikitext(ext_link)
ext_link = lang_code and ext_link:attr("lang", lang_code) or ext_link
ext_link = script_code and ext_link:addClass(script_code) or ext_link
return tostring(ext_link)
end
end
function export.show(frame)
local output = {}
local params = {
= {list = true},
= {type = "string"},
= {type = "boolean"},
= {},
}
local args = require("Module:parameters").process(frame.args and frame.args or frame:getParent().args, params)
local lang = args.lang and m_languages.getByCode(args.lang) or nil
local targets = args
local displays = {}
for i, char in ipairs(targets) do
if char:find(":") then
local target, display = char:match("(+):(.+)")
if target then
targets = lang and (lang:makeSortKey(target)) or target
displays = display
else
error('Parameter ' .. i .. ' is badly formatted. It should contain a key to use in the link, a colon, and then the displayed text.')
end
else
targets = lang and (lang:makeSortKey(char)) or char
displays = char
end
end
local script_code
if lang then
script_code = lang:findBestScript(table.concat(displays)):getCode()
elseif table.concat(displays) ~= "" then
script_code = require("Module:scripts").findBestScriptWithoutLang(table.concat(displays)):getCode()
end
local subcat, queryType = args.subcat
if subcat then
queryType = "subcatfrom"
-- ]
require("Module:debug").track("table-of-contents/subcat")
else
queryType = "from"
end
if args.top then
local link = link(nil, args.top)
table.insert(output, link)
if targets and targets then
table.insert(output, " – ")
end
end
for i, char in ipairs(targets) do
local link = link(queryType, char, displays, lang and lang:getCode() or nil, script_code)
table.insert(output, link)
end
if not lang then
table.insert(output, "]")
end
return table.concat(output, " ") .. require("Module:TemplateStyles")("Module:table of contents/style.css")
end
function export.full(frame)
local params = {
= {list = true},
= {},
= {type = "string", required = true},
= {type = "boolean"}
}
local args = require("Module:parameters").process(frame.args and frame.args or frame:getParent().args, params)
local lang = m_languages.getByCode(args.lang)
local lang_code = lang:getCode()
local targets = args
local displays = {}
local script_code = lang:findBestScript(table.concat(args)):getCode()
local subcat, queryType = args.subcat
if subcat then
queryType = "subcatfrom"
-- ]
require("Module:debug").track("table-of-contents/subcat")
else
queryType = "from"
end
local output = mw.html.create("table")
:attr("id", "toc")
:addClass("toc plainlinks")
:attr("summary", "Contents")
:attr("cellpadding", "5")
:attr("border", "yes")
:css("text-align", "center")
:tag("tr")
:tag("th")
:attr("colspan", #args)
:wikitext("Contents (" .. link(nil, "Top") .. ")")
:allDone()
local row = output:tag("tr")
local cell = {}
for i, char in ipairs(args) do
local target = lang:makeSortKey(char)
table.insert(cell, link(queryType, target, char, lang_code, script))
end
cell = row:tag("td"):wikitext(table.concat(cell, " "))
:attr("colspan", #args)
local char2_list = args.char2 and rsplit(args.char2, ",") or args
for i, char1 in ipairs(args) do
local row = output:tag("tr")
:css("text-align", "center")
for i, char2 in ipairs(char2_list) do
local cell = row:tag("td")
local display = char1 .. char2
if lang:hasDottedDotlessI() then
display = display
:gsub("İ", "i")
:gsub("I", "ı")
end
display = display:ulower()
local target = lang:makeSortKey(display)
cell = cell:wikitext(link(queryType, target, display, lang_code, script))
end
end
local row = output:tag("tr")
local cell = {}
for i = 0, 9 do
local display = tostring(i)
local target = lang:makeSortKey(display)
table.insert(cell, link(queryType, target, display, lang_code, script))
end
cell = row:tag("td"):wikitext(table.concat(cell, " "))
:attr("colspan", #args)
return tostring(output) .. require("Module:TemplateStyles")("Module:table of contents/style.css")
end
return export