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 HashTables 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.

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

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.

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

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


 * $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.