Extension:UnlinkedWikibase

From mediawiki.org
MediaWiki extensions manual
UnlinkedWikibase
Release status: beta
Implementation Parser function
Description Access to Wikibase entities from wikis that are not linked to a Wikibase site.
Author(s) (Samwilsontalk)
Latest version 3.0.1 (2023-06-09)
Compatibility policy Master maintains backward compatibility.
MediaWiki >= 1.38
Database changes No
Composer samwilson/unlinked-wikibase
License GNU General Public License 2.0 or later
Download
  • $wgUnlinkedWikibaseQueryTTL
  • $wgUnlinkedWikibaseBaseQueryEndpoint
  • $wgUnlinkedWikibaseBaseUrl
Quarterly downloads 3 (Ranked 158th)
Translate the UnlinkedWikibase extension if it is available at translatewiki.net
Vagrant role unlinkedwikibase
Issues Open tasks · Report a bug

The UnlinkedWikibase extension provides access to Wikibase entities from wikis that are not linked to a Wikibase site. For example, a private wiki with a page about Goats could retrieve metadata from the Wikidata item goat (Q2934) and display it in an infobox.

Lua data-retrieval API[edit]

The extension integrates with Scribunto to provide two Lua data-retrieval functions: one to retrieve a single entity and another one to retrieve the results of a SPARQL query.

mw.ext.UnlinkedWikibase.getEntity( id )
Returns the entire entity object (as is seen at d:Special:EntityData/Q2934.json for the goat example). This is similar to Wikibase's own mw.wikibase.getEntity( id ), which works for pages that do have sitelinks to an entity.
mw.ext.UnlinkedWikibase.query( sparql )
Runs the given SPARQL query against the Wikidata Query Service and returns the result.

Linking pages to Wikibase entities[edit]

There is also a means to associate a wiki page with a Wikibase entity. This is done with the {{#unlinkedwikibase| id=Q2934 }} parser function, which stores the given ID as a page property for the page on which it's used. This ID can then be retrieved in the context of other pages via the mw.ext.UnlinkedWikibase.getLocalTitle( id ) method, which returns a Title object for the relevant page.

Parser function {{#unlinkedwikibase: id= }}
Set a page's Wikibase entity ID.
Lua method mw.ext.UnlinkedWikibase.getLocalTitle( id )
Get a Title object for a page that uses {{#unlinkedwikibase: id= }}.

Installation[edit]

  • Download and place the file(s) in a directory called UnlinkedWikibase in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'UnlinkedWikibase' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Upgrading[edit]

Breaking change: When upgrading from 2.0 to 3.0, note that mw.ext.UnlinkedWikibase.getEntity() has changed to return 1-index arrays rather than 0-indexed as previously. For example, the value of the first title (P1476) claim should be found with item.claims.P1476[1].mainsnak.datavalue.value.text rather than item.claims.P1476[0].mainsnak.datavalue.value.text.

Configuration[edit]

To link to a different Wikibase other than Wikidata, or to configure the SPARQL query result cache timeout, you can set the following configuration variables in LocalSettings.php:

$wgUnlinkedWikibaseBaseUrl = 'https://xxx.wikibase.cloud/wiki/';
$wgUnlinkedWikibaseBaseQueryEndpoint = 'https://xxx.wikibase.cloud/query/sparql';

# Cache SPARQL results for half an hour (supported in master/1.39+, default 3600)
$wgUnlinkedWikibaseQueryTTL = 1800;

See also[edit]