API:Presenting Wikidata knowledge

Introduction
This shows how to retrieve and present facts from Wikidata about elements of your application.

Persistent language-independent facts
Millions of people discover information about all kinds of subjects by searching Wikipedia and related sites. API:Page info in search results explains how to guide readers to the best article and present descriptions and snippets from it. When presenting facts and information in your own application, you can use Wikidata items and properties to provide language-independent persistent information.

Example


Inventory lets you create an inventory of your books and share with others. It displays certain properties from Wikidata about books, such as P364 "original language of work" and P50 "author". To do so it uses Wikidata's 'Q' number items internally to identify books, for example the URL https://inventaire.io/entity/wd:Q180736 shows certain properties from Wikidata of the concept http://www.wikidata.org/entity/Q180736 the book "Les Misérables".

Data access on Wikidata explains items and identifiers in more detail.

Recipe

 * 1) Find existing interesting wiki pages in the domain of your application, e.g. books and authors, places, events.
 * 2) View the Wikidata information for those pages, choose interesting properties
 * 3) Build a viewer for this information
 * 4) Associate Wikidata items with elements of your application.
 * 5) When triggered, display their Wikidata information in the user's language
 * 6) Use the Wikidata "sitelinks" information about the item to provide links to the full Wikipedia (and Wikiquote, Wikivoyage, etc.) article about the element in the user's language

To get an article's to its unique identifier in Wikidata, you can
 * copy the link "Wikidata item" ('wikibase-dataitem' message key) in the sidebar in most skins
 * access the  variable in client-side JavaScript with
 * query the page for the page property :

Querying wikibase
The extensions Wikibase Repository and Wikibase Client power Wikidata, together with related components. Most Wikimedia sites run Wikibase Client (check with Special:Version), while only wikidata.org itself runs Wikibase Repository. Wikidata Repository implements several modules for MediaWiki's Action API all prefixed. The main workhorse API module in Wikibase Repository is  (see its generated API help). This provides data Wikidata has about item(s) in multiple languages.

''XXX sample query... language''

Alternatives
You can associate an element of your application with a page in a particular language's Wikipedia. Then as API:Page info in search results shows, you can query for and display useful information from that article such as a lead image thumbnail, opening text, and description (, |pageimages|pageterms&format=jsonfm&exsentences=2&exintro=&piprop=thumbnail&wbptterms=description&titles=Albert%20Einstein&formatversion=2 try it). A downside of this is page titles change so you may have to deal with redirects. Another is it's not multilingual: you have to know the page's title in other wikis (for example, the article in Greek Wikipedia about Les Misérables is Οι Άθλιοι), or track down a "sitelink" to the page in another language. That's why that article talks about page info in the context of search – if your user is searching for articles from a wiki, you know her language and the wiki to query.

Over time, this common information about articles in individual wikis is moving to Wikidata: So querying for Wikidata information is aligned with future developments.
 * is already returning the description of the page from Wikidata
 * The "Wikivoyage banner" image for places on Wikivoyage sites is now a property (P948) of the Wikidata item for that place (example of San Francisco).
 * The sitelinks to the same article in other languages and in other kinds of wikis are all maintained in Wikidata (example of San Francisco).