Module:World topic/sandbox explained

local p =

local Navbox = require("Module:Navbox")local country =

local function li(text) local li = mw.html.create("li") li :wikitext(text) :done return tostring(li)end

local function linktarget(x, y) if y ~= nil and y

"" then return x else return y endend

local function links(args1, args2, argsprefix, argssuffix, sorter, redlinks, override) local list = local prefix = (args1 or argsprefix or "") .. " " local suffix = args2 or argssuffix or "" for x, y in pairs(sorter) do local target = nil if redlinks then if override[y] then target = override[y] elseif y

"Georgia" or y

"Palestine" then if mw.title.new(prefix..country[y][1]..suffix).exists then target = prefix..country[y][1]..suffix else target = prefix..y..suffix end else target = prefix..linktarget(y, country[y][1])..suffix end else -- noredlinks if override[y] then if mw.title.new(override[y]).exists then target = override[y] end elseif mw.title.new(prefix..linktarget(y, country[y][1])..suffix).exists then target = prefix..linktarget(y, country[y][1])..suffix elseif y

"Georgia" or y

"Palestine" then if mw.title.new(prefix..y..suffix).exists then target = prefix..y..suffix end end end if target then table.insert(list, li(""..y.."")) end end return listend

function p.main(frame) local pframe = frame:getParent local config = frame.args local args = pframe.args return p._main(args)end

function p._main(args) local state, titlemid, title, group1 if mw.title.getCurrentTitle

"Template:World topic" then state = "autocollapse" else state = args.state end if args[1] ~= nil or args.prefix ~= nil and (args[2]

nil or args.suffix

nil) then titlemid = " the" end if args.title ~= nil then title = args.title else title = ""..(args[1] or args.prefix or "")..(titlemid or "").." World"..(args.suffix or "").."" end if args.group1 ~= nil and args.group1 ~= "" then group1 = args.group1 end local sorter = for n in pairs(country) do table.insert(sorter, n) end table.sort(sorter)

-- parse link overrides, e.g. |link_United_States=Foo sets override["United States"] = "Foo" local override = for k,v in pairs(args) do local country = mw.ustring.match(k, "^link_(.*)") if country then country = mw.ustring.gsub(country, "_", " ") override[country] = v end end local redlinks = args.noredlinks

nil local list1 = table.concat(links(args[1], args[2], args.prefix, args.suffix, sorter, redlinks, override)) local navarguments = return Navbox._navbox(navarguments)end

return p