Module:ListField

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

local getArgs = require('Module:Arguments').getArgs;
local defArgs = require('Module:Arguments').defaultArgs;
local listField = {};

function listField.func1( frame )
  local args = defArgs(getArgs(frame), 1, "");
  local arg = args[1];
  local arg1 = args[2];
  local arg2 = args[3];
  local arg3 = args[4];

  local text = ""
  function trim(s) return (string.gsub(s, "^%s*(.-)%s*$", "%1")) end
  list = {}
  id = {}
  for page,data in arg:gmatch("&&([%S]+)&&" .. arg1 .. " *= *([^\n]+)") do
    if ((data ~= "-") and (data ~= " ")) then
      data = trim(data)
      tmp = list[data]
      if (tmp == nil) then
        list[data] = { page }
        table.insert(id, data)
      else
        table.insert(tmp, page)
      end
    end
  end
  table.sort(id)
  text = text .. "Total " .. table.getn(id) .. " groups."
  local coff = tonumber(arg3)
  if (coff == nil) then coff =0 else text = text .. "Showing groups more than size=" .. coff .. "only" end
  for _,v in ipairs(id) do
    if (table.getn(list[v]) > coff) then
      text = text .. "* '''" .. v .. "'''"
      table.sort(list[v])
      for i = 1,table.getn(list[v]) do
        if (list[v][i] ~= list[v][i + 1]) then
          text  = text .. "[[" .. arg2 .. ":" .. list[v][i] .."|".. list[v][i] .."]]" end
      end
    end
  end

  return text;
end

return listField;