Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Special pages
PanEcoDevWiki
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Module:Cats
Module
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
Purge cache
General
What links here
Related changes
Page information
Cargo data
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
local p = {} -- Utility to add a value to a table if not empty local function addIfValid(tbl, val) if val and val ~= "" then table.insert(tbl, val) end end -- Parse a "*"-style hierarchy string into a flat list of all nodes local function parseTaxonomyFlat(taxonomy) local flat = {} for stars, label in taxonomy:gmatch("(%*+)([^%*]+)") do label = mw.text.trim(label) addIfValid(flat, label) end return flat end -- Main function: generate categories from fields + taxonomy function p.addCats(frame) local categories = {} -- 1. Collect from fields for k, v in pairs(frame.args) do if k:match("^has.*Type$") or k:match("^hasCategory$") or k:match("^hasClass$") then for item in mw.text.gsplit(v, ",", true) do addIfValid(categories, mw.text.trim(item)) end end end -- 2. Collect from taxonomy (hasTaxonomy) local taxonomy_str = frame.args.hasTaxonomy or "" if taxonomy_str ~= "" then local nodes = parseTaxonomyFlat(taxonomy_str) for _, node in ipairs(nodes) do addIfValid(categories, node) end end -- 3. Deduplicate local seen = {} local output = {} for _, cat in ipairs(categories) do if not seen[cat] then seen[cat] = true table.insert(output, "[[Category:" .. cat .. "]]") end end return table.concat(output, "\n") end return p
Summary:
Please note that all contributions to PanEcoDevWiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, 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 (see
PanEcoDevWiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Template used on this page:
Module:Cats/doc
(
edit
)
Search
Search
Editing
Module:Cats
Add topic