User:X!/Source

The following is automatically generated by X!. It uses ClueBot classes for interacting with the wiki, and also uses some of ClueBot's code for interacting with IRC.

&lt;?PHP

/* * SoxBot Anti Testing Bot * Copyright (C) 2009 X! (soxred93 _at_ gmail _dot_ com) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or  * (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */	ini_set('memory_limit', '64M'); define( 'SIGNATURE', 'SoxBot III (talk | owner)' ); define( 'SCORELIMIT', -3 );

$testlist = array(		'/\/' =&gt; -5,		'/\'\'\'Bold text\'\'\'/'			                         =&gt; -3,		'/\'\'Italic text\'\'/'			                              =&gt; -3,		'/\'\'\'\'\'Bold text\'\'\'\'\'/'			                  =&gt; -6,		'/\'\'\'\'\'Italic text\'\'\'\'\'/'			                  =&gt; -6,		'/\[http:\/\/www\.example\.com link title\]/'	              =&gt; -8,		'/== Headline text ==/'				                          =&gt; -12,		'/\&lt;math\&gt;Insert formula here\&lt;\/math\&gt;/'			          =&gt; -20,		'/\&lt;nowiki\&gt;Insert non-formatted text here\&lt;\/nowiki\&gt;/'	  =&gt; -20,		'/#REDIRECT \[\[Insert text\]\]/'			                  =&gt; -10,		'/\&lt;s\&gt;Strike-through text\&lt;\/s\&gt;/'			                  =&gt; -3,		'/\&lt;sup\&gt;Superscript text\&lt;\/sup\&gt;/'		                  =&gt; -3,		'/\&lt;sub\&gt;Subscript text\&lt;\/sub\&gt;/'			                  =&gt; -3,		'/\&lt;small\&gt;Small Text\&lt;\/small\&gt;/'				              =&gt; -3, '/\&lt;!-- Comment --\&gt;/'		                                 =&gt; -15, '/\&lt;gallery\&gt; (Image|File):Example.jpg\|Caption1 (Image|File):Example.jpg\|Caption2 \&lt;\/gallery\&gt;/m'													 =&gt; -5, '/\&lt;blockquote\&gt; Block quote \&lt;\/blockquote\&gt;/m'													 =&gt; -5, '/'.preg_quote('{| class=&quot;wikitable&quot; border=&quot;1&quot; ! header 1 ! header 2 ! header 3		'/\&lt;ref\&gt;Insert footnote text here\&lt;\/ref\&gt;/'				 =&gt; -5,		'/(ghjk|asdf|zxcv)/i'			                              =&gt; -8,		'/--\[\[Special:Contributions\/.*\|.*\]\]/'                   =&gt; -5	); function score ($list,$data,&amp;$matches = null) { $score = 0; foreach ($list as $preg =&gt; $pts) { if ($x = preg_match_all($preg.'S',$data,$m)) { $matches[$preg] = $x; $score += $pts * $x; }		}		return $score; }	function getWarningLevel( $user ) { global $wpq; $warning = 0; $talk = $wpq-&gt;getpage('User talk:'.$user); if (preg_match_all('/&lt;!-- Template:uw-[a-z]*(\d)(im)? --&gt;.*(\d{2}):(\d{2}), (\d+) ([a-zA-Z]+) (\d{4}) \(UTC\)/iU', $talk,$m,PREG_SET_ORDER)) { foreach ($m as $r) { $month = array('January' =&gt; 1, 'February' =&gt; 2, 'March' =&gt; 3,'April' =&gt; 4, 'May' =&gt; 5, 'June' =&gt; 6, 'July' =&gt; 7, 'August' =&gt; 8, 'September' =&gt; 9, 'October' =&gt; 10,'November' =&gt; 11, 'December' =&gt; 12); if ((time - gmmktime($r[3],$r[4],0,$month[$r[6]],$r[5],$r[7])) &lt;= (2*24*60*60)) { if ($r[1] &gt; $warning) { $warning = $r[1]; } }			}		}		echo &quot;\n\n\n$warning\n\n\n&quot;; return $warning; }	declare(ticks = 1); function sig_handler($signo) { switch ($signo) { case SIGCHLD: while (($x = pcntl_waitpid(0, $status, WNOHANG)) != -1) { if ($x == 0) break; $status = pcntl_wexitstatus($status); }				break; }	}	pcntl_signal(SIGCHLD,  &quot;sig_handler&quot;); require('./wikibot.classes.php'); require('./bot.config.php'); //require('../database.inc');
 * row 1, cell 1
 * row 1, cell 2
 * row 1, cell 3
 * row 2, cell 1
 * row 2, cell 2
 * row 2, cell 3
 * }').'/m'														     =&gt; -5,
 * row 2, cell 3
 * }').'/m'														     =&gt; -5,

$http  = new http; $wpapi	= new wikipediaapi; $wpq	= new wikipediaquery; $wpi	= new wikipediaindex; $wpapi-&gt;login($user,$pass); $whitelist = $wpq-&gt;getpage('User:'.$user.'/Whitelist');

//Parse User:&lt;owner&gt;/Channels.js, to be joined later $ircconfig = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$owner.'/Channels.js')); $tmp = array; foreach($ircconfig as $tmpline) { if (substr($tmpline,0,1) != '#') { $tmpline = explode('=',$tmpline,2); $tmp[trim($tmpline[0])] = trim($tmpline[1]); } } $ircchannel = $tmp['ircchannel']; $irctechchannel = $tmp['irctechchannel']; $ircverbosechannel = $tmp['ircverbosechannel']; $ircotherchannels = $tmp['ircotherchannels']; $ircvandalismchannel = $tmp['ircvandalismchannel']; $ircaivchannel = $tmp['ircaivchannel']; $channels = array_filter(array($ircchannel,$irctechchannel,$ircotherchannels,$ircverbosechannel,$ircvandalismchannel,$ircaivchannel)); unset($tmp,$tmpline); $stalk = array; $edit = array; $stalkedit = array; $tmp = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$user.'/Autostalk.js')); foreach ($tmp as $tmp2) { if (substr($tmp2,0,1) != '#') { $tmp3 = explode('|',$tmp2,2); $stalk[$tmp3[0]] = trim($tmp3[1]); } } $tmp = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$user.'/Autoedit.js')); foreach ($tmp as $tmp2) { if (substr($tmp2,0,1) != '#') { $tmp3 = explode('|',$tmp2,2); $edit[$tmp3[0]] = trim($tmp3[1]); } } $tmp = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$user.'/Autostalkedit.js')); foreach ($tmp as $tmp2) { if (substr($tmp2,0,1) != '#') { $tmp3 = explode('|',$tmp2,3); $stalkedit[$tmp3[0]][$tmp3[1]] = trim($tmp3[2]); } } unset($tmp,$tmp2,$tmp3); $st2 = array; foreach ($stalkedit as $user =&gt; $s2) { $st2[$user] = $s2; }	print_r($st2); //print_r($stalk);print_r($edit);

$channels = array_unique(array_merge($channels,$stalk,$edit,$st2)); echo implode(', ', $channels); unset($st2);

$mysql = mysql_connect( $mysqlhost.':'.$mysqlport,$mysqluser,$mysqlpass ); @mysql_select_db( $mysqldb, $mysql ) or die( &quot;MySQL error: &quot; .mysql_error ); $irc = fsockopen($ircserver,$ircport,$ircerrno,$ircerrstr,15); $ircpid = pcntl_fork; if ($ircpid == 0) { fwrite( $irc,'PASS '.$ircpass.&quot;\n&quot; ); fwrite( $irc,'USER '.$user.' &quot;1&quot; :SoxBot.'.&quot;\n&quot; ); fwrite( $irc,'NICK '.$user.&quot;\n&quot; ); fwrite( $irc,'IDENTIFY '.$ircpass.&quot;\n&quot; ); sleep(5); while (!feof($irc)) { $data = str_replace(array(&quot;\n&quot;,&quot;\r&quot;),'',fgets($irc,1024)); echo 'IRC: '.$data.&quot;\n&quot;; $d = explode(' ',$data); $m = $d; unset($m[0], $m[1], $m[2]); $m = substr(implode(' ', $m),1); if (strtolower($d[0]) == 'ping') { fwrite( $irc,'PONG '.$d[1].&quot;\n&quot; ); } elseif (($d[1] == '376') or ($d[1] == '422') or (preg_match('/ERROR :Closing Link: (.*) \(Excess Flood\)/', $data) ) ) { sleep(5); foreach ($channels as $chan) { fwrite( $irc,'JOIN '.$chan.&quot;\n&quot; ); sleep(2); }				//sleep(15); foreach (explode(',',$ircchannel) as $y) { fwrite( $irc,'PRIVMSG '.$y.' :IRC logging enabled.'.&quot;\n&quot; ); }			} elseif (preg_match('/ERROR :Closing Link: (.*) \(Excess Flood\)/', $data)) { sleep(5); echo &quot;Trying to rejoin.\n&quot;; foreach ($channels as $chan) { fwrite( $irc,'JOIN '.$chan.&quot;\n&quot; ); sleep(2); }				sleep(15); foreach (explode(',',$ircchannel) as $y) { fwrite( $irc,'PRIVMSG '.$y.' :IRC logging enabled.'.&quot;\n&quot; ); }			} elseif (strtolower($d[1]) == 'privmsg') { //echo 'IRC: '.$data.&quot;\n&quot;; if ($m == 'Thanks, SoxBot!') { echo &quot;Yep!\n&quot;; sleep(rand(3,6)); fwrite( $irc,'PRIVMSG '.$d[2].' :No problem!'.&quot;\n&quot; ); }				if (substr($d[3],0,2) == ':!') { if (strtolower($d[2]) == '#wikipedia-en') { $tmp = explode('!',substr($d[0],1)); $cmd = 'NOTICE '.$tmp[0]; } elseif (strtolower($d[2]) == strtolower($user)) { $tmp = explode('!',substr($d[0],1)); $cmd = 'NOTICE '.$tmp[0]; } else { $cmd = 'PRIVMSG '.$d[2]; } switch (substr(strtolower($d[3]),2)) { case 'lastedit': if (preg_match(&quot;/\[\[(.*)\]\]/&quot;,$data,$m)) { $rv = $wpapi-&gt;revisions($m[1],1,'older'); fwrite($irc,$cmd.' :'.$m[1].' http://en.wikipedia.org/w/index.php?title='.urlencode($m[1]).'&amp;diff=prev' .									'&amp;oldid='.urlencode($rv[0]['revid']).' * '.$rv[0]['user'].' * '.$rv[0]['comment'].&quot;\n&quot;); } else { fwrite( $irc,$cmd.' :Couldn\'t find link.'.&quot;\n&quot; ); }							break; case 'stalk': if (preg_match(&quot;/\[\[User:(.*)\]\]/&quot;,$data,$m)) { $uc = $wpapi-&gt;usercontribs($m[1],1); fwrite($irc,$cmd.' :'.$uc[0]['title'].' http://en.wikipedia.org/w/index.php?title='.urlencode($uc[0]['title']).'&amp;diff=prev' .									'&amp;oldid='.urlencode($uc[0]['revid']).' * '.$m[1].' * '.$uc[0]['comment'].&quot;\n&quot;); } else { fwrite( $irc,$cmd.' :Couldn\'t find link.'.&quot;\n&quot; ); }							break; case 'status': $titles = unserialize(file_get_contents('titles.txt')); foreach ($titles as $title =&gt; $time) { if ((time - $time) &gt; (24*60*60)) { unset($titles[$title]); }							}							file_put_contents('titles.txt',serialize($titles)); $count = count($titles);

if (!preg_match('/(yes|enable|true)/i',$wpq-&gt;getpage('User:'.$user.'/Run'))) { $run = false; } else { $run = true; }							$top5beat = array; if (!mysql_ping($mysql)) { $mysql = mysql_pconnect($mysqlhost.':'.$mysqlport,$mysqluser,$mysqlpass,/* Force reconnect --&gt; */ true); mysql_select_db($mysqldb, $mysql); } $q = mysql_query('SELECT `user`,COUNT(`id`) AS `count` FROM `cluebot_enwiki`.`beaten` WHERE `user` != \'\' GROUP BY `user` HAVING `count` &gt; 1 ORDER BY `count` DESC LIMIT 5'); while ($x = mysql_fetch_assoc($q)) { $top5beat[] = $x['user'].' ('.$x['count'].')'; }							unset($x,$q); $top5beat = implode(' - ',$top5beat);

fwrite( $irc,$cmd.' :I am '.$user.'. I am currently '.($run?'enabled':'disabled').'.  I currently have '.$wpq-&gt;contribcount($user).' contributions.'.&quot;\n&quot; );

fwrite( $irc,$cmd.' :I have attempted to revert '.$count.' unique article/user combinations in the last 24 hours. '.&quot;\n&quot; ); fwrite( $irc,$cmd.' :The following users have beat me to the revert the most: '.$top5beat.&quot;\n&quot; );

fwrite( $irc,$cmd.' :I log all information to '.$ircchannel.'. This channel is '.$d[2].'.'.&quot;\n&quot; );

unset($count,$run,$time,$top5beat); break; case 'beaten': if (preg_match(&quot;/\[\[User:(.*)\]\]/&quot;,$data,$m)) { $x = mysql_fetch_assoc(mysql_query('SELECT COUNT(`id`) AS `count` FROM `beaten` WHERE `user` = \''.mysql_real_escape_string($m[1]).'\' GROUP BY `user`')); $y = mysql_fetch_assoc(mysql_query('SELECT SQL_CALC_FOUND_ROWS COUNT(`id`) AS `count2` FROM `beaten` GROUP BY `user` HAVING `count2` &gt; \''.mysql_real_escape_string($x['count']).'\' LIMIT 1')); $z = mysql_fetch_assoc(mysql_query('SELECT FOUND_ROWS as `ahead`')); fwrite( $irc,$cmd.' :User:'.$m[1].' has beaten me '.(($x['count'] != '')?$x['count']:'0').' times. There are '.$z['ahead'].' users who have beaten me more times.'.&quot;\n&quot; ); unset($x,$y); } else { fwrite( $irc,$cmd.' :Couldn\'t find link.'.&quot;\n&quot; ); }							break; case 'count': if (preg_match(&quot;/\[\[User:(.*)\]\]/&quot;,$data,$n)) { fwrite( $irc,$cmd.' :User:'.$n[1].' has '.$wpq-&gt;contribcount($n[1]).&quot; contributions. For more info, see http://toolserver.org/~soxred93/ec/&quot;.$n[1].&quot; \n&quot; ); } else { fwrite( $irc,$cmd.' :Couldn\'t find link.'.&quot;\n&quot; ); }							break; case 'maxlag': $ml = $wpi-&gt;getMaxlag; print_r($ml); fwrite( $irc,$cmd.' :Current maxlag level: '.$ml[2].&quot; seconds lagged. Server: &quot;.$ml[1].&quot;. \n&quot; ); break; case 'eval': $tmp = explode(' ',$data,6); $tmp1 = explode('!',substr($d[0],1)); if ($d[4] == md5($thesecret.'-'.$user)) { unset($tmp[0], $tmp[1], $tmp[2], $tmp[3], $tmp[4]); $code = implode($tmp, ' '); echo &quot;\n\n\n\n\n&quot;.$code.&quot;\n\n\n\n\n&quot;; $result = eval($code); fwrite( $irc,$cmd.' :Eval result: &quot;'.$result.'&quot;'.&quot;\n&quot; ); unset($tmp, $code); } else { fwrite( $irc,$cmd.' :Code incorrect.'.&quot;\n&quot; ); }							break; }				}			}		}		die; }

$wpi-&gt;forcepost('User:'.$user.'/Source',		'The following is automatically generated by '.$user.&quot;. It uses ClueBot classes for interacting with the wiki, and also uses some of ClueBot's code for interacting with IRC.\n\n&quot;.'&lt;pre&gt;'.htmlentities(file_get_contents(__FILE__)).&quot;&lt;/pre&gt;\n\n\n\n&quot;,		'Automated source upload.');

$stalk = array; $edit = array; $stalkedit = array; $tmp = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$user.'/Autostalk.js')); foreach ($tmp as $tmp2) { if (substr($tmp2,0,1) != '#') { $tmp3 = explode('|',$tmp2,2); $stalk[$tmp3[0]] = trim($tmp3[1]); } } $tmp = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$user.'/Autoedit.js')); foreach ($tmp as $tmp2) { if (substr($tmp2,0,1) != '#') { $tmp3 = explode('|',$tmp2,2); $edit[$tmp3[0]] = trim($tmp3[1]); } } $tmp = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$user.'/Autostalkedit.js')); foreach ($tmp as $tmp2) { if (substr($tmp2,0,1) != '#') { $tmp3 = explode('|',$tmp2,3); $stalkedit[$tmp3[0]][$tmp3[1]] = trim($tmp3[2]); } } unset($tmp,$tmp2,$tmp3); print_r($stalk);print_r($edit);print_r($stalkedit);

while (1) { $feed = fsockopen($feedhost,$feedport,$feederrno,$feederrstr,30);

if (!$feed) { sleep(10); $feed = fsockopen($feedhost,$feedport,$feederrno,$feederrstr,30); if (!$feed) die($feederrstr.' ('.$feederrno.')'); }

fwrite( $feed,'USER '.$user.' &quot;1&quot; &quot;1&quot; :SoxBot Wikipedia Bot.'.&quot;\n&quot; ); fwrite( $feed,'NICK '.$user.&quot;\n&quot; );

while (!feof($feed)) { $rawline = fgets($feed,1024); $line = str_replace(array(&quot;\n&quot;,&quot;\r&quot;,&quot;\002&quot;),'',$rawline); $line = preg_replace('/\003(\d\d?(,\d\d?)?)?/','',$line); if (!$line) { fclose($feed); break; } $linea= explode(' ',$line,4);

if (strtolower($linea[0]) == 'ping') { fwrite( $feed,'PONG '.$linea[1].&quot;\n&quot; ); } elseif (($linea[1] == '376') or ($linea[1] == '422')) { fwrite( $feed,'JOIN '.$feedchannel.&quot;\n&quot; ); } elseif ((strtolower($linea[1]) == 'privmsg') and (strtolower($linea[2]) == strtolower($feedchannel))) { $message = substr($linea[3],1); if (preg_match('/^\[\[((Talk|User|Wikipedia|File|MediaWiki|Template|Help|Category|Portal|Special)(( |_)talk)?:)?([^\x5d]*)\]\] (\S*) (http:\/\/en\.wikipedia\.org\/w\/index\.php\?diff=(\d*)&amp;oldid=(\d*)|http:\/\/en\.wikipedia\.org\/wiki\/\S+)? \* ([^*]*) \* (\(([^)]*)\))? (.*)$/S',$message,$m)) {					$messagereceived = microtime(1);					$change['namespace'] = $m[1];					$change['title'] = $m[5];					$change['flags'] = $m[6];					$change['url'] = $m[7];					$change['revid'] = $m[8];					$change['old_revid'] = $m[9];					$change['user'] = $m[10];					$change['length'] = $m[12];					$change['comment'] = $m[13];					if( $change['namespace'] == '2' ) {						echo 'FEED: '.$line.&quot;\n&quot;;					}

$stalkchannel = array; foreach ($stalk as $key =&gt; $value) { if (fnmatch(str_replace('_',' ',$key),str_replace('_',' ',$change['user']))) { $stalkchannel = array_merge($stalkchannel,explode(',',$value)); }					}					foreach ($stalkedit as $user =&gt; $titlechan) { //echo $user.&quot;\n&quot;; //print_r($titlechan); foreach ($titlechan as $title =&gt; $channel) { if (fnmatch(str_replace('_',' ',$user),str_replace('_',' ',$change['user']))) { if (fnmatch(str_replace('_',' ',$title),str_replace('_',' ',$change['namespace'].$change['title']))) { $stalkchannel = array_merge($stalkchannel,explode(',',$channel)); }							}						}					}					foreach ($edit as $key =&gt; $value) if (fnmatch(str_replace('_',' ',$key),str_replace('_',' ',$change['namespace'].$change['title']))) $stalkchannel = array_merge($stalkchannel,explode(',',$value)); $stalkchannel = array_unique($stalkchannel); print_r($stalkchannel); foreach ($stalkchannel as $y) { fwrite($irc,'PRIVMSG '.$y.' :'.chr(3).'01'.'New edit: '.chr(3).chr(3).'07'.$change['namespace'].$change['title'].chr(3).chr(3).'01'.' '.chr(3).chr(3).'04'.$change['flags'].chr(3).chr(3).'02'.' http://en.wikipedia.org/w/index.php?title=' . urlencode($change['namespace'].$change['title']).'&amp;diff=prev'.'&amp;oldid='.urlencode($change['revid']).chr(3).' '.chr(3).'04'.'* '.chr(3).'03'.$change['user'] .chr(3) . ' '.chr(3).'04'.' * '.chr(3).'('.$change['length'].') '.chr(3).'10'.$change['comment'].&quot;\n&quot;); }					if (($change['namespace'] == 'User:')) { if (strtolower($change['title']) == strtolower($user.'/Run')) { $run = $wpq-&gt;getpage('User:'.$user.'/Run'); } if (strtolower($change['title']) == strtolower($user.'/Whitelist')) { $whitelist = $wpq-&gt;getpage('User:'.$user.'/Whitelist'); } if (strtolower($change['title']) == strtolower($user.'/Autostalk.js')) { fwrite( $irc,'PART '.implode(',',$stalk).&quot; Parting due to &quot;.$change['user'].&quot; editing User:&quot;.$user.'/Autostalk.js'.&quot;\n&quot; ); sleep(2); unset($stalk); $tmp = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$user.'/Autostalk.js')); foreach ($tmp as $tmp2) { if (substr($tmp2,0,1) != '#') { $tmp3 = explode('|',$tmp2,2); $stalk[$tmp3[0]] = trim($tmp3[1]); } } unset($tmp,$tmp2,$tmp3); print_r($stalk); fwrite( $irc,'JOIN '.implode(',',$stalk).&quot;\n&quot; ); sleep(2); }						echo $change['title']; if (strtolower($change['title']) == strtolower($user.'/Autoedit.js')) { fwrite( $irc,'PART '.implode(',',$edit).&quot; Parting due to &quot;.$change['user'].&quot; editing User:&quot;.$user.'/Autoedit.js'.&quot;\n&quot; ); sleep(2); unset($edit); $tmp = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$user.'/Autoedit.js')); foreach ($tmp as $tmp2) { if (substr($tmp2,0,1) != '#') { $tmp3 = explode('|',$tmp2,2); $edit[$tmp3[0]] = trim($tmp3[1]); } } unset($tmp,$tmp2,$tmp3); print_r($edit); fwrite( $irc,'JOIN '.implode(',',$edit).&quot;\n&quot; ); sleep(2); }						if (strtolower($change['title']) == strtolower($user.'/Autostalkedit.js')) { fwrite( $irc,'PART '.implode(',',$stalkedit).&quot; Parting due to &quot;.$change['user'].&quot; editing User:&quot;.$user.'/Autostalkedit.js'.&quot;\n&quot; ); sleep(2); unset($stalkedit); $tmp = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$user.'/Autostalkedit.js')); foreach ($tmp as $tmp2) { if (substr($tmp2,0,1) != '#') { $tmp3 = explode('|',$tmp2,3); $stalkedit[$tmp3[0]][$tmp3[1]] = trim($tmp3[2]); } 							}							unset($tmp,$tmp2,$tmp3); print_r($stalkedit); fwrite( $irc,'JOIN '.implode(',',$stalkedit).&quot;\n&quot; ); sleep(2); }						if (strtolower($change['title']) == strtolower($owner.'/Channels.js')) { $ircconfig = explode(&quot;\n&quot;,$wpq-&gt;getpage('User:'.$owner.'/Channels.js')); $tmp = array; foreach($ircconfig as $tmpline) { if (substr($tmpline,0,1) != '#') { $tmpline = explode('=',$tmpline,2); $tmp[trim($tmpline[0])] = trim($tmpline[1]); } } print_r($tmp);

$tmpold = array; $tmpnew = array; foreach ($tmp as $tmp2) foreach (explode(',',$tmp2) as $tmp3) $tmpnew[$tmp3] = 1; foreach (explode(',',$ircchannel.','.$irctechchannel.','.$ircotherchannels.','.$ircvandalismchannel.','.$ircaivchannel.','.$ircverbosechannel) as $tmp3) $tmpold[$tmp3] = 1;

foreach ($tmpold as $tmp2 =&gt; $tmp3) if (isset($tmpnew[$tmp2])) unset($tmpold[$tmp2],$tmpnew[$tmp2]); foreach ($tmpnew as $tmp2 =&gt; $tmp3) $tmpnew1[] = $tmp2; foreach ($tmpold as $tmp2 =&gt; $tmp3) $tmpold1[] = $tmp2;

$tmpold = $tmpold1; $tmpnew = $tmpnew1; unset($tmpold1,$tmpnew1);

fwrite( $irc,'JOIN '.implode(',',$tmpnew).&quot;\n&quot; ); fwrite( $irc,'PART '.implode(',',$tmpold).&quot; Parting due to &quot;.$change['user'].&quot; editing User:&quot;.$owner.'/Channels.js'.&quot;\n&quot; );

$ircchannel = $tmp['ircchannel']; $irctechchannel = $tmp['irctechchannel']; $ircverbosechannel = $tmp['ircverbosechannel']; $ircotherchannels = $tmp['ircotherchannels']; $ircvandalismchannel = $tmp['ircvandalismchannel']; $ircaivchannel = $tmp['ircaivchannel'];

unset($tmp,$tmpline,$tmpold,$tmpnew,$tmp2,$tmp3); }					}

if (($change['namespace'] != '') || ($change['flags'] == 'move')) continue;

$change['justtitle'] = $change['title']; $change['title'] = $change['namespace'].$change['title']; /*if( $status == 'dryrun' ) { //print_r($testlist); $d = $wpi-&gt;diff($change['title'],$change['old_revid'],$change['revid']); //print_r($d); $s = score($testlist,$d[0],$log); $s -= score($testlist,$d[1],$log2); echo &quot;\n&quot;.$s.&quot;\n&quot;; if( ($s &lt; 0) 							&amp;&amp; ((($wpq-&gt;contribcount($change['user']) &lt; 50) || preg_match('/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/', $change['user'])))) { echo &quot;\n\n\n\n\n\n&quot;.$s.&quot;\n\n\n\n\n\n&quot;; $diff = 'http://en.wikipedia.org/w/index.php'. '?title='.urlencode($change['title']). '&amp;diff='.urlencode($change['revid']). '&amp;oldid='.urlencode($change['old_revid']); $towrite = file_get_contents('trainingdata.txt'). &quot;*Would revert [$diff revision &quot;.$change['revid'].&quot;] on page &quot;.$change['title'] . 								&quot;: Registers a score of $s. \n&quot;; file_put_contents('trainingdata.txt',$towrite); unset($diff, $towrite, $d, $s); }					}					continue;*/ $diff = $wpi-&gt;diff($change['title'],$change['old_revid'],$change['revid']); $score = score($testlist,$diff[0],$log); $score -= score($testlist,$diff[1],$log2); $url = 'http://en.wikipedia.org/w/index.php?title='.urlencode($change['title']).'&amp;diff='.urlencode($change['revid']).'&amp;oldid='.urlencode($change['old_revid']); $pid = @pcntl_fork; if ($pid != 0) continue; $tmp = unserialize(file_get_contents('titles.txt')); if(!preg_match('/(yes|enable|true)/i',$wpq-&gt;getpage('User:'.$user.'/Run'))) { continue; }					if (						($score &lt;= SCORELIMIT)						&amp;&amp; (!preg_match('/\&lt;code\&gt;/', $wpq-&gt;getpage($change['title']))) //Ignore pages with &lt;code&gt;						&amp;&amp; ((($wpq-&gt;contribcount($change['user']) &lt; 50) || preg_match('/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/', $change['user'])))//Ignore accounts with &gt;50 edits						&amp;&amp; (!preg_match('/^\* \[\[User:('.preg_quote($change['user'],'/').')|\1\]\] \- .*/',$whitelist)) //Ignore users listed on User:SoxBot III/Whitelist 						&amp;&amp; ((!isset($tmp[$change['title'].$change['user']])) || ((time - $tmp[$change['title'].$change['user']]) &gt; (24*60*60)))						&amp;&amp; ($tmp[$change['title'].$change['user']] = time)						&amp;&amp; ((file_put_contents('titles.txt',serialize($tmp))) !== false) &amp;&amp; (($change['length'] &lt; 800) || ($score &lt;= -35)) ) { 						$curmaxlag = $wpi-&gt;getMaxlag;						if( $curmaxlag &gt; $maxlag ) {							foreach(explode(',',$irctechchannel) as $y) {								fwrite( $irc,'PRIVMSG '.$y.' :'.$curmaxlag[1].' is lagged out by '.$curmaxlag[2].' seconds. ('.$curmaxlag[0].')'.&quot;\n&quot; ); usleep(500);							}							continue;						}						unset($curmaxlag);						foreach (explode(',',$ircchannel) as $y) {							fwrite( $irc,'PRIVMSG '.$y.' :Reverting '.$change['revid'].'.'.&quot;\n&quot; ); usleep(500);						}						foreach (array as $y) {							fwrite( $irc,'PRIVMSG '.$y.' :Reverting revision '.$change['revid'].' by '.$change['user'].'.'.&quot;\n&quot; ); usleep(500);						}						unset($diff, $revision, $url);						$currev = $wpapi-&gt;revisions($change['title']);						print_r($currev);						if (($currev[0]['revid'] != $change['revid']) &amp;&amp; ($currev[0]['user'] != $change['user'])) {							mysql_query('INSERT INTO `beaten` (`id`,`article`,`diff`,`user`) VALUES (NULL,\.mysql_real_escape_string($change['title']).'\',\.mysql_real_escape_string($change['url']).'\',\''.mysql_real_escape_string($currev['user']).'\')');							foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Inserting '.$change['revid'].' into `beaten` table.'.&quot;\n&quot; ); usleep(500); }						}						else { $query = 'SELECT date,user,article FROM testing WHERE user=\''. mysql_real_escape_string($change['user']). '\' AND article=\''. mysql_real_escape_string($change['title']). '\' AND date=\''. date( 'Y-m-d' ). '\';';							echo $query; if (!mysql_ping($mysql)) { $mysql = mysql_connect($mysqlhost.':'.$mysqlport,$mysqluser,$mysqlpass,/* Force reconnect --&gt; */ true);echo &quot;Ping?\n&quot;; mysql_select_db($mysqldb, $mysql); }							$result = mysql_query($query); if( !$result ) { die( &quot;MySQL error: &quot;.mysql_error ); } foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Querying if '.$change['user'].' has been reverted recently.'.&quot;\n&quot; ); usleep(500); }							echo &quot;Querying if user has been reverted recently.\n&quot;; if ( mysql_num_rows( $result ) != 0 ) { continue; foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Yes, not reverting.'.&quot;\n&quot; ); usleep(500); }							}							foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :No, will continue to revert.'.&quot;\n&quot; ); usleep(500); }							$query = 'INSERT INTO `testing` '. '(`id`,`user`,`article`,`diff`,`old_id`,`new_id`,`reverted`,`date`,`score`) '. 'VALUES '. '(NULL,\.mysql_real_escape_string($change['user']).'\',' .								'\.mysql_real_escape_string($change['title']).'\',' .								'\.mysql_real_escape_string($change['url']).'\',' .								'\.mysql_real_escape_string($change['old_revid']).'\',' .								'\.mysql_real_escape_string($change['revid']).'\',0,' .								'\.date( 'Y-m-d' ).'\',' .								'\''.mysql_real_escape_string($score).'\');'; echo $query; if (!mysql_ping($mysql)) { $mysql = mysql_pconnect($mysqlhost.':'.$mysqlport,$mysqluser,$mysqlpass,/* Force reconnect --&gt; */ true); if (!$mysql) { die('Could not connect: ' . mysql_error); } if (!mysql_select_db($mysqldb, $mysql)) { die ('Can\'t use database : ' . mysql_error); } }							mysql_query($query); foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Inserting '.$change['revid'].' into `testing`.'.&quot;\n&quot; ); usleep(500); }							echo &quot;Inserting into `testing`\n&quot;;echo $query; if (mysql_affected_rows( $mysql ) == 0) { echo &quot;Problem?\n&quot;; foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :MySQL error? '.mysql_error.&quot;\n&quot; ); usleep(500); }								continue; } 							$mysqlid = mysql_insert_id;

$token = $http-&gt;get('http://en.wikipedia.org/w/api.php?action=query&amp;prop=revisions&amp;rvtoken=rollback&amp;titles=Main%20Page&amp;format=txtfm'); $token = unserialize($token); $token = $token['query']['pages'][$wpq-&gt;getpageid($change['title'])]['revisions'][0]['rollbacktoken']; echo &quot;Token: $token\n&quot;; foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Getting rollback token.'.&quot;\n&quot; ); usleep(500); }							if( $token == '' ) { foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Error getting token.'.&quot;\n&quot; ); usleep(500); }							}							$return = $wpapi-&gt;rollback(								$change['title'],								$change['user'],								'Reverting possible test edit(s) by '.$change['user'].' ' .								'to '.(($revid == 0)?'older version':'version by '.$revdata['user']).'. ' .								'Was this a mistake? (BOT EDIT)',								$token							); foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Rolling back '.$change['revid'].'.'.&quot;\n&quot; ); usleep(500); }							echo &quot;Reverting.\n&quot;; if (isset($return['rollback'])) { foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Returned true, attempting to warn.'.&quot;\n&quot; ); usleep(500); }								$warning = getWarningLevel( $change['user'] ); $warning++;

if ($warning &lt; 5) { $append = ''; if ( $warning == 1 ) { $append = &quot;:If this is a shared IP address, and you didn't make the edit, consider creating an account for yourself so you can avoid further irrelevant notices.\n&quot;; }									elseif ($warning &gt; 2) { foreach (explode(',',$ircvandalismchannel) as $y) { fwrite( $irc,'PRIVMSG '.$y.' :computer bl add '.$change['user'].' x='.(24*$warning).' r=Test edits to '.$change['title'].' (#'.$warning.').'.&quot;\n&quot; ); usleep(500); }									}									else { }									$talk = $wpq-&gt;getpage('User talk:'.$change['user']); $wpi-&gt;post(										'User talk:'.$change['user'],$talk.&quot;\n\n&quot;.''.$change['title'].' '.SIGNATURE.' '.&quot;\n&quot;.$append,'Warning user of test edits (Warning #'.$warning.')',false,null,false); foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Warning '.$change['user'].'.'.&quot;\n&quot; ); usleep(500); }								}								elseif ($warning &gt; 4) { $aiv = $wpq-&gt;getpage('Wikipedia:Administrator intervention against vandalism/TB2'); if ( preg_match('/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/', $change['user']) ) { $template = &quot;IPvandal&quot;; }									else { $template = &quot;Vandal&quot;; }

if (!preg_match('/'.preg_quote($change['user'],'/').'/i',$aiv)) { foreach(explode(',',$ircaivchannel) as $y) { fwrite( $irc,'PRIVMSG '.$y.' :!admin Reporting User:'.$change['user'].' to WP:AIV. Contributions: Special:Contributions/'.$change['user'].' Block: Special:Blockip/'.$change['user'].''.&quot;\n&quot; ); usleep(500); }										foreach (explode(',',$ircvandalismchannel) as $y) { fwrite( $irc,'PRIVMSG '.$y.' :computer bl add '.$change['user'].' x='.(24*$warning).' r=Vandalism to '.$change['title'].' (#'.$warning.&quot;).\n&quot; ); usleep(500); }										$aiv = $aiv. &quot;\n&quot;. &quot;* &quot;. &quot;User made possible test edits, such as .&quot; 1]. &quot;.SIGNATURE.&quot; &quot;; $wpi-&gt;post('Wikipedia:Administrator intervention against vandalism/TB2',$aiv,'Reporting &quot;.$change['user'].&quot; (BOT EDIT)&quot;); foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Warning level is 4, reporting to AIV.'.&quot;\n&quot; ); usleep(500); } 									} else { foreach (explode(',',$ircreportchannel) as $y) { fwrite( $irc,'PRIVMSG '.$y.' :!admin User:'.$change['user'].' has vandalized at least one time while being listed on WP:AIV. Contributions: Special:Contributions/'.$change['user'].' Block: Special:Blockip/'.$change['user'].''.&quot;\n&quot; ); usleep(500); }									}								}

mysql_query('UPDATE `testing` SET `reverted` = 1 WHERE `id` = \.mysql_real_escape_string($mysqlid).'\); } 							else { foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Returned false, figuring out why.'.&quot;\n&quot; ); usleep(500); }								$currev = $wpapi-&gt;revisions($change['title']); if (($currev[0]['revid'] != $change['revid']) &amp;&amp; ($currev[0]['user'] != $change['user'])) { mysql_query('INSERT INTO `beaten` (`id`,`article`,`diff`,`user`) VALUES (NULL,\.mysql_real_escape_string($change['title']).'\',\.mysql_real_escape_string($change['url']).'\',\''.mysql_real_escape_string($rev['user']).'\')'); foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :I was beaten by '.$rev['user'].'!'.&quot;\n&quot; ); usleep(500); }								}								else { foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :There was an unknown rollback error.'.&quot;\n&quot; ); usleep(500); }									file_put_contents('errors.txt',file_get_contents('errors.txt').&quot;Date: &quot;.date( 'Y-m-d' ).&quot;\n&quot;.$return.&quot;\n--\n&quot;) or die('Error'); foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :Rollback result has been posted to errors.txt.'.&quot;\n&quot; ); usleep(500); }									echo &quot;ERROR\n&quot;; }							}//End if ($return !== FALSE) }//End if beaten check foreach (array as $y) { fwrite( $irc,'PRIVMSG '.$y.' :-- Done --.'.&quot;\n&quot; ); usleep(500); }					}//End check for vandalism die; }//End regex for parsing IRC feed }//End checking for privmsg }//End while }//End while ?&gt;