Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Special pages
Random page
Wiki Discord
Contents
Neighbors
Galaxy
> Hexia
> Norvan
> Pashah
> Taffeh
Creatures
> Insects
> Fishes
> Shore-Dwellers
Items
> Dishes
> Furniture
Game Systems
> Dress Up
> Luca Arbor
> Loomix Footprints
> Loomix Vehicle Services
> Loomix Homes
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Editing
Module
:
Navbox Automatic Groups
Module
Discussion
English
Read
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit source
View history
General
What links here
Related changes
Page information
Appearance
move to sidebar
hide
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.
Anti-spam check. Do
not
fill this in!
local p = {} local PREFIX = '__NAVBOX_AUTO_GROUPS__' local NOGROUP = '[nogroup]' local CONTROL_ARGS = { groups = true, base = true, list = true, list_type = true, not_format = true, start = true } -- Trim a value local function trim(value) return mw.text.trim(tostring(value or '')) end -- Split the groups parameter local function splitGroups(value) local result = {} for _, group in ipairs(mw.text.split(value, ';', true)) do group = trim(group) if group ~= '' then result[#result + 1] = group end end return result end -- Normalize a group name for override matching local function normalizeGroupName(value) value = trim(value):gsub('%s+', ' ') return mw.ustring.lower(value) end -- Replace the group placeholder local function substituteGroup(value, group) return tostring(value or ''):gsub('%%%%group%%%%', function() return group end) end -- Link a group name if the page exists local function linkGroup(group) local page = mw.text.decode(group or '') local frame = mw.getCurrentFrame() if page ~= '' and not page:match('[#<>%[%]{}]+') and frame:callParserFunction('PROTECTIONEXPIRY:edit', page) ~= '' then return '[[' .. group .. '|' .. group .. ']]' end return group end -- Find list_<group> overrides local function getListOverrides(args) local overrides = {} for key, value in pairs(args) do local groupName = tostring(key):match('^list_(.+)$') if groupName then overrides[normalizeGroupName(groupName)] = tostring(value) end end return overrides end -- Build DPL arguments local function getDplArgs(args, group, exclusions) local dplArgs = {} local notFormat = tostring(args.not_format or '%%group%%') for key, value in pairs(args) do key = tostring(key) if not CONTROL_ARGS[key] and not key:match('^list_.+$') then if type(value) == 'string' then dplArgs[key] = substituteGroup(value, group) else dplArgs[key] = value end end end -- Add automatically generated DPL exclusions for i, exclusion in ipairs(exclusions) do dplArgs['not' .. i] = substituteGroup(notFormat, exclusion) end return dplArgs end -- Expand Navbox DPL local function expandDpl(frame, args, group, exclusions) local dplArgs = getDplArgs(args, group, exclusions) return frame:expandTemplate{ title = 'Navbox DPL', args = dplArgs } end -- Check whether expanded content actually contains anything local function hasContent(value) return mw.text.trim(tostring(value or '')) ~= '' end -- Main function p.main(frame) local args = {} -- Get arguments passed directly to the module for key, value in pairs(frame.args) do args[key] = value end -- Get arguments passed through Template:Navbox Automatic Groups local parent = frame:getParent() if parent then for key, value in pairs(parent.args) do if args[key] == nil then args[key] = value end end end local groupsArg = trim(args.groups) local base = trim(args.base) local defaultList = tostring(args.list or '') local listType = mw.ustring.lower(trim(args.list_type)) local start = tonumber(trim(args.start)) or 1 if groupsArg == '' then error('Navbox Automatic Groups: missing groups parameter.') end if start < 1 or start % 1 ~= 0 then error('Navbox Automatic Groups: start must be a positive integer.') end local groups = splitGroups(groupsArg) local overrides = getListOverrides(args) local exclusions = {} -- Build the list of named groups used for [nogroup] exclusions for _, group in ipairs(groups) do if normalizeGroupName(group) ~= normalizeGroupName(NOGROUP) then exclusions[#exclusions + 1] = group end end local rows = {} for _, group in ipairs(groups) do local isNoGroup = normalizeGroupName(group) == normalizeGroupName(NOGROUP) local targetGroup = isNoGroup and base or group if isNoGroup and base == '' then error('Navbox Automatic Groups: [nogroup] requires a base parameter.') end local overrideKey = normalizeGroupName(isNoGroup and 'nogroup' or group) local list = overrides[overrideKey] if list == nil then if listType == 'dpl' then list = expandDpl( frame, args, targetGroup, isNoGroup and exclusions or {} ) else list = substituteGroup(defaultList, targetGroup) list = list:gsub('%%%%not%%%%', '') end else list = substituteGroup(list, targetGroup) list = list:gsub('%%%%not%%%%', '') end -- Do not create a row when the generated list is empty if hasContent(list) then local row = { list = list } -- Link normal group names when the corresponding page exists if not isNoGroup then row.group = linkGroup(group) end rows[#rows + 1] = row end end return PREFIX .. mw.text.jsonEncode({ start = start, rows = rows }) end return p
Summary:
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:||}}
{{#if:<condition>|<result if true>|<result if false>}}
{{#ifeq:|||}}
{{#ifeq:<text1>|<text2>|<result if text1=text2>|<result if text1≠text2>}}
{{#expr:}}
{{#expr:<mathematical expression>}}
{{#switch:||#default=}}
{{#switch:<text1>|<text2>=<result if text1=text2>|<text3>=<result if text1=text3>|#default=<result if no valid match>}}
{{#replace:||}}
{{#replace:<text1>|<plain text to find in text1>|<plain text to insert in place of the text found>}}
{{#titleparts:}}
{{#replace:<page name>}}
{{#tag:|}}
{{#tag:<name of html tag>|<content inside html 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
—
,
­
Pages included on this page:
Template:Documentation/Header
(
edit
)
Template:Documentation/styles.css
(
edit
)
Template:T
(
edit
)
Template:TOC Right
(
edit
)
Module:Arguments
(
edit
)
Module:Arguments/i18n
(
edit
)
Module:Common/i18n
(
edit
)
Module:Config
(
edit
)
Module:Documentation
(
edit
)
Module:Documentation/config
(
edit
)
Module:Documentation/i18n
(
edit
)
Module:Entrypoint
(
edit
)
Module:Exists
(
edit
)
Module:Fallbacklist
(
edit
)
Module:Feature
(
edit
)
Module:Formatting
(
edit
)
Module:I18n
(
edit
)
Module:Languages
(
edit
)
Module:Navbox Automatic Groups/doc
(
edit
)
Module:TableTools
(
edit
)
Module:Yesno
(
edit
)
This page is a member of 2 hidden categories:
Category:Pages using DynamicPageList4 parser function
Category:Pages using DynamicPageList4
Search
Search
Editing
Module
:
Navbox Automatic Groups
Add topic