This module implements {{wikipedia}}
, {{slim-wikipedia}}
, {{pedia}}
and {{R:wp}}
, plus other-project templates similar to {{pedia}}
, including {{R:wbooks}}
, {{R:wnews}}
, {{R:wsource}}
, {{R:wquote}}
, {{R:wversity}}
and {{specieslite}}
.
local m_params = require("Module:parameters")
local concat = table.concat
local full_link = require("Module:links").full_link
local insert = table.insert
local export = {}
local function track(page)
require("Module:debug/track")("interproject/" .. page)
end
local function process_links(linkdata, prefix, name, wmlang, sc)
prefix = prefix .. ":" .. (wmlang:getCode() == "en" and "" or wmlang:getCode() .. ":")
local links = {}
local iplinks = {}
local lang = wmlang:getWiktionaryLanguage()
local ipalt = name .. " " .. (wmlang:getCode() == "en" and "" or "<sup>" .. wmlang:getCode() .. "</sup>")
for _, link in ipairs(linkdata) do
link.lang = lang
link.sc = sc
link.track_sc = true
link.no_nonstandard_sc_cat = true
link.tr = "-"
if link.fragment ~= nil then
link.alt = (link.alt or link.term) .. ' § ' .. link.fragment
end
link.term = prefix .. link.term
if link.alt == link.term then
link.alt = nil
end
insert(iplinks, "<span class=\"interProject\">]</span>")
insert(links, full_link(link, "bold"))
end
return links, iplinks
end
function export.wikipedia_box(frame)
local plain_param = {}
local params = {
= plain_param,
= plain_param,
= plain_param,
= {alias_of = "cat"},
= {type = "boolean"},
= {type = "wikimedia language", method = "fallback", default = "en"},
= plain_param,
= plain_param,
= plain_param,
= plain_param,
= plain_param,
= {type = "script"},
= plain_param
}
local args = m_params.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 = args
local sc = args
local linkdata = {}
if args then
insert(linkdata, {term = "Category:" .. args, alt = args or args})
elseif args then
insert(linkdata, {term = "Portal:" .. args, alt = args or args})
else
insert(linkdata, {term = args or mw.loadData("Module:headword/data").pagename,
alt = args,
fragment = args})
end
if args or args then
if args then
insert(linkdata, {term = "Category:" .. args, alt = args or args})
else
insert(linkdata, {term = args, alt = args})
end
end
local links, iplinks = process_links(linkdata, "w", "Wikipedia", wmlang, sc)
if frame.args then
return
"<div class=\"interproject-box sister-wikipedia sister-project noprint floatright\">" ..
"<div style=\"float: left;\">]</div>" ..
"<div style=\"margin-left: 15px;\">" ..
" " ..
concat(links, " and ") ..
" on " ..
(wmlang:getCode() == "en" and "" or wmlang:getCanonicalName() .. " ") ..
"Wikipedia" ..
"</div>" ..
"</div>" .. frame:extensionTag("templatestyles", "", {src="Module:interproject/style.css"})
else
local linktype
if args then
linktype = "a category"
elseif args then
linktype = "articles"
elseif args then
linktype = "categories"
elseif args then
linktype = "a portal"
else
linktype = "an article"
end
return
"<div class=\"interproject-box sister-wikipedia sister-project noprint floatright\">" ..
"<div style=\"float: left;\">]</div>" ..
"<div style=\"margin-left: 60px;\">" ..
wmlang:getCanonicalName() .. " ] has " .. linktype .. " on:" ..
"<div style=\"margin-left: 10px;\">" .. concat(links, " and ") .. "</div>" ..
"</div>" ..
concat(iplinks) .. ((args == mw.loadData("Module:headword/data").pagename and not args) and "]" or "") ..
"</div>" .. frame:extensionTag("templatestyles", "", {src="Module:interproject/style.css"})
end
end
function export.projectlink(frame, compat)
local plain_param = {}
local required = {required = true}
local boolean = {type = "boolean"}
local iparams = {
= required,
= required,
= required,
= boolean,
= boolean,
}
local 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 = {
= {type = "wikimedia language", method = "fallback", required = lang_required, default = "en"},
= plain_param,
= plain_param,
= boolean,
= plain_param,
= {type = "script"},
= plain_param
}
local args = m_params.process(frame:getParent().args, params)
local wmlang = args
local sc = args
local term = args or mw.loadData("Module:headword/data").pagename
local linkdata = {term = term, alt = args, fragment = args}
if args then
if linkdata.alt then
linkdata.alt = "''" .. linkdata.alt .. "''"
else
-- While it is true that the link module automatically removes italics from terms,
-- linkdata.term is used outside this module too (image link and "interProject" link)
linkdata.alt = "''" .. linkdata.term .. "''"
end
end
local links, iplinks = process_links({linkdata}, iargs, iargs, wmlang, sc)
return
" .. "|15px|link=" .. iargs .. ":" .. (wmlang:getCode() == "en" and "" or wmlang:getCode() .. ":") .. term .. "]] " ..
concat(links, " and ") ..
" on " ..
(wmlang:getCode() == "en" and "" or "the " .. wmlang:getCanonicalName() .. " ") ..
" " .. iargs .. (args and "" or ".") ..
concat(iplinks)
end
return export