I just wanted to share my setup of a wikifarm for a multi-language wiki using the same mediawiki installation. After a few days of trial and error I finally seem to have it working, but I didn't use any of the automatically generated scripts that probably wouldn't have worked in my case. In any case this is my setup.
- I have installed the mediawiki package in a subdomain, let's call it: https://mywiki.example.com
- After doing some initial customizations, I took the next step to make a wikifarm for different languages. I copied the "template" database tables of my initial installation to two other database tables with language suffixes ("_en" and "_it")
- I created two aliases in my apache vhost file, one for each of the languages that I will currently support:
Alias /en/ /var/wikiinstallationpath
Alias /it/ /var/wikiinstallationpath
- I added logic in the LocalSettings to pick up on the language based on the url "subdirectory":
#Let's try to setup a wiki family
if ( defined( 'MW_DB' ) ) {
// Set $wikiId from the defined constant 'MW_DB' that is set by maintenance scripts.
$wikiId = MW_DB;
} elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'mywiki.example.com' && substr($_SERVER['REQUEST_URI'], 0, 3) == '/en') {
$wikiId = 'en';
} elseif (isset($_SERVER['SERVER_NAME']) && $_SERVER['SERVER_NAME'] == 'mywiki.example.com' && substr($_SERVER['REQUEST_URI'], 0, 3) == '/it') {
$wikiId = 'it';
} else {
// Fail gracefully if no value was set to the $wikiId variable, i.e. if no wiki was determined
die( 'It was not possible to determine the wiki ID.' );
}
- Then I use that wikiID to choose the database:
# MySQL specific settings
$wgDBprefix = "";
$wgDBname = 'mywiki_' . $wikiId;
$wgSharedDB = 'mywiki';
$wgCacheDirectory = "/tmp/mediawiki_".$wikiId."_cache";
$wgUploadDirectory = "$IP/images";
$wgUploadPath = "/images";
- Seeing that the language "subdirectories" are aliased to the script path by apache, I figure I can tell mediawiki that my script path is in the language subdirectory (physically non existent, virtually an alias of the real script path):
$wgScriptPath = "/$wikiId";
$wgScriptExtension = ".php";
$wgArticlePath = "{$wgScriptPath}/$1";
$wgUsePathInfo = true;
$wgServer = "https://mywiki.example.com";
## The URL path to static resources (images, scripts, etc.)
$wgResourceBasePath = $wgScriptPath;
- Then I have an .htaccess in my root directory:
RewriteEngine On
#For the time being we don't use the base hostname, if requested we redirect to the english version
RedirectMatch ^/$ /en/
#Let's do Short URLs
RewriteCond %{HTTP_HOST} ^(mywiki.example.com)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php [L]
With this current setup, I am successfully serving my pages with short URLs, and the interwiki links are also being generated as short urls. Interwiki links between languages are working nicely too. Now that I've installed the Wikibase extension I just have to figure out how to populate the sites table and use sitelinks to link between my two languages.