Jump to content

Module:Higher education task force

Permanently protected module
From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Pharos (talk | contribs) at 21:27, 13 February 2025 (highly experimental test page, do not use yet). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
local HigherEducationTaskForce = {}

local wikidata_items = {
  student = 'Q132302671', -- Wikidata item for WikiProject Students
  cuny = 'Q132192407', -- Wikidata item for CUNY WikiProject
  uva = 'Q21831051' -- Wikidata item for UVA WikiProject
}

local p = {}

function p.getData( frame )
  local keyword = frame.args[1]
  if not keyword then
    return nil -- No keyword provided
  end

  local wikidata_item_id = wikidata_items[keyword]
  if not wikidata_item_id then
    return nil -- Keyword not found
  end

  local data = {}
  data.wikidata_item = wikidata_item_id

  local entity = mw.wikibase.getEntity( wikidata_item_id )
  if not entity then
    return nil -- Could not fetch entity from Wikidata
  end

  -- TF_1_NAME (P1476 - title)
  if entity.claims and entity.claims.P1476 then
    local titleClaim = entity.claims.P1476[1] -- Assuming only one title
    if titleClaim.mainsnak.datavalue and titleClaim.mainsnak.datavalue.value then
      data.tf_1_name = titleClaim.mainsnak.datavalue.value.text
    end
  end

  -- TF_1_NESTED (P1813 - short name)
  if entity.claims and entity.claims.P1813 then
    local shortNameClaim = entity.claims.P1813[1] -- Assuming only one short name
    if shortNameClaim.mainsnak.datavalue and shortNameClaim.mainsnak.datavalue.value then
      data.tf_1_nested = shortNameClaim.mainsnak.datavalue.value.text
    end
  end

  -- TF_1_IMAGE (P154 - logo image)
  if entity.claims and entity.claims.P154 then
    local imageClaim = entity.claims.P154[1] -- Assuming only one logo image
    if imageClaim.mainsnak.datavalue and imageClaim.mainsnak.datavalue.value then
      local imageName = imageClaim.mainsnak.datavalue.value.value -- Get the filename
      data.tf_1_image = imageName
    end
  end

  -- TF_1_MAIN_CAT (P910 - topic category)
  if entity.claims and entity.claims.P910 then
    local mainCatClaim = entity.claims.P910[1] -- Assuming only one topic category
    if mainCatClaim.mainsnak.datavalue and mainCatClaim.mainsnak.datavalue.value then
      local categoryItemId = mainCatClaim.mainsnak.datavalue.value['entity-type'] == 'item' and mainCatClaim.mainsnak.datavalue.value.id
      if categoryItemId then
        local categoryEntity = mw.wikibase.getEntity( categoryItemId )
        if categoryEntity and categoryEntity.labels and categoryEntity.labels.en then
          data.tf_1_main_cat = categoryEntity.labels.en.value .. " articles" -- Append " articles" as per example
        end
      end
    end
  end


  return data
end


function p.getWikidataItem( frame )
  local data = p.getData( frame )
  if data then
    return data.wikidata_item
  else
    return nil
  end
end

function p.getTFName( frame )
  local data = p.getData( frame )
  if data then
    return data.tf_1_name
  else
    return nil
  end
end

function p.getTFNested( frame )
  local data = p.getData( frame )
  if data then
    return data.tf_1_nested
  else
    return nil
  end
end

function p.getTFImage( frame )
  local data = p.getData( frame )
  local imageName = data and data.tf_1_image
  if imageName then
    return imageName
  else
    return nil
  end
end


function p.getTFMainCat( frame )
  local data = p.getData( frame )
  if data then
    return data.tf_1_main_cat
  else
    return nil
  end
end


return p