Module:Do not move to Commons

Module documentation[view] [edit] [history] [purge]

Implements {{Do not move to Commons}}.

--[=[
Implements [[Template:Do not move to Commons]]
]=]

local p = {} --p stands for package

local getArgs = require('Module:Arguments').getArgs
local yesno = require('Module:Yesno')
local messageBox = require('Module:Message box').main

function p._do_not_move_to_commons(args)
	local localyear = tonumber(os.date("%Y"))
	local namespace = mw.title.getCurrentTitle().nsText
	
	local expiry = args.expiry or args.expire or args.expires or args['until']
	-- hacky, needs to handle non-math input into expr better
	if expiry and tonumber(string.sub(expiry, 1, 1)) then
		expiry = tonumber(mw.ext.ParserFunctions.expr(tostring(expiry)))
	else
		expiry = nil
	end
	
	local has_expired = expiry and expiry < localyear
	local why = args.why or args.reason
	local test = yesno(args.test or 'no')
	
	local text = "<p><strong>Do not copy this file to Wikimedia Commons.</strong></p>"
	if test then
		text = text .. "<p>" .. (why or "This is a temporary or test file, or otherwise only relevant to English Wikisource, and therefore [[commons:Commons:Project scope|out of scope]] for [[commons:main page|Wikimedia Commons]].") .. "</p>"
	else
		text = text .. "<p>This file is in the [[w:public domain|public domain]] in the [[w:United States|United States]] but " .. (why or "<strong>not in its country of origin</strong>") .. ". [[commons:main page|Wikimedia Commons]] only accepts files that are in the public domain (or otherwise [[commons:Commons:Licensing|freely licensed]]) in both the country of origin and the United States.</p><p style='font-size:83%;'>For more details, see [[Commons:Commons:Licensing|Commons:Licensing]], [[Wikipedia:Public domain]], [[Wikipedia:Copyrights]] and [[Template talk:PD-US|talk for the PD-US license template]].</p>"
	end
	if expiry then
		text = text .. "<p style='font-size:83%;'>This message expires at the end of " .. expiry .. ".</p>"
	end
	
	local category
	local nocat = yesno(args.parent) or yesno(args.nocat) or yesno(args.demo) or (namespace ~= "File" and namespace ~= "Category")
	if nocat then
		category = ""
	elseif has_expired then
		category = "[[Category:Media now suitable for Commons]]"
	elseif expiry then
		category = "[[Category:Media not suitable for Commons/" .. expiry .. "]]"
	elseif test then
		category = "[[Category:Media not suitable for Commons/test]]"
	else
		category = "[[Category:Media not suitable for Commons/not listed]]"
	end
	
	-- check if invocation uses numbered parameters, since those aren't supported
	local has_unnamed_parameters = false
	for k, v in pairs(args) do
		if tonumber(k) then
			has_unnamed_parameters = true
		end
	end
	if has_unnamed_parameters then
		category = category .. "[[Category:Do not move to Commons usage with unnamed parameters]]"
	end
	
	if has_expired then
		return category
	else
		return messageBox(
			"imbox",
			{
				['type'] = "style",
				['imageright'] = '<span style="line-height:50%; text-align:center;">[[File:PD-icon.svg|40px|link=|Public license]]<br><br>[[File:Flag of the United States.svg|50px|link=|Flag of the United States]]</span>',
				['text'] = text .. category
			}
		)
	end
end

function p.do_not_move_to_commons(frame)
	local args = getArgs(frame)
	return p._do_not_move_to_commons(args)
end

return p