User:SoxBot X/Source

The following is automatically generated by SoxBot X.

Bot Hierarchy

 * bot.php
 * classes.php
 * functions.php

Source code
&lt;?php

/* Copyright (C) 2008 Soxred93 - http://en.wikipedia.org/wiki/User:X!

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., 675 Mass Ave, Cambridge, MA 02139, USA.



include( &quot;./functions.php&quot; );

initialize;

postSource;

$rollback = getList('Rollback'); $acc = getList('Acc');

foreach ($rollback as $rreq) { process('Rollback', $rreq[0], $rreq[1], $rreq[2]); }

foreach ($acc as $areq) { process('Acc', $areq[0], $areq[1], $areq[2]); }

echo &quot;DONE!!!\n&quot;;

?&gt;

&lt;?php

include('../MainPageBot/classes.php');

//Setup the classes $http    	 = new http; $wpapi      = new wikipediaapi; $wpq        = new wikipediaquery; $wpi        = new wikipediaindex; $user       = 'SoxBot X';

function initialize { global $wpapi, $user; $pass = file_get_contents('../.password');//Password

echo &quot;Logging in...\n&quot;;

$wpapi-&gt;login( $user,$pass );//Login unset( $pass ); //Security reasons return $user; }

function postSource { //Post the source code global $wpi, $user; echo &quot;\nPosting source code...\n&quot;; $wpi-&gt;forcepost('User:'.$user.'/Source',               &quot;The following is automatically generated by User:SoxBot X.\n\n&quot; .                &quot;==Bot Hierarchy==\n*bot.php\n*classes.php\n*functions.php\n&quot; .                &quot;==Source code==\n&quot; .                &quot;\n&lt;pre&gt;&quot;.htmlentities(file_get_contents('./bot.php')).&quot;&lt;/pre&gt;\n\n&quot; .                &quot;\n&lt;pre&gt;&quot;.htmlentities(file_get_contents('./functions.php')).&quot;&lt;/pre&gt;\n\n&quot; .                &quot;\n&lt;pre&gt;&quot;.htmlentities(file_get_contents('../MainPageBot/classes.php')).&quot;&lt;/pre&gt;\n&quot;,                'Automated source upload.'); }

function getList($pagetitle) { global $wpq; $page = $wpq-&gt;getpage('Wikipedia:Requests for permissions/'.$pagetitle); echo &quot;\nGetting the text of Wikipedia:Requests for permissions/$pagetitle...\n&quot;; $m = preg_split('/====(.*)====/i', $page, -1, PREG_SPLIT_OFFSET_CAPTURE); $requests = array; foreach ($m as $key =&gt; $req) { if (preg_match('/\{\{subst:rfp/', $req[0])) { continue; } if (preg_match('/\&lt;!--noautoarchive/i', $req[0])) { continue; } $username = preg_match('/\{\{Usercheck-short\|(.*)\}\}/i', $req[0], $name); $username = $name[1]; if (!$username &amp;&amp; $key != 0) { die; } if (preg_match('/\{done/i', $req[0])) { echo $username.&quot;'s request was done.\n&quot;; $requests[] = array('done', $username, trim($req[0])); }		elseif (preg_match('/\{not\s?done/i', $req[0])) { echo $username.&quot;'s request was not done.\n&quot;; $requests[] = array('not done', $username, trim($req[0])); }		else { echo $username.&quot;'s request has not been completed yet.\n&quot;; continue; }	}	print_r($requests); return $requests; }

function process($pagetitle,$action,$user,$request) { global $wpq, $wpi; $currentTime = time; preg_match('/\{\{done\}\}\s?.*\s?(\d{1,2}):(\d{1,2}),\s(\d+)\s(\w+)\s(\d{4})/i', $request, $time); $months = array('January' =&gt; '01', 'February' =&gt; '02', 'March' =&gt; '03', 'April' =&gt; '04', 'May' =&gt; '05', 'June' =&gt; '06', 'July' =&gt; '07', 'August' =&gt; '08', 'September' =&gt; '09', 'October' =&gt; '10', 'November' =&gt; '11', 'December' =&gt; '12'); $thenTime = strtotime($time[5].&quot;-&quot;.$months[$time[4]].&quot;-&quot;.$time[3].&quot;T&quot;.$time[1].&quot;:&quot;.$time[2].&quot;:00Z&quot;); if (date('U', $currentTime) - date('U', $thenTime) &lt; 3600 )	{ echo &quot;Too soon!\n&quot;; return false; }	$page = $wpq-&gt;getpage('Wikipedia:Requests for permissions/'.$pagetitle); echo &quot;\nGetting the text of Wikipedia:Requests for permissions/$pagetitle in order to remove $user...\n&quot;;

$newpage = str_ireplace('====User:'.$user.&quot;====&quot;.$request, '', $page); if ($newpage == $page) { echo &quot;Failed to remove $user!&quot;; return false; }	$wpi-&gt;post('Wikipedia:Requests for permissions/'.$pagetitle, $newpage, &quot;Removing $user, done.&quot;); $date = date('F Y', $currentTime); if ($action == 'done') { $action = &quot;Approved&quot;; }	elseif ($action == 'not done') { $action = &quot;Denied&quot;; }	else { die(&quot;???&quot;); }	$title=&quot;Wikipedia:Requests for permissions/$action/$date&quot;; $log = $wpq-&gt;getpage($title); if (preg_match(&quot;/$user/i&quot;, $log)) { return true; } if (!preg_match(&quot;/&quot;.date('F d').&quot;/i&quot;, $log)) { $log.=&quot;\n==&quot;.date('F d').&quot;==\n&quot;; } if ($action == 'Denied') { $log.=&quot;====User:$user====\n$request\n&quot;; }	else { $log.=&quot;*\n&quot;; }	$wpi-&gt;post($title, $log, &quot;Adding $user&quot;); if ($action == &quot;Denied&quot;) { $usertalk=$wpq-&gt;getpage(&quot;User talk:$user&quot;); if (!preg_match('/rollback request/i', $usertalk)) { $wpi-&gt;post(&quot;User talk:$user&quot;, $usertalk . &quot;\n==Your rollback request==\nHi! I regret that I must inform you that your request for the rollback permission has been denied. You can discover why by checking the archives at Requests for permissions/Denied/$date. ~\n&quot;, &quot;Your request for rollback has been denied.&quot;); }	} } ?&gt;

&lt;?PHP class http { private $ch; private $uid; public $postfollowredirs; public $getfollowredirs;

function data_encode ($data, $keyprefix = &quot;&quot;, $keypostfix = &quot;&quot;) { assert( is_array($data) ); $vars=null; foreach($data as $key=&gt;$value) { if(is_array($value)) $vars .= $this-&gt;data_encode($value, $keyprefix.$key.$keypostfix.urlencode(&quot;[&quot;), urlencode(&quot;]&quot;)); else $vars .= $keyprefix.$key.$keypostfix.&quot;=&quot;.urlencode($value).&quot;&amp;&quot;; }                       return $vars; }

function __construct { $this-&gt;ch = curl_init; $this-&gt;uid = dechex(rand(0,99999999)); curl_setopt($this-&gt;ch,CURLOPT_COOKIEJAR,'./tmp/cookies.dat'); curl_setopt($this-&gt;ch,CURLOPT_COOKIEFILE,'./tmp/cookies.dat'); curl_setopt($this-&gt;ch,CURLOPT_MAXCONNECTS,100); curl_setopt($this-&gt;ch,CURLOPT_CLOSEPOLICY,CURLCLOSEPOLICY_LEAST_RECENTLY_USED); $this-&gt;postfollowredirs = 0; $this-&gt;getfollowredirs = 1; }

function post ($url,$data) { //                     echo 'POST: '.$url.&quot;\n&quot;; $time = microtime(1); curl_setopt($this-&gt;ch,CURLOPT_URL,$url); curl_setopt($this-&gt;ch,CURLOPT_COOKIEJAR,'./tmp/cookies.dat'); curl_setopt($this-&gt;ch,CURLOPT_COOKIEFILE,'./tmp/cookies.dat'); curl_setopt($this-&gt;ch,CURLOPT_FOLLOWLOCATION,$this-&gt;postfollowredirs); curl_setopt($this-&gt;ch,CURLOPT_MAXREDIRS,10); curl_setopt($this-&gt;ch,CURLOPT_HEADER,0); curl_setopt($this-&gt;ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($this-&gt;ch,CURLOPT_TIMEOUT,30); curl_setopt($this-&gt;ch,CURLOPT_CONNECTTIMEOUT,10); curl_setopt($this-&gt;ch,CURLOPT_POST,1); //                     curl_setopt($this-&gt;ch,CURLOPT_POSTFIELDS, substr($this-&gt;data_encode($data), 0, -1) ); curl_setopt($this-&gt;ch,CURLOPT_POSTFIELDS, $data); $data = curl_exec($this-&gt;ch); //var_dump($data); echo 'POST: '.$url.' ('.(microtime(1) - $time).' s) ('.strlen($data).&quot; b)\n&quot;; return $data; }

function get ($url) { //echo 'GET: '.$url.&quot;\n&quot;; $time = microtime(1); curl_setopt($this-&gt;ch,CURLOPT_URL,$url); curl_setopt($this-&gt;ch,CURLOPT_COOKIEJAR,'./tmp/cookies.dat'); curl_setopt($this-&gt;ch,CURLOPT_COOKIEFILE,'./tmp/cookies.dat'); curl_setopt($this-&gt;ch,CURLOPT_FOLLOWLOCATION,$this-&gt;getfollowredirs); curl_setopt($this-&gt;ch,CURLOPT_MAXREDIRS,10); curl_setopt($this-&gt;ch,CURLOPT_HEADER,0); curl_setopt($this-&gt;ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($this-&gt;ch,CURLOPT_TIMEOUT,30); curl_setopt($this-&gt;ch,CURLOPT_CONNECTTIMEOUT,10); curl_setopt($this-&gt;ch,CURLOPT_HTTPGET,1); $data = curl_exec($this-&gt;ch); //var_dump($data); echo 'GET: '.$url.' ('.(microtime(1) - $time).' s) ('.strlen($data).&quot; b)\n&quot;; return $data; }

function __destruct { curl_close($this-&gt;ch); //@unlink('/tmp/cluewikibot.cookies.dat'); }       }

class wikipediaquery { private $http; private $api; public $queryurl = 'http://en.wikipedia.org/w/query.php'; //Obsolete, but kept for compatibility purposes.

function __construct { global $__wp__http; if (!isset($__wp__http)) { $__wp__http = new http; }                       $this-&gt;http = &amp;$__wp__http; $this-&gt;api = new wikipediaapi; }               private function checkurl { $this-&gt;api-&gt;apiurl = str_replace('query.php','api.php',$this-&gt;queryurl); }               function getpage ($page) { $this-&gt;checkurl; //                     $ret = unserialize($this-&gt;http-&gt;get($this-&gt;queryurl.'?what=content&amp;format=php&amp;titles='.urlencode($page))); //                     foreach ($ret['pages'] as $page) { //                             return $page['content']['*']; //                     }                        $ret = $this-&gt;api-&gt;revisions($page,1,'older',true,null,true,false,false,false); return $ret[0]['*']; }

function getpageid ($page) { $this-&gt;checkurl; //                     $ret = unserialize($this-&gt;http-&gt;get($this-&gt;queryurl.'?what=content&amp;format=php&amp;titles='.urlencode($page))); //                     foreach ($ret['pages'] as $page) { //                             return $page['id']; //                     }                        $ret = $this-&gt;api-&gt;revisions($page,1,'older',false,null,true,false,false,false); return $ret['pageid']; }

function contribcount ($user) { $this-&gt;checkurl; //                     $ret = unserialize($this-&gt;http-&gt;get($this-&gt;queryurl.'?what=contribcounter&amp;format=php&amp;titles=User:'.urlencode($user))); //                     foreach ($ret['pages'] as $page) { //                             return $page['contribcounter']['count']; //                     }                        $ret = $this-&gt;api-&gt;users($user,1,null,true); if ($ret !== false) return $ret[0]['editcount']; return false; }       }

class wikipediaapi { private $http; public $apiurl = 'http://en.wikipedia.org/w/api.php';

function __construct { global $__wp__http; if (!isset($__wp__http)) { $__wp__http = new http; }                       $this-&gt;http = &amp;$__wp__http; }

function login ($user,$pass) { $data = $this-&gt;http-&gt;post($this-&gt;apiurl.'?action=login&amp;format=php',array('lgname' =&gt; $user, 'lgpassword' =&gt; $pass)); //print_r(unserialize($data)); //                     if ($data) echo $data.&quot;\n\n&quot;; }

function getedittoken { $x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;format=php&amp;prop=info&amp;intoken=edit&amp;titles=Main%20Page'); $x = unserialize($x); foreach ($x['query']['pages'] as $y) { return $y['edittoken']; }               }

function recentchanges ($count = 10,$namespace = null,$dir = 'older',$ts = null) { $append = ''; if ($ts !== null) { $append .= '&amp;rcstart='.urlencode($ts); } $append .= '&amp;rcdir='.urlencode($dir); if ($namespace !== null) { $append .= '&amp;rcnamespace='.urlencode($namespace); } $x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;list=recentchanges&amp;rcprop=user|comment|flags|timestamp|title|ids|sizes&amp;format=php&amp;rclimit='.$count.$append); $x = unserialize($x); return $x['query']['recentchanges']; }

function search ($search,$limit = 10,$offset = 0,$namespace = 0,$what = 'text',$redirs = false) { $append = ''; if ($limit != null) $append .= '&amp;srlimit='.urlencode($limit); if ($offset != null) $append .= '&amp;sroffset='.urlencode($offset); if ($namespace != null) $append .= '&amp;srnamespace='.urlencode($namespace); if ($what != null) $append .= '&amp;srwhat='.urlencode($what); if ($redirs == true) $append .= '&amp;srredirects=1'; else $append .= '&amp;srredirects=0'; $x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;list=search&amp;format=php&amp;srsearch='.urlencode($search).$append); $x = unserialize($x); return $x['query']['search']; }

function logs ($user = null,$title = null,$limit = 50,$type = null,$start = null,$end = null,$dir = 'older') { $append = ''; if ($user != null) $append.= '&amp;leuser='.urlencode($user); if ($title != null) $append.= '&amp;letitle='.urlencode($title); if ($limit != null) $append.= '&amp;lelimit='.urlencode($limit); if ($type != null) $append.= '&amp;letype='.urlencode($type); if ($start != null) $append.= '&amp;lestart='.urlencode($start); if ($end != null) $append.= '&amp;leend='.urlencode($end); if ($dir != null) $append.= '&amp;ledir='.urlencode($dir); $x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;format=php&amp;list=logevents&amp;leprop=ids|title|type|user|timestamp|comment|details'.$append); $x = unserialize($x); return $x['query']['logevents']; }

function usercontribs ($user,$count = 50,&amp;$continue = null,$dir = 'older') { if ($continue != null) { $append = '&amp;ucstart='.urlencode($continue); } else { $append = ''; }                       $x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;format=php&amp;list=usercontribs&amp;ucuser='.urlencode($user).'&amp;uclimit='.urlencode($count).'&amp;ucdir='.urlencode($dir).$append); $x = unserialize($x); $continue = $x['query-continue']['usercontribs']['ucstart']; return $x['query']['usercontribs']; }

function revisions ($page,$count = 1,$dir = 'older',$content = false,$revid = null,$wait = true,$getrbtok = false,$dieonerror = true,$redirects = false) { $x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;prop=revisions&amp;titles='.urlencode($page).'&amp;rvlimit='.urlencode($count).'&amp;rvprop=timestamp|ids|user|comment'.(($content)?'|content':).'&amp;format=php&amp;meta=userinfo&amp;rvdir='.urlencode($dir).(($revid !== null)?'&amp;rvstartid='.urlencode($revid):).(($getrbtok == true)?'&amp;rvtoken=rollback':).(($redirects == true)?'&amp;redirects':)); $x = unserialize($x); if ($revid !== null) { $found = false; if (!isset($x['query']['pages']) or !is_array($x['query']['pages'])) { if ($dieonerror == true) die('No such page.'.&quot;\n&quot;); else return false; }                               foreach ($x['query']['pages'] as $data) { if (!isset($data['revisions']) or !is_array($data['revisions'])) { if ($dieonerror == true) die('No such page.'.&quot;\n&quot;); else return false; }                                       foreach ($data['revisions'] as $data2) if ($data2['revid'] == $revid) $found = true; unset($data,$data2); break; }

if ($found == false) { if ($wait == true) { sleep(1); return $this-&gt;revisions($page,$count,$dir,$content,$revid,false,$getrbtok,$dieonerror); } else { if ($dieonerror == true) die('Revision error.'.&quot;\n&quot;); }                               }                        }                        foreach ($x['query']['pages'] as $key =&gt; $data) { $data['revisions']['ns'] = $data['ns']; $data['revisions']['title'] = $data['title']; $data['revisions']['currentuser'] = $x['query']['userinfo']['name']; //                             $data['revisions']['currentuser'] = $x['query']['userinfo']['currentuser']['name']; $data['revisions']['continue'] = $x['query-continue']['revisions']['rvstartid']; $data['revisions']['pageid'] = $key; return $data['revisions']; }               }

function users ($start = null,$limit = 1,$group = null,$reqirestart = false,&amp;$continue = null) { $append = ''; if ($start != null) $append .= '&amp;aufrom='.urlencode($start); if ($group != null) $append .= '&amp;augroup='.urlencode($group); $x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;list=allusers&amp;format=php&amp;auprop=blockinfo|editcount|registration|groups&amp;aulimit='.urlencode($limit).$append); $x = unserialize($x); $continue = $x['query-continue']['allusers']['aufrom']; if (($requirestart == true) and ($x['query']['allusers'][0]['name'] != $start)) return false; return $x['query']['allusers']; }

function categorymembers ($category,$count = 500,&amp;$continue = null) { if ($continue != null) { $append = '&amp;cmcontinue='.urlencode($continue); } else { $append = ''; }                       $category = 'Category:'.str_ireplace('category:','',$category); $x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;list=categorymembers&amp;cmtitle='.urlencode($category).'&amp;format=php&amp;cmlimit='.$count.$append); $x = unserialize($x); $continue = $x['query-continue']['categorymembers']['cmcontinue']; return $x['query']['categorymembers']; }

function listcategories (&amp;$start = null,$limit = 50,$dir = 'ascending',$prefix = null) { $append = ''; if ($start != null) $append .= '&amp;acfrom='.urlencode($start); if ($limit != null) $append .= '&amp;aclimit='.urlencode($limit); if ($dir != null) $append .= '&amp;acdir='.urlencode($dir); if ($prefix != null) $append .= '&amp;acprefix='.urlencode($prefix);

$x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;list=allcategories&amp;acprop=size&amp;format=php'.$append); $x = unserialize($x);

$start = $x['query-continue']['allcategories']['acfrom'];

return $x['query']['allcategories']; }

function backlinks ($page,$count = 500,&amp;$continue = null,$filter = null) { if ($continue != null) { $append = '&amp;blcontinue='.urlencode($continue); } else { $append = ''; }                       if ($filter != null) { $append .= '&amp;blfilterredir='.urlencode($filter); }

$x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;list=backlinks&amp;bltitle='.urlencode($page).'&amp;format=php&amp;bllimit='.$count.$append); $x = unserialize($x); $continue = $x['query-continue']['backlinks']['blcontinue']; return $x['query']['backlinks']; }

function embeddedin ($page,$count = 500,&amp;$continue = null) { if ($continue != null) { $append = '&amp;eicontinue='.urlencode($continue); } else { $append = ''; }                       $x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;list=embeddedin&amp;eititle='.urlencode($page).'&amp;format=php&amp;eilimit='.$count.$append); $x = unserialize($x); $continue = $x['query-continue']['embeddedin']['eicontinue']; return $x['query']['embeddedin']; }

function listprefix ($prefix,$namespace = 0,$count = 500,&amp;$continue = null) { $append = '&amp;apnamespace='.urlencode($namespace); if ($continue != null) { $append .= '&amp;apfrom='.urlencode($continue); }                       $x = $this-&gt;http-&gt;get($this-&gt;apiurl.'?action=query&amp;list=allpages&amp;apprefix='.urlencode($prefix).'&amp;format=php&amp;aplimit='.$count.$append); $x = unserialize($x); $continue = $x['query-continue']['allpages']['apfrom']; return $x['query']['allpages']; }       }

class wikipediaindex { private $http; public $indexurl = 'http://en.wikipedia.org/w/index.php'; private $postinterval = 0; private $lastpost; private $edittoken;

function __construct { global $__wp__http; if (!isset($__wp__http)) { $__wp__http = new http; }                       $this-&gt;http = &amp;$__wp__http; }

function post ($page,$data,$summery = '',$minor = false,$rv = null,$bot = true) { global $user; global $maxlag; global $irc; global $irctechchannel; global $run; global $maxlagkeepgoing;

$wpq = new wikipediaquery; $wpq-&gt;queryurl = str_replace('index.php','query.php',$this-&gt;indexurl); $wpapi = new wikipediaapi; $wpapi-&gt;apiurl = str_replace('index.php','api.php',$this-&gt;indexurl);

if ((!$this-&gt;edittoken) or ($this-&gt;edittoken == '')) $this-&gt;edittoken = $wpapi-&gt;getedittoken; if ($rv == null) $rv = $wpapi-&gt;revisions($page,1,'older',true); if (!$rv[0]['*']) $rv[0]['*'] = $wpq-&gt;getpage($page);

//Fake the edit form. $now = gmdate('YmdHis', time); $token = htmlspecialchars($this-&gt;edittoken); $tmp = date_parse($rv[0]['timestamp']); $edittime = gmdate('YmdHis', gmmktime($tmp['hour'],$tmp['minute'],$tmp['second'],$tmp['month'],$tmp['day'],$tmp['year'])); $html = &quot;&lt;input type='hidden' value=\&quot;{$now}\&quot; name=\&quot;wpStarttime\&quot; /&gt;\n&quot;; $html.= &quot;&lt;input type='hidden' value=\&quot;{$edittime}\&quot; name=\&quot;wpEdittime\&quot; /&gt;\n&quot;; $html.= &quot;&lt;input type='hidden' value=\&quot;{$token}\&quot; name=\&quot;wpEditToken\&quot; /&gt;\n&quot;; $html.= '&lt;input name=&quot;wpAutoSummary&quot; type=&quot;hidden&quot; value=&quot;'.md5('').'&quot; /&gt;'.&quot;\n&quot;;

if (preg_match('/'.preg_quote('','/').'/iS',$rv[0]['*'])) { return false; }          /* Honor the bots flags */ if (preg_match('/'.preg_quote('','/').'/iS',$rv[0]['*'])) { return false; } if (preg_match('/'.preg_quote('','/').'/iS',$rv[0]['*'])) { return false; } if (preg_match('/'.preg_quote('','/').'/iS',$rv[0]['*'],$m)) { if (in_array(explode(',',$m[1]),$user)) { return false; } } /* /Honor the bots flags */ if (!preg_match('/'.preg_quote($user,'/').'/iS',$rv['currentuser'])) { return false; } /* We need to be logged in */ //                     if (preg_match('/'.preg_quote('You have new messages','/').'/iS',$rv[0]['*'])) { return false; } /* Check talk page */ if (!preg_match('/(yes|enable|true)/iS',((isset($run))?$run:$wpq-&gt;getpage('User:'.$user.'/Run')))) { return false; } /* Check /Run page */

$x = $this-&gt;forcepost($page,$data,$summery,$minor,$html,$maxlag,$maxlagkeepgoing,$bot); /* Go ahead and post. */                       $this-&gt;lastpost = time; return $x; }

function forcepost ($page,$data,$summery = '',$minor = false,$edithtml = null,$maxlag = null,$mlkg = null,$bot = true) { $post['wpSection'] = ''; $post['wpScrolltop'] = ''; if ($minor == true) { $post['wpMinoredit'] = 1; } $post['wpTextbox1'] = $data; $post['wpSummary'] = $summery; if ($edithtml == null) { $html = $this-&gt;http-&gt;get($this-&gt;indexurl.'?title='.urlencode($page).'&amp;action=edit'); } else { $html = $edithtml; }                       preg_match('|\&lt;input type\=\\\'hidden\\\' value\=\&quot;(.*)\&quot; name\=\&quot;wpStarttime\&quot; /\&gt;|U',$html,$m); $post['wpStarttime'] = $m[1]; preg_match('|\&lt;input type\=\\\'hidden\\\' value\=\&quot;(.*)\&quot; name\=\&quot;wpEdittime\&quot; /\&gt;|U',$html,$m); $post['wpEdittime'] = $m[1]; preg_match('|\&lt;input type\=\\\'hidden\\\' value\=\&quot;(.*)\&quot; name\=\&quot;wpEditToken\&quot; /\&gt;|U',$html,$m); $post['wpEditToken'] = $m[1]; preg_match('|\&lt;input name\=\&quot;wpAutoSummary\&quot; type\=\&quot;hidden\&quot; value\=\&quot;(.*)\&quot; /\&gt;|U',$html,$m); $post['wpAutoSummary'] = $m[1]; if ($maxlag != null) { $x = $this-&gt;http-&gt;post($this-&gt;indexurl.'?title='.urlencode($page).'&amp;action=submit&amp;maxlag='.urlencode($maxlag).'&amp;bot='.(($bot == true)?'1':'0'),$post); if (preg_match('/Waiting for ([^ ]*): ([0-9.-]+) seconds lagged/S',$x,$lagged)) { global $irc; if (is_resource($irc)) { global $irctechchannel; foreach(explode(',',$irctechchannel) as $y) { fwrite($irc,'PRIVMSG '.$y.' :'.$lagged[1].' is lagged out by '.$lagged[2].' seconds. ('.$lagged[0].')'.&quot;\n&quot;); }                                       }                                        sleep(10); if ($mlkg != true) { return false; } else { $x = $this-&gt;http-&gt;post($this-&gt;indexurl.'?title='.urlencode($page).'&amp;action=submit&amp;bot='.(($bot == true)?'1':'0'),$post); } }                               return $x; } else { return $this-&gt;http-&gt;post($this-&gt;indexurl.'?title='.urlencode($page).'&amp;action=submit&amp;bot='.(($bot == true)?'1':'0'),$post); }               }

function diff ($title,$oldid,$id,$wait = true) { $deleted = ''; $added = '';

$html = $this-&gt;http-&gt;get($this-&gt;indexurl.'?title='.urlencode($title).'&amp;action=render&amp;diff='.urlencode($id).'&amp;oldid='.urlencode($oldid).'&amp;diffonly=1');

if (preg_match_all('/\&amp;amp\;(oldid\=|undo=)(\d*)\\\'\&gt;(Revision as of|undo)/USs', $html, $m, PREG_SET_ORDER)) { //print_r($m); if ((($oldid != $m[0][2]) and (is_numeric($oldid))) or (($id != $m[1][2]) and (is_numeric($id)))) { if ($wait == true) { sleep(1); return $this-&gt;diff($title,$oldid,$id,false); } else { die('Revision error.'.&quot;\n&quot;); }                               }                        }                        if (preg_match_all('/\&lt;td class\=(\&quot;|\\\')diff-addedline\1\&gt;\&lt;div\&gt;(.*)\&lt;\/div\&gt;\&lt;\/td\&gt;/USs', $html, $m, PREG_SET_ORDER)) { //print_r($m); foreach ($m as $x) { $added .= htmlspecialchars_decode(strip_tags($x[2])).&quot;\n&quot;; }                       }

if (preg_match_all('/\&lt;td class\=(\&quot;|\\\')diff-deletedline\1\&gt;\&lt;div\&gt;(.*)\&lt;\/div\&gt;\&lt;\/td\&gt;/USs', $html, $m, PREG_SET_ORDER)) { //print_r($m); foreach ($m as $x) { $deleted .= htmlspecialchars_decode(strip_tags($x[2])).&quot;\n&quot;; }                       }

//echo $added.&quot;\n&quot;.$deleted.&quot;\n&quot;;

if (preg_match('/action\=rollback\&amp;amp\;from\=.*\&amp;amp\;token\=(.*)\&quot;/US', $html, $m)) { $rbtoken = $m[1]; $rbtoken = urldecode($rbtoken); //                             echo 'rbtoken: '.$rbtoken.' -- '; print_r($m); echo &quot;\n\n&quot;; return array($added,$deleted,$rbtoken); }

return array($added,$deleted); }

function rollback ($title,$user,$reason = null,$token = null,$bot = true) { if (($token == null) or (!$token)) { $wpapi = new wikipediaapi; $wpapi-&gt;apiurl = str_replace('index.php','api.php',$this-&gt;indexurl); $token = $wpapi-&gt;revisions($title,1,'older',false,null,true,true); if ($token[0]['user'] == $user) { echo 'Token: '; print_r($token); echo &quot;\n\n&quot;; $token = $token[0]['rollbacktoken']; } else { return false; }                       }                        $x = $this-&gt;http-&gt;get($this-&gt;indexurl.'?title='.urlencode($title).'&amp;action=rollback&amp;from='.urlencode($user).'&amp;token='.urlencode($token).(($reason != null)?'&amp;summary='.urlencode($reason):'').'&amp;bot='.(($bot == true)?'1':'0')); echo 'Rollback return: '.$x.&quot;\n&quot;; if (!preg_match('/action complete/iS',$x)) return false; return $x; }

function move ($old,$new,$reason) { $wpapi = new wikipediaapi; $wpapi-&gt;apiurl = str_replace('index.php','api.php',$this-&gt;indexurl); if ((!$this-&gt;edittoken) or ($this-&gt;edittoken == '')) $this-&gt;edittoken = $wpapi-&gt;getedittoken;

$token = htmlspecialchars($this-&gt;edittoken);

$post = array (                                       'wpOldTitle'    =&gt; $old,                                        'wpNewTitle'    =&gt; $new,                                        'wpReason'      =&gt; $reason,                                        'wpWatch'       =&gt; '0',                                        'wpEditToken'   =&gt; $token,                                        'wpMove'        =&gt; 'Move page'                                ); return $this-&gt;http-&gt;post($this-&gt;indexurl.'?title=Special:Movepage&amp;action=submit',$post); }

function upload ($page,$file,$desc) { $post = array (                                       'wpUploadFile'          =&gt; '@'.$file,                                        'wpSourceType'          =&gt; 'file',                                        'wpDestFile'            =&gt; $page,                                        'wpUploadDescription'   =&gt; $desc,                                        'wpLicense'             =&gt; '',                                        'wpWatchthis'           =&gt; '0',                                        'wpIgnoreWarning'       =&gt; '1',                                        'wpUpload'              =&gt; 'Upload file'                                ); return $this-&gt;http-&gt;post($this-&gt;indexurl.'?title=Special:Upload&amp;action=submit',$post); }

function hasemail ($user) { $tmp = $this-&gt;http-&gt;get($this-&gt;indexurl.'?title=Special:EmailUser&amp;target='.urlencode($user)); if (stripos($tmp,&quot;No e-mail address&quot;) !== false) return false; return true; }               function email ($user,$subject,$body) { $wpapi = new wikipediaapi; $wpapi-&gt;apiurl = str_replace('index.php','api.php',$this-&gt;indexurl); if ((!$this-&gt;edittoken) or ($this-&gt;edittoken == '')) $this-&gt;edittoken = $wpapi-&gt;getedittoken;

$post = array (                                       'wpSubject'     =&gt; $subject,                                        'wpText'        =&gt; $body,                                        'wpCCMe'        =&gt; 0,                                        'wpSend'        =&gt; 'Send',                                        'wpEditToken'   =&gt; $this-&gt;edittoken                                );

return $this-&gt;http-&gt;post($this-&gt;indexurl.'?title=Special:EmailUser&amp;target='.urlencode($user).'&amp;action=submit',$post); }               function delete ($page,$reason=null) { $wpapi = new wikipediaapi; $wpapi-&gt;apiurl = str_replace('index.php','api.php',$this-&gt;indexurl); if ((!$this-&gt;edittoken) or ($this-&gt;edittoken == '')) $this-&gt;edittoken = $wpapi-&gt;getedittoken; $token = htmlspecialchars($this-&gt;edittoken); $post = array('title' =&gt; $page,'token' =&gt; $token,'reason' =&gt; $reason);

$x = $this-&gt;http-&gt;post( $wpapi-&gt;apiurl.'?action=delete&amp;format=php',$post ); return unserialize($x); }               function unprotect ($page,$reason=null) { $wpapi = new wikipediaapi; $wpapi-&gt;apiurl = str_replace('index.php','api.php',$this-&gt;indexurl); if ((!$this-&gt;edittoken) or ($this-&gt;edittoken == '')) $this-&gt;edittoken = $wpapi-&gt;getedittoken; $token = htmlspecialchars($this-&gt;edittoken); $post = array (                                       'mwProtect-reason'      =&gt; $reason,                                        'mwProtectWatch'        =&gt; '0',                                        'mwProtect-cascade'     =&gt; '0',                                        'mwProtect-expiry-edit' =&gt; ,                                        'mwProtect-expiry-move' =&gt; ,                                        'mw-Protect-submit'     =&gt; 'Confirm',                                        'wpEditToken'           =&gt; $token,                                        'mwProtect-level-edit'  =&gt; ,                                        'mwProtect-level-move'  =&gt;                                 ); return $this-&gt;http-&gt;post($this-&gt;indexurl.'?title='.urlencode($page).'&amp;action=unprotect',$post); }               function protect ($page,$reason=null,$edit='sysop',$move='sysop',$editexpire='infinite',$moveexpire='infinite') { $wpapi = new wikipediaapi; $wpapi-&gt;apiurl = str_replace('index.php','api.php',$this-&gt;indexurl); if ((!$this-&gt;edittoken) or ($this-&gt;edittoken == '')) $this-&gt;edittoken = $wpapi-&gt;getedittoken; $token = htmlspecialchars($this-&gt;edittoken); $post = array (                                       'mwProtect-reason'      =&gt; $reason,                                        'mwProtectWatch'        =&gt; '0',                                        'mwProtect-cascade'     =&gt; '0',                                        'mwProtect-expiry-edit' =&gt; $editexpire,                                        'mwProtect-expiry-move' =&gt; $moveexpire,                                        'mw-Protect-submit'     =&gt; 'Confirm',                                        'wpEditToken'           =&gt; $token,                                        'mwProtect-level-edit'  =&gt; $edit,                                        'mwProtect-level-move'  =&gt; $move                                ); return $this-&gt;http-&gt;post($this-&gt;indexurl.'?title='.urlencode($page).'&amp;action=protect',$post); }               function salt ($page,$reason=null,$create='sysop',$expire='infinite') { $wpapi = new wikipediaapi; $wpapi-&gt;apiurl = str_replace('index.php','api.php',$this-&gt;indexurl); if ((!$this-&gt;edittoken) or ($this-&gt;edittoken == '')) $this-&gt;edittoken = $wpapi-&gt;getedittoken; $token = htmlspecialchars($this-&gt;edittoken); $post = array (                                       'mwProtect-reason'      =&gt; $reason,                                        'mwProtectWatch'        =&gt; '0',                                        'mwProtect-expiry'      =&gt; $expire,                                        'mw-Protect-submit'     =&gt; 'Confirm',                                        'wpEditToken'           =&gt; $token,                                        'mwProtect-level-create'  =&gt; $create                                ); return $this-&gt;http-&gt;post($this-&gt;indexurl.'?title='.urlencode($page).'&amp;action=protect',$post); }               function block ($user,$expire='infinite',$reason='Vandalism',$anon=1,$account=1,$autoblock=1,$emailban=0) { $wpapi = new wikipediaapi; $wpapi-&gt;apiurl = str_replace('index.php','api.php',$this-&gt;indexurl); if ((!$this-&gt;edittoken) or ($this-&gt;edittoken == '')) $this-&gt;edittoken = $wpapi-&gt;getedittoken; $token = htmlspecialchars($this-&gt;edittoken); $post = array (                                       'wpBlockAddress'       =&gt; $user,                                        'wpBlockReason'         =&gt; $reason,                                        'wpAnonOnly'            =&gt; $anon,                                        'wpBlockOther'         =&gt; $expire,                                        'wpBlock'              =&gt; 'Block',                                        'wpEditToken'           =&gt; $token,                                        'wpCreateAccount'      =&gt; $account,                                        'wpEnableAutoblock'    =&gt; $autoblock,                                        'wpEmailBan'           =&gt; $emailban,                                        'wpWatchUser'          =&gt; 0,                                ); return $this-&gt;http-&gt;post($this-&gt;indexurl.'?title=Special:BlockIP&amp;action=submit',$post); }               function unblock ($user,$reason=null) { $wpapi = new wikipediaapi; $wpapi-&gt;apiurl = str_replace('index.php','api.php',$this-&gt;indexurl); if ((!$this-&gt;edittoken) or ($this-&gt;edittoken == '')) $this-&gt;edittoken = $wpapi-&gt;getedittoken; $token = htmlspecialchars($this-&gt;edittoken); $post = array (                                       'wpUnblockAddress'     =&gt; $user,                                        'wpUnblockReason'      =&gt; $reason,                                        'wpBlock'              =&gt; 'Unblock',                                        'wpEditToken'           =&gt; $token                                ); return $this-&gt;http-&gt;post($this-&gt;indexurl.'?title=Special:IPBlockList&amp;action=submit',$post); }       } ?&gt;