Moduł:Licbox
Z Nonsensopedii, polskiej encyklopedii humoru
local function showContents(table)
local string = ""
for k, v in pairs(table) do
mw.log(k .. " = " .. v)
string = string .. type(k) .. " " .. k .. " = " .. v .. "\n"
end
return string
end
local function getLicboxType(type)
local types =
{
none = "none",
cc = "cc",
pd = "pd",
["copyrighted-free"] = "free",
free = "free",
restricted = "info",
info = "info",
gnu = "default"
}
return types[type] or "default"
end
function getMetadataTable(licenseName, args) -- args opcjonalne
local isCCLicense = licenseName:find("CC") ~= nil
local metadataTable
if not isCCLicense then
local licenseList = require("Moduł:Lista licencji")
if licenseList[mw.ustring.upper(licenseName)] ~= nil then
metadataTable = licenseList[mw.ustring.upper(licenseName)].metadata
end
else
local CCTemplates = require("Moduł:Szablony CC")
metadataTable = CCTemplates.getMetadata(licenseName, args["atrybucja"] or "").metadata
end
return metadataTable
end
local function setSMWProperties(args, licenseName)
local props = {}
props["Ma tekst licencji"] = args["2"]
props["Ma niesformatowany tekst licencji"] = args["3"]
if args["grafika"] ~= nil then
props["Ma grafikę (szablon licencji)"] = args["grafika"]
end
props["Ma typ licencji"] = getLicboxType(args["typ"])
local metadataTable = getMetadataTable(licenseName, args)
props["Ma krótką nazwę licencji"] = metadataTable["licensetpl_short"]
props["Ma długą nazwę licencji"] = metadataTable["licensetpl_long"]
props["Wymaga atrybucji"] = metadataTable["licensetpl_attr_req"] == "true"
props["Wymaga linku do tekstu licencji"] = metadataTable["licensetpl_link_req"] == "true"
props["Jest licencją niewolną"] = metadataTable["licensetpl_nonfree"] == "true"
if metadataTable["licensetpl_link"] ~= nil then
props["Ma link do licencji"] = metadataTable["licensetpl_link"]
end
if metadataTable["licensetpl_attr"] ~= nil then
props["Ma atrybucję"] = metadataTable["licensetpl_attr"]
end
if metadataTable["wikidataID"] ~= nil then
props["Ma identyfikator wikidanych"] = metadataTable["wikidataID"]
end
mw.smw.set(props)
end
local p = {}
local tools = require("Moduł:Narzędzia")
local licenseTools = require("Moduł:Narzędzia licencyjne")
function p._getCode(args, templateName)
local licenseName = mw.text.trim(args["1"])
templateName = templateName or args["templatename"]
local code = ""
if args["mini"] ~= nil then
code = "<table style='margin: 0;' data-template='" .. templateName .. "' class='licbox licbox-mini licbox-"
code = code .. getLicboxType(args["typ"])
code = code .. "'><tr><td class='licname' style='text-align: left; padding-left: 1px;' title='"
if args["3"] ~= nil then
code = code .. args["3"]
else
code = code .. args["2"]
end
code = code .. "'>"
-- w miarę ładne elementy HTML informujące o modyfikatorach
local domniemanieHTML = '<abbr class="domniemanie" title="Licencja domniemana">[[Plik:Aiga_information.png|20px|link=]]</abbr>'
local copydownHTML = '<abbr class="copydown" title="Licencja copydown">[[Plik:Copydown.png|20px|link=]]</abbr>'
-- ten cały klocek kodu jest po to, żeby była zachowana odpowiednia kolejność modyfikatorów
if args["domniemanie"] and args["copydown"] then
if args["domniemanie"] < args["copydown"] then
code = code .. domniemanieHTML .. " " .. copydownHTML .. " "
else
code = code .. copydownHTML .. " " .. domniemanieHTML .. " "
end
else
if args["copydown"] then
code = code .. copydownHTML .. " "
end
if args["domniemanie"] then
code = code .. domniemanieHTML .. " "
end
end
code = code .. "<b>" .. mw.ustring.upper(licenseName) .. "</b></td></tr></table>"
else
code = "<table style='margin: 0;' data-template='" .. templateName .. "' class='licbox licbox-"
code = code .. getLicboxType(args["typ"])
code = code .. "'><tr>"
if args["grafika"] ~= nil then
code = code .. "<td class='licbox-grafika' style='padding: 5px; text-align: center;'>" .. args["grafika"] .. "</td>"
end
code = code .. "\n<td style='padding: 5px;'>" .. args["2"] .. "</td>\n</tr><tr><td class='licname' "
if args["grafika"] ~= nil then
code = code .. "colspan='2'"
end
code = code .. ">'''<span class='licensetpl_short'><b>" .. mw.ustring.upper(licenseName) .. "</b></span>'''</td></tr></table>"
--[[ metadata
SZABLONY, KTÓRE NIE POWINNY MIEĆ METADANYCH:
* domniemanie
* copydown
* self
* free-screenshot
]]--
if mw.ustring.lower(templateName) == "domniemanie" or mw.ustring.lower(templateName) == "copydown" then
-- modifier template, no metadata
return code
end
local isCCLicense = licenseName:find("CC") ~= nil
local metadataTable
if not isCCLicense then
local licenseList = require("Moduł:Lista licencji")
if licenseList[mw.ustring.upper(licenseName)] ~= nil then
metadataTable = licenseList[mw.ustring.upper(licenseName)].metadata
else
mw.logObject(mw.ustring.upper(licenseName))
mw.logObject(licenseList)
end
else
local CCTemplates = require("Moduł:Szablony CC")
metadataTable = CCTemplates.getMetadata(licenseName, args["atrybucja"]).metadata
end
if metadataTable == nil then
-- error("Licencja " .. licenseName .. " nie jest zdefiniowana w Moduł:Lista licencji")
mw.smw.set({["Nie ma metadanych"] = true})
local function wrap(tag, text)
return "<" .. tag .. ">" .. text .. "</" .. tag .. ">"
end
code = code .. wrap("big", wrap("big", wrap("big", wrap("big", "NIE MA PODANYCH METADANYCH!!!"))))
return code
end
local metadata = ""
for name, value in pairs(metadataTable) do
metadata = metadata .. "<span class='" .. name .. "'>" .. "<nowiki>" .. value .. "</nowiki>" .. "</span>"
end
-- atrybucja
if args["atrybucja"] then
metadata = metadata .. "<span class='licensetpl_attr'>" .. args["atrybucja"] .. "</span>"
end
metadata = "<div class='licensetpl_wrapper' style='display:none'>" .. metadata .. "</div>"
code = code .. metadata
end
-- jeśli jesteśmy na stronie szablonu licencji
if (mw.title.getCurrentTitle().text == templateName) or true then
setSMWProperties(args, licenseName)
end
return code
end
function p.run(frame)
local args = tools.getArgs(frame)
local code = p._getCode(args, mw.ustring.lower(frame:getParent():getTitle()))
if args["demo"] ~= nil then
return frame:preprocess(code)
end
return code
end
return p