Wiki Family: Difference between revisions
Jump to navigation
Jump to search
| Line 67: | Line 67: | ||
</graphviz> | </graphviz> | ||
== Localsettings.php == | == Localsettings.php (code) == | ||
<source lang='php'> | |||
<?php | |||
/** | |||
* MediaWiki wikifamily handling code | |||
* | |||
* Taken from Drupal code to tap multisite configuration. | |||
*/ | |||
// returns true if $needle is a substring of $haystack | |||
function contains($needle, $haystack) | |||
{ | |||
return strpos($haystack, $needle) !== false; | |||
} | |||
/** | |||
* Find the appropriate configuration directory for the current request | |||
*/ | |||
function findConfiguration($confdir,$domain,$debug) { | |||
$host=$_SERVER['SERVER_NAME']; | |||
$host=str_replace(".q.",".",$host); | |||
if ($debug) { | |||
print ("find Configuration for ".$host." in ".$confdir." for domain ".$domain."<br>"); | |||
} | |||
if ($host) return $host; else return NULL; | |||
} | |||
/** | |||
* optionally add the given settings | |||
*/ | |||
function optionalRequireSettings($settings) { | |||
if (file_exists($settings)) { | |||
require_once($settings); | |||
} | |||
} | |||
# switch on for debuging | |||
$debug=false; | |||
# the main configuration directory in which all wiki farm member sites are configured | |||
$confdir = '/var/www/mediawiki/sites'; | |||
# The Prefix to use for local/specialized configuration files | |||
$prefix="BITPlan"; | |||
# find the configuration for the current request | |||
$domain="bitplan.com"; | |||
$conf=findConfiguration($confdir,$domain,$debug); | |||
#$conf=NULL; | |||
# if we found a configuration then use it | |||
if ($conf) { | |||
# make sure all farm members use the same .smw.json file | |||
# https://www.semantic-mediawiki.org/wiki/Help:$smwgConfigFileDir | |||
global $smwgConfigFileDir; | |||
global $wgWikiFarmSite; | |||
$wgWikiFarmSite=str_replace(".".$domain,"",$conf); | |||
# uncomment for better debugging | |||
if ($debug) { | |||
ini_set('display_errors', '1'); | |||
ini_set('display_startup_errors', '1'); | |||
error_reporting(E_ALL); | |||
$wgShowExceptionDetails=true; | |||
} | |||
$smwgConfigFileDir = $confdir; | |||
# | |||
# first use the specific LocalSettings for the site | |||
$lsettings="$confdir/$conf/LocalSettings.php"; | |||
if ($debug) { | |||
print ("Localsettings from ".$lsettings); | |||
} | |||
require_once( $lsettings ); | |||
# then use the global settings for the farm | |||
# if there are further specific settings for the site use them | |||
$gsettings=array("$confdir/{$prefix}Settings.php","$confdir/$conf/{$prefix}Settings.php"); | |||
foreach ($gsettings as $gsetting) { | |||
if (file_exists($gsetting)) { | |||
require_once($gsetting); | |||
} | |||
} | |||
} else { | |||
$IP = '.'; | |||
require_once( './includes/DefaultSettings.php' ); # used for printing the version | |||
require_once( './includes/NoLocalSettings.php' ); | |||
die("wikifarm could not find configuration for $wgServer"); | |||
} | |||
?> | |||
</source> | |||
Revision as of 07:24, 25 November 2020
Principle
https://www.mediawiki.org/wiki/Manual:Wiki_family
Example Setup
Directory Layout

Localsettings.php (code)
<?php
/**
* MediaWiki wikifamily handling code
*
* Taken from Drupal code to tap multisite configuration.
*/
// returns true if $needle is a substring of $haystack
function contains($needle, $haystack)
{
return strpos($haystack, $needle) !== false;
}
/**
* Find the appropriate configuration directory for the current request
*/
function findConfiguration($confdir,$domain,$debug) {
$host=$_SERVER['SERVER_NAME'];
$host=str_replace(".q.",".",$host);
if ($debug) {
print ("find Configuration for ".$host." in ".$confdir." for domain ".$domain."<br>");
}
if ($host) return $host; else return NULL;
}
/**
* optionally add the given settings
*/
function optionalRequireSettings($settings) {
if (file_exists($settings)) {
require_once($settings);
}
}
# switch on for debuging
$debug=false;
# the main configuration directory in which all wiki farm member sites are configured
$confdir = '/var/www/mediawiki/sites';
# The Prefix to use for local/specialized configuration files
$prefix="BITPlan";
# find the configuration for the current request
$domain="bitplan.com";
$conf=findConfiguration($confdir,$domain,$debug);
#$conf=NULL;
# if we found a configuration then use it
if ($conf) {
# make sure all farm members use the same .smw.json file
# https://www.semantic-mediawiki.org/wiki/Help:$smwgConfigFileDir
global $smwgConfigFileDir;
global $wgWikiFarmSite;
$wgWikiFarmSite=str_replace(".".$domain,"",$conf);
# uncomment for better debugging
if ($debug) {
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
$wgShowExceptionDetails=true;
}
$smwgConfigFileDir = $confdir;
#
# first use the specific LocalSettings for the site
$lsettings="$confdir/$conf/LocalSettings.php";
if ($debug) {
print ("Localsettings from ".$lsettings);
}
require_once( $lsettings );
# then use the global settings for the farm
# if there are further specific settings for the site use them
$gsettings=array("$confdir/{$prefix}Settings.php","$confdir/$conf/{$prefix}Settings.php");
foreach ($gsettings as $gsetting) {
if (file_exists($gsetting)) {
require_once($gsetting);
}
}
} else {
$IP = '.';
require_once( './includes/DefaultSettings.php' ); # used for printing the version
require_once( './includes/NoLocalSettings.php' );
die("wikifarm could not find configuration for $wgServer");
}
?>