Wikibase/Installation
This page provides a step-by-step instruction how to install a basic version of Wikibase. It just explains the minimal configuration needed for Wikibase. If you're interested in a more advanced configuration, please refer to the advanced configuration guide. A complete documentation exist in the docs folder for Wikibase, see Github: wikimedia/mediawiki-extensions-Wikibase/docs.
Prerequisites[edit]
MediaWiki[edit]
Technically, Wikibase is an extension (actually two extensions) to MediaWiki, so you need to set up MediaWiki first.
Composer[edit]
The easiest way to install all dependencies of Wikibase is using Composer. Here you can find installation instructions for Composer.
Installation[edit]
A basic installation of Wikibase is pretty much straight forward and basically consists of 4 steps:
- getting Wikibase
- fetching dependencies
- modifying LocalSettings.php
- running some maintenance scripts.
The following guide will lead you through these steps.
Meet the prerequisites[edit]
Make sure you've set up MediaWiki and installed Composer.
Get Wikibase[edit]
Download the version of Wikibase that matches your Mediawiki installation into the extensions folder of your MediaWiki installation. There are several ways to download Wikibase.
Download from Git[edit]
- For getting the latest unstable version of Wikibase, do:
cd extensions
git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/Wikibase.git
cd Wikibase
git submodule update --init --recursive # get the dependencies using submodules
- You should use a version of Wikibase that corresponds with the version of MediaWiki itself. For getting a specific version of Wikibase you have to specify the branch you want to download. For example, to install Wikibase for Mediawiki version 1.34.x use the Wikibase branch REL1_34:
cd extensions
git clone -b REL1_34 https://github.com/wikimedia/mediawiki-extensions-Wikibase.git Wikibase
cd Wikibase
git submodule update --init --recursive # get the dependencies using submodules
Make sure the folder you just downloaded is called Wikibase
and located in extensions/
Download archive[edit]
- Instead of using Git you can alternatively download an archive with the latest version of Wikibase or choose to download a specific version of Wikibase.
- Make sure you extract the archive into a new folder called
Wikibase
inside the extensions folder of your MediaWiki installation.
Fetch all dependencies[edit]
Using the composer-merge-plugin
Include the following into composer.local.json
at the root of your mediawiki installation:
{
"extra": {
"merge-plugin": {
"include": [
"extensions/Wikibase/composer.json"
]
}
},
"require": {
"monolog/monolog": "~2.0.2"
}
}
and run from the root of your mediawiki installation using just one of these methods:
# always
rm composer.lock
# if composer is available as a binary
composer install --no-dev
# if you downloaded composer.phar
php composer.phar install --no-dev
# Or use dockerized version (does not require PHP or composer installed)
docker run -it --rm --user $(id -u):$(id -g) -v ~/.composer:/tmp -v $(pwd):/app docker.io/composer install --no-dev
Adjust your LocalSettings.php[edit]
Add the following lines to LocalSettings.php of your MediaWiki installation. You have three options, depending on whether you want to enable Wikibase Repository, Wikibase Client or both of them.
Enable Wikibase Repository only[edit]
$wgEnableWikibaseRepo = true;
$wgEnableWikibaseClient = false;
require_once "$IP/extensions/Wikibase/repo/Wikibase.php";
require_once "$IP/extensions/Wikibase/repo/ExampleSettings.php";
$wgWBRepoSettings['siteLinkGroups'] = [ 'mywikigroup' ];
$wgLocalDatabases = [ 'enwiki', 'fawiki' ];
$wgWBRepoSettings['localClientDatabases'] = array(
'en' => 'enwiki',
'fa' => 'fawiki'
);
Important: If you're using master or 1.36 (and above) you need to use extension registration instead. The above code will fail:
wfLoadExtension( 'WikibaseRepository', "$IP/extensions/Wikibase/extension-repo.json" );
require_once "$IP/extensions/Wikibase/repo/ExampleSettings.php";
$wgWBRepoSettings['siteLinkGroups'] = [ 'mywikigroup' ];
$wgLocalDatabases = [ 'enwiki', 'fawiki' ];
$wgWBRepoSettings['localClientDatabases'] = array(
'en' => 'enwiki',
'fa' => 'fawiki'
);
Enable Wikibase Client only[edit]
$wgEnableWikibaseRepo = false;
$wgEnableWikibaseClient = true;
require_once "$IP/extensions/Wikibase/client/WikibaseClient.php";
require_once "$IP/extensions/Wikibase/client/ExampleSettings.php";
$wgWBClientSettings['repoUrl'] = 'https://pool.my.wiki';
$wgWBClientSettings['repoScriptPath'] = '';
$wgWBClientSettings['repoArticlePath'] = '/wiki/$1';
$wgWBClientSettings['repositories']['']['repoDatabase'] = 'poolwiki';
$wgWBClientSettings['repositories']['']['changesDatabase'] = 'poolwiki';
$wgWBClientSettings['siteLinkGroups'] = [ 'mywikigroup' ];
$wgWBClientSettings['siteGlobalID'] = 'en';
For another lang-wiki client, like Farsi, change the siteGlobalID to:
$wgWBClientSettings['siteGlobalID'] = 'fa';
Important: Similar to above, if you're using 1.36 or master, you need to use this instead:
wfLoadExtension( 'WikibaseClient', "$IP/extensions/Wikibase/extension-client.json" );
require_once "$IP/extensions/Wikibase/client/ExampleSettings.php";
$wgWBClientSettings['repoUrl'] = 'https://pool.my.wiki';
$wgWBClientSettings['repoScriptPath'] = '';
$wgWBClientSettings['repoArticlePath'] = '/wiki/$1';
$wgWBClientSettings['repositories']['']['repoDatabase'] = 'poolwiki';
$wgWBClientSettings['repositories']['']['changesDatabase'] = 'poolwiki';
$wgWBClientSettings['siteLinkGroups'] = [ 'mywikigroup' ];
$wgWBClientSettings['siteGlobalID'] = 'en';
Enable Wikibase Repository and Wikibase Client[edit]
$wgEnableWikibaseRepo = true;
$wgEnableWikibaseClient = true;
require_once "$IP/extensions/Wikibase/repo/Wikibase.php";
require_once "$IP/extensions/Wikibase/repo/ExampleSettings.php";
require_once "$IP/extensions/Wikibase/client/WikibaseClient.php";
require_once "$IP/extensions/Wikibase/client/ExampleSettings.php";
These configurations assume that your interwiki prefixes are en and fa. Adjust as needed.
Important: Similar to above:
wfLoadExtension( 'WikibaseRepository', "$IP/extensions/Wikibase/extension-repo.json" );
require_once "$IP/extensions/Wikibase/repo/ExampleSettings.php";
wfLoadExtension( 'WikibaseClient', "$IP/extensions/Wikibase/extension-client.json" );
require_once "$IP/extensions/Wikibase/client/ExampleSettings.php";
Run the setup scripts[edit]
Finally, you have to run some maintenance scripts.
- Run the database update script of your MediaWiki installation:
php maintenance/update.php
- Run the script that populates the sites table:
php extensions/Wikibase/lib/maintenance/populateSitesTable.php
Note: By default, this populates the sites table with Wikimedia's project list. See Manual:Sites table#Managing the sites table for options to list non-WMF projects.
For Wikibase Repository only[edit]
- Run
php extensions/Wikibase/repo/maintenance/rebuildItemsPerSite.php
For Wikibase Client only[edit]
- If you want to run a Wikibase Client, you'll also need to run the script that populates the interwiki table:
php extensions/Wikibase/client/maintenance/populateInterwiki.php
This will overwrite existing links in your interwiki table with (by default) Wikipedia values. Don't do this if you have existing inter-language link data you need to keep.
For Wikibase Repository and Wikibase Client[edit]
php extensions/Wikibase/repo/maintenance/rebuildItemsPerSite.php
php extensions/Wikibase/client/maintenance/populateInterwiki.php
(Again, running populateInterwiki.php will overwrite existing links in your interwiki table with (by default) Wikipedia values.)
Verify your installation[edit]
Wikibase Repository[edit]
To verify your Wikibase Repository installation, in your MediaWiki go to Special:NewItem and you should be able to create your first Item. Enter a label and optional description and aliases and hit Create. You should be redirected to the item page.
Wikibase Client[edit]
If you've enabled Wikibase Client and everything is correct, you should see an "Add links" link in the languagelinks section in the sidebar of the main page.
Enable Sitelinks[edit]
Sitelinks are special links that contain a site and a title, and go from individual Items to pages on other wikis. In Wikidata these go to other Wikimedia sites such as Wikipedia, Wikisource and Wikivoyage. Among other things, Sitelinks are used to allow referencing a property of the Item on the linked page in the client wiki, a feature that is called Direct access.
1. Configure your sitelink groups[edit]
First, you need to think about how to group the client-wikis you want to see in your sitelinks area on the Items in your repo-wiki.
Define custom groups[edit]
In your repo-wiki, replace the content of $wgWBRepoSettings['siteLinkGroups']
in LocalSettings.php
with the groups you would like to see there.
For example, consider the following line being added to LocalSettings.php
:
$wgWBRepoSettings['siteLinkGroups'] = [ 'wikipedia', 'mywikigroup', 'anothergroup' ];
This will allow three groups in the SiteLinks box on the Item's page:
- the standard defined
wikipedia
for the global Wikipedia sites - two custom wikis groups – here named
mywikigroup
andanothergroup
just for example
The names defined here will be relevant to the site_group
field in the sites
table as specified below.
In your client-wiki, add the same siteLinkGroups
$wgWBClientSettings['siteLinkGroups'] = [ 'wikipedia', 'mywikigroup', 'anothergroup' ];
Deactivate the sitelinks feature[edit]
If you do not want your installation to make use of sitelinks at all, then you can deactivate that feature by setting the configuration to an empty array:
$wgWBRepoSettings['siteLinkGroups'] = [];
$wgWBClientSettings['siteLinkGroups'] = [];
2. Localize your own groups[edit]
To show the correct heading for your own groups, you have to create the page MediaWiki:Wikibase-sitelinks-mywikigroup
[1] with the desired heading as text.
You can create subpages to set the heading in different languages, e.g. MediaWiki:Wikibase-sitelinks-mywikigroup/de
to create the German heading.
3. Add the Wikis to the sites table[edit]
To be able to add sitelinks to Items in your repo-wiki, you need add the client-wikis to the sites table. Take care that the group name used there must be one of the group names you added above. Following the example above, for instance, there would be one or more sites with mywikigroup
and anothergroup
as text in the site_group
field.
Please also note that you need to set both the file path and the page path, and they do need to include the $1
placeholder.
To add your wiki an id ending on wiki to the mywikigroup group, run
cd maintenance
php addSite.php --pagepath=https://mw.wiki/wiki/\$1 --filepath=https://mw.wiki/w/\$1 --language en --interwiki-id en en mywikigroup
php addSite.php --pagepath=https://fa.mw.wiki/wiki/\$1 --filepath=https://fa.mw.wiki/w/\$1 --language fa --interwiki-id fa fa mywikigroup
Be sure to do this on the repo-wiki and all client-wikis, so that the "add links" in the other languages section works correctly.
For further details on how to add sites to the table, please see these specific instructions.
4. Let the repo-wiki know about the databases of the other client-wikis[edit]
$wgLocalDatabases = [ 'enwiki', 'fawiki' ];
$wgWBRepoSettings['localClientDatabases'] = array(
'en' => 'enwiki',
'fa' => 'fawiki'
);
localClientDatabases: An array of locally accessible client databases, for use by the dispatchChanges.php
script. This setting determines which wikis changes are pushed to directly. It must be given either as an associative array, mapping global site IDs to logical database names, or, if the database names are the same as the site IDs, as a list of databases. The default is an empty array, indicating no local client databases.
5. Verify that you can add sitelinks[edit]
- Go to
Special:SetSiteLink
in your repo-wiki and try to link an existing Item (field "ID") to one of the above configured sites (field "Site ID") by providing an existing page on that wiki (field "Sitelink"). It should either work or give you a useful error message. - On the page you added above, check that Direct access works by referencing a property of the Item in a parser function
Troubleshooting[edit]
There are very few languages I can set labels for in a new item[edit]
Make sure you installed Extension:UniversalLanguageSelector
There are no sites I can link pages to in an item[edit]
One or more of the following may help:
php lib/maintenance/populateSitesTable.php
php repo/maintenance/rebuildItemsPerSite.php