Module:also: Difference between revisions

ਕੋਈ ਸੋਧ ਸਾਰ ਨਹੀਂ
No edit summary
No edit summary
Line 3: Line 3:
local m_links = require("Module:links")
local m_links = require("Module:links")
local getArgs = require('Module:Arguments').getArgs
local getArgs = require('Module:Arguments').getArgs
function export.codify(text) --removes diacritics and non-alphanumeric characters, converts to upper case
text = mw.ustring.toNFC(text)
text = mw.ustring.lower(text)
text = mw.ustring.gsub(text,"[áàâäǎăāãåąắăằắẳẵặâầẩẫấậả]","a")
text = mw.ustring.gsub(text,"[æǣǽ]","ae")
text = mw.ustring.gsub(text,"[ćċĉčç]","c")
text = mw.ustring.gsub(text,"[ďđḍðḑ]","d")
text = mw.ustring.gsub(text,"[éèėêëěĕēẽęẹɛǝəềểễếệ]","e")
text = mw.ustring.gsub(text,"[ġĝğģ]","g")
text = mw.ustring.gsub(text,"[ĥħḥḩ]","h")
text = mw.ustring.gsub(text,"[ıíìîïǐĭīĩįị]","i")
text = mw.ustring.gsub(text,"[ĵ]","j")
text = mw.ustring.gsub(text,"[ķ]","k")
text = mw.ustring.gsub(text,"[ĺŀľļłḷḹ]","l")
text = mw.ustring.gsub(text,"[ṃ]","m")
text = mw.ustring.gsub(text,"[ńňñņṇŋ]","n")
text = mw.ustring.gsub(text,"[óòôöǒŏōõǫọőøɔơồ]","o")
text = mw.ustring.gsub(text,"[œ]","oe")
text = mw.ustring.gsub(text,"[ŕřŗṛṝꝛɽɍʀȑȓṙ]","r")
text = mw.ustring.gsub(text,"[śŝšşșṣ]","s")
text = mw.ustring.gsub(text,"[ß]","ss")
text = mw.ustring.gsub(text,"[ťţțṭ]","t")
text = mw.ustring.gsub(text,"[þ]","th")
text = mw.ustring.gsub(text,"[úùûüǔŭūũůųụűǘǜǚǖưứừ]","u")
text = mw.ustring.gsub(text,"[ŵ]","w")
text = mw.ustring.gsub(text,"[ýŷÿỹȳ]","y")
text = mw.ustring.gsub(text,"[źżž]","z")
text = mw.ustring.upper(text)
text = mw.ustring.gsub(text,"%W","")
return text
end


function export.show(frame)
function export.show(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local links = {}
local links = {}
local here = args["test"] or mw.title.getCurrentTitle().subpageText
if args[1] then -- manual mode
if args[1] then -- manual mode
local i = 1
local i = 1
while args[i] do
while args[i] do
table.insert(links, "'''" .. m_links.full_link{term = args[i]} .. "'''")
if args[i] ~= here then
table.insert(links, "'''" .. m_links.full_link{term = args[i]} .. "'''")
end
i = i + 1
i = i + 1
end
end
else -- auto mode
else
local here = args["test"] or mw.title.getCurrentTitle().subpageText
return nil
local data = mw.loadData("Module:also/data")
--[[
local termlist = mw.loadData("Module:also/data")
local data = {}
for _, term in ipairs(termlist) do -- sorts data into "codes"
local code = export.codify(term)
if data[code] == nil then data[code] = {} end
table.insert(data[code], term)
end
]]--
local here_key = ""
for key, pages in pairs(data) do
if here_key == "" then
for _, page in ipairs(pages) do
if page == here then
here_key = key
break
end
end
else
break
end
end
if here_key == "" then
local toAdd = false
local check_key = export.codify(here)
for key, _ in pairs(data) do
if check_key == key then
toAdd = true
break
end
end
if toAdd then
mw.log("possibility found: " .. check_key)
return "<div class=\"noprint maintenance-box maintenance-box-yellow\" style=\"background:#FFFFDD; width:{{{width|90}}}%; margin: 0.75em auto; border:1px dashed #888822; padding: 0.25em; \">\n{|\n| rowspan=\"2\" | [[File:Nuvola apps important yellow.svg|50px]]\n! style=\"text-align: left;\" | Possible <code>{{[[Template:also|also]]}}</code> group detected!\n|-\n| Please add this term to the [[Module:also/data|data set]].\n|}</div>[[Category:Terms which require adding to also data]]"
else
return nil
end
end
for _, page in ipairs(data[here_key]) do
if page ~= here then
table.insert(links, "'''" .. m_links.full_link{term = page} .. "'''")
end
end
end
end
if links[1] then
if links[1] then
table.sort(links, function(a,b) return a < b end)
return "<dt><dd>''See also:'' " .. table.concat(links, ", ") .. "</dd></dt>"
return "<dt><dd>''See also:'' " .. table.concat(links, ", ") .. "</dd></dt>"
else
else