Module:T-CountryHub: Difference between revisions

// via Wikitext Extension for VSCode
// via Wikitext Extension for VSCode
Line 178: Line 178:
     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
          
          
         -- Derive ccTLD from ISO code via CountryData module
         -- Derive ccTLD from ISO code via CountryData module
         local isoCode = CountryData.getCountryCodeByName(queryCountryName)
         local isoCode = CountryData.getCountryCodeByName(args.has_country)
         local ccTLDText
         local ccTLDText
         if isoCode and #isoCode == 2 then
         if isoCode and #isoCode == 2 then
Line 192: Line 191:
         -- Fetch ICANN region for the country
         -- Fetch ICANN region for the country
         local regionParams = {
         local regionParams = {
             string.format('[[Has country::%s]]', queryCountryName),
             string.format('[[Has country::%s]]', args.has_country),
             '?Has ICANN region',
             '?Has ICANN region',
             format = 'plain',
             format = 'plain',
             limit = 1
             limit = 1
         }
         }
         local regionData = askCached('infoBox:region:' .. queryCountryName, 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 = NormalizationText.processWikiLink(regionText, 'strip')
Line 219: Line 218:
         end
         end


         local countryData = CountryData.getCountryByName(queryCountryName)
         local countryData = CountryData.getCountryByName(args.has_country)
         local countryNamesToMatch = {}
         local countryNamesToMatch = {}
         if countryData then
         if countryData then
Line 229: Line 228:
             end
             end
         else
         else
             table.insert(countryNamesToMatch, normalizeForMatching(queryCountryName))
             table.insert(countryNamesToMatch, normalizeForMatching(args.has_country))
         end
         end


Line 251: Line 250:


         if not foundMatch then
         if not foundMatch then
             ISOCText = string.format('[[Internet Society %s Chapter]]', queryCountryName)
             ISOCText = string.format('[[Internet Society %s Chapter]]', args.has_country)
         end
         end
          
          
         -- Check for a Youth IGF initiative in the country
         -- Check for a Youth IGF initiative in the country
         local youthParams = {
         local youthParams = {
             string.format('[[Category:Youth IGF %s]]', queryCountryName),
             string.format('[[Category:Youth IGF %s]]', args.has_country),
             limit = 1
             limit = 1
         }
         }
         local youthData = askCached('infoBox:youth:' .. queryCountryName, youthParams)
         local youthData = askCached('infoBox:youth:' .. args.has_country, youthParams)
         local youthText
         local youthText
         if youthData[1] and youthData[1]['result'] and youthData[1]['result'] ~= '' then
         if youthData[1] and youthData[1]['result'] and youthData[1]['result'] ~= '' then
             youthText = youthData[1]['result']
             youthText = youthData[1]['result']
         else
         else
             youthText = string.format('[[Youth IGF %s]]', queryCountryName)
             youthText = string.format('[[Youth IGF %s]]', args.has_country)
         end
         end
          
          
         local flagImageWikitext = ""
         local flagImageWikitext = ""
         if queryCountryName and queryCountryName ~= "" then
         if args.has_country and args.has_country ~= "" then
             local isoCode = CountryData.getCountryCodeByName(queryCountryName)
             local isoCode = CountryData.getCountryCodeByName(args.has_country)
             if isoCode and #isoCode == 2 then
             if isoCode and #isoCode == 2 then
                 local flagFile = "Flag-" .. string.lower(isoCode) .. ".svg"
                 local flagFile = "Flag-" .. string.lower(isoCode) .. ".svg"
Line 366: Line 365:
     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 params = {
         local params = {
             string.format('[[Has country::%s]] [[Has entity type::Organization]]', queryCountryName),
             string.format('[[Has country::%s]] [[Has entity type::Organization]]', args.has_country),
             limit    = 50
             limit    = 50
         }
         }
         local data = askCached('organizations:' .. queryCountryName, params)
         local data = askCached('organizations:' .. args.has_country, params)
         local htmlTable = renderTable(data, {'Organizations'})
         local htmlTable = renderTable(data, {'Organizations'})
         -- local processedBrowseLink = generateProcessedBrowseLink(
         -- local processedBrowseLink = generateProcessedBrowseLink(
Line 392: Line 390:
     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 params = {
         local params = {
             string.format('[[Has country::%s]] [[Has entity type::Person]]',  
             string.format('[[Has country::%s]] [[Has entity type::Person]]',  
             queryCountryName),
             args.has_country),
             limit    = 20
             limit    = 20
         }
         }
         local data = askCached('people:' .. queryCountryName, params)
         local data = askCached('people:' .. args.has_country, params)
         local tableHtml = renderTable(data, {'People'})
         local tableHtml = renderTable(data, {'People'})
         -- local processedLink = generateProcessedBrowseLink(
         -- local processedLink = generateProcessedBrowseLink(
Line 421: Line 418:
     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 params = {
         local params = {
             string.format('[[Has country::%s]]', queryCountryName),
             string.format('[[Has country::%s]]', args.has_country),
             '[[Category:Laws]]',
             '[[Category:Laws]]',
             mainlabel = 'Law', sort = 'Has date', order = 'desc',
             mainlabel = 'Law', sort = 'Has date', order = 'desc',
             limit    = 50
             limit    = 50
         }
         }
         local data = askCached('laws:' .. queryCountryName, params)
         local data = askCached('laws:' .. args.has_country, params)
         local tableHtml = renderTable(data, {'Laws and Regulations'})
         local tableHtml = renderTable(data, {'Laws and Regulations'})
         -- local processedLink = generateProcessedBrowseLink(
         -- local processedLink = generateProcessedBrowseLink(
Line 446: Line 442:
     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 params = {
         local params = {
             string.format('[[Has country::%s]]', queryCountryName),
             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    = 50
         }
         }
         local data = askCached('documents:' .. queryCountryName, params)
         local data = askCached('documents:' .. args.has_country, params)
         local tableHtml = renderTable(data, {'Key Documents'})
         local tableHtml = renderTable(data, {'Key Documents'})
         -- local processedLink = generateProcessedBrowseLink(
         -- local processedLink = generateProcessedBrowseLink(
Line 471: Line 466:
     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 params = {
         local params = {
             string.format('[[Has country::%s]] [[Has entity type::TLD]] [[Has TLD subtype::geoTLD]]', queryCountryName),
             string.format('[[Has country::%s]] [[Has entity type::TLD]] [[Has TLD subtype::geoTLD]]', args.has_country),
             limit    = 50
             limit    = 50
         }
         }
         local data = askCached('geoTlds:' .. queryCountryName, params)
         local data = askCached('geoTlds:' .. args.has_country, params)
         local tableHtml = renderTable(data, {'GeoTLDs'})
         local tableHtml = renderTable(data, {'GeoTLDs'})
         -- local processedLink = generateProcessedBrowseLink(
         -- local processedLink = generateProcessedBrowseLink(
Line 494: Line 488:
     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 params = {
         local params = {
             string.format('[[Has country::%s]]', queryCountryName),  
             string.format('[[Has country::%s]]', args.has_country),  
             '[[Has entity type::Event]]',  
             '[[Has entity type::Event]]',  
             limit    = 50
             limit    = 50
Line 507: Line 500:
         --    "Has_country",  
         --    "Has_country",  
         --    "Browse all events for %s",  
         --    "Browse all events for %s",  
         --    queryCountryName
         --    args.has_country
         -- )
         -- )
          
          
         local data = askCached('events:' .. queryCountryName, params)
         local data = askCached('events:' .. args.has_country, params)
          
          
         if not data or #data == 0 then
         if not data or #data == 0 then
Line 526: Line 519:
     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 params = {
         local params = {
             string.format('[[Has country::%s]] [[Has entity type::Organization]] [[Has organization type::Government agency]]', queryCountryName),
             string.format('[[Has country::%s]] [[Has entity type::Organization]] [[Has organization type::Government agency]]', args.has_country),
             limit    = 10
             limit    = 10
         }
         }
         local data = askCached('nra:' .. queryCountryName, params)
         local data = askCached('nra:' .. args.has_country, params)
         local tableHtml = renderTable(data, {'National Authorities'})
         local tableHtml = renderTable(data, {'National Authorities'})
         return tableHtml
         return tableHtml
Line 544: Line 536:
     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 params = {
         local params = {
             string.format('[[Has country::%s]]', queryCountryName),
             string.format('[[Has country::%s]]', args.has_country),
             '[[Category:Resource]]',
             '[[Category:Resource]]',
             mainlabel = 'Resource',
             mainlabel = 'Resource',
             limit    = 10
             limit    = 10
         }
         }
         local data = askCached('resources:' .. queryCountryName, params)
         local data = askCached('resources:' .. args.has_country, params)
         local tableHtml = renderTable(data, {'Resources'})
         local tableHtml = renderTable(data, {'Resources'})
         return tableHtml
         return tableHtml