Multiple Mediawiki Installations on the Same Codebase
From Charlie.Huggardlee.Net
As I have progressed in my use of Mediawiki, I have found that I enjoy using Mediawiki as a framework to quickly install a website that is easy to create, edit, and maintain. As the number of independent websites grew, the number of code installations I was having to maintain also grew, becoming rather tedious to maintain. In this article, I present the methods I used to help my sanity at least a little bit.
Layout
|
Directory Layout | |
|
|
|
Installation Layout ~ Click links for examples | |
|
|
For this, I used an layout similar to the one on the right. Each wiki is it's own subdomain and each subdomain directory where a wiki is installed is listed in a file /base/mediawiki_installations. It would be rather simple to extend this method to where wikis were installed in separate directories of the same subdomain, but slight modifications would have to be made in the rest of the instructions.
Within each installation directory: ./w/ is always a symbolic link to the codebase. ./LocalSettings.php defines specific wiki settings (./w/LocalSettings.php is responsible for the common settings) ./CommandLine.php is a wrapper for running maintenance scripts and ./.htaccess helps with pretty URLs. If uploads are enabled for a wiki, then a seperate ./images/ directory is necessary, and if one would like to write custom skins, it's necessary to create a ./skins/ directory. If written properly, these last 2 files can be shared among all installations. Each of these files will be covered in more detail later.
Selection of the proper LocalSettings.php
As you may (or may not) already know, LocalSettings.php is the central point to wiki configuration, and the wiki software looks for this special file at the top level of the code base (in our example /base/mediawiki) and loads all of the preferences, extensions, etc, from this point. For our purposes, the codebase LocalSettings.php will be responsible for setting up some default configurations, as well as loading the proper site's LocalSettings.php For this purpose, I introduce a $baseIP variable to hold the full path to the particular wiki installation directory. When executing command line scripts, the $baseIP is set by the command line wrapper detected in a similar manner that $IP is set from a standard MediaWiki installation. When requested by the server, some detection of the requested path is needed. As my installation directories are the same level as my mediawiki installation directory, and are all their own subdomain, this is simply a matter of:
$baseIP = substr($IP,0,strrpos($IP,'/')+1) . strtolower($_SERVER[SERVER_NAME]);
But extending that to handle subdirectory installations would be pretty easy.
With two separate LocalSettings.php this necessitates having to choose which variables should be set at what level (locally vs. globally) and how they should be initialized, but that should be apparent from the examples.
Pretty URLs & mod_rewrite
- For more detail see: Beautifying Mediawiki URLs
As each wiki would be hosted from a location used primarily to host the wiki, I decided that I wanted to have URLs that were of the form http://subdomain.domain.tld/Article_Name and used mod_rewrite to accomplish this.
Custom Skins & Download Directories
As each site is different, the need for custom skinning becomes necessary, and the potential for browsable non-wiki directories (Espically on those wikis with lots of potential binary files that shouldn't be uploaded to the wiki itself). Custom skinning was accomplished by having the global LocalSettings.php look for the presence of a skins directory in the local wiki directory (e.g. $baseIP/skins). In code:
## Establish a non-default style directory if one exists if( is_dir( "${baseIP}/skins" ) ) { $wgStylePath = "/skins"; /// defaults to "{$wgScriptPath}/skins" $wgStyleDirectory = "{$baseIP}/skins"; /// defaults to "{$IP}/skins" }
Non-wikified downloads was simply a matter of making sure that the rewrite rules properly ignored any request to the downloads directory if such a directory exists:
RewriteCond %{DOCUMENT_ROOT}/downloads -d RewriteCond %{REQUEST_URI} !^/downloads/.*$ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.+)$ w/index.php?title=$1 [L,QSA]
For convenience, I originally made a wiki article Downloads with a link to the download directory, but then figured that people would rather click a link and arrive there, so I did a little more mod_rewrite magic to convert a request for "Downloads" to a request for "downloads":
RewriteCond %{DOCUMENT_ROOT}/downloads -d RewriteRule ^Downloads$ /downloads/ [L,R] RewriteCond %{DOCUMENT_ROOT}/downloads -d RewriteRule ^Downloads(.+)$ /downloads$1 [L,R]
New Installations
Unfortunately this remains to be the rocky part of this scheme, and I don't have a good solution to it other than temporarily editing w/config/index.php to skip the check for ../LocalSettings.php. I tried putting handwriting a ./LocalSettings.php in the new-wiki's directory and running php CommandLine.php w/maintenance/update.php but unfortunately it currently (as of r30177) assumes the presence of particular tables in the database and therefore fails. If you come up with a better idea, drop me a note below!
Summary
Mediawiki makes for a good start for quick editable websites, with the tricks I presented in this article, hopefully maintaining multiple installations becomes a breeze for you as well. As always, I welcome any and all feedback on this article.
--Charlie Huggard 10:38, 27 January 2008 (CST)
or read what others have said
| Author | Charlie Huggard + |
| Post date | 27 January 2008 16:38 + |
| Read more | true + |

