Module:also: Difference between revisions
Jump to navigation
Jump to search
TheNightAvl (talk | contribs) mNo edit summary Tags: Mobile edit Mobile web edit Advanced mobile edit |
TheNightAvl (talk | contribs) No edit summary |
||
Line 90: | Line 90: | ||
if toAdd then | if toAdd then | ||
mw.log("possibility found: " .. check_key) | 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>" | 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 | else | ||
return nil | return nil |
Revision as of 17:40, 16 June 2024
{{also}}
local export = {}
local m_links = require("Module:links")
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)
local args = getArgs(frame)
local links = {}
if args[1] then -- manual mode
local i = 1
while args[i] do
table.insert(links, "'''" .. m_links.full_link{term = args[i]} .. "'''")
i = i + 1
end
else -- auto mode
local here = args["test"] or mw.title.getCurrentTitle().subpageText
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
if links[1] then
table.sort(links, function(a,b) return a < b end)
return "<dt><dd>''See also:'' " .. table.concat(links, ", ") .. "</dd></dt>"
else
return nil
end
end
return export