User:CFeng (WMF)/MachineVisionSetup



This page introduces you to install mediawiki-docker and set up the MachineVision extension.

Install Docker Compose[edit]

Clone mediawiki-docker-dev[edit]

Clone the code to the path you would like to work on, I would recommend to clone it into ~/Documents:

git clone

And now, it is in the ~/Documents/mediawiki-docker-dev/

Please note this might be the offical one:

Clone MediaWiki and the skin[edit]

Since the repository above only contains settings and scripts about setting up MediaWiki on Docker, we will need to install the MediaWiki by ourselves.

Clone it into ~/Documents:

git clone 

And now, it is in the ~/Documents/mediawiki/

Also, you will need a default skin for the entire MediaWiki page to the skins folder:

 cd ~/Documents/mediawiki/skins/</code>
 git clone Vector

Install Composer[edit]

Before running the MediaWiki installation scripts, you will need the Composer. Please download and install it on your machine.

Run composer install for MediaWiki[edit]

Run the followingg script to install MediaWiki

 cd ~/Documents/mediawiki
 composer install

Create a LocalSettings.php for MediaWiki[edit]

The LocalSettings.php contains the information that MediaWiki needs and you will need to update this file every time you add extensions.

Since the MachineVision needs a lot of extensions and other settings, here is the copy of my LocalSettings.php and please copy that into the ~/Documents/mediawiki/


Install extensions for mediawiki[edit]

The LocalSettings.php has the following code:

 wfLoadExtension( 'CirrusSearch' );
 wfLoadExtension( 'Elastica' );
 wfLoadExtension( 'MachineVision' );
 wfLoadExtension( 'UniversalLanguageSelector' );
 wfLoadExtension( 'UploadWizard' );
 wfLoadExtension( 'WikibaseCirrusSearch' );
 wfLoadExtension( 'WikibaseMediaInfo' );
 wfLoadExtension( 'WikimediaEditorTasks' );

which you will need to install the extensions manually.

Please go to the to find the extensions and copy them to the ~/Documents/mediawiki/extensions/

or, you can run the following scripts:

 cd ~/Documents/mediawiki/extensions
 git clone CirrusSearch
 git clone Elastica
 git clone MachineVision
 git clone UniversalLanguageSelector
 git clone Wikibase
 git clone WikibaseCirrusSearch
 git clone WikibaseMediaInfo
 git clone WikimediaEditorTasks

Setting up Wikibase[edit]

Include the following into composer.local.json at the ~/Documents/mediawiki/:

  "extra": {
    "merge-plugin": {
      "include": [

and run the script to apply the changes at the ~/Documents/mediawiki/ installation

composer install

MediaWiki-Docker environment configuration[edit]

Copy the default.env in ~/Documents/mediawiki-docker-dev and into a new file called local.env.

Please make sure to update the mediawiki path of your installation.


Some other settings in the local.env you might need to update, for example, the PHP version you've installed, or the port has already taken by other services.

Create and start the Docker container[edit]

cd ~/Documents/mediawiki-docker-dev

The script waits up to 120 secs (4 x 30 seconds) for the database containers to initialize and respond.

Host name resolution configuration[edit]

Adding the following configuration to your /etc/hosts # mediawiki-docker-dev # mediawiki-docker-dev # mediawiki-docker-dev # mediawiki-docker-dev

Please note that you might need sudo when editing the hosts.

For more details of mediawiki-docker configuration, please visit:

MachineVision extension configuration[edit]

Run composer install in the MachineVision extension folder:

cd ~/Documents/mediawiki/extensions/MachineVision
composer install

and then go to the mediawiki-docker to ssh into the webserver container

cd ~/Documents/mediawiki-docker-dev
php maintenance/update.php

Import the MachineVision mapping data[edit]

Download the mapping data from Google:

Extract the downloaded file from its archive and place it somewhere that MediaWiki can access it. To import, run the following maintenance script:

php maintenance/populateFreebaseMapping.php --mappingFile [FILE_PATH].nt

This process may take some time to complete.

Apply and enable the Google Cloud Vision API[edit]

Go to and create a project, for example, MachineVision and then click on APIs & Services on the left menu to enable the API we need.

In the API list, search Cloud vision and enable it.

To use the API, we will NEED to add credentials to the project. Once you have created a credential, you can choose the format of the credential to be JSON, and download it to your machine.

Not sure if this is associate with the service, but you might need to activate the free trial status with $300.00 credit on your account in order to activate the service successfully.

Since we have already set the credential path in LocalSettings.php, we will need to copy the credential to ~/Documents/mediawiki and rename the file as machine-vision-credentials.json to match the following setting:

 $wgMachineVisionGoogleCredentialsFileLocation = '/var/www/mediawiki/machine-vision-credentials.json';

For more details please vision here:

Upload images and test the API[edit]

Go to, create an account and log in. Once you have logged in, you can upload images to the MediaWiki.

After the images being uploaded, you will need to run a script to communicate with Cloud Vision API.

cd ~/Documents/mediawiki-docker-dev
php maintenance/runJobs.php

and, check the local ImageLabel API to see if you have done all the configurations right.

If you see an empty response, please make sure you have set up the Cloud Vision API credential correctly.