Module:T-CountryHub: Difference between revisions

// via Wikitext Extension for VSCode
Maintenance update // via Wikitext Extension for VSCode
 
(37 intermediate revisions by the same user not shown)
Line 21: Line 21:
local CountryData  = safeRequire('Module:CountryData')
local CountryData  = safeRequire('Module:CountryData')
local TemplateHelpers = safeRequire('Module:TemplateHelpers')
local TemplateHelpers = safeRequire('Module:TemplateHelpers')
local LinkParser = safeRequire('Module:LinkParser')
local NormalizationText = safeRequire('Module:NormalizationText')
local NormalizationText = safeRequire('Module:NormalizationText')
local NormalizationDiacritic = safeRequire('Module:NormalizationDiacritic')
local NormalizationDiacritic = safeRequire('Module:NormalizationDiacritic')
local MasonryLayout = safeRequire('Module:MasonryLayout')
local mw            = mw
local mw            = mw
local html          = mw.html
local html          = mw.html
Line 69: Line 71:
end
end


-- -- generateProcessedBrowseLink: Constructs and preprocesses a MediaWiki link for browsing data, with {{fullurl:...}} correctly expanded by MediaWiki before the link is rendered.
-- renderSection: A wrapper function that performs a cached SMW query and renders a table only if results are found.
-- local function generateProcessedBrowseLink(template, browseType, browseQueryParam, linkTextPattern, country)
-- @param key string: The base cache key for the query.
--    -- Explicitly URL-encode the country name for use in the URL query parameter
-- @param params table: The parameters for the smw.ask query.
--     local encodedCountry = mw.uri.encode(country, 'QUERY') -- 'QUERY' mode is for query string values
-- @param columns table: A list of column headers for the table.
 
-- @return string: An HTML table if data is found, otherwise an empty string.
--    local browseLinkString = string.format(
local function renderSection(key, params, columns)
--         '[{{fullurl:Special:BrowseData/%s|%s=%s}} %s →]',
     local data = askCached(key, params)
--        browseType,
    if not data or #data == 0 then
--        browseQueryParam,
         return ''
--        encodedCountry,  -- Use the encoded country name for the URL part
     end
--         string.format(linkTextPattern, country) -- Use the original country name for the display text
     return renderTable(data, columns)
--    )
end
   
--     if template.current_frame and template.current_frame.preprocess then
--        local ok, result = pcall(function() return template.current_frame:preprocess(browseLinkString) end)
--        if ok then
--            return result
--         else
--            return browseLinkString -- Fallback on preprocess error
--        end
--     end
--     return browseLinkString -- Fallback if no frame or preprocess
-- end


local errorContext = ErrorHandling.createContext("T-CountryHub")
local errorContext = ErrorHandling.createContext("T-CountryHub")
Line 110: Line 101:
         people = true,
         people = true,
         laws = true,
         laws = true,
         documents = true,
         documents = false,
         geoTlds = true,
         geoTlds = true,
         meetings = true,
         meetings = true,
         nra = true,
         nra = true,
         resources = true,
         resources = false,
         semanticProperties = true,
         semanticProperties = true,
         categories = true,
         categories = true,
Line 130: Line 121:
template.config.blockSequence = {
template.config.blockSequence = {
     'wrapperOpen',
     'wrapperOpen',
     'infoBox',
     'featureBanner',
    'intro',
     'overview',
     'overview',
     'organizations',
     'intelligentMasonry',
    'people',
    'laws',
    'documents',
    'geoTlds',
    'meetings',
    'nra',
    'resources',
     'wrapperClose',
     'wrapperClose',
     'categories',
     'categories',
     'errors'
     'errors'
}
-- MASONRY LAYOUT CONFIGURATION
local cardDefinitions = {
    {blockId = 'intro', feature = 'intro', title = 'Welcome'},
    {blockId = 'organizations', feature = 'organizations', title = 'Organizations'},
    {blockId = 'people', feature = 'people', title = 'People'},
    {blockId = 'geoTlds', feature = 'geoTlds', title = 'GeoTLDs'},
    {blockId = 'meetings', feature = 'meetings', title = 'Internet Governance Events'},
    {blockId = 'nra', feature = 'nra', title = 'National Authorities'},
    {blockId = 'laws', feature = 'laws', title = 'Laws and Regulations'},
    {blockId = 'documents', feature = 'documents', title = 'Key Documents'},
    {blockId = 'resources', feature = 'resources', title = 'Resources'},
    {blockId = 'infoBox', feature = 'infoBox', title = 'Country Info'}
}
local masonryOptions = {
    columns = 3,
    mobileColumns = 1,
    containerClass = 'country-hub-masonry-container',
    columnClass = 'country-hub-masonry-column',
    cardClass = 'country-hub-masonry-card',
    -- Note: We cannot detect mobile server-side in MediaWiki
    -- The MasonryLayout will output both desktop and mobile HTML
    -- CSS media queries will handle the actual display
    mobileMode = false -- Always use desktop mode in Lua, CSS handles responsive
}
}


Line 170: Line 179:
          
          
         return '<div class="country-hub-wrapper">' -- .. flagImageWikitext -- Appended flag
         return '<div class="country-hub-wrapper">' -- .. flagImageWikitext -- Appended flag
    end
}
-- Feature Preview Banner
template.config.blocks.featureBanner = {
    feature = 'fullPage',
    render = function(template, args)
        return '<div class="country-hub-feature-banner">' ..
              '<strong>Country Hubs</strong> have been enabled as a feature preview and are still under testing.' ..
              ' Contribute more knowledge to our database so that they can keep growing!' ..
              '</div>'
     end
     end
}
}
Line 198: Line 218:
         local regionData = askCached('infoBox:region:' .. args.has_country, regionParams)
         local regionData = askCached('infoBox:region:' .. args.has_country, regionParams)
         local regionText = regionData[1] and regionData[1]['Has ICANN region'] or ''
         local regionText = regionData[1] and regionData[1]['Has ICANN region'] or ''
         regionText = NormalizationText.processWikiLink(regionText, 'strip')
         regionText = LinkParser.processWikiLink(regionText, 'strip')
          
          
         -- Check for an ISOC chapter in the country using fuzzy matching
         -- Check for an ISOC chapter in the country using fuzzy matching
Line 251: Line 271:
         if not foundMatch then
         if not foundMatch then
             ISOCText = string.format('[[Internet Society %s Chapter]]', args.has_country)
             ISOCText = string.format('[[Internet Society %s Chapter]]', args.has_country)
        end
       
        -- Check for a Youth IGF initiative in the country
        local youthParams = {
            string.format('[[Category:Youth IGF %s]]', args.has_country),
            limit = 1
        }
        local youthData = askCached('infoBox:youth:' .. args.has_country, youthParams)
        local youthText
        if youthData[1] and youthData[1]['result'] and youthData[1]['result'] ~= '' then
            youthText = youthData[1]['result']
        else
            youthText = string.format('[[Youth IGF %s]]', args.has_country)
         end
         end
          
          
Line 312: Line 319:
             :tag('th'):wikitext('ISOC chapter'):done()
             :tag('th'):wikitext('ISOC chapter'):done()
             :tag('td'):wikitext(ISOCText):done()
             :tag('td'):wikitext(ISOCText):done()
            :done()
       
        -- Youth IGF row
        infoBox:tag('tr')
            :tag('th'):wikitext('Youth IGF'):done()
            :tag('td'):wikitext(youthText):done()
             :done()
             :done()
          
          
Line 339: Line 340:


-- ANCHOR: OVERVIEW
-- ANCHOR: OVERVIEW
-- template.config.blocks.overview = {
template.config.blocks.overview = {
--     feature = 'overview',
     feature = 'overview',
--     render = function(template, args)
     render = function(template, args)
--         local displayCountry = (args.country or mw.title.getCurrentTitle().text or ""):gsub('_',' ')
         local displayCountry = (args.country or mw.title.getCurrentTitle().text or ""):gsub('_',' ')
--         local queryCountryName = args.has_country
         local queryCountryName = args.has_country
--         local params = {
         local params = {
--             string.format('[[Has country::%s]]', queryCountryName),
             string.format('[[Has country::%s]]', queryCountryName),
--             '[[Category:Country]]',
             '[[Category:Country]]',
--             '?Has description',
             '?Has description',
--             format = 'plain',
             format = 'plain',
--             limit  = 1
             limit  = 1
--         }
         }
--         local data = askCached('overview:' .. queryCountryName, params)
         local data = askCached('overview:' .. queryCountryName, params)
--         local desc = (data[1] and data[1]['Has description']) or ''
         local desc = (data[1] and data[1]['Has description']) or ''
--         if desc == '' then
         if desc == '' then
--             desc = 'No overview description found for ' .. displayCountry .. '.'
             desc = 'No overview description found for ' .. displayCountry .. '.'
--         end
         end
--         return '== Overview ==\n' .. desc
         return '== Overview ==\n' .. desc
--     end
     end
-- }
}


-- ANCHOR: ORGANIZATIONS
-- ANCHOR: ORGANIZATIONS
Line 364: Line 365:
     feature = 'organizations',
     feature = 'organizations',
     render = function(template, args)
     render = function(template, args)
        local displayCountry = (args.country or mw.title.getCurrentTitle().text or ""):gsub('_',' ')
         local params = {
         local params = {
             string.format('[[Has country::%s]] [[Has entity type::Organization]]', args.has_country),
             string.format('[[Has country::%s]] [[Has entity type::Organization]]', args.has_country),
             limit    = 50
             limit    = 20
         }
         }
         local data = askCached('organizations:' .. args.has_country, params)
         local data = askCached('organizations:' .. args.has_country, params)
        local htmlTable = renderTable(data, {'Organizations'})
         -- Store the raw count for masonry layout
         -- local processedBrowseLink = generateProcessedBrowseLink(
         template._rawDataCounts = template._rawDataCounts or {}
         --    template,
         template._rawDataCounts.organizations = #data
         --    "Organization",
         -- Only render if we have data
        --    "Has_country",
         if #data == 0 then
        --    "Browse all organizations for %s",
            return ''
         --     queryCountryName
        end
         -- )
        return renderTable(data, {'Organizations'})
        return '<div class="icannwiki-hubs-container"><div class="icannwiki-hub-column">\n'
            -- .. '=== Organizations ===\n'
            .. htmlTable .. '\n' -- .. processedBrowseLink .. '\n'
            .. '</div>'
     end
     end
}
}
Line 389: Line 385:
     feature = 'people',
     feature = 'people',
     render = function(template, args)
     render = function(template, args)
        local displayCountry = (args.country or mw.title.getCurrentTitle().text or ""):gsub('_',' ')
         local params = {
         local params = {
             string.format('[[Has country::%s]] [[Has entity type::Person]]',  
             string.format('[[Has country::%s]] [[Has entity type::Person]]',  
Line 396: Line 391:
         }
         }
         local data = askCached('people:' .. args.has_country, params)
         local data = askCached('people:' .. args.has_country, params)
        local tableHtml = renderTable(data, {'People'})
         -- Store the raw count for masonry layout
         -- local processedLink = generateProcessedBrowseLink(
         template._rawDataCounts = template._rawDataCounts or {}
         --    template,
         template._rawDataCounts.people = #data
         --    "Person",
         -- Only render if we have data
        --    "Has_country",
         if #data == 0 then
        --    "Browse all people for %s",
            return ''
         --     queryCountryName
        end
         -- )
        return renderTable(data, {'People'})
        local html = '<div class="icannwiki-hubs-container"><div class="icannwiki-hub-column">\n' ..
                    -- '=== People ===\n' ..
                    tableHtml .. '\n' ..
                    -- processedLink .. '\n' ..
                    '</div></div>'
        return html
     end,
     end,
}
}
Line 417: Line 406:
     feature = 'laws',
     feature = 'laws',
     render = function(template, args)
     render = function(template, args)
        local displayCountry = (args.country or mw.title.getCurrentTitle().text or ""):gsub('_',' ')
         local params = {
         local params = {
             string.format('[[Has country::%s]]', args.has_country),
             string.format('[[Has country::%s]] [[Has entity type::Norm]]', args.has_country),
            '[[Category:Laws]]',
             limit    = 20
            mainlabel = 'Law', sort = 'Has date', order = 'desc',
             limit    = 50
         }
         }
         local data = askCached('laws:' .. args.has_country, params)
         local data = askCached('laws:' .. args.has_country, params)
        local tableHtml = renderTable(data, {'Laws and Regulations'})
         -- Store the raw count for masonry layout
         -- local processedLink = generateProcessedBrowseLink(
         template._rawDataCounts = template._rawDataCounts or {}
         --    template,
         template._rawDataCounts.laws = #data
         --    "Laws",
         -- Only render if we have data
         --     "Has_country",
         if #data == 0 then
         --    "Browse all laws and regulations for %s",
            return ''
        --    queryCountryName
         end
         -- )
         return renderTable(data, {'Laws and Regulations'})
         return tableHtml
     end,
     end,
}
}
Line 441: Line 426:
     feature = 'documents',
     feature = 'documents',
     render = function(template, args)
     render = function(template, args)
        local displayCountry = (args.country or mw.title.getCurrentTitle().text or ""):gsub('_',' ')
         local params = {
         local params = {
             string.format('[[Has country::%s]]', args.has_country),
             string.format('[[Has country::%s]]', args.has_country),
             '[[Category:Document]]',
             '[[Category:Document]]',
             mainlabel = 'Document', sort = 'Has date', order = 'desc',
             mainlabel = 'Document', sort = 'Has date', order = 'desc',
             limit    = 50
             limit    = 20
         }
         }
         local data = askCached('documents:' .. args.has_country, params)
         return renderSection('documents:' .. args.has_country, params, {'Key Documents'})
        local tableHtml = renderTable(data, {'Key Documents'})
        -- local processedLink = generateProcessedBrowseLink(
        --    template,
        --    "Document",
        --    "Has_country",
        --    "Browse all documents for %s",
        --    queryCountryName
        -- )
        return tableHtml
     end,
     end,
}
}
Line 465: Line 440:
     feature = 'geoTlds',
     feature = 'geoTlds',
     render = function(template, args)
     render = function(template, args)
        local displayCountry = (args.country or mw.title.getCurrentTitle().text or ""):gsub('_',' ')
         local params = {
         local params = {
             string.format('[[Has country::%s]] [[Has entity type::TLD]] [[Has TLD subtype::geoTLD]]', args.has_country),
             string.format('[[Has country::%s]] [[Has entity type::TLD]] [[Has TLD subtype::geoTLD]]', args.has_country),
             limit    = 50
             limit    = 20
         }
         }
         local data = askCached('geoTlds:' .. args.has_country, params)
         local data = askCached('geoTlds:' .. args.has_country, params)
        local tableHtml = renderTable(data, {'GeoTLDs'})
         -- Store the raw count for masonry layout
         -- local processedLink = generateProcessedBrowseLink(
         template._rawDataCounts = template._rawDataCounts or {}
         --    template,
         template._rawDataCounts.geoTlds = #data
         --    "TLD",
         -- Only render if we have data
         --     "Has_country",
         if #data == 0 then
         --    "Browse all TLDs for %s",
            return ''
        --    queryCountryName
         end
         -- )
         return renderTable(data, {'GeoTLDs'})
         return tableHtml
     end,
     end,
}
}
Line 487: Line 460:
     feature = 'meetings',
     feature = 'meetings',
     render = function(template, args)
     render = function(template, args)
        local displayCountry = (args.country or mw.title.getCurrentTitle().text or ""):gsub('_',' ')
         local params = {
         local params = {
             string.format('[[Has country::%s]]', args.has_country),  
             string.format('[[Has country::%s]]', args.has_country),  
             '[[Has entity type::Event]]',  
             '[[Has entity type::Event]]',  
             limit    = 50
             limit    = 20
         }
         }
       
        -- local processedLink = generateProcessedBrowseLink(
        --    template,
        --    "Event",
        --    "Has_country",
        --    "Browse all events for %s",
        --    args.has_country
        -- )
       
         local data = askCached('events:' .. args.has_country, params)
         local data = askCached('events:' .. args.has_country, params)
          
         -- Store the raw count for masonry layout
         if not data or #data == 0 then
         template._rawDataCounts = template._rawDataCounts or {}
        template._rawDataCounts.meetings = #data
        -- Only render if we have data
        if #data == 0 then
             return ''
             return ''
         end
         end
          
         return renderTable(data, {'Internet Governance Events'})
        local tableHtml = renderTable(data, {'Internet Governance Events'})  
        return tableHtml
     end,
     end,
}
}
Line 518: Line 481:
     feature = 'nra',
     feature = 'nra',
     render = function(template, args)
     render = function(template, args)
        local displayCountry = (args.country or mw.title.getCurrentTitle().text or ""):gsub('_',' ')
         local params = {
         local params = {
             string.format('[[Has country::%s]] [[Has entity type::Organization]] [[Has organization type::Government agency]]', args.has_country),
             string.format('[[Has country::%s]] [[Has entity type::Organization]] [[Has organization type::Government agency]]', args.has_country),
             limit    = 10
             limit    = 20
         }
         }
         local data = askCached('nra:' .. args.has_country, params)
         local data = askCached('nra:' .. args.has_country, params)
         local tableHtml = renderTable(data, {'National Authorities'})
         -- Store the raw count for masonry layout
        return tableHtml
        template._rawDataCounts = template._rawDataCounts or {}
        template._rawDataCounts.nra = #data
        -- Only render if we have data
        if #data == 0 then
            return ''
        end
        return renderTable(data, {'National Authorities'})
     end,
     end,
}
}


-- -- REVIEW: CONNECTED COUNTRIES
-- -- REVIEW: CONNECTED COUNTRIES (COLONIES)


-- ANCHOR: RESOURCES
-- ANCHOR: RESOURCES
Line 535: Line 503:
     feature = 'resources',
     feature = 'resources',
     render = function(template, args)
     render = function(template, args)
        local displayCountry = (args.country or mw.title.getCurrentTitle().text or ""):gsub('_',' ')
         local params = {
         local params = {
             string.format('[[Has country::%s]]', args.has_country),
             string.format('[[Has country::%s]]', args.has_country),
             '[[Category:Resource]]',
             '[[Category:Resource]]',
             mainlabel = 'Resource',
             mainlabel = 'Resource',
             limit    = 10
             limit    = 20
         }
         }
         local data = askCached('resources:' .. args.has_country, params)
         return renderSection('resources:' .. args.has_country, params, {'Resources'})
        local tableHtml = renderTable(data, {'Resources'})
        return tableHtml
     end,
     end,
}
-- Data wrapper blocks
template.config.blocks.dataWrapperOpen = {
    feature = 'fullPage',
    render  = function() return '<div class="country-hub-data-container">' end
}
template.config.blocks.dataWrapperClose = {
    feature = 'fullPage',
    render  = function() return '</div>' end
}
}


Line 552: Line 527:
     feature = 'countryWrapper',
     feature = 'countryWrapper',
     render  = function() return '</div>' end
     render  = function() return '</div>' end
}
-- INTELLIGENT MASONRY LAYOUT INTEGRATION
-- Single block that handles all masonry logic at render-time (Blueprint pattern)
template.config.blocks.intelligentMasonry = {
    feature = 'fullPage',
    render = function(template, args)
        return MasonryLayout.renderIntelligentLayout(template, args, {
            cardDefinitions = cardDefinitions,
            options = masonryOptions,
            blockRenderers = {
                intro = template.config.blocks.intro,
                organizations = template.config.blocks.organizations,
                people = template.config.blocks.people,
                geoTlds = template.config.blocks.geoTlds,
                meetings = template.config.blocks.meetings,
                nra = template.config.blocks.nra,
                laws = template.config.blocks.laws,
                documents = template.config.blocks.documents,
                resources = template.config.blocks.resources,
                infoBox = template.config.blocks.infoBox
            }
        })
    end
}
}