Difference between revisions of "Wiki Family"
Jump to navigation
Jump to search
Line 157: | Line 157: | ||
die("wikifarm could not find configuration for $wgServer"); | die("wikifarm could not find configuration for $wgServer"); | ||
} | } | ||
+ | ?> | ||
+ | </source> | ||
+ | = worksite.php = | ||
+ | <source lang='php'> | ||
+ | <?php | ||
+ | // see https://www.mediawiki.org/wiki/Manual:Wiki_family#Updating_wikifarm_from_the_commandline | ||
+ | // show an error and die | ||
+ | function error($msg) { | ||
+ | die($msg); | ||
+ | } | ||
+ | |||
+ | // check command line arguments | ||
+ | if (count($argv)<3) { | ||
+ | error("usage: worksite [sitename] [update|runJobs|debug|updateNameSpaceCache]"); | ||
+ | } | ||
+ | |||
+ | //$argv gets commandline arguments | ||
+ | $siteid= $argv[1]; // siteid e.g. test | ||
+ | $work = $argv[2]; // work to do e.g. update | ||
+ | |||
+ | // set domain name | ||
+ | #$site = $siteid. '.bitplan.com'; | ||
+ | $site = $siteid; | ||
+ | $_SERVER['SERVER_NAME'] = $site; | ||
+ | $_SERVER['HTTP_HOST'] = $site; | ||
+ | $_MWCONFIGFILE="/var/www/mediawiki/sites/$site/FullLocalSettings.php"; | ||
+ | define( 'MW_CONFIG_FILE', $_MWCONFIGFILE); | ||
+ | echo '-------------------------------------- | ||
+ | Running '.$work.'.php for ' . $site . ' | ||
+ | -------------------------------------- | ||
+ | '; | ||
+ | switch ($work) { | ||
+ | case "debug": | ||
+ | echo "$work in progess ..."; | ||
+ | echo "MWCONFIGFILE: ".$_MWCONFIGFILE; | ||
+ | #include($_MWCONFIGFILE); | ||
+ | global $cargoavailable; | ||
+ | echo "Cargo:".$cargoavailable; | ||
+ | break; | ||
+ | case "updateEntityCountMap": | ||
+ | include("extensions/SemanticMediaWiki/maintenance/updateEntityCountMap.php"); | ||
+ | break; | ||
+ | case "updateNameSpaceCache": | ||
+ | #$language= | ||
+ | #$namespaces=$language->getNamespaces(); | ||
+ | #foreach ($namespace ...) | ||
+ | break; | ||
+ | default: | ||
+ | include("maintenance/$work.php"); | ||
+ | } | ||
+ | |||
?> | ?> | ||
</source> | </source> |
Revision as of 08:32, 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");
}
?>
worksite.php
<?php
// see https://www.mediawiki.org/wiki/Manual:Wiki_family#Updating_wikifarm_from_the_commandline
// show an error and die
function error($msg) {
die($msg);
}
// check command line arguments
if (count($argv)<3) {
error("usage: worksite [sitename] [update|runJobs|debug|updateNameSpaceCache]");
}
//$argv gets commandline arguments
$siteid= $argv[1]; // siteid e.g. test
$work = $argv[2]; // work to do e.g. update
// set domain name
#$site = $siteid. '.bitplan.com';
$site = $siteid;
$_SERVER['SERVER_NAME'] = $site;
$_SERVER['HTTP_HOST'] = $site;
$_MWCONFIGFILE="/var/www/mediawiki/sites/$site/FullLocalSettings.php";
define( 'MW_CONFIG_FILE', $_MWCONFIGFILE);
echo '--------------------------------------
Running '.$work.'.php for ' . $site . '
--------------------------------------
';
switch ($work) {
case "debug":
echo "$work in progess ...";
echo "MWCONFIGFILE: ".$_MWCONFIGFILE;
#include($_MWCONFIGFILE);
global $cargoavailable;
echo "Cargo:".$cargoavailable;
break;
case "updateEntityCountMap":
include("extensions/SemanticMediaWiki/maintenance/updateEntityCountMap.php");
break;
case "updateNameSpaceCache":
#$language=
#$namespaces=$language->getNamespaces();
#foreach ($namespace ...)
break;
default:
include("maintenance/$work.php");
}
?>
runjobs
#!/bin/bash
# WF 2015-06-08
# run jobs for all sites
jobs=$(pgrep -fla runjobs | wc -l)
if [ $jobs -gt 3 ]
then
echo "$jobs runjobs already running ..."
exit 1
fi
cd /srv/www/mediawiki/code
host=$(hostname)
cat $host.sites | egrep -v "^#" | while read siteid site
do
#./update $siteid
#echo $siteid
#echo $site
/usr/bin/php /srv/www/mediawiki/code/worksite.php $site runJobs \
--conf /srv/www/mediawiki/sites/$site/FullLocalSettings.php >> /var/log/mediawiki/runJobs_$siteid.log 2>&1
done