Wikibase Repository development environment (mwcli)

June 23, 2024 0 By addshore
This entry is part 4 of 7 in the series Wikibase ecosystem

Back in 2022, while working at Wikimedia Germany, I ran two sessions with people from the Wikibase Stakeholder Group, focused on Ecosystem Enablement.

These sessions were video recorded and documented in quite a lot of detail, but following through with the videos would probably lead to a bit of a drawn out experience, as they were focused around a workshop setting with participants following along.

  • Session 1, 2022-04-28: Using mwcli, loading extensions, understanding Mediawiki’s general extension mechanism (Video, Overview)
  • Session 2, 2022-05-24: Running your first extension, Wikibase stable interface policy, Mediawiki hooks, building a new API function (Video, Overview)

In this post, I will focus on the core steps required to get a MediaWiki and Wikibase Repository development environment setup in a few minutes with mwcli, and will serve as a basis for some blog posts that I will be writing in the future.

Getting mwcli

If you head to the home page of mwcli, you’ll see a link to an installation guide.

At the time of writing this, the “quick” command for downloading the executable, and putting it in your PATH would be the following:

ARCH=amd64 VER=v0.25.0 MW_PLATFORM=$(uname | tr '[:upper:]' '[:lower:]') bash -c 'curl -s "https://gitlab.wikimedia.org/api/v4/projects/16/packages/generic/mwcli/${VER}/mw_${VER}_${MW_PLATFORM}_${ARCH}" -o mw && curl -s "https://gitlab.wikimedia.org/api/v4/projects/16/packages/generic/mwcli/${VER}/mw_${VER}_${MW_PLATFORM}_${ARCH}.sha256" -o mw.sha256 && echo $(cat mw.sha256 | tr -d '\n') " mw" > mw.sha256 && shasum -a 256 -c mw.sha256 && rm -v mw.sha256'Code language: JavaScript (javascript)

After doing this, you should be able to run the mw version command.

In order to run the development environment, you also need docker installed.

I recommend following the specific documentation for installing Docker for your respective platform at https://docs.docker.com/get-docker/.

Setting up a development environment

We will be making use of the docker based development environment provided by mwcli. The generic first setup is well documented, but we will be going above and beyond that.

In essence, once the mw binary and docker are both installed on the system, we will be running the following commands (and answering some questions along the way)…

In a nutshell this:

  • Creates some mediawiki containers (and other base containers) in a docker compose environment
  • Adds a mysql container to that docker compose environment
    • mysql will be used as Wikibase has the best tested support for mysql
  • Gets the Wikibase extension from Gerrit, leaving the remote set to ssh with the username addshore
  • Copies the example composer.local.json file into place
  • Installs the mysql database for mediawiki
mw dev mediawiki create
mw dev mysql create
mw dev mediawiki get-code --extension Wikibase --gerrit-username addshore
mw dev mediawiki exec cp composer.local.json-sample composer.local.json
mw dev mediawiki composer update -- --ignore-platform-reqs
mw dev mediawiki install --dbtype mysql
...
***************************************
Installation successful 🎉

Link: http://default.mediawiki.mwdd.localhost:8080
User: admin
Pass: mwddpassword

If you want to access the wiki from your command line you may need to add it to your hosts file.
You can do this with the `hosts add` command that is part of this development environment.
***************************************Code language: PHP (php)

You should end up with a fresh MediaWiki install, that looks something like the following

We then need to actually install Wikibase.

For this, we can take a look at the very basic instructions for the extension on mediawiki.org, which you will find for most MediaWiki extensions.

The plan is to develop against the Wikibase Repository, so we need to add these lines to our LocalSettings.php file:

# Load Wikibase Repository
wfLoadExtension( 'WikibaseRepository', "$IP/extensions/Wikibase/extension-repo.json" );
require_once "$IP/extensions/Wikibase/repo/ExampleSettings.php";Code language: PHP (php)

And run the mediawiki update command, to add the Wikibase database tables…

mw dev mw mwscript update -- --quick

We should then be able to head to the Special:Version page of the created wiki and see that the Wikibase Repo is installed.

Making changes

Now that the code is loaded, you should be able to start poking around.

I’d recommend opening the whole MediaWiki installation in your favourite IDE (mine is Visual Studio Code) in order to have the best experience while navigating the files and attempting code changes.

If you ever want to throw the whole development environment away and start fresh, you can run mw dev destroy and then start fresh with roughly the same commands as above.

Series Navigation<< Lexeme and MediaInfo, implementing EntityDocumentEntitySchema, and the entity flip-flop >>