The following is automatically generated by SoxBot X.
The following is automatically generated by SoxBot X.
bot.php
|
|---|
<?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( "./functions.php" );
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 "DONE!!!\n";
?>
|
functions.php
|
|---|
<?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 "Logging in...\n";
$wpapi->login( $user,$pass );//Login
unset( $pass ); //Security reasons
return $user;
}
function postSource() {
//Post the source code
global $wpi, $user;
echo "\nPosting source code...\n";
$wpi->forcepost('User:'.$user.'/Source',
"The following is automatically generated by [[User:SoxBot X|]].\n\n" .
"==Bot Hierarchy==\n*bot.php\n*classes.php\n*functions.php\n" .
"==Source code==\n" .
"{{collapse top|bot.php}}\n<pre>".htmlentities(file_get_contents('./bot.php'))."</pre>\n{{collapse bottom}}\n" .
"{{collapse top|functions.php}}\n<pre>".htmlentities(file_get_contents('./functions.php'))."</pre>\n{{collapse bottom}}\n" .
"{{collapse top|classes.php}}\n<pre>".htmlentities(file_get_contents('../MainPageBot/classes.php'))."</pre>\n{{collapse bottom}}" ,
'Automated source upload.');
}
function getList($pagetitle) {
global $wpq;
$page = $wpq->getpage('Wikipedia:Requests for permissions/'.$pagetitle);
echo "\nGetting the text of Wikipedia:Requests for permissions/$pagetitle...\n";
$m = preg_split('/====(.*)====/i', $page, -1, PREG_SPLIT_OFFSET_CAPTURE);
$requests = array();
foreach ($m as $key => $req) {
if (preg_match('/\{\{subst:rfp/', $req[0])) { continue; }
if (preg_match('/\<!--noautoarchive/i', $req[0])) { continue; }
$username = preg_match('/\{\{Usercheck-short\|(.*)\}\}/i', $req[0], $name);
$username = $name[1];
if (!$username && $key != 0) { die(); }
if (preg_match('/\{done/i', $req[0])) {
echo $username."'s request was done.\n";
$requests[] = array('done', $username, trim($req[0]));
}
elseif (preg_match('/\{not\s?done/i', $req[0])) {
echo $username."'s request was not done.\n";
$requests[] = array('not done', $username, trim($req[0]));
}
else {
echo $username."'s request has not been completed yet.\n";
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' => '01', 'February' => '02', 'March' => '03', 'April' => '04', 'May' => '05', 'June' => '06', 'July' => '07', 'August' => '08', 'September' => '09', 'October' => '10', 'November' => '11', 'December' => '12');
$thenTime = strtotime($time[5]."-".$months[$time[4]]."-".$time[3]."T".$time[1].":".$time[2].":00Z");
if (date('U', $currentTime) - date('U', $thenTime) < 3600 ) {
echo "Too soon!\n";
return false;
}
$page = $wpq->getpage('Wikipedia:Requests for permissions/'.$pagetitle);
echo "\nGetting the text of Wikipedia:Requests for permissions/$pagetitle in order to remove $user...\n";
$newpage = str_ireplace('====[[User:'.$user."]]====".$request, '', $page);
if ($newpage == $page) {
echo "Failed to remove $user!";
return false;
}
$wpi->post('Wikipedia:Requests for permissions/'.$pagetitle, $newpage, "Removing $user, done.");
$date = date('F Y', $currentTime);
if ($action == 'done') {
$action = "Approved";
}
elseif ($action == 'not done') {
$action = "Denied";
}
else {
die("???");
}
$title="Wikipedia:Requests for permissions/$action/$date";
$log = $wpq->getpage($title);
if (preg_match("/$user/i", $log)) { return true; }
if (!preg_match("/".date('F d')."/i", $log)) { $log.="\n==".date('F d')."==\n"; }
if ($action == 'Denied') {
$log.="====[[User:$user]]====\n$request\n";
}
else {
$log.="*{{Usercheck-short|$user}}\n";
}
$wpi->post($title, $log, "Adding $user");
if ($action == "Denied") {
$usertalk=$wpq->getpage("User talk:$user");
if (!preg_match('/rollback request/i', $usertalk)) {
$wpi->post("User talk:$user", $usertalk . "\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 [[Wikipedia:Requests for permissions/Denied/$date#$user]]. ~~~~\n", "Your request for rollback has been denied.");
}
}
}
?>
|
classes.php
|
|---|
<?PHP
class http {
private $ch;
private $uid;
public $postfollowredirs;
public $getfollowredirs;
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("["), 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/cookies.dat');
curl_setopt($this->ch,CURLOPT_COOKIEFILE,'./tmp/cookies.dat');
curl_setopt($this->ch,CURLOPT_MAXCONNECTS,100);
curl_setopt($this->ch,CURLOPT_CLOSEPOLICY,CURLCLOSEPOLICY_LEAST_RECENTLY_USED);
$this->postfollowredirs = 0;
$this->getfollowredirs = 1;
}
function post ($url,$data) {
// echo 'POST: '.$url."\n";
$time = microtime(1);
curl_setopt($this->ch,CURLOPT_URL,$url);
curl_setopt($this->ch,CURLOPT_COOKIEJAR,'./tmp/cookies.dat');
curl_setopt($this->ch,CURLOPT_COOKIEFILE,'./tmp/cookies.dat');
curl_setopt($this->ch,CURLOPT_FOLLOWLOCATION,$this->postfollowredirs);
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) );
curl_setopt($this->ch,CURLOPT_POSTFIELDS, $data);
$data = curl_exec($this->ch);
//var_dump($data);
echo 'POST: '.$url.' ('.(microtime(1) - $time).' s) ('.strlen($data)." b)\n";
return $data;
}
function get ($url) {
//echo 'GET: '.$url."\n";
$time = microtime(1);
curl_setopt($this->ch,CURLOPT_URL,$url);
curl_setopt($this->ch,CURLOPT_COOKIEJAR,'./tmp/cookies.dat');
curl_setopt($this->ch,CURLOPT_COOKIEFILE,'./tmp/cookies.dat');
curl_setopt($this->ch,CURLOPT_FOLLOWLOCATION,$this->getfollowredirs);
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);
$data = curl_exec($this->ch);
//var_dump($data);
echo 'GET: '.$url.' ('.(microtime(1) - $time).' s) ('.strlen($data)." b)\n";
return $data;
}
function __destruct () {
curl_close($this->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->http = &$__wp__http;
$this->api = new wikipediaapi;
}
private function checkurl() {
$this->api->apiurl = str_replace('query.php','api.php',$this->queryurl);
}
function getpage ($page) {
$this->checkurl();
// $ret = unserialize($this->http->get($this->queryurl.'?what=content&format=php&titles='.urlencode($page)));
// foreach ($ret['pages'] as $page) {
// return $page['content']['*'];
// }
$ret = $this->api->revisions($page,1,'older',true,null,true,false,false,false);
return $ret[0]['*'];
}
function getpageid ($page) {
$this->checkurl();
// $ret = unserialize($this->http->get($this->queryurl.'?what=content&format=php&titles='.urlencode($page)));
// foreach ($ret['pages'] as $page) {
// return $page['id'];
// }
$ret = $this->api->revisions($page,1,'older',false,null,true,false,false,false);
return $ret['pageid'];
}
function contribcount ($user) {
$this->checkurl();
// $ret = unserialize($this->http->get($this->queryurl.'?what=contribcounter&format=php&titles=User:'.urlencode($user)));
// foreach ($ret['pages'] as $page) {
// return $page['contribcounter']['count'];
// }
$ret = $this->api->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->http = &$__wp__http;
}
function login ($user,$pass) {
$data = $this->http->post($this->apiurl.'?action=login&format=php',array('lgname' => $user, 'lgpassword' => $pass));
//print_r(unserialize($data));
// if ($data) echo $data."\n\n";
}
function getedittoken () {
$x = $this->http->get($this->apiurl.'?action=query&format=php&prop=info&intoken=edit&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 .= '&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['query']['recentchanges'];
}
function search ($search,$limit = 10,$offset = 0,$namespace = 0,$what = 'text',$redirs = false) {
$append = '';
if ($limit != null) $append .= '&srlimit='.urlencode($limit);
if ($offset != null) $append .= '&sroffset='.urlencode($offset);
if ($namespace != null) $append .= '&srnamespace='.urlencode($namespace);
if ($what != null) $append .= '&srwhat='.urlencode($what);
if ($redirs == true) $append .= '&srredirects=1';
else $append .= '&srredirects=0';
$x = $this->http->get($this->apiurl.'?action=query&list=search&format=php&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.= '&leuser='.urlencode($user);
if ($title != null) $append.= '&letitle='.urlencode($title);
if ($limit != null) $append.= '&lelimit='.urlencode($limit);
if ($type != null) $append.= '&letype='.urlencode($type);
if ($start != null) $append.= '&lestart='.urlencode($start);
if ($end != null) $append.= '&leend='.urlencode($end);
if ($dir != null) $append.= '&ledir='.urlencode($dir);
$x = $this->http->get($this->apiurl.'?action=query&format=php&list=logevents&leprop=ids|title|type|user|timestamp|comment|details'.$append);
$x = unserialize($x);
return $x['query']['logevents'];
}
function usercontribs ($user,$count = 50,&$continue = null,$dir = 'older') {
if ($continue != null) {
$append = '&ucstart='.urlencode($continue);
} else {
$append = '';
}
$x = $this->http->get($this->apiurl.'?action=query&format=php&list=usercontribs&ucuser='.urlencode($user).'&uclimit='.urlencode($count).'&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->http->get($this->apiurl.'?action=query&prop=revisions&titles='.urlencode($page).'&rvlimit='.urlencode($count).'&rvprop=timestamp|ids|user|comment'.(($content)?'|content':'').'&format=php&meta=userinfo&rvdir='.urlencode($dir).(($revid !== null)?'&rvstartid='.urlencode($revid):'').(($getrbtok == true)?'&rvtoken=rollback':'').(($redirects == true)?'&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.'."\n");
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.'."\n");
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->revisions($page,$count,$dir,$content,$revid,false,$getrbtok,$dieonerror);
} else {
if ($dieonerror == true) die('Revision error.'."\n");
}
}
}
foreach ($x['query']['pages'] as $key => $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,&$continue = null) {
$append = '';
if ($start != null) $append .= '&aufrom='.urlencode($start);
if ($group != null) $append .= '&augroup='.urlencode($group);
$x = $this->http->get($this->apiurl.'?action=query&list=allusers&format=php&auprop=blockinfo|editcount|registration|groups&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,&$continue = null) {
if ($continue != null) {
$append = '&cmcontinue='.urlencode($continue);
} else {
$append = '';
}
$category = 'Category:'.str_ireplace('category:','',$category);
$x = $this->http->get($this->apiurl.'?action=query&list=categorymembers&cmtitle='.urlencode($category).'&format=php&cmlimit='.$count.$append);
$x = unserialize($x);
$continue = $x['query-continue']['categorymembers']['cmcontinue'];
return $x['query']['categorymembers'];
}
function listcategories (&$start = null,$limit = 50,$dir = 'ascending',$prefix = null) {
$append = '';
if ($start != null) $append .= '&acfrom='.urlencode($start);
if ($limit != null) $append .= '&aclimit='.urlencode($limit);
if ($dir != null) $append .= '&acdir='.urlencode($dir);
if ($prefix != null) $append .= '&acprefix='.urlencode($prefix);
$x = $this->http->get($this->apiurl.'?action=query&list=allcategories&acprop=size&format=php'.$append);
$x = unserialize($x);
$start = $x['query-continue']['allcategories']['acfrom'];
return $x['query']['allcategories'];
}
function backlinks ($page,$count = 500,&$continue = null,$filter = null) {
if ($continue != null) {
$append = '&blcontinue='.urlencode($continue);
} else {
$append = '';
}
if ($filter != null) {
$append .= '&blfilterredir='.urlencode($filter);
}
$x = $this->http->get($this->apiurl.'?action=query&list=backlinks&bltitle='.urlencode($page).'&format=php&bllimit='.$count.$append);
$x = unserialize($x);
$continue = $x['query-continue']['backlinks']['blcontinue'];
return $x['query']['backlinks'];
}
function embeddedin ($page,$count = 500,&$continue = null) {
if ($continue != null) {
$append = '&eicontinue='.urlencode($continue);
} else {
$append = '';
}
$x = $this->http->get($this->apiurl.'?action=query&list=embeddedin&eititle='.urlencode($page).'&format=php&eilimit='.$count.$append);
$x = unserialize($x);
$continue = $x['query-continue']['embeddedin']['eicontinue'];
return $x['query']['embeddedin'];
}
function listprefix ($prefix,$namespace = 0,$count = 500,&$continue = null) {
$append = '&apnamespace='.urlencode($namespace);
if ($continue != null) {
$append .= '&apfrom='.urlencode($continue);
}
$x = $this->http->get($this->apiurl.'?action=query&list=allpages&apprefix='.urlencode($prefix).'&format=php&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->http = &$__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->queryurl = str_replace('index.php','query.php',$this->indexurl);
$wpapi = new wikipediaapi; $wpapi->apiurl = str_replace('index.php','api.php',$this->indexurl);
if ((!$this->edittoken) or ($this->edittoken == '')) $this->edittoken = $wpapi->getedittoken();
if ($rv == null) $rv = $wpapi->revisions($page,1,'older',true);
if (!$rv[0]['*']) $rv[0]['*'] = $wpq->getpage($page);
//Fake the edit form.
$now = gmdate('YmdHis', time());
$token = htmlspecialchars($this->edittoken);
$tmp = date_parse($rv[0]['timestamp']);
$edittime = gmdate('YmdHis', gmmktime($tmp['hour'],$tmp['minute'],$tmp['second'],$tmp['month'],$tmp['day'],$tmp['year']));
$html = "<input type='hidden' value=\"{$now}\" name=\"wpStarttime\" />\n";
$html.= "<input type='hidden' value=\"{$edittime}\" name=\"wpEdittime\" />\n";
$html.= "<input type='hidden' value=\"{$token}\" name=\"wpEditToken\" />\n";
$html.= '<input name="wpAutoSummary" type="hidden" value="'.md5('').'" />'."\n";
if (preg_match('/'.preg_quote('{{nobots}}','/').'/iS',$rv[0]['*'])) { return false; } /* Honor the bots flags */
if (preg_match('/'.preg_quote('{{bots|allow=none}}','/').'/iS',$rv[0]['*'])) { return false; }
if (preg_match('/'.preg_quote('{{bots|deny=all}}','/').'/iS',$rv[0]['*'])) { return false; }
if (preg_match('/'.preg_quote('{{bots|deny=','/').'(.*)'.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->getpage('User:'.$user.'/Run')))) { return false; } /* Check /Run page */
$x = $this->forcepost($page,$data,$summery,$minor,$html,$maxlag,$maxlagkeepgoing,$bot); /* Go ahead and post. */
$this->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->http->get($this->indexurl.'?title='.urlencode($page).'&action=edit');
} else {
$html = $edithtml;
}
preg_match('|\<input type\=\\\'hidden\\\' value\=\"(.*)\" name\=\"wpStarttime\" /\>|U',$html,$m);
$post['wpStarttime'] = $m[1];
preg_match('|\<input type\=\\\'hidden\\\' value\=\"(.*)\" name\=\"wpEdittime\" /\>|U',$html,$m);
$post['wpEdittime'] = $m[1];
preg_match('|\<input type\=\\\'hidden\\\' value\=\"(.*)\" name\=\"wpEditToken\" /\>|U',$html,$m);
$post['wpEditToken'] = $m[1];
preg_match('|\<input name\=\"wpAutoSummary\" type\=\"hidden\" value\=\"(.*)\" /\>|U',$html,$m);
$post['wpAutoSummary'] = $m[1];
if ($maxlag != null) {
$x = $this->http->post($this->indexurl.'?title='.urlencode($page).'&action=submit&maxlag='.urlencode($maxlag).'&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].')'."\n");
}
}
sleep(10);
if ($mlkg != true) { return false; }
else { $x = $this->http->post($this->indexurl.'?title='.urlencode($page).'&action=submit&bot='.(($bot == true)?'1':'0'),$post); }
}
return $x;
} else {
return $this->http->post($this->indexurl.'?title='.urlencode($page).'&action=submit&bot='.(($bot == true)?'1':'0'),$post);
}
}
function diff ($title,$oldid,$id,$wait = true) {
$deleted = '';
$added = '';
$html = $this->http->get($this->indexurl.'?title='.urlencode($title).'&action=render&diff='.urlencode($id).'&oldid='.urlencode($oldid).'&diffonly=1');
if (preg_match_all('/\&\;(oldid\=|undo=)(\d*)\\\'\>(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->diff($title,$oldid,$id,false);
} else {
die('Revision error.'."\n");
}
}
}
if (preg_match_all('/\<td class\=(\"|\\\')diff-addedline\1\>\<div\>(.*)\<\/div\>\<\/td\>/USs', $html, $m, PREG_SET_ORDER)) {
//print_r($m);
foreach ($m as $x) {
$added .= htmlspecialchars_decode(strip_tags($x[2]))."\n";
}
}
if (preg_match_all('/\<td class\=(\"|\\\')diff-deletedline\1\>\<div\>(.*)\<\/div\>\<\/td\>/USs', $html, $m, PREG_SET_ORDER)) {
//print_r($m);
foreach ($m as $x) {
$deleted .= htmlspecialchars_decode(strip_tags($x[2]))."\n";
}
}
//echo $added."\n".$deleted."\n";
if (preg_match('/action\=rollback\&\;from\=.*\&\;token\=(.*)\"/US', $html, $m)) {
$rbtoken = $m[1];
$rbtoken = urldecode($rbtoken);
// echo 'rbtoken: '.$rbtoken.' -- '; print_r($m); echo "\n\n";
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->apiurl = str_replace('index.php','api.php',$this->indexurl);
$token = $wpapi->revisions($title,1,'older',false,null,true,true);
if ($token[0]['user'] == $user) {
echo 'Token: '; print_r($token); echo "\n\n";
$token = $token[0]['rollbacktoken'];
} else {
return false;
}
}
$x = $this->http->get($this->indexurl.'?title='.urlencode($title).'&action=rollback&from='.urlencode($user).'&token='.urlencode($token).(($reason != null)?'&summary='.urlencode($reason):'').'&bot='.(($bot == true)?'1':'0'));
echo 'Rollback return: '.$x."\n";
if (!preg_match('/action complete/iS',$x)) return false;
return $x;
}
function move ($old,$new,$reason) {
$wpapi = new wikipediaapi; $wpapi->apiurl = str_replace('index.php','api.php',$this->indexurl);
if ((!$this->edittoken) or ($this->edittoken == '')) $this->edittoken = $wpapi->getedittoken();
$token = htmlspecialchars($this->edittoken);
$post = array
(
'wpOldTitle' => $old,
'wpNewTitle' => $new,
'wpReason' => $reason,
'wpWatch' => '0',
'wpEditToken' => $token,
'wpMove' => 'Move page'
);
return $this->http->post($this->indexurl.'?title=Special:Movepage&action=submit',$post);
}
function upload ($page,$file,$desc) {
$post = array
(
'wpUploadFile' => '@'.$file,
'wpSourceType' => 'file',
'wpDestFile' => $page,
'wpUploadDescription' => $desc,
'wpLicense' => '',
'wpWatchthis' => '0',
'wpIgnoreWarning' => '1',
'wpUpload' => 'Upload file'
);
return $this->http->post($this->indexurl.'?title=Special:Upload&action=submit',$post);
}
function hasemail ($user) {
$tmp = $this->http->get($this->indexurl.'?title=Special:EmailUser&target='.urlencode($user));
if (stripos($tmp,"No e-mail address") !== false) return false;
return true;
}
function email ($user,$subject,$body) {
$wpapi = new wikipediaapi; $wpapi->apiurl = str_replace('index.php','api.php',$this->indexurl);
if ((!$this->edittoken) or ($this->edittoken == '')) $this->edittoken = $wpapi->getedittoken();
$post = array
(
'wpSubject' => $subject,
'wpText' => $body,
'wpCCMe' => 0,
'wpSend' => 'Send',
'wpEditToken' => $this->edittoken
);
return $this->http->post($this->indexurl.'?title=Special:EmailUser&target='.urlencode($user).'&action=submit',$post);
}
function delete ($page,$reason=null) {
$wpapi = new wikipediaapi;
$wpapi->apiurl = str_replace('index.php','api.php',$this->indexurl);
if ((!$this->edittoken) or ($this->edittoken == '')) $this->edittoken = $wpapi->getedittoken();
$token = htmlspecialchars($this->edittoken);
$post = array('title' => $page,'token' => $token,'reason' => $reason);
$x = $this->http->post( $wpapi->apiurl.'?action=delete&format=php',$post );
return unserialize($x);
}
function unprotect ($page,$reason=null) {
$wpapi = new wikipediaapi; $wpapi->apiurl = str_replace('index.php','api.php',$this->indexurl);
if ((!$this->edittoken) or ($this->edittoken == '')) $this->edittoken = $wpapi->getedittoken();
$token = htmlspecialchars($this->edittoken);
$post = array
(
'mwProtect-reason' => $reason,
'mwProtectWatch' => '0',
'mwProtect-cascade' => '0',
'mwProtect-expiry-edit' => '',
'mwProtect-expiry-move' => '',
'mw-Protect-submit' => 'Confirm',
'wpEditToken' => $token,
'mwProtect-level-edit' => '',
'mwProtect-level-move' => ''
);
return $this->http->post($this->indexurl.'?title='.urlencode($page).'&action=unprotect',$post);
}
function protect ($page,$reason=null,$edit='sysop',$move='sysop',$editexpire='infinite',$moveexpire='infinite') {
$wpapi = new wikipediaapi; $wpapi->apiurl = str_replace('index.php','api.php',$this->indexurl);
if ((!$this->edittoken) or ($this->edittoken == '')) $this->edittoken = $wpapi->getedittoken();
$token = htmlspecialchars($this->edittoken);
$post = array
(
'mwProtect-reason' => $reason,
'mwProtectWatch' => '0',
'mwProtect-cascade' => '0',
'mwProtect-expiry-edit' => $editexpire,
'mwProtect-expiry-move' => $moveexpire,
'mw-Protect-submit' => 'Confirm',
'wpEditToken' => $token,
'mwProtect-level-edit' => $edit,
'mwProtect-level-move' => $move
);
return $this->http->post($this->indexurl.'?title='.urlencode($page).'&action=protect',$post);
}
function salt ($page,$reason=null,$create='sysop',$expire='infinite') {
$wpapi = new wikipediaapi; $wpapi->apiurl = str_replace('index.php','api.php',$this->indexurl);
if ((!$this->edittoken) or ($this->edittoken == '')) $this->edittoken = $wpapi->getedittoken();
$token = htmlspecialchars($this->edittoken);
$post = array
(
'mwProtect-reason' => $reason,
'mwProtectWatch' => '0',
'mwProtect-expiry' => $expire,
'mw-Protect-submit' => 'Confirm',
'wpEditToken' => $token,
'mwProtect-level-create' => $create
);
return $this->http->post($this->indexurl.'?title='.urlencode($page).'&action=protect',$post);
}
function block ($user,$expire='infinite',$reason='[[WP:Vandalism|Vandalism]]',$anon=1,$account=1,$autoblock=1,$emailban=0) {
$wpapi = new wikipediaapi; $wpapi->apiurl = str_replace('index.php','api.php',$this->indexurl);
if ((!$this->edittoken) or ($this->edittoken == '')) $this->edittoken = $wpapi->getedittoken();
$token = htmlspecialchars($this->edittoken);
$post = array
(
'wpBlockAddress' => $user,
'wpBlockReason' => $reason,
'wpAnonOnly' => $anon,
'wpBlockOther' => $expire,
'wpBlock' => 'Block',
'wpEditToken' => $token,
'wpCreateAccount' => $account,
'wpEnableAutoblock' => $autoblock,
'wpEmailBan' => $emailban,
'wpWatchUser' => 0,
);
return $this->http->post($this->indexurl.'?title=Special:BlockIP&action=submit',$post);
}
function unblock ($user,$reason=null) {
$wpapi = new wikipediaapi; $wpapi->apiurl = str_replace('index.php','api.php',$this->indexurl);
if ((!$this->edittoken) or ($this->edittoken == '')) $this->edittoken = $wpapi->getedittoken();
$token = htmlspecialchars($this->edittoken);
$post = array
(
'wpUnblockAddress' => $user,
'wpUnblockReason' => $reason,
'wpBlock' => 'Unblock',
'wpEditToken' => $token
);
return $this->http->post($this->indexurl.'?title=Special:IPBlockList&action=submit',$post);
}
}
?>
|
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.