Module:File license: Difference between revisions

From Tardis Wiki, the free Doctor Who reference
No edit summary
No edit summary
Line 13: Line 13:
local intent = args["intent"] or "to illustrate articles"
local intent = args["intent"] or "to illustrate articles"
local tentative = args["tentative"] or ""
local tentative = args["tentative"] or ""
local ownWork = args["ownWork"] or ""
if tentative == "false" then
if tentative ~= "" then
tentativeText = "It is believed that use"
tentativeText = "It is believed that use"
else
else
Line 62: Line 63:
local finalLicense = '<div id="license">' .. imageCode .. "This file is " .. typeOfFileArticle .. " '''" .. typeOfFile .. "'''" .. sourceText .. ". It's copyright is owned by " .. copyrightHolderText .. ".<br/>" .. tentativeText .. " of this " .. typeOfFile .. " " .. intent .. " on Tardis Wiki, hosted on servers in __ by Wiki Federation, " .. licenseText .. '<span style="display:none;" ' .. licenseMachinedata .. "</span></div>"
local finalLicense = '<div id="license">' .. imageCode .. "This file is " .. typeOfFileArticle .. " '''" .. typeOfFile .. "'''" .. sourceText .. ". It's copyright is owned by " .. copyrightHolderText .. ".<br/>" .. tentativeText .. " of this " .. typeOfFile .. " " .. intent .. " on Tardis Wiki, hosted on servers in __ by Wiki Federation, " .. licenseText .. '<span style="display:none;" ' .. licenseMachinedata .. "</span></div>"
if ownWork ~= "" then
finalLicense = '<div style="padding:5px;" id="license">I, the copyright holder of this work, hereby publish it under the following license:' .. finalLicense .. "</div>"
end
return finalLicense
return finalLicense
end
end


return p
return p

Revision as of 20:20, 4 March 2024

Documentation for this module may be created at Module:File license/doc

local p = {} --p stands for package
local h = {} --h stands for helper

function p.makeLicense(frame)
	local args = frame:getParent().args
	
	local image = args["image"] or ""
	local imageSize = tonumber(args["imageSize"]) or 80
	local typeOfFile = args["typeOfFile"] or "image"
	local source = args["source"] or ""
	local license = args["license"] or ""
	local copyrightHolder = args["copyrightHolder"] or ""
	local intent = args["intent"] or "to illustrate articles"
	local tentative = args["tentative"] or ""
	local ownWork = args["ownWork"] or ""
	
	if tentative ~= "" then
		tentativeText = "It is believed that use"
	else
		tentativeText = "Use"
	end
	
	local typeOfFileArticle = "a"
	local vowels = {["a"] = true, ["e"] = true, ["i"] = true, ["o"] = true, ["u"] = true}
	if vowels[string.sub(typeOfFile, 1, 1)] then
		typeOfFileArticle = "an"
	end
	
	local sourceText = ""
	if source ~= "" then
		sourceText = " from " .. source
	end
	
	local imageCode = ""
	if image ~= "" then
		imageCode = '<span style="margin-top:5px;float:left;margin-right:10px;">[[File:' .. image .. '|' .. tostring(imageSize) .. "px]]</span>"
	else
		local imageData = mw.loadData("Module:File license/data/images")
		if imageData[copyrightHolder] then
			imageCode = '<span style="margin-top:5px;float:left;margin-right:10px;">[[File:' .. imageData[copyrightHolder] .. '|' .. tostring(imageSize) .. "px]]</span>"
		end
	end
	
	local copyrightHolderText = ""
	if copyrightHolder ~= "" then
		local copyrightHolderData = mw.loadData("Module:File license/data/copyright holders")
		if copyrightHolderData[copyrightHolder] then
			copyrightHolderText = frame:preprocess(copyrightHolderData[copyrightHolder])
		elseif copyrightHolderDisplay then
			copyrightHolderText = "[[" .. copyrightHolder .. "|" .. copyrightHolderDisplay .. "]]"
		else
			copyrightHolderText = copyrightHolder
		end
	end
	
	local licenseData = mw.loadData("Module:File license/data/licenses")
	local licenseText = ""
	local licenseMachinedata = ""
	if licenseData[license] then
		licenseText = frame:preprocess(licenseData[license][1])
		licenseMachinedata = 'class="licensetpl"><span class="licensetpl_short">' .. licenseData[license][2] .. '</span><span class="licensetpl_long">' .. licenseData[license][3] .. '</span><span class="licensetpl_link">' .. frame:preprocess("<nowiki>" .. licenseData[license][4] .. "</nowiki>") .. '</span><span class="licensetpl_link_req">' .. licenseData[license][5] .. '</span><span class="licensetpl_attr_req">' .. licenseData[license][6] .. '</span><span class="licensetpl_attr">' .. copyrightHolderText .. '</span><span class="licensetpl_nonfree">' .. licenseData[license][7] .. '</span>'
	end
	
	local finalLicense = '<div id="license">' .. imageCode .. "This file is " .. typeOfFileArticle .. " '''" .. typeOfFile .. "'''" .. sourceText .. ". It's copyright is owned by " .. copyrightHolderText .. ".<br/>" .. tentativeText .. " of this " .. typeOfFile .. " " .. intent .. " on Tardis Wiki, hosted on servers in __ by Wiki Federation, " .. licenseText .. '<span style="display:none;" ' .. licenseMachinedata .. "</span></div>"
	
	if ownWork ~= "" then
		finalLicense = '<div style="padding:5px;" id="license">I, the copyright holder of this work, hereby publish it under the following license:' .. finalLicense .. "</div>"
	end
	return finalLicense
end

return p