User:Mike Peel/Commons linking

This page summarises how Wikidata links to Wikimedia Commons (and vice-versa).

Links from Wikidata to Commons edit

Wikidata items edit

Sitelinks edit

Sitelinks are bidirectional: you can follow them from Wikidata to go to Commons, or you can follow them from Commons ('Wikidata item' in the sidebar) to go to Wikidata. You can also access Wikidata information from within the sitelinked category/page. They are also automatically updated when a page is moved, and removed when a page is deleted (both for galleries and categories). They are not automatically updated with page creations or if a redirect is created, instead they need to be added manually or by bot to the appropriate item.

Commons sitelinks are under 'Other links' at the bottom of the page. Only one sitelink can be added per item.

The generally accepted convention is:

  • Commons Gallery links go on 'topic' items (those that link to Wikipedia articles)
  • Commons Category links to on 'category' items (those that link to Wikipedia categories)
  • If there is no category item and no Commons Gallery, then the Commons Category can be sitelinked from the topic item
  • If there is a gallery and a category, but not a 'category' item, then one can be created to link to the Commons category
  • 'Creator' and other namespaces should not be linked to via sitelinks

Wikidata:Notability allows the above convention, but it currently excludes the creation of category items that only exist on Commons. In particular 1.4 states that "Category items with a sitelink only to Wikimedia Commons are not permitted, unless either a) there is a corresponding main item which has a sitelink to a Commons gallery or b) the item is used in a Commons-related statement"

Linking between topic, list and category items edit

There are also more specific linking properties between topics and categories, including:

Links to individual images edit

Individual images can be included in Wikidata items using the following properties. Ideally only 1 image per property. Category items should not have images.

String Properties edit

There are a few properties that provide one-way links from Wikidata to Commons using strings. These are not automatically updated: they have to be manually or bot edited. Some bots (which?) add new values to these.

P373 edit

Blockers for deletion:

  • Links to more general categories that relate to the item
  • Wikipedia sitelinks use the property, see

P935 edit

Blockers for deletion:

  • We have links to many galleries that don't exist, or are redirected to categories
  • There are many poor quality Commons galleries that we probably don't want to link to.
  • There are many galleries that we don't yet have links to.

P1472 edit

  • There is currently no other way to link to these from Wikidata
  • They may no longer be needed anyway, as they can be migrated over to using Wikidata directly

Bot maintenance edit

  • Pi bot has various tasks that keep sitelinks and properties up-to-date and semi-synchronised.

Links from Commons to Wikidata edit

Wikidata Infobox edit

Wikidata information is included in Commons categories and galleries. These rely on the Commons sitelinks, and use commons:Template:Wikidata Infobox to show:

  • The topic item if directly sitelinked to that
  • The topic item if sitelinked to a category item that has category's main topic (P301) (the first category's main topic (P301) will be followed), plus some parts of the category item
  • The category item if directly sitelinked to that, and there is no category's main topic (P301) value
  • If there is no sitelink, then links to find the item on Wikidata, or create a new item, will be shown

Structured Data on Commons edit

File pages on Commons now use Wikidata information directly (not via any templates), and share the properties that are used on Wikidata. In particular, depicts (P180) describes what a photograph depicts, and these use Wikidata items.

Links from other sites to Commons using Wikidata edit

Lua edit

commons:Module:WikidataIB has a "getCommonsLink" function. This will:

  • Return the Commons sitelink from the current item, if there is one
  • Otherwise, it will follow through the first topic's main category (P910) value to see if there is a Commons sitelink there that it can return
  • Otherwise, it will follow through the first category related to list (P1754) value to see if there is a Commons sitelink there that it can return
  • Otherwise, it will return nothing.
  • If you set onlycat=True then it will only return a category item if there is one available, ignoring any non-category items.

Templates edit

en:Template:Commons category and en:Template:Commons category-inline both use getCommonsLink to retrieve values, and to populate the tracking categories at en:Category:Commons category Wikidata tracking categories. This is also live on simple-wiki.

MediaWiki edit

The 'Commons' link in the sidebar is drawn from the sitelink, following topic's main category (P910) and category related to list (P1754) as appropriate, with a fall-back to Commons category (P373) if needed. See phabricator:T232927.

SPARQL queries edit

You can fetch the item's commons sitelink by including the following in your SPARQL query:

?commonscat schema:about ?item; schema:isPartOf <https://commons.wikimedia.org/>.

Requests for Comments edit