< 모듈:요약정보
이 모듈에 대한 설명문서는 모듈:요약정보/호환/설명문서에서 만들 수 있습니다
local p = {}
local function clean(value)
if value == nil then
return nil
end
value = mw.text.trim(tostring(value))
if value == '' then
return nil
end
return value
end
local function first(args, keys)
for _, key in ipairs(keys) do
local value = clean(args[key])
if value then
return value
end
end
return nil
end
local function combine(a, b)
if a and b then
return a .. '<br />' .. b
end
return a or b
end
local function getArgs(frame)
local parent = frame:getParent()
if parent then
for key, value in pairs(parent.args) do
if clean(value) then
return parent.args
end
end
end
return frame.args
end
local FIELD_MAP = {
{'본명', {'본명', '출생명', 'birth_name'}},
{'사인', {'사망원인', 'death_cause'}},
{'발견지', {'발견지', 'body_discovered'}},
{'거주지', {'거주지', 'residence'}},
{'성별', {'성별'}},
{'국적', {'국적', '국가', 'nationality'}},
{'민족', {'민족', 'ethnicity'}},
{'시민권', {'시민권', 'citizenship'}},
{'본관', {'본관', 'family clan'}},
{'별칭', {'별명', '별칭', 'other_names', 'othername', 'alias'}},
{'학력', {'대학', '모교', '학력', 'alma_mater'}},
{'경력', {'경력', '업적', '유명', 'known_for'}},
{'직업', {'직업', 'occupation', 'profession'}},
{'활동 영역', {'활동영역', '활동 영역'}},
{'활동 기간', {'활동기간', 'years_active', 'yearsactive'}},
{'관련 활동', {'관련활동'}},
{'고용주', {'고용주', 'employer'}},
{'소속', {'소속', 'organization', 'organizations'}},
{'현직', {'현직'}},
{'전직', {'전직'}},
{'봉급', {'봉급', 'salary'}},
{'순자산', {'순자산', 'net_worth', 'networth'}},
{'작위', {'작위', 'Peerage'}},
{'칭호', {'칭호', 'title'}},
{'칭호 기간', {'기간', '칭호기간', 'term'}},
{'전임자', {'전임자', 'predecessor'}},
{'후임자', {'후임자', 'successor'}},
{'정당', {'정당', 'party'}},
{'적수', {'적수', 'opponents'}},
{'위원', {'위원', 'boards'}},
{'등단', {'등단'}},
{'활동추가', {'활동추가'}},
{'종교', {'종교', 'religion'}},
{'키', {'키', '신장'}},
{'몸무게', {'몸무게', '체중'}},
{'모색', {'모색', '머리색깔'}},
{'눈 색깔', {'눈 색깔', '눈색깔'}},
{'신체 사이즈', {'신체사이즈', '쓰리사이즈'}},
{'드레스 사이즈', {'드레스사이즈', '드레스 사이즈'}},
{'부모', {'부모', 'parents'}},
{'형제', {'형제'}},
{'배우자', {'배우자', 'spouse'}},
{'자녀', {'자녀', 'children'}},
{'동거인', {'동거인', '연인', 'partner'}},
{'가족', {'가족', 'family'}},
{'친척', {'친척', 'relations', 'relatives'}},
{'병역', {'병역', 'army'}},
{'상훈', {'상훈', '수상', 'awards'}},
{'호출부호', {'호출부호', 'callsign'}},
{'각주', {'각주', 'footnotes'}},
{'기타', {'기타', 'misc'}},
{'웹사이트', {'웹사이트', '사이트', 'website'}},
{'추가', {'추가', '모듈'}},
{'추가2', {'추가2', '모듈2'}},
{'추가3', {'추가3', '모듈3'}}
}
function p.person(frame)
local source = getArgs(frame)
local result = {}
local order = {}
local handled = {}
local function mark(keys)
for _, key in ipairs(keys) do
handled[key] = true
end
end
local function setField(label, value)
value = clean(value)
if value then
result[label] = value
order[#order + 1] = label
end
end
local titleKeys = {'제목', '이름', 'name'}
local nativeKeys = {'원어이름', 'native_name'}
local imageKeys = {'그림', '사진', 'image'}
local sizeKeys = {'크기', '그림크기', 'image_size', 'imagesize'}
local captionKeys = {
'설명', '그림설명', 'caption', 'image_caption'
}
local altKeys = {'툴팁', '그림툴팁', 'alt'}
mark(titleKeys)
mark(nativeKeys)
mark(imageKeys)
mark(sizeKeys)
mark(captionKeys)
mark(altKeys)
local title = first(source, titleKeys)
local native = first(source, nativeKeys)
local image = first(source, imageKeys)
local size = first(source, sizeKeys) or '225px'
local caption = first(source, captionKeys)
local alt = first(source, altKeys)
if title then
result['제목'] = title
end
if native then
result['원제'] = native
end
if image == '값찾기' then
local success, value = pcall(function()
return frame:preprocess('{{#property:P18}}')
end)
if success then
image = clean(value)
else
image = nil
end
end
if image then
if alt and not image:match('^%[%[') then
local filename = image
:gsub('^파일:', '')
:gsub('^[Ff]ile:', '')
result['그림1'] =
'[[파일:' .. filename ..
'|' .. size ..
'|alt=' .. alt .. ']]'
else
result['그림1'] = image
end
result['그림1 크기'] = size
if caption then
result['그림1 설명'] = caption
end
end
local birthDateKeys = {'출생일', 'birth_date'}
local birthPlaceKeys = {'출생지', 'birth_place'}
local deathDateKeys = {'사망일', 'death_date'}
local deathPlaceKeys = {'사망지', 'death_place'}
local restingKeys = {
'매장지', 'resting_place', 'restingplace'
}
local restingCoordinateKeys = {
'매장지좌표', 'resting_place_coordinates'
}
mark(birthDateKeys)
mark(birthPlaceKeys)
mark(deathDateKeys)
mark(deathPlaceKeys)
mark(restingKeys)
mark(restingCoordinateKeys)
local birth = combine(
first(source, birthDateKeys),
first(source, birthPlaceKeys)
)
local death = combine(
first(source, deathDateKeys),
first(source, deathPlaceKeys)
)
local resting = combine(
first(source, restingKeys),
first(source, restingCoordinateKeys)
)
local specialFields = {
['출생'] = birth,
['사망'] = death,
['매장지'] = resting
}
setField(
'본명',
first(source, FIELD_MAP[1][2])
)
setField('출생', specialFields['출생'])
setField('사망', specialFields['사망'])
for index, spec in ipairs(FIELD_MAP) do
mark(spec[2])
if index > 1 then
if spec[1] == '거주지' then
setField('매장지', resting)
end
setField(spec[1], first(source, spec[2]))
end
end
local signatureKeys = {'서명', 'signature'}
mark(signatureKeys)
local signature = first(source, signatureKeys)
if signature then
if not signature:match('^%[%[') then
signature = signature
:gsub('^파일:', '')
:gsub('^[Ff]ile:', '')
signature =
'[[파일:' .. signature .. '|128px]]'
end
setField('서명', signature)
end
local ignored = {
'제목모양',
'항목순서',
'home_town'
}
mark(ignored)
local colorKeys = {
'표배경색',
'표글씨색',
'테두리색',
'제목배경색',
'제목글씨색',
'항목배경색',
'항목글씨색',
'값배경색',
'값글씨색',
'이미지배경색',
'이미지글씨색',
'추가정보배경색',
'추가정보글씨색',
'하단배경색',
'하단글씨색',
'배경색상코드',
'글씨색상코드'
}
mark(colorKeys)
for _, key in ipairs(colorKeys) do
if clean(source[key]) then
result[key] = clean(source[key])
end
end
local extraKeys = {}
for key, value in pairs(source) do
if type(key) == 'string' then
local normalizedKey = clean(key)
if normalizedKey
and not handled[normalizedKey]
and clean(value)
and not result[normalizedKey]
then
extraKeys[#extraKeys + 1] = normalizedKey
end
end
end
table.sort(extraKeys)
for _, key in ipairs(extraKeys) do
setField(key, source[key])
end
result['항목순서'] = table.concat(order, ',')
return frame:expandTemplate({
title = '요약정보',
args = result
})
end
return p