wikipediawikipedia-apiwikidatawikimediawikimedia-commons

Sitelinks for files on commons.wikimedia: is it possible to query them with SPARQL or API?


I know how to query sitelinks for wikidata items with SPARQL (see below), is there some similar way to get sitelinks for files on commons.wikimedia? For example, if we open this image info page, at the bottom of the page we have two lists "File usage on Commons" and "File usage on other wikis". Is it possible to get these lists programmatically (with SPARQL or some other API)?

SELECT ?billGates  ?image  ?article
WHERE 
{
  VALUES ?billGates { wd:Q5284  }
  ?billGates wdt:P18 ?image.

  #?article schema:about ?billGates .  # this correctly returns 201 sitelinks for wikidata item

 { ?articleIm1 schema:about ?image. }         # this returns 0 sitelinks
  union  { ?image schema:about ?articleIm2.}  # this returns 0 sitelinks
}

Solution

  • Have a look at https://commons.wikimedia.org/w/api.php?action=help&modules=query%Bglobalusage

    For example, the usage of the Bill Gates image on all Wikimedia wikis you can find with https://commons.wikimedia.org/w/api.php?action=query&prop=globalusage&gulimit=500&titles=File:Bill_Gates_-_World_Economic_Forum.jpg