<?php

require('/data/project/mybot/Peachy/Init.php');

$site = Peachy::newWiki("mybot");

$list = $site->initPage("User:Mybot/optin");

$users = $list->get_links(); 

function nobots($p) {
	$text = $p->get_text();
	if (preg_match('/\{\{(nobots|bots\|allow=none|bots\|deny=all|bots\|optout=all|bots\|deny='.preg_quote($user,'/').')\}\}/iS',$text)) 
		return false;
	if (preg_match('/\{\{(bots\|allow=all|bots\|allow='.preg_quote($user,'/').')\}\}/iS', $text))
		return true;
	if (preg_match('/\{\{(bots\|allow=.*?)\}\}/iS', $text))
		return false;
	return true;
}

foreach ($users as $u) {
	$page = $site->initPage($u);
	if (nobots($page) ) {
		continue;
	}
	$data = shell_exec("./analyze_user $u");
	$text = "Bot report of pages you might be interested in editing:\n";
	foreach($data as $article) {
		$text .= "* [[$article]]\n";
	}
	$text .= '-- ~~~~';
	$talk = $page->get_talkID();
	$talk->append($text, "Bot list", true);
}