MediaWiki-Docker/Extension/ContentTranslation

Installing the dependencies and setting up the environment should take about 15 minutes.

Note that this instructions are slightly different from general mediawiki docker installation instructions since the default sqlite database is not enough for ContentTranslation.

  • Clone all the required repositories.
git clone --depth=1 https://gerrit.wikimedia.org/r/mediawiki/core.git mediawiki
git clone "https://gerrit.wikimedia.org/r/mediawiki/services/cxserver" cxserver

cd mediawiki

git clone "https://gerrit.wikimedia.org/r/mediawiki/skins/Vector" skins/Vector
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/Cite" extensions/Cite
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/ContentTranslation" extensions/ContentTranslation
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/UniversalLanguageSelector" extensions/UniversalLanguageSelector
git clone --recursive "https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor" extensions/VisualEditor
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/BetaFeatures" extensions/BetaFeatures
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/GlobalPreferences" extensions/GlobalPreferences
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/MobileFrontend" extensions/MobileFrontend
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/EventLogging" extensions/EventLogging

Configurations

edit
Prepare cxserver
edit

In the cxserver directory a default configuration file is given as config.dev.yaml.

Copy it to config.yaml to customize. For detailed setup, refer Content translation/cxserver/Setup

In the mediawiki directory, using a text editor, create a .env file in the root of the MediaWiki core repository, and copy these contents into that file:

MW_DOCKER_PORT=8080
MW_SCRIPT_PATH=/w
MW_SERVER=http://localhost:8080
MEDIAWIKI_USER=Admin
MEDIAWIKI_PASSWORD=dockerpass
XDEBUG_CONFIG='' 
CXSERVER_PORT=8090

Create a docker-compose.override.yml containing the following:

services:
  mediawiki:
    # On Linux, these lines ensure file ownership is set to your host user/group
    user: "${MW_DOCKER_UID}:${MW_DOCKER_GID}"
  mediawiki-web:
    user: "${MW_DOCKER_UID}:${MW_DOCKER_GID}"
  mariadb-main:
    image: 'bitnami/mariadb:latest'
    volumes:
      - mariadbdata:/bitnami/mariadb
    environment:
      - MARIADB_REPLICATION_MODE=master
      - MARIADB_REPLICATION_USER=repl_user
      - MARIADB_REPLICATION_PASSWORD=repl_password
      - MARIADB_ROOT_PASSWORD=main_root_password
      - MARIADB_USER=my_user
      - MARIADB_PASSWORD=my_password
      - MARIADB_DATABASE=my_database
  mariadb-replica:
    image: 'bitnami/mariadb:latest'
    depends_on:
      - mariadb-main
    environment:
      - MARIADB_REPLICATION_MODE=slave
      - MARIADB_REPLICATION_USER=repl_user
      - MARIADB_REPLICATION_PASSWORD=repl_password
      - MARIADB_MASTER_HOST=mariadb-main
      - MARIADB_MASTER_PORT_NUMBER=3306
      - MARIADB_MASTER_ROOT_PASSWORD=main_root_password

  cxserver:
    build:
        context: ../cxserver
    volumes:
      # map local to remote folder, exclude node_modules
      - ../cxserver:/opt/cxserver
      - /opt/cxserver/node_modules
    ports:
      - "${CXSERVER_PORT:-8090}:8080"
    command: npm start
    
  eventlogging:
    build:
      context: ./extensions/EventLogging
    volumes:
      # map local to remote folder, exclude node_modules
      - ./extensions/EventLogging:/opt/eventlogging
      - /opt/eventlogging/node_modules
    ports:
      - "${EVENTLOGGING_PORT:-8192}:8192"
    command: npm run eventgate-devserver

volumes:
  mariadbdata:
    driver: local

Run the following command to add your user ID and group ID to your .env file:

echo "MW_DOCKER_UID=$(id -u)" >> .env
echo "MW_DOCKER_GID=$(id -g)" >> .env

Installation

edit

Start the environment:

docker compose up -d

Install Composer dependencies:

docker compose exec mediawiki composer update

Install mediawiki and database

docker compose exec mediawiki php maintenance/install.php --dbuser root --dbserver mariadb-main --dbname=my_database --dbpass=main_root_password  --scriptpath=/w --server="http://localhost:8080/" --lang en --pass dockerpass mediawiki admin

At this point, a file named LocalSettings.php will be created in the mediawiki folder. You will be able to access your wiki at http://localhost:8080. You should also see the cxserver API endpoint running at http://localhost:8090

Prepare Extensions

edit

To enable the cloned extensions, Add the following code at the bottom of your LocalSettings.php:

wfLoadSkin( 'Vector' );

wfLoadExtension( 'Cite' );
wfLoadExtension( 'ContentTranslation' );
# For CX3 Vue based application
$wgContentTranslationVueDashboard=true; 
$wgContentTranslationSiteTemplates = [
	"view" => "//$1.wikipedia.org/wiki/$2",
	"action"=> "//$1.wikipedia.org/w/index.php?title=$2",
	"api"=> "https://$1.wikipedia.org/w/api.php",
	// Use the CXSERVER_PORT here
	"cx"=> "http://localhost:8090/v1",
	"restbase"=> "https://$1.wikipedia.org/api/rest_v1"
];

wfLoadExtension( 'UniversalLanguageSelector' );
wfLoadExtension( 'BetaFeatures' );
wfLoadExtension( 'Cite' );

wfLoadExtension( 'VisualEditor' );
$wgDefaultUserOptions['visualeditor-enable'] = 1;
$wgEnableRestAPI = true;
wfLoadExtension( 'Parsoid', 'vendor/wikimedia/parsoid/extension.json' );
$wgVirtualRestConfig['modules']['parsoid'] = [
	'url' => $wgServer . $wgScriptPath . '/rest.php',
];

wfLoadExtension( 'MobileFrontend' );
wfLoadExtension( 'GlobalPreferences' );
wfLoadExtension( 'EventLogging' );

// This is the eventgate-devserver URI.
// Set this to wherever you are running eventgate-devserver
// at an address that your browser can access.
$wgEventLoggingServiceUri = 'http://localhost:8192/v1/events';

// By default EventLogging waits 30 seconds before sending
// batches of queued events.  That's annoying in a dev env.
$wgEventLoggingQueueLingerSeconds = 1;

// By settings $wgEventLoggingStreamNames to false, we instruct EventLogging
// to not use any EventStreamConfig. Instead, all streams will be seen as
// if they are configured and registered. See the EventStreamConfig
// [README](https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/extensions/EventStreamConfig/+/master/README.md//mediawiki-config)
// for instructions on how to set up stream config.
$wgEventLoggingStreamNames = false;

$GLOBALS['wgGlobalPreferencesDB'] = 'my_database';

These extensions need more database tables. To add them to our database, run:

docker compose exec mediawiki php maintenance/run.php update.php

The EventLogging extension does not have a Docker configuration. Just create a file named Dockerfile in the EventLogging extension folder with the following content:

FROM node:10-buster

WORKDIR /opt/eventlogging
COPY . ./
RUN npm install

At this point, you should be able to see Content Translation enabled in your wiki.

Please try navigating to http://localhost:8080/wiki/Special:ContentTranslation

Usage

edit
Running commands
edit

You can use docker compose exec mediawiki bash to open a bash shell in the MediaWiki container, or you can run commands in the container from your host, for example: docker compose exec mediawiki php maintenance/run.php update.php

Running tests
edit
PHPUnit
edit

Run all tests:

docker compose exec mediawiki composer phpunit:entrypoint

Run a single test:

docker compose exec mediawiki composer phpunit:entrypoint -- /path/to/test

Limitations

edit

The nodejs is missing in the container. So working with linting tools, developing with vuejs for CX3 may be limiting. Such customizations are possible with a Dockerfile overriding and building it on top of base image.