Using Wiki Garden

This is the guide to setting up the Wiki Garden extension, written by Yaron Koren to allow for the running of Referata and, more generally, any other wiki farm.

First steps

Wiki Garden works by having a different database for each hosted wiki. The code is the same for all wikis; only the data and settings are different. Settings for each wiki are stored in a central table, called 'sites'. You will need to designate one wiki/subdomain/database as the "main" one, which holds this table - it's highly recommended to go with 'www'.

If you already have a wiki set up, we recommend to change the name of the database it runs on to 'www' (or 'prefix_www', if every database on your system requires a prefix). You'll correspondingly have to change the value of $wgDBname in LocalSettings.php.

If you don't have a wiki set up, you should first create it before installing Wiki Garden.

Installing the code

To install the code, place the entire 'WikiGarden' directory within your MediaWiki 'extensions' directory

Creating directories

Within the main MediaWiki directory, you should create the following three directories, and make them all world-readable and world-writeable:

Apache configuration

You'll need to have wildcard subdomains set up, so that * will all be handled as one site.

You'll also need permission to create multiple databases.

Also, assuming you're using Apache, you need to make some changes to the Apache httpd.conf file. Here's the relevant part of Referata's file, handling the rewriting of the /RDF and /images files; you'll need to make similar additions to your file:

RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.referata\.com
RewriteCond /home/yaron57/public_html/w/RDF/%1 -d
RewriteRule ^/RDF/(.*xml) /home/yaron57/public_html/w/RDF/%1/$1 [L]
RewriteRule ^/RDF /home/yaron57/public_html/w/RDF/index.php [L]

# www or no subdomain
RewriteCond %{HTTP_HOST} ^referata\.com
RewriteRule ^/w/images/(.*) /home/yaron57/public_html/w/images/www/$1 [L]

RewriteCond %{HTTP_HOST} ^referata\.com
RewriteRule ^/w/skins/common/images/logos/(.*) /home/yaron57/public_html/w/skins/common/images/logos/www/$1 [L]

# with subdomain
RewriteCond %{HTTP_HOST} ^([^\.]+)\.referata\.com
RewriteRule ^/w/images/(.*) /home/yaron57/public_html/w/images/%1/$1 [L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.referata\.com
RewriteRule ^/w/skins/common/images/logos/(.*) /home/yaron57/public_html/w/skins/common/images/logos/%1/$1 [L]

RewriteCond %{HTTP_HOST} ^([^\.]+)\.referata\.com
RewriteRule ^/w/skins/common/images/favicon/(.*) /home/yaron57/public_html/w/skins/common/images/favicon/%1/$1 [L]

Modifying MediaWiki

Several small changes need to be made, unfortunately, directly to the MediaWiki code for Wiki Garden to work.

1. In the file /includes/Skin.php:

a. if you're planning to allow custom skins - in the function newFromKey():

Replace the lines

                        $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
                        if( file_exists( $deps ) ) include_once( $deps );
                        require_once( "{$wgStyleDirectory}/{$skinName}.php" );


                        if (file_exists("{$wgStyleDirectory}/custom/{$skinName}.php")) {
                                $deps = "{$wgStyleDirectory}/custom/{$skinName}.deps.php";
                                if( file_exists( $deps ) ) include_once( $deps );
                                require_once( "{$wgStyleDirectory}/custom/{$skinName}.php" );
                        } else {
                                $deps = "{$wgStyleDirectory}/{$skinName}.deps.php";
                                if( file_exists( $deps ) ) include_once( $deps );
                                require_once( "{$wgStyleDirectory}/{$skinName}.php" );

b. in the function topLinks():

Below the line

                        global $wgTitle;


                        $this->mTitle = $wgTitle;

c. In the function bottomLinks():

Below the line

                if ( $wgOut->isArticleRelated() ) {


                        $this->mTitle = $wgTitle;

d. Finally, if your wiki uses Semantic MediaWiki, it's a good idea to modify the function getPoweredBy() - at the bottom, add:

                global $wgScriptPath;
                $url2 = htmlspecialchars( "$wgScriptPath/extensions/SemanticMediaWiki/skins/images/smw_button.png" );
                $img2 = '<a href=""><img src="'.$url2.'" alt="Powered by Semantic MediaWiki" /></a>';
                return $img . " " . $img2;

2. In the file /languages/messages/MessagesEn.php (or the equivalent in whatever non-English language you're using):

a. Right above the declaration of the $messages array, add the following:

global $wgServer;

b. Change the setting of the 'sidebar' message to read something like:

'sidebar' => "
* navigation
** mainpage|mainpage-description
** recentchanges-url|recentchanges
** Special:BrowseData|browsedata
* Add data
** Form:Example|Add... (change this)
* help
** helppage|help
**|Referata help
* Data export
** Special:ViewXML|viewxml
** $wgServer/RDF|RDF
* LANGUAGES", # do not translate or duplicate this message to other languages

(This one is very Referata-specific; and in fact you don't need to change this value at all - but if you want to modify the default sidebar, this is the place to do it.)

Modifying LocalSettings.php

You will need to make several additions to LocalSettings.php. First, you will need to set MediaWiki to not use 'hashing' for setting uploaded files (so that uploaded files don't end up in a directory like '/images/a/a1'):

$wgHashedUploadDirectory = false;

If your wiki already used hashing before, you might need to just wipe out the /images directory and re-upload everything - I'm not sure about that.

Also, make sure that there are appropriate values for the variables $wgRightsText, $wgRightsUrl and $wgDefaultSkin. The values for these variables are used to set the default values for newly-created sites.

Then, wherever you have extensions included in LocalSettings.php, you'll need to add in Wiki Garden, and some variables that it requires. Here are the relevant calls within Referata's own LocalSettings.php, which should mostly be copied and modified for your own wiki. First is the inclusion of the code, and some basic variables.

include_once( "$IP/extensions/WikiGarden/WikiGarden.php" );
$egWikiGardenDomain = '';
$egWikiGardenAdminName = 'Yaron Koren';
$egWikiGardenAnnouncementsEmail = '';
$egWikiGardenDBNamePrefix = 'yaron57_';
$egWikiGardenDefaultLogo = "$wgScriptPath/skins/common/images/referata-site-logo.png";

A note about $egWikiGardenDefaultLogo: this is the default logo for created sites that don't have a logo of their own uploaded. It is different from the logo for the main site, which is defined by$wgLogo. Of course, the two can be set to the same image.

Then, some arrays you can optionally add to, or change. The first, $egWikiGardenMainSubdomains, holds the set of subdomains that are considered 'main', i.e. from which users can create their own sites. By default it holds just one value: 'www'. That should probably be good enough for most wiki farms. The second, $egWikiGardenAdminDefaultGroups, holds the set of groups that someone who creates a new site will belong to, by default, as the administrator for that site. By default it holds two values: 'sysop' and 'bureaucrat'. Because Referata contains the Widgets extension, it adds a third value to that list: 'widgeteditor'.

$egWikiGardenMainSubdomains[] = 'de';
$egWikiGardenAdminDefaultGroups[] = 'widgeteditor';

The following two lines need to be placed as-is in the file - $wgUploadDirectory has to be set before any of the extensions are initialized, which is why these lines are here:

$egWikiGardenSubdomain = efWikiGardenGetSiteSubdomain();
$wgUploadDirectory = "$IP/images/$egWikiGardenSubdomain";

By default, all users are allowed to create new sites. If you want to change this, you will need to modify the settings for the 'createsite' permission. For instance, to set it so that only administrators can create sites, add the following:

$wgGroupPermissions['*']['createsite'] = false;
$wgGroupPermissions['sysop']['createsite'] = true;

Then there are the set of service levels that a specific wiki can belong to. For a non-profit wiki, there should really only be one, with zero cost. Here is the configuration for just the 'basic' level on Referata - anything here can be changed, although 'monthly rate' should stay at 0:

$egWikiGardenServiceSettings = array(
        'basic' => array(
                'name' => 'Basic (free)',
                'short name' => '',
                'monthly rate' => 0,
                'private allowed' => false,
                'virtual domain allowed' => false,
                'ads allowed' => false,
                'favicon allowed' => false,
                'disk megabytes' => 100,

However many service levels are defined, the first one in the list will be the default level for new sites.

Finally, there are some global variables relating to payment and subscriptions, that you may or may not need:

$egWikiGardenSubscriptionsEmail = '';
$egWikiGardenCurrency = 'USD';
$egWikiGardenPayPalIdentityToken = "token-here";

Setting up the database

By this point, you should already have a wiki in place. However, this may or may not be the wiki that you want to serve as the 'main site' for your garden, the one from which all other wikis/sites will be created. If you do, it's recommended to rename the database that it uses to 'www', if you haven't done so already - see 'First steps', at the top.

If you don't want this to be the main wiki, you should make this the "temporary" main wiki instead: first, pick a subdomain that this wiki will take, and rename the database accordingly (if necessary). Then change LocalSettings.php to set this to be the main subdomain. Then, via the page Special:CreateSite, create the real main site, at 'www' or wherever else. Once that's done, change LocalSettings.php back to use the real main subdomain, and transfer the two new database tables (see following) to the real main database, and everything should work.

There are two steps that need to be done now. First, two tables need to be added to the main database - 'sites', which we mentioned before, and 'action_history', which holds a record of site creations, deletions, etc. for record-keeping. Second, a starting row needs to be added to both tables, to store information on this first site.

To create the tables, go to the file /maintenance/WG_InitializeDB.sql, and, in one way or another, run this SQL in the database.

Then, to add the first row to each of these two tables, you'll need to create some custom SQL. If you want the name of your main wiki to be 'My Wiki', at the subdomain 'www', with a database table called 'mydb_www', and in English, the SQL should look like this:

INSERT INTO sites (url, name, owner_id, db_name, namespace, language_code)
VALUES ('www', 'My Wiki', 1, 'mydb_www', 'My Wiki', 'en');

INSERT INTO action_history (site_id, site_url, action)
VALUES (1, 'www', 'Created');

If you want values different from those, you'll have to modify the SQL accordingly - hopefully the way to modify it makes sense. Then call the SQL in the same way that you called the SQL to create the tables.

Other recommended extensions

You can see the Referata version page for the set of extensions installed on Referata. All of these are useful, but the only one specifically recommended for wikis that use Wiki Garden is Admin Links, which should help all administrators on the site.


The /maintenance folder in the WikiGarden folder contains several utility scripts:

Running Wiki Garden

See the main Wiki Garden page for, hopefully, all the information you need to get started on actually running it.

Yaron Koren, May 38, 2010