Jump to content

Module:Sandbox/SiBr4

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by SiBr4 (talk | contribs) at 20:44, 25 August 2015. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

local p = {}

-------------------------

function p.listdata(frame)

local args = require('Module:Arguments').getArgs(frame)

local map = {}
for k,v in pairs(args) do
  if tonumber(k) ~= nil then
    table.insert(map, k)
  end
end
table.sort(map)

local list = mw.html.create('table')
list:css("background-color","#ecfcf4")

for n = 1, #map, 1 do
  local row = list:tag("tr")
  local c = args[map[n]]
  local p = "Template:Country data "..c
  local var = args["var"..map[n]]
  local note = args["note"..map[n]]
  local vartext
  if var
    then vartext = " (<code>"..var.."</code> variant)"
    else vartext = ""
  end
  if require('Module:Redirect').luaIsRedirect(p)
    then row:tag("td"):css("padding","0px 10px"):addClass("plainlinks"):wikitext("["..mw.title.new(p):fullUrl("redirect=no").." "..p.."]"..vartext)
    else row:tag("td"):css("padding","0px 10px"):wikitext("[["..p.."]]"..vartext)
  end
  row:tag("td"):css("padding","0px 10px"):wikitext(frame:expandTemplate({title="flaglist", args={c, variant=(var or "")}}))
  row:tag("td"):css("padding","0px 10px"):wikitext(note or "")
end

return list

end

-------------------------

function p.rgnvbx(frame)

local function blank(s)
  if string.find(s or "","^%s*$") then return nil else return s end
end
local function yn(s,def)
  if s then
    local yn_map = {yes=1, y=1, ["true"]=1, ["1"]=1, no=0, n=0, ["false"]=0, ["0"]=0, [""]=0}
    return yn_map[string.lower(s)]
  else
    return def
  end
end

local args = require("Module:Arguments").getArgs(frame, {removeBlanks = false, trim = false})
local nbargs = {
  name = args.name or error("No name parameter"),
  state = args.state or "autocollapse",
  titlestyle = args.titlestyle,
  bodystyle = args.bodystyle,
  abovestyle = args.abovestyle,
  belowstyle = args.belowstyle,
  groupstyle = args.groupstyle,
  liststyle = args.liststyle,
  listclass = "hlist",
  image = args.image,
  above = args.above,
}

local data
if blank(args.data)
  then data = mw.loadData(args.data)
  else error("No data page specified")
end

local pref = blank((args.prefix or "").." ") or blank(args[1]) or ""
local suff = blank(" "..(args.suffix or "")) or blank(args[2]) or ""
local art
if args.article
  then art = (yn(args.article,0)~=0)
  else art = (pref~="" and suff=="")
end
local nrl = (yn(args.noredlinks,0)~=0)

if args.title
  then nbargs.title = args.title
  else
  	local linkart = (art and data.region_the) and (pref=="" and "The " or "the ") or ""
    local link = pref..linkart..(data.region or error("No region parameter"))..suff
    if nrl and mw.title.new(link).exists
      then nbargs.title = "[["..link.."]]"
      else nbargs.title = link
    end
end

for i = 1, (data.ngroups or 1), 1 do
  local gdata = data["group"..i].data
  local list = mw.html.create("ul")
  for j,country in ipairs(gdata) do--for j = 1, data["group"..i].ndata, 1 do
    local code = country[1]
    local name = args[code.."_name"] or country[2]
    local switch = country.switch
    local citem, cunl
    if (yn(args[code],1)~=0 and (yn(args[switch or ""],1)~=0 or yn(args[code],2)~=2)) then
      local lname = country.link or country[2]
      local lart = (art and country.the) and "the " or ""
      local link
      if yn(args[code],1)==1
      	then link = pref..lart..lname..suff
        else link = args[code] or (pref..lart..lname..suff)
      end
      if (not nrl or mw.title.new(link).exists) and (not country.hidden or yn(args[code],0)~=0 or yn(args[switch],0)~=0) then
        citem = list:tag("li"):wikitext("[["..link.."|"..name.."]]")
      end
    else
      cunl = true
    end
    if country.subgroup then
      local sublist = mw.html.create("ul")
      local nsub = 0
      for k,scountry in ipairs(country.subgroup) do
        local scode = scountry[1]
        local sswitch = scountry.switch
        local sname = args[scode.."_name"] or scountry[2]
        local slname = scountry.link or scountry[2]
        local slart = (art and scountry.the) and "the " or ""
        local slink
        if yn(args[scode],0)==1
          then slink = pref..slart..slname..suff
          else slink = args[scode] or (pref..slart..slname..suff)
        end
        if (not nrl or mw.title.new(slink).exists) and (not country.subgroup.hidden and not scountry.hidden
               or yn(args[scode],0)~=0 or yn(args[country.subgroup.switch or ""],0)~=0 or yn(args[sswitch or ""],0)~=0) then
          sublist:tag("li"):wikitext("[["..slink.."|"..sname.."]]")
          nsub = nsub + 1
        end
      end
      if nsub > 0 then
        if cunl then
          citem = list:tag("li"):wikitext(name):node(sublist)
        else
          citem:node(sublist)
        end
      end
    end
  end
  nbargs["group"..i] = data["group"..i].name
  nbargs["list"..i] = tostring(list)
end

return require("Module:Navbox")._navbox(nbargs)

end

-------------------------

function p.ec(frame)

local p = frame:preprocess("{{Wikipedia:List of Wikipedians by number of edits/5001โ€“6000}}")
local i = string.find(p,"User:SiBr4")
if i then
  return string.sub(p,i-10,i-6)
else
  return "?"
end

end

-------------------------

function p.test(frame)

return ""

end

-------------------------

return p