Module:Interproject

local export = {}

local function track(page) require("Module:debug/track")("interproject/" .. page) return true end

local function process_links(linkdata, prefix, name, wmlang, sc) prefix = prefix .. ":" .. (wmlang:getCode == "en" and "" or wmlang:getCode .. ":") local links = {} local iplinks = {} local m_links = require("Module:links") local lang = wmlang:getWiktionaryLanguage local ipalt = name .. " " .. (wmlang:getCode == "en" and "" or "" .. wmlang:getCode .. "") for i, link in ipairs(linkdata) do		link.lang = lang link.sc = sc link.term = prefix .. link.term link.tr = "-" table.insert(iplinks, "" .. ipalt .. " ") table.insert(links, m_links.full_link(link, "bold")) end return links, iplinks end

function export.wikipedia_box(frame) local params = { [1] = {},		[2] = {},		["cat"] = {}, ["category"] = {alias_of = "cat"}, ["i"] = {type = "boolean"}, ["lang"] = {default = "en"}, ["mul"] = {}, ["mullabel"] = {}, ["mulcat"] = {}, ["mulcatlabel"] = {}, ["portal"] = {}, ["sc"] = {}, }	local args = require("Module:parameters").process(frame:getParent.args, params) if args.mul or args.mullabel or args.mulcat or args.mulcatlabel then track("wikipedia-box-mul") end

local wmlang = require("Module:wikimedia languages").getByCodeWithFallback(args["lang"]) or error("The Wikimedia language code \"" .. args["lang"] .. "\" is not valid.") local sc = args["sc"] and require("Module:scripts").getByCode(args["sc"], "sc") or nil

local linkdata = {} if args["cat"] then table.insert(linkdata, {term = "Category:" .. args["cat"], alt = args[1] or args["cat"]}) elseif args["portal"] then table.insert(linkdata, {term = "Portal:" .. args["portal"], alt = args[1] or args["portal"]}) else local term = args[1] or mw.title.getCurrentTitle.text table.insert(linkdata, {term = term, alt = args[2] or term}) end if args["mul"] or args["mulcat"] then if args["mulcat"] then table.insert(linkdata, {term = "Category:" .. args["mulcat"], alt = args["mulcatlabel"] or args["mulcat"]}) else table.insert(linkdata, {term = args["mul"], alt = args["mullabel"] or args["mul"]}) end end local links, iplinks = process_links(linkdata, "w", "Wikipedia", wmlang, sc) if frame.args["slim"] then return "" .. " " .. "" .. " " ..			table.concat(links, " and ") .. " on " .. (wmlang:getCode == "en" and "" or wmlang:getCanonicalName .. " ") .. "Wikipedia" .. " " ..			" "	else local linktype if args["cat"] then linktype = "a category" elseif args["mul"] then linktype = "articles" elseif args["mulcat"] then linktype = "categories" elseif args["portal"] then linktype = "a portal" else linktype = "an article" end return "" .. " " .. "" .. wmlang:getCanonicalName .. " Wikipedia has " .. linktype .. " on:" .. "" .. table.concat(links, " and ") .. " " ..			" " ..			table.concat(iplinks) .. ((args[1] == mw.title.getCurrentTitle.text and not args[2]) and "" or "") .. " "	end end

function export.projectlink(frame, compat) local m_params = require("Module:parameters") local iparams = { ["prefix"] = {required = true}, ["name"] = {required = true}, ["image"] = {required = true}, ["requirelang"] = {type = "boolean"}, ["compat"] = {type = "boolean"}, }

iargs = m_params.process(frame.args, iparams) compat = compat or iargs.compat local lang_required = iargs.requirelang or false

local lang_param = compat and "lang" or 1 local term_param = compat and 1 or 2 local alt_param = compat and 2 or 3

local params = { [lang_param] = {required = lang_required}, [term_param] = {}, [alt_param] = {}, ["i"] = {type = "boolean"}, ["nodot"] = {}, ["sc"] = {}, }	local args = m_params.process(frame:getParent.args, params)

local wmlang = args[lang_param] or "en" wmlang = require("Module:wikimedia languages").getByCodeWithFallback(wmlang) or error("The Wikimedia language code \"" .. wmlang .. "\" is not valid.") local sc = args["sc"] and require("Module:scripts").getByCode(args["sc"], "sc") or nil

local term = args[term_param] or mw.title.getCurrentTitle.text local linkdata = {term = term, alt = args[alt_param] or term} if args["i"] then linkdata.alt = "''" .. linkdata.alt .. "''"	end local links, iplinks = process_links({linkdata}, iargs["prefix"], iargs["name"], wmlang, sc) return " " ..		table.concat(links, " and ") .. " on " .. (wmlang:getCode == "en" and "" or "the " .. wmlang:getCanonicalName .. " ") .. " " .. iargs["name"] .. (args["nodot"] and "" or ".") .. table.concat(iplinks) end

return export