Module:ModNames

local p = {}

local g = require("Module:Common")

-- Table that maps page names to sequences of abbreviations. -- The (normalized) page name is automatically included as an abbr. -- All other abbrs must be normalized, i. e. all lowercase and alphanumeric characters only. p.name2abbrs = { ["Actually Additions"] = {"actadd"}; ["Additional BuildCraft Objects"] = {"abo"}; ["Advanced Genetics"] = {"ag"}; ["Advanced Machines"] = {"am"}; ["Advanced Power Management"] = {"apm"}; ["Advanced Solar Panels"] = {"asp", "advancedsolarpanel"}; ["Adventure Backpack"] = {}; ["Adventurer's Amulets"] = {}; ["AgriCraft"] = {}; ["Another One Bites the Dust"] = {"aobd"}; ["AppleMilkTea2"] = {"amt2"}; ["Applied Energistics"] = {"ae", "appeng"}; ["Applied Energistics 2"] = {"ae2"}; ["Arcane Engineering"] = {}; ["Archimedes' Ships"] = {"archship", "archimedes"}; ["Ars Magica 2"] = {"am2"}; ["Assembly Line"] = {}; ["ATLauncher"] = {"atl"}; ["Atomic Science"] = {"as"}; ["Automagy 1"] = {"automagy"}; ["Automagy 2"] = {}; ["Avaritia"] = {}; ["Backpacks"] = {"bp"}; ["Balkon's WeaponMod"] = {"weaponmod"}; ["Basic Components"] = {}; ["Better Furnaces"] = {"FLabsBF"}; ["BetterChests"] = {}; ["BetterStorage"] = {}; ["BiblioCraft"] = {}; ["Big Reactors"] = {"br"}; ["Biomes O' Plenty"] = {"bop"}; ["Blood Magic"] = {"bm", "awwayoftime"}; ["Botania"] = {}; ["Botanical Addons"] = {"shadowfox_botany"}; ["Brandon's Core"] = {}; ["BuildCraft"] = {"bc", "bc3", "buildcraft3", "buildcraft4", "buildcraft5", "buildcraft6"}; ["BuildCraft Tools"] = {"bct"}; ["Carpenter's Blocks"] = {"cb"}; ["ChaosCraft"] = {"chaos"}; ["ChickenChunks"] = {"chc", "chchunks"}; ["ChargePads"] = {"cp"}; ["Charlotte's Utilities"] = {}; ["Chisel"] = {}; ["CodeChickenCore"] = {"ccc", "chickenbonescore"}; ["CompactSolars"] = {"cs", "compsol", "compactsolararrays"}; ["Compact Windmills"] = {"cw", "cwm"}; ["ComputerCraft"] = {"cc"}; ["Cooking for Blockheads"] = {"cookingbook"}; ["Craft Arcanum 1"] = {"craftarcanum"}; ["DartCraft"] = {"dc"}; ["Decocraft"] = {"props"}; ["Dense Ores"] = {"do"}; ["Dimensional Anchors"] = {"da"}; ["Dimensional Doors"] = {"dd", "dimdoors"}; ["Divine RPG"] = {"drpg", "divinerpg"}; ["Draconic Evolution"] = {"de"}; ["ElectriCraft"] = {}; ["Electro-Magic Tools"] = {"emt"}; ["Emasher Resource"] = {"emasher"}; ["EnderIO"] = {"eio"}; ["EnderStorage"] = {"es", "enderchest", "enderchests"}; ["Ender Prospecting"] = {}; ["Ender Zoo"] = {"ez"}; ["Engineer's Toolbox"] = {"etb"}; ["EnhancedPortals 2"] = {"ep2", "enhancedportals"}; ["Equivalent Exchange"] = {"ee"}; ["Equivalent Exchange 2"] = {"ee2"}; ["Equivalent Exchange 3"] = {"ee3"}; ["Essential Thaumaturgy"] = {"essenthaum"}; ["Ex Astris"] = {"exaliquo"}; ["Ex Nihilo"] = {"en", "exn"}; ["Extra Bees"] = {"eb"}; ["Extra Cells"] = {"ec"}; ["Extra Cells 2"] = {"ec2"}; ["Extra Trees"] = {"et"}; ["ExtrabiomesXL"] = {"ebxl", "extrabiomes"}; ["Extra Utilities"] = {"eu", "extrautils"}; ["Extra Utilities 2"] = {"eu2", "extrautils2"}; ["Factorization"] = {"fz"}; ["Feed The Beast"] = {"ftb"}; ["Flan's Mod"] = {}; ["Food Plus"] = {}; ["Forbidden Magic"] = {}; ["Forestry"] = {"fy"}; ["Forge IRC"] = {}; ["Forge Mod Loader"] = {"fml", "forgeml"}; ["FullThrottle Alchemist"] = {"fta", "projectalchemy"}; ["Gadomancy"] = {}; ["Galacticraft"] = {"gc"}; ["Garden Stuff"] = {"gardencore", "gardencontainers", "gardentrees"}; ["GasCraft"] = {}; ["Gendustry"] = {}; ["Gravitation Suite"] = {"gs", "gravisuite", "graviationsuite" --sic}; ["Gravity Gun"] = {"gravigun"}; ["GregTech"] = {"gt"}; ["Hammerz"] = {}; ["Hardcore Ender Expansion"] = {"hee"}; ["Hardcore Questing Mode"] = {"hqm", "hardcorequest", "hardcorequesting", "hardcorequestingmod"}; ["IndustrialCraft 2"] = {"ic", "ic2", "industrialcraft"}; ["IndustrialCraft 2 Experimental"] = {"ic2x", "ic2exp"}; ["ICBM"] = {}; ["Immersive Engineering"] = {"ie"}; ["Inventory Tweaks"] = {"invtweaks"}; ["Iron Chests"] = {"ich", "ironchests", "ironchest"}; ["JABBA"] = {}; ["Logistics Pipes"] = {"lp", "logipipes", "logisticpipes"}; ["Magic Bees"] = {"mb", "thaumicbees"}; ["Magic Cookies"] = {"magiccookie"}; ["Magical Crops"] = {}; ["Magical Decorations"] = {"mdeco"}; ["Magneticraft"] = {}; ["Mekanism"] = {"mk", "mekanismgenerators"}; ["Metalurgy"] = {"me"}; ["Metalurgy 3"] = {"me3"}; ["MFFS Calclavia"] = {}; ["Millénaire"] = {"mil", "millenaire"}; ["Minecraft"] = {"mc", "vanilla", "vanillaminecraft"}; ["Minecraft Forge"] = {"forge", "mcforge"}; ["MineChem"] = {}; ["MineFactory Reloaded"] = {"mfr", "minefactory"}; ["Misc Peripherals"] = {}; ["Mod Coder Pack"] = {"mcp", "minecraftcoderpack"}; ["Modular Force Field System"] = {"mffs"}; ["Modular Powersuits"] = {"mps", "powersuits"}; ["MPSaddons"] = {"mpsa"}; ["Mystcraft"] = {"myst"}; ["Natura"] = {}; ["Nether Ores"] = {"no"}; ["Not Enough Items"] = {"nei"}; ["Nuclear Control"] = {"nc"}; ["ObsidiPlates"] = {"obsidianplates", "obsidian pressure plates"}; ["OmniTools"] = {}; ["One More"] = {"om"}; ["OpenBlocks"] = {"ob"}; ["OpenComputers"] = {"oc", "opencomp"}; ["Pam's BoneCraft"] = {"pbc", "bonecraft"}; ["Pam's DesertCraft"] = {"pdc", "desertcraft"}; ["Pam's HarvestCraft"] = {"pam", "ph", "hc", "phc", "harvestcraft"}; ["Pam's Temperate Plants"] = {"ptp", "temperateplants"}; ["Pam's Weee! Flowers"] = {"pamflowers", "pwf", "weeeflowers"}; ["Petroleum Generator (Mod)"] = {"petrogen", "petroleumgenerator"}; ["Plugins for Forestry"] = {"pff"}; ["PneumaticCraft"] = {"pneumaticraft"}; ["Portal Gun (Mod)"] = {"pg", "pgm", "portalgun", "portalgunmod"}; ["Power Converters"] = {"pc"}; ["Primitive Mobs"] = {}; ["Professor Flaxbeard's Wondrous Steam Power Mod"] = {"fsp", "fsm", "wsp", "pfwsp", "pfwspm", "steampower", "flaxbeardsteampower", "flaxbeardssteampower", "steamcraft"}; ["Progressive Automation"] = {}; ["Project Red"] = {"pr", "projred"}; ["Project Zulu"] = {"pz"}; ["qCraft"] = {"qc"}; ["QuarryPlus"] = {"qp"}; ["Railcraft"] = {"rc"}; ["Random Things"] = {}; ["RedPower 2"] = {"rp", "rp2", "redpower"}; ["Redstone Arsenal"] = {"ra"}; ["ReactorCraft"] = {}; ["Rei's Minimap"] = {"reimap", "reiminimap"}; ["RFTools"] = {"rft"}; ["Risugami's ModLoader"] = {"rml", "modloader"}; ["RotaryCraft"] = {"rotc"}; ["Secret Rooms"] = {"sr", "secretroomsmod"}; ["Simply Jetpacks"] = {"sj"}; ["Solar Expansion"] = {"se"}; ["Soul Shards"] = {"ss"}; ["Steve's Carts 2"] = {"sc2", "stevescarts"}; ["Steve's Factory Manager"] = {"sfm"}; ["Sync"] = {}; ["Tainted Magic"] = {}; ["Technomancy"] = {}; ["Thaumaturgical Knowledge"] = {"benway_knowledge"}; ["Thaumcraft"] = {"tc"}; ["Thaumcraft 3"] = {"tc3"}; ["Thaumcraft 4"] = {"tc4", "tc41", "thaumcraft41"}; ["Thaumcraft 5"] = {"tc5"}; ["Thaumcraft Gates"] = {}; ["Thaumic Additions"] = {}; ["Thaumic Bases 1"] = {"thaumicbases"}; ["Thaumic Bases 2"] = {}; ["Thaumic Energistics"] = {}; ["Thaumic Expansion"] = {}; ["Thaumic Exploration"] = {}; ["Thaumic Horizons"] = {}; ["Thaumic Infusion"] = {}; ["Thaumic Revelations"] = {"trevelations"}; ["Thaumic Upholstry"] = {"tu"}; ["Thaumic Warden"] = {"twarden"}; ["ThaumOres"] = {}; ["Thermal Dynamics"] = {"td"}; ["Thermal Expansion"] = {"te"}; ["Thermal Expansion 2"] = {"te2"}; ["Thermal Expansion 3"] = {"te3"}; ["Thermal Expansion 4"] = {"te4"}; ["Thermal Foundation"] = {"tf"}; ["Tinkers' Construct"] = {"tic", "tcon", "tconstruct", "tinkerersconstruct"}; ["Tinkers' Mechworks"] = {"tim", "tmech", "tmechworks"}; ["Tinkers' Steelworks"] = {"tis", "tsteel", "tsteelworks"}; ["TrainCraft"] = {}; ["Traveller's Gear"] = {}; ["Tropicraft"] = {}; ["Thaumic Tinkerer 1"] = {"tt", "thaumictinkerer"}; ["Thaumic Tinkerer 2"] = {"tt2"}; ["The Elysium"] = {"elysium"}; ["TubeStuff"] = {"ts"}; ["Twilight Forest"] = {}; ["Warp Theory"] = {}; ["Wireless Redstone ChickenBones Edition"] = {"wrcbe", "wirelessredstone", "wirelessredstonecbe"}; ["Witchery"] = {"witch"}; ["Witching Gadgets"] = {}; ["Xeno's Reliquary"] = {"reliquary", "xreliquary", "xr"}; ["XyCraft"] = {"xy"}; }

-- Table that maps page names to display titles p.name2display = { ["IndustrialCraft 2"] = "IndustrialCraft2"; ["IndustrialCraft 2 Experimental"] = "IndustrialCraft2 Experimental"; ["Petroleum Generator (Mod)"] = "Petroleum Generator"; ["Portal Gun (Mod)"] = "Portal Gun"; }

p.abbr2name = {} -- Table that maps lowercase abbreviations to page names

-- Table of misc. suffixes to strip from item/block names -- Format is similar to that of abbr2name for easier use p.miscSuffixes = { ["block"] = "Block"; ["mob"] = "Mob"; ["mod"] = "Mod"; ["modpack"] = "Modpack"; ["item"] = "Item"; }

-- Remove any wikilink or template call from s, returning only the link target or template name. function p.unlink(s) return (s:match("[%[%{]+([^%|%]%}]+)[^%]%}]*[%]%}]+") or s) end

-- Strip common wiki markup characters from s. This implicitly calls p.unlink(s). function p.unmarkup(s) return (p.unlink(s):gsub("[%|%[%]%{%}]+", ""):gsub("''+", "")) end

-- Convert s to lowercase and strip all non-alphanumeric characters. This implicitly calls p.unmarkup(s). function p.normalize(s) return (p.unmarkup(s):lower:gsub("[^%w]+", "")) end

-- Populate p.abbr2name for name, abbrs in pairs(p.name2abbrs) do	for i, abbr in ipairs(abbrs) do		p.abbr2name[p.normalize(abbr)] = name end -- Include normalized name as an abbr p.abbr2name[p.normalize(name)] = name end

-- Expand abbr to a page name. If abbr is not recognized, return p.unmarkup(abbr). function p.getPagename(abbr) return p.abbr2name[p.normalize(abbr)] or p.unmarkup(abbr) end

-- Expand abbr to a display name. If no special display name is known, return p.getPagename(abbr). function p.getDisplayname(abbr) local pn = p.getPagename(abbr) return p.name2display[pn] or pn end

-- Expand abbr into a full wikilink, with proper target and display title. -- If p.normalize(abbr) is either "unknown" or "various", no linking or expansion is performed. -- If smwprop is given, make the wikilink a SMW property assignment, with smwprop being the property name. function p.getWikilink(abbr, smwprop) local labbr = p.normalize(abbr) if labbr == "unknown" or labbr == "various" then return abbr else if g.isGiven(smwprop) then smwprop = smwprop .. "::"		else smwprop = "" end return "" .. p.getDisplayname(abbr) .. "" end end

-- Remove known disambig suffixes from the end of label, such as (Block) or (BuildCraft). -- Unknown suffixes are left in place - for example "Machine Frame (Basic)" is not modified. function p.stripSuffix(label) -- Pattern matching all parenthesized suffixes (e.g. "(BuildCraft)", "(Block)", etc.) local suffix = label:match("%(.+%)$") if suffix ~= nil then local trimmed = suffix:sub(2, -2):lower if p.abbr2name[trimmed] or p.miscSuffixes[trimmed] then return label:sub(1, -(#suffix + 2)) end end return label end

-- MediaWiki wrappers around the above functions function p.mwGetPagename(frame) return p.getPagename(frame.args[1]) end function p.mwGetDisplayname(frame) return p.getDisplayname(frame.args[1]) end function p.mwGetWikilink(frame) return p.getWikilink(frame.args[1], frame.args[2]) end function p.mwStripSuffix(frame) return p.stripSuffix(frame.args[1]) end

return p