Extension:Simple Farm

Simple Farm is a simple MediaWiki farm extension by Daniel Werner. It automatically forwards to a certain wiki (within one single MediaWiki installation) that should be accessed by either a virtual script path (using a tiny bit of mod-rewrite) or by using sub-domains. It is also possible to have members of the same farm using either of these methods, not all members have to use the same. Furthermore, 'Simple Farm' comes with a maintenance script which allows to maintain several farm members at the same time, e.g. doing database updates for all or certain farm members by executing just one command.

How it Works
Simple Farm kicks in before the MediaWiki has initialized all of its components. At this stage the wiki has not even made a connection to its database, global variables and functions are not all initialized, just most Extensions might be registered already. At this stage, Simple Farm takes over initialization to load a wiki from a certain database and set required global configuration variables accordingly. After that job is done, it is even possible to load further global settings according to one farm members specific needs.

Basically the same happens in Maintenance mode via command-line. There is one script which will take commands which should be executed for each or just some specific farm members. Then the script will connect to one wiki to have Mediawikis maintenance functionality available, from there it will handle the commands for each farm member wikis independently.

Setup and Installation
First of all, you have to downloaded the code and place the SimpleFarm directory within your MediaWiki extensions directory. Then add the following code near the bottom of your LocalSettings.php file:

FarmMembers.php would be a new php file with the necessary farm setup you had to create within your MediaWiki installation directory. The content of that file will be explained next. The comment at the bottom is just a placeholder for additional per farm member configuration. Finally, you won't get around applying some rewrite rules to your wikis environment.

Setting-up Farm Members
This section will introduce available settings to control the farms behavior and to register members. This configuration might be in a separate php file so you won't have it all over your LocalSettings.php.

A valid setup in a FarmMembers.php could look like this:

is the config varariable to define all the members of the wiki farm. It is an array containing a sub-array per farm member. The following associative Array keys are obligatory: Furthermore, one of the following methods has to be chosen: and/or:
 * db : The farms database name
 * name : The name of the farm member wiki. This value will end up in $wgSitename.
 * addresses: one or more (as array of strings) server names associated with the wiki. Can be used for sub-domain based farm members like farm1.mw.org, farm2.mw.org..., farmX.mw.org If this method is chosen, $wgScriptPath must be set in LocalSettings.php. Even if this method is not chosen, the addresses key should contain one address anyway.
 * scriptpath : Virtual script path to the particular wiki directory. Can be used for a rewrite rules based wiki farm setup. This will set the $wgScriptPath variable automatically. There should be a .htaccess file in the parent directory of the farm to redirect all paths to the farms MediaWiki directory. Example: mw.org/farm1, mw.org/farm2..., mw.org/farmX where for the first member the value had to be , for the second   and so on.

The following key is optional:
 * maintain : Flag whether or not the wiki is in maintaining mode right now. The following flags are allowed:
 * /  : Normal mode, no maintenance is going on right now.
 * : Blocks simple browser access to the wiki but accessing the wiki with maintain url parameter still is possible.
 * : Blocks all attempts to access the wiki except for command-line based maintenance.
 * : Block all attempts to access the wiki, even command-line maintenance.

Settings per Member
Simple Farm will just set the most important configuration variables, you might want to set certain configuration variables according to the chosen farm member. There are several ways of doing that, the two most convenient are presented here.

Using an Configuration File per Member
You can simply add the following lines to your LocalSettings.php after the  line. Now you can create a new directory wikiconfigs within your MediaWiki installation directory which can contain several files named after each wikis database name +. In these files you can apply settings just like in Localsettings.php with the exception that they will only apply for a particular farm member.

Using $egSimpleFarmMembers
It is possible to add further, custom keys to each farm member array within. Within LocalSettings.php they can then be accessed via. It is recommended to put a prefix in front of these additional keys (e.g. ) or to simply use the name of the global configuration variable they will end up in. This will prevent complications with future option keys added by Simple Farm extension.

Wherever  is defined:

In LocalSettings.php (after the  line.) these additional keys can be accessed:

In case one of the accessed keys is not defined for one farm, false will be returned! Instead of using  a prettier   could be used if PHP 5.3 is running on the server.

Setting-up Rewrite Rules
To be Added

Configuration Variables
Besides the required setup, there are some optional configuration variables controlling some of Subpage Funs behavior:


 * $egSimpleFarmMembers : Please see the section for detail information.


 * $egSimpleFarmMainMemberDB : Database name of one of the  wikis. If null (default), it will be set when   was called. The default value is the first key of   then. This main member is important for maintenance since the generic maintenance script will connect to the main member first to have full basic MediaWiki maintenance support.


 * $egSimpleFarmIgnoredDomainPrefixes : In case some farm members work sub-domain wise, this array can contain sub-domain prefixes which will be ignored when choosing to which farm member the given sub-domain name belongs to. By default, this is set to, which means in something like "http://www.member1.myfarm.com" the www.member1 part would be considered the string to choose the farm member from but since www is set to be ignored, only member1 will be left. Of course, the same can be achieved by using rewrite rules.


 * $egSimpleFarmWikiSelectEnvVarName : Name of the environment variable used to select a wiki via command-line access if only one wiki should be selected directly instead of using the provided maintenace script. By default the name of this environment variable is.


 * $egSimpleFarmErrorNoMemberFoundCallback : Allows to define a PHP callback function which should be called in case no wiki has been found. This can happen in case somebody is using an url which would require a non-existing farm member. Note: It would be nice if we could use the hook system of MediaWiki instead, but at this stage, the hook system has not even initialized. There might be a more complex system for this in the future.

Affected Configuration Variables
There are several global configuration variables which will be affected by Simple Farm. Some might just be conditionally be affected, others in any case. Be aware, that setting any of these variables before  might overwrite their value!

The following variables are affected: