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
- Most Wikidata items have either instance of (P31) or subclass of (P279)
- Items with instance of (P31)=Wikimedia category (Q4167836) are considered to be 'category' items here
- Items with instance of (P31)=Wikimedia list article (Q13406463) are considered to be 'list' items here
- All other items are 'topic' items
- Wikimedia lists category (Q56428020) are more complicated (and not currently included)
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
- Topic and category items are linked via the inverse pair of properties category's main topic (P301) and topic's main category (P910)
- Likewise, list and category items are linked via list related to category (P1753) and category related to list (P1754)
- category combines topics (P971) is useful where a category combines multiple topics
There are also more specific linking properties between topics and categories, including:
- category for people born here (P1464)
- category for pictures taken with equipment (P2033)
- category for recipients of this award (P2517)
- category for the interior of the item (P7561)
- category for ship name (P7782)
- category for maps (P7867)
- ...
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.
- image (P18)
- montage image (P2716)
- nighttime view (P3451)
- chemical structure (P117)
- image of grave (P1442)
- image with frame (P7420)
- image of backside (P7417)
- signature (P109)
- creator's signature (P7457)
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/>.