Module:Infobox 🔗


From VEDA Wiki
Jump to: navigation, search

Documentation for this module may be created at Module:Infobox/doc

local p = {} -- p stands for package

-- Обработчик для групповых параметров "синонимы" в Шаблон:Артефакт Шаблон:Гипотеза Шаблон:Местность Шаблон:Организация Шаблон:Персона Шаблон:Пирамида Шаблон:Событие 
function p.synonyms( frame )
  local t = {}
  local interwiki_links = {}
  local name = frame.args[1]
  local listitem = frame.args['listitem'] == 'true' and '<br>' or '; ' -- additional param for items lists
  if #name == 0 then
    return ''
  end

  for i in string.gmatch(name, "[^;]+") do
    if string.match(i, ":") then
      table.insert(interwiki_links, "[[" .. i .. "]]")
--    table.insert(t, "[[" .. i .. "]]")
    end
    table.insert(t, "[[" .. string.gsub(i,'.*%:(.*)','%1') .. "]]")
  end

  --table.insert(t, ")")
  local out = table.concat(t, listitem)
  if listitem == '; ' then
    out = "(" .. out
    out = out .. ")" .. table.concat(interwiki_links, '')
  end
  return out
end



-- Обработчик для Шаблон:Событие
function p.event_members( frame )
  local name = frame.args[1]
  local count = 0 -- computes overall amount of members as 1 per person or as number in 'Количество' field
  local t = {[=[<table border=0>
<tr><td colspan=2>
<div {{DivWrapOpts}}>[[Category:WrapBlock]]
<table border=0 width=100%><tr><td colspan="2" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold; text-align: center;">Members</td></tr></table>
<div class="mw-collapsible-content">
<table border=0>
]=]}

  for i in string.gmatch(name, "[^;]+") do repeat
-- continue if line is "empty" (namely is "!!!;" or only ";") see: https://forum.defold.com/t/any-replace-for-continue-statement-in-lua-loops/65554/2
    if #i <6 then
      do break end
    end

    local field2 = ''
    local field3 = ''
    table.insert(t, [=[<tr>
  <td colspan="2" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold; text-align: center;">Member</td>
</tr>]=])

    local l = {}
    for k in string.gmatch(i, "[^!]+") do
      table.insert(l, k:match( "^%s*(.-)%s*$" ))
    end

    if l[2] == nil or l[2] == '' or l[2] == ' ' then
      field2 = ''
    else
      field2 = [=[<tr>
  <td colspan="2"><hr></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Category:</td>
  <td>]=] .. l[2] .. '</td></tr>'
    end -- if l[2]

    if l[3] == nil or l[3] == '' or l[3] == ' ' then
      field3 = ''
      count = count + 1
    else
      field3 = [=[<tr>
  <td colspan="2"><hr></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Amount:</td>
  <td>]=] .. l[3] .. '</td></tr>'
      count = count + l[3]
    end -- if l[3]

    table.insert(t, [=[<tr>
  <td colspan="2"><hr></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Name:</td>
  <td>[[]=] .. l[1] .. ']]</td></tr>' .. [=[[[Category:]=] .. l[1] .. [=[]]]=]
.. field2 .. field3)

  until true end -- 'for i' cycle
      table.insert(t, [=[</table>
</div></div>
</td></tr>
<tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Total:</td>
  <td>not less than 
]=] .. count .. '</td></tr>')

  return table.concat(t, "")
end -- p.event_members( frame )



-- Обработчик для Шаблон:Организацияи Шаблон:Персона. Принимает в неименованных параметрах - данные из шаблона, а в именованных параметрах указаны наименования полей, разные для разных шаблонов.
function p.persons_activities( frame )
  local name = frame.args[1]
-- additional named parameters for fields names
  local activity_title = frame.args['activity_title'] and frame.args['activity_title'] or ''
--  local activity_head = frame.args['activity_head'] == 'true' and [=[<tr>
--  <td colspan="2" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold; text-align: center;">Head</td>
--</tr>]=] or ''
  local activity_area = frame.args['activity_area'] and frame.args['activity_area'] or ''
  local activity_position = frame.args['activity_position'] and frame.args['activity_position'] or ''
  local t = {[=[<table border=0>
<tr><td colspan=2>
<div {{DivWrapOpts}}>[[Category:WrapBlock]]
<table border=0 width=100%><tr><td colspan="2" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold; text-align: center;">]=] .. activity_title .. [=[</td></tr></table>
<div class="mw-collapsible-content">
<table border=0>
]=]}

  for i in string.gmatch(name, "[^;]+") do repeat
-- continue if line is "empty" (namely is "!!!;" or only ";") see: https://forum.defold.com/t/any-replace-for-continue-statement-in-lua-loops/65554/2
    if #i <6 then
      do break end
    end

    local field2 = ''
    table.insert(t, '')

    local l = {}
-- Лидер!Профессия!Лидер_с!Лидер_по;
-- or
-- деятельность! должность! нач! кон;
    for k in string.gmatch(i, "[^!]+") do
      table.insert(l, k:match( "^%s*(.-)%s*$" )..' ')
    end

-- UNFIXED BUG: if param defined with ! wo spaces (name!!date1!date2;) the the real l[2] is absent and substitutes by l[3]. Any fixes dont work. 
    if l[2] == '' or l[2] == nil or l[2] == ' ' then
      field2 = ''
    else
      field2 = [=[<tr>
  <td colspan="2"></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">]=] .. activity_position .. [=[:</td>
  <td>]=] .. l[2] .. '</td></tr>'
    end -- if l[2]

--- time range formatting
    local timerange = ''
    if     (l[3] == nil or l[3] == '' or l[3] == ' ') and (l[4] == nil or l[4] == '' or l[4] == ' ') then
             timerange = ' — '
    elseif (l[3] == nil or l[3] == '' or l[3] == ' ') and (l[4] ~= nil or l[4] ~= '' or l[4] ~= ' ') then
             timerange = 'по ' .. l[4]
    elseif (l[3] ~= nil or l[3] ~= '' or l[3] ~= ' ') and (l[4] == nil or l[4] == '' or l[4] == ' ') then
             timerange = 'с ' .. l[3]
    elseif (l[3] ~= nil or l[3] ~= '' or l[3] ~= ' ') and (l[4] ~= nil or l[4] ~= '' or l[4] ~= ' ') then
             timerange = l[3] .. ' — ' .. l[4]
    else
             timerange = ''
    end

    if timerange ~= '' then
    timerange = [=[<tr>
  <td colspan="2"></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">Даты:</td>
  <td>]=] .. timerange .. '</td></tr> <tr><td>&nbsp;</td><td>&nbsp;</td></tr>'
    end

if (l[3] == nil or l[3] == '' or l[3] == ' ') and (l[4] == nil or l[4] == '' or l[4] == ' ') then
      timerange = ''
end

    table.insert(t, [=[<tr>
  <td colspan="2"></td>
</tr><tr>
  <td align="left" width="10%" bgcolor="#{{#dplvar:boxbgcolor}}" style="font-weight: bold;">]=] .. activity_area .. [=[:</td>
  <td>[[]=] .. l[1] .. ']]</td></tr>' .. [=[[[Category:]=] .. l[1] .. [=[]]]=]
.. field2 .. timerange) -- WAS: .. field2 .. field3 .. field4 .. timerange)

  until true end -- 'for i' cycle
      table.insert(t, [=[</table>
</div></div>
</td></tr>
]=])

  return table.concat(t, "")
end -- p.persons_activities( frame )


return p