<?php
define("WS_ADMIN",true);
require_once( "../common/WSInit.php" );
require_once( "WikiAccess.php" );
require_once('WikiBot.php');
if (!isset($args[3])) {
print "USAGE: PostMessage.php [post-options] [-message=file] <summary> <wiki-option> <page-option> <config-file> [<config-file>...]\n";
die();
}
$summary= $args[0];
$wikiopt= $args[1];
$pageopt= $args[2];
$msgfile= @$options['message'];
$talk= @$options['talk'];
$existing= @$options['existing'];
if ($msgfile==='-' || $msgfile===NULL) $msgfile= 'php://stdin';
$txt= file_get_contents($msgfile);
if ($txt===false || $txt===NULL) {
die("failed to read message file $msgfile\n");
}
if (trim($txt)==='') {
die("empty message in $msgfile, nothing to post. exiting.\n");
}
for ($i=3; $i<sizeof($args); $i++) {
$conf= $args[$i];
if (!file_exists($conf)) {
wsfLog("WARNING: file not found: $conf", LL_WARN);
continue;
}
$files= array();
if (is_dir($conf)) {
$files= glob("$conf/*.config");
if (!$files) {
wsfLog("WARNING: no configuration files found in $conf", LL_WARN);
continue;
}
else {
wsfLog("using ".sizeof($files)." config files in directory $conf", LL_INFO);
}
}
else {
$files[]= $conf;
}
foreach ($files as $conf) {
if (isset($config)) unset($config);
ob_start();
include($conf);
ob_end_clean();
if (!$config) {
wsfLog("WARNING: no configuration declared in file $conf", LL_WARN);
continue;
}
$domain= $config[$wikiopt];
$page= $config[$pageopt];
if (!$domain) {
wsfLog("WARNING: no wiki domain specified as option $wikiopt in $conf", LL_WARN);
continue;
}
if (!$page) {
wsfLog("WARNING: no wiki page specified as option $pageopt in $conf", LL_WARN);
continue;
}
wsfLog("processing $page on $domain from $conf", LL_INFO);
unset($wiki);
$wiki= WikiAccess::newInstance( $domain );
$wiki->initTranslations();
if ($talk) $page= $wiki->getTalkPage($page);
unset($bot);
$bot= new WikiBot($wiki);
if (isset($useropt)) $bot->user= @$config[$useropt];
if (isset($passopt)) $bot->password= @$options[$passopt];
if ($existing) {
$s= @$bot->load(array(
'title' => $page,
'action' => 'raw',
));
if ($s===NULL || $s===false || $s==='' || $s==="\0") {
wsfLog("WARNING: page $page does not exist on wiki $domain, skipping.", LL_WARN);
continue;
}
}
$bot->edit( $page, $txt, $summary,
@$options['insert-before'], @$options['insert-after'], @$options['insert-replace'],
@$options['separator'] );
$wiki->close();
}
}
?>
PostMessage.php
application/x-php, 3091 bytes (load raw)

