The following post was automatically generated by Cyberbot I.

<?php

/*while( $vol == "" ) {
	echo "What volume is this issue in?\n";
	$vol = trim(fgets(STDIN));
}

while( $issue == "" ) {
	echo "What issue is this?\n";
	$issue = trim(fgets(STDIN));
}*/

define('PILLAR','PILLAR'); 
require_once('/home/cyberpower678/pillar/trunk/class.pillar.php');

$pillar = Pillar::ini_launch('/home/cyberpower678/configs/afd-calc.cfg');
$site = $pillar->cursite;

$enablepage = "User:Cyberbot I/Run/Newsletter";
try {
	$run = new Page($site,$enablepage);
	$run = $run->get_text();
} catch (PillarException $e) {
	die( "Got an error when getting the enable page.\n" );
}
if( !preg_match( '/(enable|yes|run|go|start)/i', $run ) ) {
	die( "Bot is disabled.\n" );
}

if( $argv[2] != "--nosource" || 1 == 1 ) {
	try {
		$page = new Page($pillar->cursite,'User:SoxBot/Source/Signpost');
	} catch (PillarException $e) {
		continue;
	}
	
	try {
		$page->put('The following post was automatically generated by [[User:'.$user.'|'.$user."]].\n\n<pre>" .
		htmlentities(file_get_contents(__FILE__)) . 
		"</pre>",'Automatic source code upload ([[WP:BOT|BOT]])');
	} catch (PillarException $e) {
		continue;
	}
}
 

$delivery['page']  = 'Wikipedia:Wikipedia_Signpost/Tools/Spamlist';
$delivery['text']  = "\n\n{{subst:Wikipedia:Wikipedia Signpost/Tools/Spamlist/Message}} \n\r<small>Delivered by ~~~ at ~~~~~</small>";
$delivery['sum']   = "Delivering [[WP:POST|Wikipedia Signpost]] ([[User:".$user."|BOT]])";
$errors = array();

try {
	$deliverypage = new Page($pillar->cursite,$delivery['page']);
	$deliverytext = $deliverypage->get_text();
} catch (PillarException $e) {
	continue;
}

if( $argv[1] != "--continue" ) {
	preg_match_all('/[^\>]\[\[(User|User_talk|User talk):.+\]\]/Si',$deliverytext,$pages);
	foreach ($pages[0] as $i => $p) {
		$temp = explode('|',$p);
		$p = preg_replace(array('/.*\[\[(User|User_talk|User talk):/Si','/\]\].*/i'),'',$temp[0]);
		deliver($p);
	}
}
else {
	$p = unserialize(file_get_contents('signpost.errors.log'));
	foreach( $p as $page ) {
		$p = $p[0];
		$p = preg_replace('/(User|User_talk|User talk):/Si','',$page);
		deliver($p);
	}
}

print_r($pages);die();


function deliver($page) {
	//Delivers the newsletter to $page
	global $wpi, $wpapi, $wpq, $delivery, $errors, $pillar, $argv;
	$page = "User_talk:".trim($page);

	try {
		$page_instance = new Page($pillar->cursite,$page);
		$content = $page_instance->get_text();
	} catch (PillarException $e) {
		$errors[] = array($page,$e);
	}

	if (preg_match('/#REDIRECT \[\[.+\]\]/Si',$content,$new_page)) {
		$page = str_replace(array('#REDIRECT [[',']]'),'',$new_page[0]);
		try {
			unset($page_instance);
			$page_instance = new Page($pillar->cursite,$page);
			$content = $page_instance->get_text();
		} catch (PillarException $e) {
			$errors[] = array($page,$e);
		}
		if( !preg_match('/(User|User_talk|User talk):/Si', $page) ) return;
	}
	
   	echo "Sending to $page\n";
   	
   	preg_match('/--start=(.*)/',$argv[1],$m);
   	$tmparr = array(
   		$page,
   		@$m[1]
   	);
   		
   	sort($tmparr);
   	print_r($tmparr);
   	if( $tmparr[0] == $page ) {
   		echo "Already sent, skipping.\n";
   	}		
   	else {
	   	if( $page_instance->checkexcluded() ) continue;
	   	
	   	if ($content != ''){
	   		try {
				$page_instance->put($content.$delivery['text'],$delivery['sum'],false);
			} catch (PillarException $e) {
				$errors[] = array($page,$e);
			}
	   	}
   	}
} 

print_r($errors);

file_put_contents('signpost.errors.log',serialize($errors));