跳去內容

模組:Infobox artist

出自維基百科,自由嘅百科全書
模組解[]
--呢個模組用嚟執行 {{Infobox artist}} 模
--稍後會將 {{藝人}} 模亦改為通過呢個模組執行,但藝人明細模結構較為複雜,要實現需要更長時間。
--請將新增參數加落模組:Infobox artist/parameterList
--由Dabao qian喺2016年12月19號自中文維基百科引入。

local p = {}

local getArgs = require('Module:Arguments').getArgs

local infobox = require('Module:Infobox').infobox

local parameterList = mw.loadData('Module:Infobox artist/parameterList')

local function getData(args, idx)
	for _, v in ipairs(parameterList[idx]) do
		if args[v] then	return args[v] end
	end
end

function p.artist(frame)
	local args = getArgs(frame)
	return p._artist(args)
end

function p._artist(args)
	-- 艺术家信息框模板。
	local list = {}
	local cont = 5
	
	list.bodyclass = 'vcard plainlist'
	list.bodystyle = 'width:275px; font-size: 95%;'
	
	list.above = (mw.getCurrentFrame():expandTemplate({ 
		title = 'Br separated entries', 
		args = { 
			(args.honorific_prefix and
    			'<span class="honorific-prefix" style="font-size:77%; font-weight:normal;">' .. args.honorific_prefix .. '</span>' or ''),
    		'<span class=fn">' .. (getData(args, 'name') or mw.title.getCurrentTitle().baseText) .. '</span>',
		 	(args.honorific_suffix and
    			'<span class="honorific-suffix" style="font-size:77%; font-weight:normal;">' .. args.honorific_suffix .. '</span>' or ''),
		} }))
	
	list.abovestyle = 'text-align: center; font-size: 120%; background:' .. (getData(args, 'death_date') and 'silver;' or (getData(args, 'death_place') and 'silver;' or '#6495ED;') )
	list.headerstyle = 'background:' .. (getData(args, 'death_date') and 'silver;' or (getData(args, 'death_place') and 'silver;' or '#6495ED;') )
	list.labelstyle = 'white-space:nowrap;'
	
	list.image = require('Module:InfoboxImage').InfoboxImage{ args = { 
		image = getData(args, 'image'),
		size = getData(args, 'image_size'),
		sizedefault = 'frameless',
		upright = '1',
		alt = args.alt,
		suppressplaceholder = yes,
	} }
	list.caption = list.image and getData(args, 'caption')
	
	list.header1 = '藝術家'
	
	list.label2 = '原文名'
	list.data2 = (args.native_name and
		'<span class="nickname"' .. (args.native_name_lang and ' lang="' .. args.native_name_lang .. '" "xml:lang="' .. args.native_name_lang .. '"' or '') .. '>' .. args.native_name .. '</span>' or '')
	
	list.label3 = '出世'
	list.data3 = (mw.getCurrentFrame():expandTemplate({
		title = 'Br separated entries',
		args = {
			(getData(args, 'birth_name') and
				'<span class="nickname">' .. getData(args, 'birth_name') .. '</span>' or ''),
			getData(args, 'birth_date'),
			(getData(args, 'birth_place') and
				'<span class="birthplace">' .. getData(args, 'birth_place') .. '</span>' or ''),
			} } ))
	
	list.label4 = '死'
	list.data4 = (mw.getCurrentFrame():expandTemplate({
		title = 'Br separated entries',
		args = {
			getData(args, 'death_date'),
			(getData(args, 'death_place') and
				'<span class="deathplace">' .. getData(args, 'death_place') .. '</span>' or ''),
			} } ))
	
	list.label5 = '墓地'
	list.data5 = (mw.getCurrentFrame():expandTemplate({
		title = 'Br separated entries',
		args = {args.resting_place, args.resting_place_coordinates}
		} ))
	
	for i, v in ipairs(parameterList) do
		local data = getData(args, i)
		if data then
			cont = cont + 1
			list['data'..cont] = data
			list['label'..cont] = v.label
			list['header'..cont] = v.header
		end
	end
	
	list.class1 = 'title role'
	list.class5 = 'label'
	list.class6 = 'category'
	list.class11 = 'category'
	list.class12 = 'category'
	list.class14 = 'note'
	list.class15 = 'org'
	list.rowclass17 = 'note'
	list.class18 = 'url'
	
	return infobox(list) .. (mw.getCurrentFrame():expandTemplate({
		title = 'Wikidata image',
		args = {getData(args, 'image')}
		} ))
end

return p