Modül:Bilgikutusu karakter/ad

Westeros Türkiye Vikipedi sitesinden
15.29, 19 Ekim 2023 tarihinde Targario (mesaj | katkılar) tarafından oluşturulmuş 19281 numaralı sürüm

Bu modül için bir Modül:Bilgikutusu karakter/ad/belge belgelendirmesi oluşturabilirsiniz

local getArgs = require('Module:Bağımsız değişkenler').getArgs
local yesno = require('Module:Yesno')
local infobox_image = require('Module:InfoboxImage').InfoboxImage
local br = require('Module:Separated entries').br
local roman = require('Module:Roman').main
local coa = require('Module:Coa/core').main

local function split(inputstr, sep)
  -- This function splits a string by the given separating character
  sep = sep or '%s'
  local t = {}
  for field, s in mw.ustring.gmatch(inputstr, "([^" .. sep .. "]*)(" .. sep .. "?)") do
    table.insert(t, field)
    if s == "" then
      return t
    end
  end
end

local function is_empty(s)
  -- This function checks whether a string is empty
  return s == nil or s == ''
end

local function overspecified_arms(arms)
  arms = mw.ustring.lower(arms)
  local patterns = {
    "^%[%[file:",
    "%|.*%]%]$",
    "^house ",
    "^coin of",
    "%.png$",
    "%.svg$",
    "%.jpe?g$",
    "^none",
  }
  for _, pattern in pairs(patterns) do
    if mw.ustring.find(arms, pattern) then
      return "[[Category:Character pages with overspecified arms]]"
    end
  end
  return ""
end

local function generate_arms(arms, size)
  --This function generates small coat of arms icons
  return coa{
    arms,
    format = 'image',
    size = size or 'infobox-l',
  } .. overspecified_arms(arms)
end

local p = {}

function p.main(frame)
  local MAX_ARMS = 5
  local args = getArgs(frame)
  args.arms1 = args.arms1 or args.arms or args.arma

  local template = args.nametemplate or nil
  local regnalnumber = args.regnalnumber or ""
  local lastfirst = yesno(args.lastfirst) -- whether last name comes before first name

  local name_parts = {}
  name_parts.fullname = args.name or args.fullname or args.karakteradi or ""
  name_parts.title = args.title or args.unvan or ""
  name_parts.nickname = args.nickname or args.lakap or ""
  name_parts.firstname = args.firstname or args.ad or ""
  name_parts.particle = args.particle or ""
  name_parts.lastname = args.lastname or args.soyad or ""
  name_parts.epithet = args.epithet or args.sifat or ""
  name_parts.romanregnalnumber = roman({ regnalnumber }) or ""

  local categories = {}

  if is_empty(template) then
    if not is_empty(name_parts.firstname) then
      if not is_empty(name_parts.lastname) then
        if lastfirst then
          template = 'title/nickname-lastname-particle-firstname-romanregnalnumber/epithet'
        else
          template = 'title/nickname-firstname-romanregnalnumber-particle-lastname/epithet'
        end
      else
        template = 'title/nickname-firstname-epithet/'
      end
    elseif not is_empty(name_parts.lastname) then
      template = '/nickname-title-particle-lastname/epithet'
    elseif not is_empty(name_parts.nickname) then
      template = '/title-nickname/epithet'
    elseif not is_empty(name_parts.title) then
      template = '/title/epithet'
    elseif not is_empty(name_parts.epithet) then
      template = '/epithet/'
    elseif not is_empty(name_parts.fullname) then
      template = '/fullname/'
      categories = {"Eski sözdizimi adına sahip karakter sayfaları"}
    end
  else
    table.insert(categories, "Character pages with custom nametemplate")
  end

  -- Parse name template to get the above, core, and below texts
  local above_template, core_template, below_template = unpack(split(template, '/'))
  local above = ''
  for _, part in pairs(split(above_template, '-')) do
    if not is_empty(name_parts[part]) then
      above = above .. ' ' .. name_parts[part]
    end
  end
  local core = ''
  for _, part in pairs(split(core_template, '-')) do
    if not is_empty(name_parts[part]) then
      core = core .. ' ' .. name_parts[part]
    end
  end
  local below = ''
  for _, part in pairs(split(below_template, '-')) do
    if not is_empty(name_parts[part]) then
      below = below .. ' ' .. name_parts[part]
    end
  end
  -- Build above and below texts and full name
  local above_span = ""
  if not is_empty(above) then
    above_span = mw.html.create('span')
    above_span:css('font-size', '80%')
              :css('font-weight', 'normal')
              :wikitext(above)
  end
  local below_span = ""
  if not is_empty(below) then
    below_span = mw.html.create('span')
    below_span:css('font-size', '80%')
              :css('font-weight', 'normal')
              :wikitext(below)
  end
  local name = br({
    tostring(above_span),
    core,
    tostring(below_span),
  })

  local complete_name
  -- The module looks different based on the number of arms to display
  if args.arms1 and args.arms2 and args.arms3 then
    -- Three or more arms
    complete_name = mw.html.create('div')
    complete_name:css('text-align', 'justify')
                 :css('text-justify', 'distribute-all-lines')
    local coasize
    if is_empty(args.arms4) then
      coasize = 'infobox-m'
      table.insert(categories, "Character pages with 3 coats of arms")
    else
      coasize = 'infobox-s'
      table.insert(categories, "Character pages with 4+ coats of arms")
    end
    for i=1,MAX_ARMS do
      local arms = args['arms' .. tostring(i)]
      if arms then
        complete_name:wikitext(generate_arms(arms, coasize))
                     :wikitext(" ")
      end
    end
    complete_name:tag('span')
                 :css('display', 'inline-block')
                 :css('width', '100%')
                 :css('text-align', 'center')
                 :wikitext(name)
  elseif args.arms1 then
    -- One or two arms
    local arms1 = args.arms1
    local arms2
    if is_empty(args.arms2) then
      arms2 = args.arms1
      table.insert(categories, "Character pages with 1 coat of arms")
    else
      arms2 = args.arms2
      table.insert(categories, "Character pages with 2 coats of arms")
    end
    complete_name = mw.html.create('table')
    complete_name:css('width', '100%')
                 :tag('tr')
                 :tag('td'):css('border', 'none')
                 :css('vertical-align', 'top')
                 :css('text-align', 'left')
                 :css('width', '50px')
                 :wikitext(generate_arms(arms1))
                 :done()
                 :tag('td'):css('border', 'none')
                 :css('vertical-align', 'middle')
                 :css('text-align', 'center')
                 :css('padding-bottom', '5px')
                 :wikitext(name)
                 :done()
                 :tag('td'):css('border', 'none')
                 :css('vertical-align', 'top')
                 :css('text-align', 'right')
                 :css('width', '50px')
                 :wikitext(generate_arms(arms2))
  else
    -- No arms
    complete_name = name
    if categories[1] == "Character pages with new syntax name" then
      table.insert(categories, "Character pages with 0 coats of arms")
    end
  end

  -- Add all categories
  complete_name = tostring(complete_name)
  for _, category in pairs(categories) do
    complete_name = complete_name .. "[[Category:" .. category .. "]]"
  end
  return complete_name
end

return p