Module:User:Theknightwho/R:OED Online

local char = mw.ustring.char local html_create = mw.html.create local len = mw.ustring.len local loadData = mw.loadData local process_params = require("Module:parameters").process local toNFD = mw.ustring.toNFD local tostring = tostring

local pagename = loadData("Module:headword/data").pagename local comb_char_lookup = loadData("Module:utilities/data").comb_chars

local pos_display_lookup = { ["a"] = true, ["adj"] = true, ["adv"] = true, ["comb"] = true, ["conj"] = true, ["int"] = true, ["pa"] = true, ["phr"] = true, ["pple"] = true, ["pr"] = true, ["prep"] = true, ["pres"] = true, ["pron"] = true, ["n"] = true, ["v"] = true, ["vbl"] = true }

local export = {}

function export.show(frame) local plain = {} local boolean = {type = "boolean"} local alias_of_entry = {alias_of = "entry"} local alias_of_id = {alias_of = "id"} local alias_of_pos = {alias_of = "pos"} local alias_of_text = {alias_of = "text"} local params = { [1] = alias_of_entry, [2] = alias_of_pos, [3] = alias_of_id, [4] = {alias_of = "date"}, [5] = alias_of_text, ["archivedate"] = plain, ["archiveurl"] = plain, ["code"] = alias_of_id, ["date"] = plain, ["entry"] = plain, ["id"] = plain, ["nodot"] = boolean, ["noformat"] = boolean, ["part of speech"] = alias_of_pos, ["passage"] = alias_of_text, ["pos"] = plain, ["subentry"] = plain, ["subid"] = plain, ["subpos"] = plain, ["suburl"] = plain, ["text"] = plain, ["title"] = alias_of_entry, ["url"] = plain, }	local args = process_params(frame.args, params) local entry_display if args.entry then args.entry = args.entry :gsub("%f[']%f[^'](.-'*)", "%1") entry_display = args.entry elseif args.subid then entry_display = tostring(html_create("span")			:addClass("maintenance-line")			:css("color", "#777777")			:wikitext("please specify the entry name")) else entry_display = pagename end local pos_display if args.pos then args.pos = args.pos :gsub("%f[']%f[^'](.-'*)", "%1") :gsub("%s*(%d+)%s*", "%1") :gsub("%f[%w]and%f[%W]", "&") pos_display = args.pos :gsub("%f[^%z%s].-%f[%z%s0-9]", function(m)				return pos_display_lookup[m] and m .. "." or m				end) :gsub("%d+", function(m)				return tostring(html_create("sup"):wikitext(m))			end) pos_display = tostring(html_create("i"):wikitext(pos_display)) else pos_display = "" end local entryurl if args.url then entryurl = args.url elseif args.id then if len(args.id) < 10 then entryurl = "https://www.oed.com/view/Entry/" .. args.id		else entryurl = args.archiveurl or "https://doi.org/10.1093/OED/" .. args.id		end elseif args.pos then local entry = toNFD(args.entry or pagename) :ulower :gsub("<.->", "") :gsub("[']", "") :gsub("­", "") :gsub("^-?(.-)-?$", "%1") :gsub("† ?", "") :gsub(" ", "-") :gsub("[\194-\244][\128-\191]*", function(m)				return comb_char_lookup[m] and "" or m			end) local pos = args.pos :ulower :gsub("<.->", "") :gsub("[']", "") :gsub("­", "") :gsub("^(.-),.*", "%1") :gsub("^(.-) & .*", "%1") :gsub("[. ]", "") entryurl = "https://www.oed.com/dictionary/" .. entry .. "_" .. pos else error("Cannot determine entry URL from given parameters.") end return frame:expandTemplate{ title = "cite-web", args = { entry = entry_display .. ", " .. pos_display, entryurl = entryurl, work = "OED Online " .. char(0x2060), url = args.archiveurl and entryurl, archiveurl = args.archiveurl, archivedate = args.archivedate, location = "Oxford, Oxfordshire", publisher = "Oxford University Press", date = args.date, usenodot = true, nodot = args.nodot }	} end

return export