MediaWiki-Docker/Extension/Wikibase
This page instructs you to install Wikibase/Installation inside MediaWiki-Docker. All commands should be run in the directory where you installed MediaWiki. All mentioned files are also located there.
Install MediaWiki-Docker
editFollow the Quickstart instructions at MediaWiki-Docker page. Once MediaWiki is running and available at http://localhost:8080
, then continue with instructions on this page.
Clone the repository and its dependencies
editgit clone "https://gerrit.wikimedia.org/r/mediawiki/skins/MinervaNeue" skins/MinervaNeue
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite" extensions/Cite
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/MobileFrontend" extensions/MobileFrontend
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/UniversalLanguageSelector" extensions/UniversalLanguageSelector
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/Wikibase" extensions/Wikibase
cd extensions/Wikibase
git submodule update --init --recursive
Install Composer dependencies
editAdd this to composer.local.json
:
{
"extra": {
"merge-plugin": {
"include": [
"extensions/Wikibase/composer.json"
]
}
}
}
Run:
docker compose exec mediawiki composer update
Modify LocalSettings.php
editIf not already there, add this to the end of LocalSettings.php
.
wfLoadSkin( 'MinervaNeue' );
wfLoadExtension( 'Cite' );
wfLoadExtension( 'MobileFrontend' );
wfLoadExtension( 'UniversalLanguageSelector' );
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";
$wgEnableWikibaseRepo = true;
$wgEnableWikibaseClient = true;
$wgWBClientSettings['dataBridgeEnabled'] = true;
$wgWBClientSettings['dataBridgeHrefRegExp'] = '[/=]((?:Item:)?(Q[1-9][0-9]*)).*#(P[1-9][0-9]*)$';
$wgWBClientSettings['dataBridgeEditTags'] = [ 'Data Bridge' ];
$wgWBRepoSettings['dataBridgeEnabled'] = true;
$wgWBRepoSettings['taintedReferencesEnabled'] = true;
$wgWBRepoSettings['termboxEnabled'] = true;
Run maintenance scripts
editdocker compose exec mediawiki php maintenance/run.php update.php
docker compose exec mediawiki php extensions/Wikibase/lib/maintenance/populateSitesTable.php
docker compose exec mediawiki php extensions/Wikibase/repo/maintenance/rebuildItemsPerSite.php
docker compose exec mediawiki php maintenance/run.php populateInterwiki.php
Example wiki farm config
editIf you have a wiki farm setup, you may wish to use a repo-client setup for Wikibase. To achieve that, once you have installed all the dependencies, you can add the following snippet to LocalSettings.php, making any adjustments as needed.
// This is the name of the wiki group, like "Wikipedia" or "Wiktionary" in WMF production. You will also
// have to create a message page for it, so that it displays properly in the interface. In this example,
// the page would be MediaWiki:Wikibase-sitelinks-maingroup
const LOCAL_WIKI_GROUP = 'maingroup';
// NOTE: The settings below assume that the wiki farm is configured as in mw:MediaWiki-Docker/Configuration recipes/Wiki farm.
// Adjust names/paths if that is not the case.
// The primary wiki will be our Wikibase repo.
if ( $wgDBname === 'my_wiki' ) {
wfLoadExtension( 'WikibaseRepository', "$IP/extensions/Wikibase/extension-repo.json" );
require_once "$IP/extensions/Wikibase/repo/ExampleSettings.php";
$wgWBRepoSettings['siteLinkGroups'] = [ LOCAL_WIKI_GROUP ];
$wgWBRepoSettings['localClientDatabases'] = [
'w2' => 'secondwiki',
];
}
// All wikis, including the primary wiki, will have the client installed.
wfLoadExtension( 'WikibaseClient', "$IP/extensions/Wikibase/extension-client.json" );
require_once "$IP/extensions/Wikibase/client/ExampleSettings.php";
$wgWBClientSettings['repoUrl'] = 'http://localhost:8080';
$wgWBClientSettings['repoScriptPath'] = '/w';
$wgWBClientSettings['repoArticlePath'] = '/wiki/$1';
$wgWBClientSettings['entitySources'] = [
'my_wiki' => [
'repoDatabase' => 'my_wiki',
'baseUri' => 'http://localhost:8080/w',
'entityNamespaces' => [
'item' => 120,
'property' => 122,
],
'rdfNodeNamespacePrefix' => 'wd',
'rdfPredicateNamespacePrefix' => '',
'interwikiPrefix' => '',
],
];
$wgWBClientSettings['itemAndPropertySourceName'] = 'my_wiki';
$wgWBClientSettings['siteLinkGroups'] = [ LOCAL_WIKI_GROUP ];
Next, you will need to configure the sites
table. You can follow the general instructions, which should look like the following:
$mywiki = new MediaWikiSite();
$mywiki->setGlobalId( 'my_wiki' );
$mywiki->setGroup( LOCAL_WIKI_GROUP );
$mywiki->setLanguageCode( 'en' );
$mywiki->setPath( MediaWikiSite::PATH_PAGE, "http://localhost:8080/wiki/$1" );
$mywiki->setPath( MediaWikiSite::PATH_FILE, "http://localhost:8080/w/$1" );
$secondwiki = new MediaWikiSite();
$secondwiki->setGlobalId( 'secondwiki' );
$secondwiki->setGroup( LOCAL_WIKI_GROUP );
$secondwiki->setLanguageCode( 'en' );
$secondwiki->setPath( MediaWikiSite::PATH_PAGE, "http://localhost:8080/secondwiki/$1" );
$secondwiki->setPath( MediaWikiSite::PATH_FILE, "http://localhost:8080/w2/$1" );
$siteStore = \MediaWiki\MediaWikiServices::getInstance()->getSiteStore();
$siteStore->clear(); // This will remove all previous entries from the table. Remove this call if you want to keep them.
$siteStore->saveSites( [ $mywiki, $secondwiki ] );
For convenience, you may save the above as a function in LocalSettings.php, open a Bash shell inside the container (docker compose exec mediawiki bash
), and run it via shell.php for each wiki in the wiki farm.
The above is almost working, but HTTP requests (made through HttpRequestFactory) will fail because localhost:8080
is getting resolved inside the container, not the host. It should be possible to amend the configuration above to fix this (and there's also an undocumented flag), but a simpler fix is to add an alias for localhost. Open the docker-compose-override.yml file, and add the following under the mediawiki
service:
extra_hosts:
- "localhost:host-gateway"