Editing Module:Navbox

Warning: You are not logged in. Once you make an edit, a temporary account will be created for you. Learn more. Log in or create an account to continue receiving notifications after this account expires, and to access other features.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision Your text
Line 163: Line 163:
return h.render(dataTree)
return h.render(dataTree)
end
end
end
-- Expand automatic group markers
function h.expandAutomaticGroups(args)
local PREFIX = '__NAVBOX_AUTO_GROUPS__'
local value = args.automatic_groups
if type(value) ~= 'string' or value:sub(1, #PREFIX) ~= PREFIX then
return args
end
local payload = value:sub(#PREFIX + 1)
local ok, data = pcall(mw.text.jsonDecode, payload)
if not ok or type(data) ~= 'table' or type(data.rows) ~= 'table' then
error('Invalid Navbox Automatic Groups data.')
end
local index = tonumber(data.start) or 1
if index < 1 or index % 1 ~= 0 then
error('Invalid Navbox Automatic Groups start index.')
end
for _, row in ipairs(data.rows) do
local groupKey = index .. ':group'
local listKey = index .. ':list'
if args[groupKey] ~= nil or args[listKey] ~= nil then
error('Navbox Automatic Groups overlaps an existing row at index ' .. index .. '.')
end
if row.group ~= nil and row.group ~= '' then
args[groupKey] = row.group
end
if row.list ~= nil then
args[listKey] = row.list
end
index = index + 1
end
args.automatic_groups = nil
return args
end
end


Line 296: Line 343:


-- parse arguments, convert them to structured data tree
-- parse arguments, convert them to structured data tree
-- Expand automatic group markers
function h.expandAutomaticGroups(args)
local PREFIX = '__NAVBOX_AUTO_GROUPS__'
local value = args.automatic_groups
if type(value) ~= 'string' or value:sub(1, #PREFIX) ~= PREFIX then
return args
end
local payload = value:sub(#PREFIX + 1)
local ok, data = pcall(mw.text.jsonDecode, payload)
if not ok or type(data) ~= 'table' or type(data.rows) ~= 'table' then
error('Invalid Navbox Automatic Groups data.')
end
local index = tonumber(data.start) or 1
if index < 1 or index % 1 ~= 0 then
error('Invalid Navbox Automatic Groups start index.')
end
for _, row in ipairs(data.rows) do
local groupKey = index .. ':group'
local listKey = index .. ':list'
if args[groupKey] ~= nil or args[listKey] ~= nil then
error('Navbox Automatic Groups overlaps an existing row at index ' .. index .. '.')
end
if row.group ~= nil and row.group ~= '' then
args[groupKey] = row.group
end
if row.list ~= nil then
args[listKey] = row.list
end
index = index + 1
end
args.automatic_groups = nil
return args
end
function h.buildDataTree(args)
function h.buildDataTree(args)
-- parse args to a tree
-- parse args to a tree
Please note that all contributions to The Petit Planet Wiki are considered to be released under the Creative Commons Attribution-ShareAlike (see Petit Planet Wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!
Cancel Editing help (opens in new window)
Preview page with this template
Below are commonly used wikitext from MediaWiki:Edittools. Click on any to insert them in the edit box.
File Pages==Summary====Licensing=={{Fairuse}}{{File|}}
Dynamic Page List¦²«»²{¦}²«»«/»«!----»
Array in DPL¹^2{}^2^2{¹}^2
Parser Functions{{#if:||}}
{{#ifeq:|||}}
{{#expr:}}
{{#switch:||#default=}}
{{#replace:||}}
{{#titleparts:}}
{{#tag:|}}
Markup{{}}|[][[]][[Category:]]#REDIRECT [[]] [[Category:Redirect Pages]]<code></code><includeonly></includeonly><noinclude></noinclude><nowiki></nowiki><!----><br>§
Notices{{Stub|}}{{Stub Dialogue}}{{Upcoming}}{{Under Construction}}{{Placeholder|}}
Magic Words{{!}}{{formatnum:}}{{lc:}}{{uc:}}{{PAGENAME}}{{FULLPAGENAME}}{{ROOTPAGENAME}}{{BASEPAGENAME}}{{SUBPAGENAME}}{{DISPLAYTITLE:|noreplace}}__TOC____NOTOC____EXPECTUNUSEDCATEGORY____HIDDENCAT__
HTML Entities&mdash;&nbsp;&comma;&shy;