Module:T-CountryHub: Difference between revisions

// via Wikitext Extension for VSCode
Tag: Reverted
Maintenance update // via Wikitext Extension for VSCode
 
(22 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')
Line 82: Line 83:
     return renderTable(data, columns)
     return renderTable(data, columns)
end
end
-- -- generateProcessedBrowseLink: Constructs and preprocesses a MediaWiki link for browsing data, with {{fullurl:...}} correctly expanded by MediaWiki before the link is rendered.
-- local function generateProcessedBrowseLink(template, browseType, browseQueryParam, linkTextPattern, country)
--    -- Explicitly URL-encode the country name for use in the URL query parameter
--    local encodedCountry = mw.uri.encode(country, 'QUERY') -- 'QUERY' mode is for query string values
--    local browseLinkString = string.format(
--        '[{{fullurl:Special:BrowseData/%s|%s=%s}} %s →]',
--        browseType,
--        browseQueryParam,
--        encodedCountry,  -- Use the encoded country name for the URL part
--        string.format(linkTextPattern, country) -- Use the original country name for the display text
--    )
   
--    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 123: Line 100:
         organizations = true,
         organizations = true,
         people = true,
         people = true,
         laws = false,
         laws = true,
         documents = false,
         documents = false,
         geoTlds = true,
         geoTlds = true,
Line 144: Line 121:
template.config.blockSequence = {
template.config.blockSequence = {
     'wrapperOpen',
     'wrapperOpen',
    'featureBanner',
     'overview',
     'overview',
     'intelligentMasonry',
     'intelligentMasonry',
Line 168: Line 146:
     columns = 3,
     columns = 3,
     mobileColumns = 1,
     mobileColumns = 1,
    tabletColumns = 2,
     containerClass = 'country-hub-masonry-container',
     containerClass = 'country-hub-masonry-container',
     columnClass = 'country-hub-masonry-column',
     columnClass = 'country-hub-masonry-column',
     cardClass = 'country-hub-masonry-card'
     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 198: 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 226: 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 281: Line 273:
         end
         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
       
        -- Generate flag image for background
         local flagImageWikitext = ""
         local flagImageWikitext = ""
         if args.has_country and args.has_country ~= "" then
         if args.has_country and args.has_country ~= "" then
Line 307: Line 285:
         end
         end


         -- Build data for standard table rendering (like other cards)
         -- Assemble the HTML for the infobox table
         local infoData = {
        local infoBoxWrapper = html.create('div')
             {result = 'ccTLD', value = ccTLDText},
            :addClass('country-hub-infobox-wrapper')
             {result = 'ICANN region', value = regionText},
       
             {result = 'ISOC chapter', value = ISOCText},
         local infoBox = infoBoxWrapper:tag('table')
             {result = 'Youth IGF', value = youthText}
            :addClass('country-hub-infobox icannwiki-automatic-text')
        }
       
        -- Header row
        infoBox:tag('tr')
            :tag('th')
                :attr('colspan', '2')
                :addClass('country-hub-infobox-header icannwiki-automatic-text')
                :wikitext(string.format('%s', displayCountry))
                :done()
             :done()
       
        -- ccTLD row
        infoBox:tag('tr')
            :tag('th'):wikitext('ccTLD'):done()
            :tag('td'):wikitext(ccTLDText):done()
            :done()
       
        -- ICANN region row
        infoBox:tag('tr')
             :tag('th'):wikitext('ICANN region'):done()
            :tag('td'):wikitext(regionText):done()
            :done()
       
        -- REVIEW: Check for ccNSO membership or affiliation in the country / https://ccnso.icann.org/en/about/members.htm
 
        -- ISOC chapter row
        infoBox:tag('tr')
             :tag('th'):wikitext('ISOC chapter'):done()
             :tag('td'):wikitext(ISOCText):done()
            :done()
          
          
         -- Render as standard wikitable with flag background
         infoBoxWrapper:wikitext(flagImageWikitext)
        local tableHtml = renderTable(infoData, {'Country Info'})
          
          
        -- Wrap with flag background
         return tostring(infoBoxWrapper)
         return string.format(
            '<div class="country-hub-infobox-wrapper">%s%s</div>',
            tableHtml,
            flagImageWikitext
        )
     end
     end
}
}
Line 367: Line 367:
         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)
        -- Store the raw count for masonry layout
        template._rawDataCounts = template._rawDataCounts or {}
        template._rawDataCounts.organizations = #data
        -- Only render if we have data
        if #data == 0 then
            return ''
        end
         return renderTable(data, {'Organizations'})
         return renderTable(data, {'Organizations'})
     end
     end
Line 384: Line 391:
         }
         }
         local data = askCached('people:' .. args.has_country, params)
         local data = askCached('people:' .. args.has_country, params)
        -- Store the raw count for masonry layout
        template._rawDataCounts = template._rawDataCounts or {}
        template._rawDataCounts.people = #data
        -- Only render if we have data
        if #data == 0 then
            return ''
        end
         return renderTable(data, {'People'})
         return renderTable(data, {'People'})
     end,
     end,
Line 393: Line 407:
     render = function(template, args)
     render = function(template, args)
         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
         }
         }
         return renderSection('laws:' .. args.has_country, params, {'Laws and Regulations'})
         local data = askCached('laws:' .. args.has_country, params)
        -- Store the raw count for masonry layout
        template._rawDataCounts = template._rawDataCounts or {}
        template._rawDataCounts.laws = #data
        -- Only render if we have data
        if #data == 0 then
            return ''
        end
        return renderTable(data, {'Laws and Regulations'})
     end,
     end,
}
}
Line 410: Line 430:
             '[[Category:Document]]',
             '[[Category:Document]]',
             mainlabel = 'Document', sort = 'Has date', order = 'desc',
             mainlabel = 'Document', sort = 'Has date', order = 'desc',
             limit    = 50
             limit    = 20
         }
         }
         return renderSection('documents:' .. args.has_country, params, {'Key Documents'})
         return renderSection('documents:' .. args.has_country, params, {'Key Documents'})
Line 422: Line 442:
         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
         }
         }
         return renderSection('geoTlds:' .. args.has_country, params, {'GeoTLDs'})
         local data = askCached('geoTlds:' .. args.has_country, params)
        -- Store the raw count for masonry layout
        template._rawDataCounts = template._rawDataCounts or {}
        template._rawDataCounts.geoTlds = #data
        -- Only render if we have data
        if #data == 0 then
            return ''
        end
        return renderTable(data, {'GeoTLDs'})
     end,
     end,
}
}
Line 435: Line 463:
             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
         }
         }
         return renderSection('events:' .. args.has_country, params, {'Internet Governance Events'})
         local data = askCached('events:' .. args.has_country, params)
        -- Store the raw count for masonry layout
        template._rawDataCounts = template._rawDataCounts or {}
        template._rawDataCounts.meetings = #data
        -- Only render if we have data
        if #data == 0 then
            return ''
        end
        return renderTable(data, {'Internet Governance Events'})
     end,
     end,
}
}
Line 447: Line 483:
         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
         }
         }
         return renderSection('nra:' .. args.has_country, params, {'National Authorities'})
         local data = askCached('nra:' .. args.has_country, params)
        -- Store the raw count for masonry layout
        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,
}
}
Line 463: Line 507:
             '[[Category:Resource]]',
             '[[Category:Resource]]',
             mainlabel = 'Resource',
             mainlabel = 'Resource',
             limit    = 10
             limit    = 20
         }
         }
         return renderSection('resources:' .. args.has_country, params, {'Resources'})
         return renderSection('resources:' .. args.has_country, params, {'Resources'})