Module:ConfigRepository

Revision as of 03:47, 10 April 2025 by MarkWD (talk | contribs) (// via Wikitext Extension for VSCode)

Documentation for this module may be created at Module:ConfigRepository/doc

-- Module:ConfigRepository
-- Central repository for template configurations that works with TemplateHelpers
-- This module acts as a single source of truth for configurations across all templates

local p = {}

-- Store all template configurations in this table
p.templates = {
    -- Event template configuration
    Event = {
        meta = {
            description = "Module for rendering Event templates with automatic event navigation"
        },
        
        constants = {
            -- Default date formats
            dateFormats = {
                display = "%d %B %Y", -- e.g., "15 March 2025"
                semantic = "%Y-%m-%d"  -- ISO format for semantic properties
            }
        },
        
        patterns = {
            -- Patterns for event navigation detection
            seriesNumber = "^([%w%s]+)%s+(%d+)$",     -- e.g., "ICANN 76"
            seriesYear = "^([%w%s]+)%s+(%d%d%d%d)$",  -- e.g., "IGF 2023"
            
            -- Patterns for multi-value fields
            itemDelimiter = ";%s*",                   -- Semicolon delimiter for lists
            dateRange = "(%d%d?%s+%w+%s+%d%d%d%d)"    -- Date pattern for ranges
        },
        
        fields = {
            {key="logo", label="Logo"},
            {key="process", label="Process"},
            {key="start", label="Start Date"},
            {key="end", label="End Date"},
            {key="region", label="Region"},
            {keys={"country", "territory"}, label="Country"},
            {key="city", label="City"},
            {key="venue", label="Venue"},
            {key="organizer", label="Organizer"},
            {keys={"website", "url"}, label="Website"},
            {keys={"subject", "category"}, label="Subject"}
        },
        
        semantics = {
            -- Property mappings (semantic property to template field)
            properties = {
                ["Has event start date"] = "start",
                ["Has event end date"] = "end",
                ["Part of process"] = "process",
                -- "Has country" and "Has ICANN region" handled by CountryData.addCountrySemanticProperties
                ["Has city"] = "city",
                ["Has venue"] = "venue",
                ["Has event organizer"] = "organizer"
                -- "Has event subject" temporarily removed
            },
            
            -- Additional properties for special cases
            additionalProperties = {
                ["Has country"] = {"country", "territory"}
                -- "Has event subject" temporarily removed
            },
            
            -- Transformation functions for properties
            transforms = {
                ["Has event start date"] = function(value)
                    return tostring(require('Module:DateNormalization').formatDate(value))
                end,
                ["Has event end date"] = function(value)
                    return tostring(require('Module:DateNormalization').formatDate(value))
                end
            }
        }
    },
    
    -- Person template configuration
    Person = {
        meta = {
            description = "Renders profiles of people with a carousel for multiple images, supporting various normalizations"
        },
        
        mappings = {
            community = {
                {canonical = "ICANN Community",
                 synonyms = {"icann community", "icann", "community"},
                 category = "[[Category:ICANN Community]]"},
                {canonical = "ICANN Staff",
                 synonyms = {"icann staff", "staff"},
                 category = "[[Category:ICANN Staff]]"},
                {canonical = "Root Server Operator Community",
                 synonyms = {"root server operator community", "root server operator", "rso"},
                 category = "[[Category:Root Server Operator Community]]"},
                {canonical = "RIR Community",
                 synonyms = {"rir community", "rir"},
                 category = "[[Category:RIR Community]]"},
                {canonical = "Universal Acceptance Community",
                 synonyms = {"universal acceptance community", "universal acceptance", "ua"},
                 category = "[[Category:Universal Acceptance Community]]"},
                {canonical = "ISOC Community",
                 synonyms = {"isoc community", "isoc"},
                 category = "[[Category:ISOC Community]]"},
                {canonical = "IETF Member",
                 synonyms = {"ietf member", "ietf"},
                 category = "[[Category:IETF Member]]"},
                {canonical = "W3C Community",
                 synonyms = {"w3c community", "w3c"},
                 category = "[[Category:W3C Community]]"},
                {canonical = "IGF Community",
                 synonyms = {"igf community", "igf"},
                 category = "[[Category:IGF Community]]"},
                {canonical = "Governmental",
                 synonyms = {"governmental", "government"},
                 category = "[[Category:Governmental]]"},
                {canonical = "Intergovernmental",
                 synonyms = {"intergovernmental"},
                 category = "[[Category:Intergovernmental]]"}
            }
        },
        
        fields = {
            {key="community",   label="Community"},
            {key="affiliation", label="ICANN group"},
            {key="organization",label="Organization"},
            {key="region",      label="Region"},
            {key="country",     label="Country"},
            {key="languages",   label="Languages"},
            {key="website",     label="Website"},
            {key="soi",         label="SOI"},
            {key="userbox",     label="Achievements"}
        },
        
        patterns = {
            itemDelimiter = ";%s*",
            websitePattern = "^https?://[^%s]+"
        },
        
        semantics = {
            -- Property mappings (semantic property to template field)
            properties = {
                ["Has community"] = "community",
                ["Has ICANN affiliation"] = "affiliation",
                ["Has organization"] = "organization",
                -- "Has ICANN region", "Has country", "Speaks language", are all handled separately
            },
            
            -- Additional properties for special cases
            additionalProperties = {
                -- Handle multiple countries and regions in the special case handlers
                ["Has country"] = {"country"},
                ["Has ICANN region"] = {"region"}
            },
            
            -- Transformation functions for properties
            transforms = {
                ["Has community"] = function(value)
                    local CanonicalForms = require('Module:CanonicalForms')
                    return select(1, CanonicalForms.normalize(value, p.templates.Person.mappings.community)) or value
                end,
                ["Speaks language"] = function(value)
                    -- Return raw value, the semantic property should store the raw data
                    return value
                end
            }
        }
    },
    
    -- TLD template configuration
    TLD = {
        meta = {
            description = "Versatile module for rendering TLD/ccTLD article templates with extensive normalization and dynamic content"
        },
        
        mappings = {
            type = {
                {canonical = "gTLD",
                 synonyms = {"gtld", "generic", "tld", "generic top level domain", "generic top-level domain", "generic tld"},
                 category = "[[Category:gTLD]]"},
                {canonical = "ccTLD",
                 synonyms = {"cctld", "country", "cc", "country code top level domain", "country code top-level domain", "country tld"},
                 category = "[[Category:ccTLD]]"}
            },
            subtype = {
                {canonical="geoTLD",
                 synonyms={"geotld","geo tld","geo","geographic","geographical","geographic top level domain","geographic top-level domain","geographic tld"},
                 css="tld-template-subtype-geotld",
                 category="[[Category:geoTLD]]"},
                {canonical="dotBrand",
                 synonyms={"dotbrand","brand","brandtld","brand tld","brand top level domain","brand top-level domain"},
                 css="tld-template-subtype-brandtld",
                 category="[[Category:dotBrand]]"},
                {canonical="Sponsored TLD",
                 synonyms={"sponsored tld","sponsored","sponsored top level domain","sponsored top-level domain"},
                 css="tld-template-subtype-sponsored",
                 category="[[Category:Sponsored TLD]]"},
                {canonical="Legacy TLD",
                 synonyms={"legacy","legacy tld","legacy top level domain","legacy top-level domain"},
                 css="tld-template-subtype-legacytld",
                 category="[[Category:Legacy TLD]]"},
                {canonical="2012 gTLD Round",
                 synonyms={"2012 gtld round", "gtld round 2012","2012 ngtld round","2012 ngtld","ngtld 2012","ngtld","2012"},
                 css="tld-template-subtype-ngtld-round-2012",
                 category="[[Category:2012 gTLD Round]]"}
            }
        },
        
        constants = {
            legacyTLDs = {
                com=true,net=true,org=true,edu=true,gov=true,mil=true,int=true,info=true,
                aero=true,asia=true,cat=true,coop=true,jobs=true,mobi=true,museum=true,
                post=true,tel=true,travel=true,xxx=true
            }
        },
        
        patterns = {
            tldExtension="%.([^%.]+)$",
            countryDelimiter="([^;]+)"
        },
        
        fields = {
            {key="type",label="Type"},
            {key="subtype",label="Subtype"},
            {key="status",label="Status"},
            {keys={"country", "territory"},label="Country"},
            {key="introduced",label="Introduced"},
            {keys={"date", "implemented"},label="Implemented"},
            {keys={"script", "language"},label="Script"},
            {key="translation",label="English version"},
            {key="ascii",label="Punycode"},
            {keys={"registry", "registryprovider"},label="Registry"},
            {key="website",label="Website"},
            {keys={"RVC", "PIC"},label="PIC/RVC"}
        },
        
        semantics = {
            -- Property mappings (semantic property to template field)
            properties = {
                ["Has TLD type"] = "type",
                ["Has TLD subtype"] = "subtype",
                ["Has TLD status"] = "status",
                -- "Has country" is handled separately through addMultiCountrySemanticProperties
                ["Date introduced"] = "introduced",
                ["Date implemented"] = "date", -- Will also handle implemented
                ["Uses writing script"] = "script", -- Will also handle language
                ["Has registry operator"] = "registry", -- Will also handle registryprovider
                ["Has PIC/RVC"] = "RVC" -- Will also handle PIC
                -- "Is IDN" is handled separately as a boolean property
            },
            
            -- Additional properties for special cases
            additionalProperties = {
                ["Has country"] = {"country", "territory"},
                ["Date implemented"] = {"date", "implemented"},
                ["Uses writing script"] = {"script", "language"},
                ["Has registry operator"] = {"registry", "registryprovider"},
                ["Has PIC/RVC"] = {"RVC", "PIC"}
            },
            
            -- Transformation functions for properties
            transforms = {
                ["Has TLD type"] = function(value)
                    local CanonicalForms = require('Module:CanonicalForms')
                    return select(1, CanonicalForms.normalize(value, p.templates.TLD.mappings.type)) or value
                end,
                ["Has TLD subtype"] = function(value)
                    local CanonicalForms = require('Module:CanonicalForms')
                    return select(1, CanonicalForms.normalize(value, p.templates.TLD.mappings.subtype)) or value
                end,
                ["Date introduced"] = function(value)
                    return tostring(require('Module:DateNormalization').formatDate(value))
                end,
                ["Date implemented"] = function(value)
                    return tostring(require('Module:DateNormalization').formatDate(value))
                end
            }
        }
    }
}

-- Get configuration for a specific template type
function p.getConfig(templateType)
    return p.templates[templateType] or {}
end

-- Get a standard config object for use with existing template modules
-- This integrates with TemplateHelpers.createStandardConfig
function p.getStandardConfig(templateType, customOverrides)
    local TemplateHelpers = require('Module:TemplateHelpers')
    
    -- Get the base configuration
    local baseConfig = p.getConfig(templateType)
    
    -- Create a standard config using TemplateHelpers
    return TemplateHelpers.createStandardConfig(baseConfig, customOverrides)
end

return p