Pergi ke kandungan

Modul:Lesen terjemahan

Daripada Wikisumber
--[=[
Implements [[Templat:Lesen terjemahan]]
]=]

local p = {} --p stands for package

local getArgs = require('Modul:Arguments').getArgs
local yesno = require('Modul:Yesno')

local license_scope = require('Modul:License_scope')._license_scope
local categoryHandler = require('Modul:Category handler').main

local namespace = mw.title.getCurrentTitle().nsText

function p._license_collapsible_container(args)
	-- license table
	local license_rows = {}
	for k = 1, #args, 2 do
		local header = args[k] or ''
		local license = args[k + 1] or ''
		license_rows[(k + 1)/2] = '<tr><th scope="row">' .. header .. '</th><td>' .. license .. '</td></tr>'
	end
	local tag_table = '<table id="licenseTags" class="mw-collapsible-content">' .. table.concat(license_rows, '') .. '</table>'
	
	-- license container
	local frame = mw.getCurrentFrame()
	local container_begin = frame:expandTemplate {
		['title'] = 'Kotak lesen mula',
		['args'] = {
			['images'] = args.images,
			['message'] = args.message
		}
	}
	local container_end = frame:expandTemplate {
		['title'] = 'Kotak lesen tamat'
	}
	
	return container_begin .. tag_table .. container_end
end

function p.license_collapsible_container(frame)
	return p._license_collapsible_container(getArgs(frame))
end

function p._no_license(args)
	local scope = args.scope or 'content'
	local category = args.category or ''
	
	local text = "<p>'''Laman ini tidak menyediakan maklumat lesen untuk karya " .. scope .. ".'''</p><p style='font-size:83%;'>Jika tiada maklumat lesen diberikan, laman tersebut mungkin akan dihapuskan. Untuk membantu, sila lihat [[Bantuan:Tag hak cipta]] atau [[" .. tostring(mw.title.getCurrentTitle().talkPageTitle) .. "|berikan komen]].</p>" .. category
	
	local frame = mw.getCurrentFrame()
	return frame:expandTemplate {
		['title'] = 'license',
		['args'] = {
			['image'] = 'Ambox_warning_pn.svg',
			['class'] = 'warningLicenseContainer',
			['text'] = text
		}
	}
end

function p.no_license(frame)
	return p._no_license(getArgs(frame))
end

function p._translation_license(args)
	local frame = mw.getCurrentFrame()
	
	local original = args.original
	local translation = args.translation
	
	local trans_ns = namespace == "Translation" or namespace == "Translation talk"
	if not translation and trans_ns then
		translation = frame:expandTemplate {
			['title'] = 'GFDL/CC-BY-SA-3.0'
		}
	end
	
	-- images in title
	local images
	if not (original and translation) then
		images = '[[Fail:Copyright.svg|20px|link=]][[Fail:Achtung.svg|20px|link=]]'
	end
	
	-- text in title
	local message = args.message
	if not message then
		message = "Terjemahan ini tertakluk kepada lesen hak cipta berasingan daripada teks asalnya. Status hak cipta terjemahan hanya terpakai pada versi ini."
	end
	
	-- license tags
	if not original then
		original = p._no_license({
			['scope'] = 'asal',
			['cateogry'] = categoryHandler{
				['main'] = '[[Kategori:Kemungkinan pelanggaran hak cipta]]'
    		}
		})
	end
	
	if not translation then
		local category
		local noCatNamespaces = {
			['Help'] = true,
			['Help talk'] = true,
			['Template'] = true,
			['Template talk'] = true,
			['Wikisource'] = true,
			['Wikisource talk'] = true,
			['Category'] = true,
			['Category talk'] = true,
			['Module'] = true,
			['Module talk'] = true
		}
		if not noCatNamespaces[namespace] then
			category = '[[Kategori:Kemungkinan pelanggaran hak cipta]]'
		end
		translation = p._no_license({
			['scope'] = 'terjemahan',
			['category'] = category
		})
	end
	
	return p._license_collapsible_container({
		['images'] = images,
		['message'] = message,
		[1] = 'asal',
		[2] = original,
		[3] = 'terjemahan',
		[4] = translation
	})
end

function p.translation_license(frame)
	return p._translation_license(getArgs(frame))
end

return p