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 handled via the Site Settings extension, which is a prerequisite - you need to have Site Settings installed and set up. The Site Settings extension stores its information in a database table called "site_settings". Only one of your databases should have this table; the wiki/subdomain/database that holds this table will be the "main" one, and it's highly recommended to go with 'www' for the name of it.

Once you have your basic wiki set up, it's recommended 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.

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 two directories, and make them 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 image files; you'll need to make similar additions to your file:

RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^([^\.]+)\.referata\.com

# 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" );

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" );
$wgWikiGardenDomain = '';
$wgWikiGardenAnnouncementsEmail = '';
$wgWikiGardenDBNamePrefix = 'yaron57_';
$wgWikiGardenDefaultLogo = "$wgScriptPath/skins/common/images/referata-site-logo.png";

A note about $wgWikiGardenDefaultLogo: 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, $wgWikiGardenMainSubdomains, 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, $wgWikiGardenAdminDefaultGroups, 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'.

$wgWikiGardenMainSubdomains[] = 'de';
$wgWikiGardenAdminDefaultGroups[] = '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:

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

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:

$wgWikiGardenServiceSettings = 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:

$wgWikiGardenSubscriptionsEmail = '';
$wgWikiGardenCurrency = 'USD';
$wgWikiGardenPayPalIdentityToken = "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 three steps that need to be done now. First, the 'site_settings' table, defined by the Site Settings extension, needs to be updated to add more fields. Second, a new table, 'action_history', needs to be created - it will hold a record of site creations, deletions, etc. for record-keeping. Third, both tables need to be populated.

To create the tables, go to the file WikiGarden.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 site_settings (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 the following utility script:

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, June 20, 2013