Friday, January 12, 2007

Mediawiki: Reusing the same code for multiple Wikis

Sometimes you may need to install separate wikis for in the same server. One inefficient solution (in terms of time and space) is to install everytime you need Wiki. Other solution is to reuse the wiki code for all. But you need to install database separately for each -for this, you first need to dump fresh database right after first installation so that it can be used for other potential Wikis that may need to be installed for other purpose in the same server.



This has been tried for Mediawiki 1.6.7 only.



1. First install Mediawiki in any folder (say wikicode).

2. Dump/Export mysql database from phpMyAdmin.

3. Create a new folder in document root (say testwiki).

4. Copy index.php and LocalSettings.php from wiki installed directory (wikicode, in our case) to the newly created folder.

The folder structure should be like this.

public_html/

wikicode/

mediawiki folders/files

testwiki/

index.php

LocalSettings.php



5. Make necessary changes in the LocalSettings.php, as shown below. The original and altered code excerpts are shown.



Original Localsettings.php right after installation.



[...]

if( defined( 'MW_INSTALL_PATH' ) ) {

$IP = MW_INSTALL_PATH;

} else {

$IP = dirname( __FILE__ );

}



$path = array( $IP, "$IP/includes", "$IP/languages" );

set_include_path( implode( PATH_SEPARATOR, $path ) );



[...]

$wgSitename = "Demowiki";



$wgScriptPath = "/wikicode";

$wgScript = "$wgScriptPath/index.php";

[...]

$wgStylePath = "$wgScriptPath/skins";

$wgStyleDirectory = "$IP/skins";

[...]

$wgUploadPath = "$wgScriptPath/images";

$wgUploadDirectory = "$IP/images";

[...]


Changed Localsettings.php in the new folder (testwiki, in our case)



[...]

if( defined( 'MW_INSTALL_PATH' ) ) {

$IP = MW_INSTALL_PATH;

} else {

$IP = dirname( __FILE__ );

}

$IP = $_SERVER['DOCUMENT_ROOT'].'/wikicode/';

$path = array( $IP, "$IP/includes", "$IP/languages" );

set_include_path( implode( PATH_SEPARATOR, $path ) );



[...]

$wgSitename = "Demowiki";



//$wgScriptPath = "/wikicode";

$wgScriptPath = "/testwiki";

$wgScript = "$wgScriptPath/index.php";

[...]

//$wgStylePath = "$wgScriptPath/skins";

$wgStylePath = "http://localhost/wikicode/skins";

$wgStyleDirectory = "$IP/skins";

[...]

$wgUploadPath = "$wgScriptPath/images";

//$wgUploadDirectory = "$IP/images";

$wgUploadDirectory = $_SERVER['DOCUMENT_ROOT'].'/demowiki/images';



6. Change database information accordingly.



Blue color represents the added lines

Green color represents the commented lines in the modified LocalSettings.php

[...] represents some codes, those are removed for brevity.



Now you can copy the folder (testwiki) as many times as you like, install databases and make necessary changes in the LocalSettings.php. This should allow you to install Wiki with very little effort from your part.



Updates:

Sorry I didn't realize that there is also a small addition in index.php, if any of you have been trying to follow this. It's funny that as I was trying to follow this myself, i realize that it's not working yet.



Original index.php



require_once( './includes/Defines.php' );


Changed index.php



set_include_path(get_include_path().PATH_SEPARATOR.$_SERVER['DOCUMENT_ROOT'].'/wikicode/');

require_once( 'includes/Defines.php' );

1 comment:

Joe said...

Thanks for the tutorial. It looks like there are some good directions on the MediaWiki wiki now: http://www.mediawiki.org/wiki/Manual:Wiki_family