Misplaced Pages

User:ClueBot/Source

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:ClueBot

This is an old revision of this page, as edited by NaomiAmethyst (talk | contribs) at 07:31, 24 July 2007. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Revision as of 07:31, 24 July 2007 by NaomiAmethyst (talk | contribs)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)

The following is automatically generated by ClueBot.


Source to ClueBot

<?PHP
	class http {
		private $ch;
		private $uid;
		function data_encode ($data, $keyprefix = "", $keypostfix = "") {
			assert( is_array($data) );
			$vars=null;
			foreach($data as $key=>$value) {
				if(is_array($value)) $vars .= $this->data_encode($value, $keyprefix.$key.$keypostfix.urlencode(""));
				else $vars .= $keyprefix.$key.$keypostfix."=".urlencode($value)."&";
			}
			return $vars;
		}
		function __construct () {
			$this->ch = curl_init();
			$this->uid = dechex(rand(0,99999999));
			curl_setopt($this->ch,CURLOPT_COOKIEJAR,'/tmp/cluewikibot.cookies.'.$this->uid.'.dat');
			curl_setopt($this->ch,CURLOPT_COOKIEFILE,'/tmp/cluewikibot.cookies.'.$this->uid.'.dat');
		}
		function post ($url,$data) {
			curl_setopt($this->ch,CURLOPT_URL,$url);
			curl_setopt($this->ch,CURLOPT_FOLLOWLOCATION,1);
			curl_setopt($this->ch,CURLOPT_MAXREDIRS,10);
			curl_setopt($this->ch,CURLOPT_HEADER,0);
			curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);
			curl_setopt($this->ch,CURLOPT_TIMEOUT,30);
			curl_setopt($this->ch,CURLOPT_CONNECTTIMEOUT,10);
			curl_setopt($this->ch,CURLOPT_POST,1);
			curl_setopt($this->ch,CURLOPT_POSTFIELDS, substr($this->data_encode($data), 0, -1) );
			return curl_exec($this->ch);
		}
		function get ($url) {
			curl_setopt($this->ch,CURLOPT_URL,$url);
			curl_setopt($this->ch,CURLOPT_FOLLOWLOCATION,1);
			curl_setopt($this->ch,CURLOPT_MAXREDIRS,10);
			curl_setopt($this->ch,CURLOPT_HEADER,0);
			curl_setopt($this->ch,CURLOPT_RETURNTRANSFER,1);
			curl_setopt($this->ch,CURLOPT_TIMEOUT,30);
			curl_setopt($this->ch,CURLOPT_CONNECTTIMEOUT,10);
			curl_setopt($this->ch,CURLOPT_HTTPGET,1);
			return curl_exec($this->ch);
		}
		function __destruct () {
			curl_close($this->ch);
			@unlink('/tmp/cluewikibot.cookies.'.$this->uid.'.dat');
		}
	}
	class wikipediaquery {
		private $http;
		private $queryurl = 'http://en.wikipedia.org/w/query.php';
		function __construct () {
			global $__wp__http;
			if (!isset($__wp__http)) {
				$__wp__http = new http;
			}
			$this->http = &$__wp__http;
		}
		function getpage ($page) {
			$ret = unserialize($this->http->get($this->queryurl.'?what=content&format=php&titles='.urlencode($page)));
			foreach ($ret as $page) {
				return $page;
			}
		}
	}
	class wikipediaapi {
		private $http;
		private $apiurl = 'http://en.wikipedia.org/w/api.php';
		function __construct () {
			global $__wp__http;
			if (!isset($__wp__http)) {
				$__wp__http = new http;
			}
			$this->http = &$__wp__http;
		}
		function login ($user,$pass) {
			$this->http->post($this->apiurl.'?action=login',array('lgname' => $user, 'lgpassword' => $pass));
		}
		function recentchanges ($count = 10,$namespace = null,$dir = 'older',$ts = null) {
			$append = '';
			if ($ts != null) { $append .= '&rcstart='.urlencode($ts); }
			$append .= '&rcdir='.urlencode($dir);
			if ($namespace != null) { $append .= '&rcnamespace='.urlencode($namespace); }
			$x = $this->http->get($this->apiurl.'?action=query&list=recentchanges&rcprop=user|comment|flags|timestamp|title|ids|sizes&format=php&rclimit='.$count.$append);
			$x = unserialize($x);
			return $x;
		}
	}
	class wikipediaindex {
		private $http;
		private $indexurl = 'http://en.wikipedia.org/search/';
		function __construct () {
			global $__wp__http;
			if (!isset($__wp__http)) {
				$__wp__http = new http;
			}
			$this->http = &$__wp__http;
		}
		function post ($page,$data,$summery = '') {
			global $user;
			$html = $this->http->get($this->indexurl.'?title='.urlencode($page).'&action=edit');
			if (preg_match('/'.preg_quote('{{nobots}}','/').'/i',$html)) { return false; }		/* Honor the bots flags */
			if (preg_match('/'.preg_quote('{{bots|allow=none}}','/').'/i',$html)) { return false; }
			if (preg_match('/'.preg_quote('{{bots|deny=all}}','/').'/i',$html)) { return false; }
			if (preg_match('/'.preg_quote('{{bots|deny=','/').'(.*)'.preg_quote('}}','/').'/i',$html,$m)) { if (in_array(explode(',',$m),$user)) { return false; } } /* /Honor the bots flags */
			if (!preg_match('/'.preg_quote($user,'/').'/i',$html)) { return false; } /* We need to be logged in */
			if (preg_match('/'.preg_quote('You have new messages','/').'/i',$html)) { return false; } /* Check talk page */
			$wpq = new wikipediaquery;
			if (!preg_match('/(yes|enable|true)/i',$wpq->getpage('User:'.$user.'/Run'))) { return false; } /* Check /Run page */
			return $this->forcepost($page,$data,$summery); /* Go ahead and post. */
		}
		function forcepost ($page,$data,$summery = '') {
			$post = '';
			$post = '';
			$post = $data;
			$post = $summery;
			$html = $this->http->get($this->indexurl.'?title='.urlencode($page).'&action=edit');
			preg_match('|\<input type\=\\\'hidden\\\' value\=\"(.*)\" name\=\"wpStarttime\" /\>|U',$html,$m);
			$post = $m;
			preg_match('|\<input type\=\\\'hidden\\\' value\=\"(.*)\" name\=\"wpEdittime\" /\>|U',$html,$m);
			$post = $m;
			preg_match('|\<input type\=\\\'hidden\\\' value\=\"(.*)\" name\=\"wpEditToken\" /\>|U',$html,$m);
			$post = $m;
			preg_match('|\<input name\=\"wpAutoSummary\" type\=\"hidden\" value\=\"(.*)\" /\>|U',$html,$m);
			$post = $m;
			$this->http->post($this->indexurl.'?title='.urlencode($page).'&action=submit',$post);
		}
	}
	$wpapi	= new wikipediaapi;
	$wpq	= new wikipediaquery;
	$wpi	= new wikipediaindex;
	include 'wikibot.config.php';
	$wpapi->login($user,$pass);
	$wpi->post('User:'.$user.'/Source','The following is automatically generated by ].\n\n\n\n==Source to ".$user."==\n\n<code>".file_get_contents(__FILE__)."</code>\n\n\n\n] 07:23, 24 July 2007 (UTC)",
		'Automated source upload.'); /* Our source code */
	$rc = $wpapi->recentchanges(500);
	$lasttime = $rc;
	$pipe = fopen('thepipe','w');
	while (1) {
		$rc = $wpapi->recentchanges(500,0,'newer',$lasttime);
		foreach ($rc as $change) {
			if (($change - $change) <= -5000) {
				echo 'Possible vandalism: '.$change.' changed by '.$change.' deleting '.($change - $change).' characters on '.$change.".\n";
				fwrite($pipe,'http://en.wikipedia.org/search/?title='.urlencode($change).'&action=history'."\n");
			}
			$lasttime = $change;
		}
		sleep(30);
	}
?>


ClueBot 07:23, 24 July 2007 (UTC)