Jump to content

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) Sam Wilson (Samwilsontalk)
Latest version 4.0.0 (2025-12-16)
Compatibility policy Master maintains backward compatibility.
MediaWiki >= 1.43
Database changes No
Composer samwilson/unlinked-wikibase
  • $wgUnlinkedWikibaseImitationMode
  • $wgUnlinkedWikibaseStatementsParserFunc
  • $wgUnlinkedWikibaseCache
  • $wgUnlinkedWikibaseSitelinkSuffix
  • $wgUnlinkedWikibaseFormatterUrlProp
  • $wgUnlinkedWikibaseSitelinkSkippedLangs
  • $wgUnlinkedWikibaseEntityTTL
  • $wgUnlinkedWikibaseQueryTTL
  • $wgUnlinkedWikibaseBaseQueryEndpoint
  • $wgUnlinkedWikibaseBaseUrl
Licence GNU General Public License 2.0 or later
Download
Help Help:Extension:UnlinkedWikibase
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. See the help page for more information about using it.

Installation

[edit]
  • Download and move the extracted UnlinkedWikibase folder to your extensions/ directory.
    Developers and code contributors should install the extension from Git instead, using:
    cd extensions/
    git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/UnlinkedWikibase
    
  • 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 changes:

  • 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.
  • When upgrading from 3.0 to 4.0, note that mw.ext.UnlinkedWikibase.getEntity() no longer returns "invalid-item-id" or "item-not-found", but in both of those cases (invalid item IDs and items not found) will now return nil. This is to match the behaviour of Wikibase .

Configuration

[edit]

URLs and caching

[edit]

To link to a different Wikibase other than Wikidata, set the following two configuration variables:

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

Entities and queries are cached for 1 and 60 minutes respectively. These can be changed as follows:

$wgUnlinkedWikibaseQueryTTL = 3600;
$wgUnlinkedWikibaseEntityTTL = 60;

Note that $wgUnlinkedWikibaseEntityTTL can be set to null if you wish to use the maintenance script to refresh the cache (see below for details).

Imitating Wikibase

[edit]

UnlinkedWikibase can be run in an experimental "imitation mode", in which it will provide parser functions and Lua methods to match (to some extent) those of the Wikibase extension. Imitation mode can be enabled by adding the following to LocalSettings.php:

$wgUnlinkedWikibaseImitationMode = true;

Imitation mode should not be enabled on wikis that are also using the Wikibase extension.

(The earlier $wgUnlinkedWikibaseStatementsParserFunc configuration variable is deprecated and will be removed at some point, but for now is an alias for the $wgUnlinkedWikibaseImitationMode.)

In imitation mode the following features are enabled:

  1. The aliasing of the mw.ext.unlinkedwikibase.* API to also be available under mw.wikibase.*.
  2. The addition of the {{#statements:}} and {{#property:}} parser functions that operate similarly to the Wikibase parser functions of the same names,

Note that imitation mode is experimental and may require future changes to make it compatible with the new parser (e.g. requiring the |from= parameter everywhere that currently assumes the current page's entity ID).

[edit]

It is possible to set a page's interlanguage links based on the sitelinks defined in its Wikibase item, using the Sitelink Suffix configuration variable. This should be set to the wiki family suffix (for example, wiki for Wikipedia or wikisource for Wikisource, when using Wikidata).

$wgUnlinkedWikibaseSitelinkSuffix = 'wiki';

Set it to false (the default) to disable this feature.

If your wiki has its own sibling wikis in other languages, and you want to keep these as being able to be set in the normal way, add their language codes to $wgUnlinkedWikibaseSitelinkSkippedLangs. For example, if you have two wikis, in Indonesian and French, then pages can link to these with e.g. [[fr:Lorem]], and they should be excluded from UnlinkedWikibase's handling:

$wgUnlinkedWikibaseSitelinkSkippedLangs = [ 'fr', 'id' ];

This relies on the Wikibase site IDs being the concatenation of their language code and family name; if this is not true for your set-up please open a task on Phabricator.

Maintenance script

[edit]

There is a Maintenance script that can be used to update the cached Wikibase entity data. It's of most use if you set $wgUnlinkedWikibaseEntityTTL = null, which will prevent the external requests from being run (other than the first time).

Run it as follows:

$ php maintenance/run.php UnlinkedWikibase:UpdateEntities

See also

[edit]