User:Santhosh.thottingal/WikiFamily
This is a guide to set up a wiki family with multiple mediawiki instances with different languages. We will use mwcli for this.
Download latest mwcli application from its releases page. Installation instructions can be found on Cli/guide/Installation#Install.
Download and Install mediawiki
mw docker mediawiki create
This will ask many questions related to the installation, including path to checkout the code. Then install the mysql database
mw docker mysql create
Now, we can create the wikis as per our requirement.
mw docker mediawiki install --dbtype=mysql --dbname=en
We gave en as dbname just to associate it with English language wiki. Using the dbname same as the language name also helps to map languages to wikis.
We can create any number of wikis as per our requirement as follows
mw docker mediawiki install --dbtype=mysql --dbname=es
mw docker mediawiki install --dbtype=mysql --dbname=ml
mw docker mediawiki install --dbtype=mysql --dbname=ta
mw docker mediawiki install --dbtype=mysql --dbname=fr
You can access each of this wikis using the following URL http://en.mediawiki.local.wmftest.net:8080, http://ig.mediawiki.local.wmftest.net:8080 etc. Note that all of them will be in English. We will soon map them to corresponding languages. mwcli will create a LocalSettings.php in the root folder of mediawiki source code it fetched in first step. It will have only one line
<?php
//require_once "$IP/includes/PlatformSettings.php";
require_once '/mwdd/MwddSettings.php';
Below this line you can add extension installations and their configurations as usual. To map each with with different languages, add the following line to LocalSettings.php
# Site language code. Same as $wgDBname or $dockerDb for this setup
$wgLanguageCode = $wgDBname;
Now all the wikis created above will have its own language just like production wikipedia has.
Setting up an HTTPS environment is mandatory. See HTTPS domain setup for more information |
Additional Services
[edit]To add new services that are not part of mwcli, follow these steps.
Let us add cxserver nodejs service to mwcli.
As a first step, setup cxserver (MediaWiki-Docker/Extension/ContentTranslation).
Then, find out the location of mwcli docker configuration files:
mw docker where
On Linux systems, it will be ~/.config/mwcli/mwdd/default. Add the source code path to .env file in the same directory. For example:
CXSERVER_VOLUMES_CODE=/home/santhosh/work/wiki/cxserver
Then create a file named custom.cxserver.yml and add the service docker-compose. Example:
services:
cxserver:
build:
context: ${CXSERVER_VOLUMES_CODE}
entrypoint: npm start
environment:
- VIRTUAL_HOST=cxserver.local.wmftest.net
- VIRTUAL_PORT=8080
volumes:
- "${CXSERVER_VOLUMES_CODE:-cxserver-code}:/opt/cxserver"
- /opt/cxserver/node_modules
depends_on:
- nginx-proxy
- dps
dns:
- ${NETWORK_SUBNET_PREFIX}.10
networks:
- dps
volumes:
cxserver-code:
The service can be started using
mw docker custom create -n custom.cxserver
And it can be accessed by using the URL http://cxserver.local.wmftest.net:8080
Installing Adminer for database administration
[edit]Adminer is very useful to interact with mysql database
mw docker adminer create
Adminer can be now accessed from http://adminer.local.wmftest.net:8080/
Note the the username is root, password is toor, server is mysql and database is en or other language codes we used when creating wikis
Installing eventlogging service for EventLogging
[edit]Create the eventlogging service
mw docker eventlogging create
The events registered by mediawiki and extension can be viewed by looking at the logs of eventlogging service.
mw docker docker-compose logs eventlogging
Installing ContentTranslation extension
[edit]To the extensions folder of mediawiki, clone the extension and dependent extensions
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
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/EventBus" extensions/EventBus
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/EventStreamConfig" extensions/EventStreamConfig
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/WikimediaEvents" extensions/WikimediaEvents
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/WikimediaMessages" extensions/WikimediaMessages
git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/TestKitchen" extensions/TestKitchen
Then add the required settings to LocalSettings.php
wfLoadExtension( 'GlobalPreferences' );
wfLoadExtension( 'UniversalLanguageSelector' );
wfLoadExtension( 'BetaFeatures' );
wfLoadExtension( 'Cite' );
wfLoadExtension( 'MobileFrontend' );
wfLoadExtension( 'TestKitchen' );
wfLoadExtension( 'VisualEditor' );
$wgDefaultUserOptions['visualeditor-enable'] = 1;
wfLoadExtension( 'ContentTranslation' );
wfLoadExtension('WikimediaMessages');
$GLOBALS['wgContentTranslationDatabase'] = 'shared';
$GLOBALS['wgContentTranslationAsBetaFeature'] = true;
$wgContentTranslationVersion = 2;
$wgContentTranslationEventLogging = true;
$wgContentTranslationEnableMT = true;
$wgContentTranslationEnableSectionTranslation = true;
$wgContentTranslationEnableAnonSectionTranslation = true;
$wgContentTranslationTranslateInTarget = true;
$wgContentTranslationDefaultParsoidClient = 'direct';
$wgContentTranslationSiteTemplates = [
"view" => "//$1.mediawiki.local.wmftest.net:8080/wiki/$2",
"action" => "//$1.mediawiki.local.wmftest.net:8080/w/index.php?title=$2",
"api" => "//$1.wikipedia.org/w/api.php",
"cx" => "http://cxserver.local.wmftest.net:8080/v1",
"cookieDomain" => "mediawiki.local.wmftest.net",
"restbase" => "https://$1.wikipedia.org/api/rest_v1"
];
$GLOBALS['wgContentTranslationCXServerAuth'] = [
"algorithm" => "HS256",
"key" => "secret",
"age" => "3600"
];
$wgContentTranslationContentImportForSectionTranslation = true;
$wgSectionTranslationTargetLanguages = ['bn',"ml", "is", "ig"];
// Enable event logging
wfLoadExtensions( [
'EventBus',
'EventStreamConfig',
'EventLogging',
'WikimediaEvents'
] );
$wgEventServices = [ '*' => [ 'url' => 'http://eventlogging:8192/v1/events' ] ];
$wgEventServiceDefault = '*';
$wgEventLoggingStreamNames = false;
$wgEventLoggingServiceUri = "http://eventlogging.local.wmftest.net:" . parse_url($wgServer)['port'] . "/v1/events";
$wgEventLoggingQueueLingerSeconds = 1;
$wgEnableEventBus = defined( "MW_PHPUNIT_TEST" ) ? "TYPE_NONE" : "TYPE_ALL";
Content Translation Database setup
[edit]The database tables required for CX wont be created by the above steps. We have to create them manually. Adminer can be very helpful there. Go to adminer, create a new database names shared as we gave it in the above settings. Use the sql scripts from sql folder of ContentTranslation database to create tables.
In the above configuration, please note the wgContentTranslationSiteTemplates. It uses the multi-language wiki URL patterns by mwcli so that CX's inter domain navigation works well. We also set the cookie domain to support this. We also used the Cxserver URL that we created above.
Note that the database remains same without any data loss between mw cli upgrades. Even if entire ~/.config/mwcli is removed and fresh installation is done, your database will be available without data loss.
Updating
[edit]To run update script in the mediawiki instances, follow these steps
mw docker docker-compose exec mediawiki php maintenance/run.php update -- --wiki en
Provide your own wiki names instead of bn above. In this tutorial, we were using wikinames same as language codes.
Running phpunit
[edit]For integration tests with phpunit, provide the wikiname as follows. For unit tests, this is not required. Not providing PHPUNIT_WIKI will result 'Database not found' errors.
mw docker docker-compose exec mediawiki bash
PHPUNIT_WIKI=en composer phpunit:integration extensions/ContentTranslation/tests/phpunit/integration/RestbaseClientTest.php
Step Debugging
[edit]To get step debugging working using XDebug, you are welcome to view the documentation on Cli/guide/Docker-Development-Environment/MediaWiki#XDebug. In a nutshell, it is important to include
MEDIAWIKI_XDEBUG_CONFIG
which informs the docker containers of your local IP and what port XDebug will be running on. Your .env file under your mwcli docker configuration files which you can get a path to using:
mw docker where
should look something like this:
MEDIAWIKI_VOLUMES_CODE=/path/to/mediawiki/
MEDIAWIKI_VOLUMES_DOT_COMPOSER=/path/to/.composer
CXSERVER_VOLUMES_CODE=/path/to/cxserver
NETWORK_SUBNET_PREFIX=10.0.0
PORT=8080
MEDIAWIKI_XDEBUG_MODE="develop,debug,profile"
MEDIAWIKI_XDEBUG_CONFIG="client_host=192.168.100.3 client_port=9003"
After, it's important to restart your mediawiki services using
mw docker mediawiki create
HTTPS domains
[edit]It is always better to enable https so that dev environment is close to production. Browsers will prevent CORS and cookies in http mode, especially if URL does not look localhost. In the case of mw cli the URL does not pass the localhost test from browsers.A simple https setup for local development is as follows.
We will use caddy server as it provide automatic https. Install caddy as per your OS. In Debian/Ubuntu systems, it can be installed using sudo apt install caddy. Then edit the configuration file /etc/caddy/Caddyfile as follows;
*.mediawiki.local.wmftest.net {
tls internal
# Extract the language code from the subdomain
@en host en.mediawiki.local.wmftest.net
handle @en {
reverse_proxy localhost:8080
}
@es host es.mediawiki.local.wmftest.net
handle @es {
reverse_proxy localhost:8080
}
# Add more languages as needed
@fr host fr.mediawiki.local.wmftest.net
handle @fr {
reverse_proxy localhost:8080
}
}
cxserver.local.wmftest.net {
tls internal
reverse_proxy localhost:8080
}
adminer.local.wmftest.net {
tls internal
reverse_proxy localhost:8080
}
Restart caddy. sudo systemctl start caddy
Now you should be able to access the mediawiki instances with https://en.mediawiki.local.wmftest.net - No need to specify port. With this setup you can use full https dev environment. A few things to note if you are using this setup:
Mediawiki will try to redirect to en.mediawiki.local.wmftest.net:8080 in between page navigation and edits. To avoid that add this line to Localsettings.php
$wgServer = "//$dockerDb.mediawiki.local.wmftest.net:443"
You should also edit the URLs in wgContentTranslationSiteTemplates to mathc with https URLs as follows
$wgContentTranslationSiteTemplates = [
"view" => "//$1.mediawiki.local.wmftest.net/w/index.php?title=$2",
"action" => "//$1.mediawiki.local.wmftest.net/w/index.php?title=$2",
"api" => "//$1.wikipedia.org/w/api.php",
"cx" => "https://cxserver.local.wmftest.net/v2",
"cookieDomain" => "mediawiki.local.wmftest.net",
"restbase" => "//$1.wikipedia.org/api/rest_v1"
]