모듈:출생지

최근 편집: 2019년 12월 10일 (화) 16:11
낙엽1124 (토론 | 기여)님의 2019년 12월 10일 (화) 16:11 판 (태어난 곳 지정 안 되어 있을 때 빈 문자열 반환, 속성 아이디 사용)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

이 모듈에 대한 설명문서는 모듈:출생지/설명문서에서 만들 수 있습니다

p = {}

local entity, qid

local function makeLink(id)
  local wt = mw.wikibase.getLabel(id)
  local title = mw.wikibase.getSitelink( id )

  if title then
    wt = '[[' .. title .. '|' .. wt .. ']]'
  end

  return wt
end

local function getCountry( placeId )
  local country = mw.wikibase.getBestStatements(placeId, 'P11')[1]
  if not country then return nil end
  local countryId = country.mainsnak.datavalue.value.id

  return makeLink(countryId)
end

function p.main(frame)
  local args = frame.args[1] ~= nil and frame.args or frame:getParent().args
  
  entity = mw.wikibase.getEntity()
  qid = mw.wikibase.getEntityIdForCurrentPage()
  local place = entity:getBestStatements( 'P10' )[1]
  if not place then return '' end
  local placeId = place.mainsnak.datavalue.value.id

  local placeId = place.mainsnak.datavalue.value.id
  local country = getCountry(placeId)
  
  if country then
    return country .. ', ' .. makeLink(placeId)
  end
  return makeLink(placeId)
end

return p