User:Leucosticte/Junkyard

' . "\n" ); } if ( $options[ 'q' ] != 'rc' && $options[ 'q' ] != 'rev' ) { die ( "Allowable options: rc, rev\n" ); }

$con = new mysqli("localhost","root","360540133613112", "mirrorbot"); if (!$con) { die('Could not connect: ' . mysql_error); }

/* Setup my classes. */ include('botclasses.php'); $wiki     = new wikipedia; $wiki->url = "http://en.wikipedia.org/w/api.php";
 * 1) $wiki->url = "http://meta.wikimedia.org/w/api.php";

/* All the login stuff. */ $user = 'LeucosticteBot'; $pass = 'RE3Uwreh'; $wiki->login($user,$pass); unset($pass);
 * 1) $user = 'Leucostice';
 * 2) $pass = 'stuPach4';

switch ( $options[ 'q' ] ) { case 'rc': // Patrolled flag removed because of a lack of patrol right :(	   $ret = $wiki->query ('?action=query&list=recentchanges&rcstart=2012-08-09T20:02:37Z' . '&rcdir=newer&rcprop=user|userid|comment|timestamp|title|ids|sizes|redirect|loginfo' . '|flags|loginfo|tags&rclimit=5&format=php', true);           #echo substr ( $ret, 0, 1500 );            #die;            #var_dump ( $ret );            #die;	    $events = $ret['query']['recentchanges'];	    $table = 'mb_rc_queue';	    $fields = array ( 'mbrcq_rc_id' => 'rcid', 'mbrcq_anon' => 'anon', 'mbrcq_rc_bot' => 'bot', 'mbrcq_rc_comment' => 'comment', 'mbrcq_rc_log_action' => 'logaction', 'mbrcq_rc_logid' => 'logid', 'mbrcq_rc_logtype' => 'logtype', 'mbrcq_rc_minor' => 'minor', 'mbrcq_rc_new' => 'new', 'mbrcq_rc_new_len' => 'newlen', 'mbrcq_rc_namespace' => 'ns', 'mbrcq_rc_old_len' => 'oldlen', 'mbrcq_rc_cur_id' => 'pageid', 'mbrcq_rc_patrolled' => 'patrolled', 'mbrcq_rc_thisoldid' => 'revid', 'mbrcq_rc_lastoldidid' => 'revoldid', 'mbrcq_redirect' => 'redirect', 'mbrcq_rc_timestamp' => 'timestamp', 'mbrcq_rc_title' => 'title', 'mbrcq_rc_type' => 'type', 'mbrcq_rc_user_text' => 'user' );	   $stringFields = array ( 'title', 'type', 'action', 'user', 'comment', 'tags', 'logaction', 'logtype' );	   $booleanFields = array ( 'anon', 'bot', 'minor', 'new', 'patrolled', 'redirect', );           $defaultFields = array ( 'mbrcq_rc_log_action' => '', 'mbrcq_rc_logid' => 'logid', 'mbrcq_rc_logtype' => 'logtype', 'mbrcq_rc_minor' => 'minor', 'mbrcq_rc_new' => 'new', 'mbrcq_rc_new_len' => 'newlen', 'mbrcq_rc_namespace' => 'ns', 'mbrcq_rc_old_len' => 'oldlen', 'mbrcq_rc_cur_id' => 'pageid', 'mbrcq_rc_patrolled' => 'patrolled', 'mbrcq_rc_thisoldid' => 'revid', 'mbrcq_rc_lastoldidid' => 'revoldid', 'mbrcq_redirect' => 'redirect', 'mbrcq_rc_timestamp' => 'timestamp', 'mbrcq_rc_title' => 'title', 'mbrcq_rc_type' => 'type', 'mbrcq_rc_user_text' => 'user' );	   break; }

$dbFields = array_keys ( $fields ); $userRow = array_values ( $fields ); $undesirables = array ( '-', ':', 'T', 'Z' ); $row = 'insert into '. $table. ' ( ' . implode ( ', ', $dbFields ) . ' ) values '; $isFirstInEvent = true; // For each user creation event in that result set foreach ( $events as $thisLogevent ) { if ( !$isFirstInEvent ) { $row .= ', '; }     $isFirstInEvent = false; $row .= '( ';     $isFirstInItem = true;      // Get rid of dashes, colons, Ts and Zs in timestamp      $thisLogevent['timestamp'] = str_replace ( $undesirables, '', $thisLogevent['timestamp'] );      // Iterate over those database fields      foreach ( $userRow as $thisRowItem ) {	    if ( !$isFirstInItem ) {		  $row .= ', ';	    }	    $isFirstInItem = false;	    // If it's a boolean field, 1 if it's there, 0 if not	    if ( in_array( $thisRowItem, $booleanFields ) ) {		  if ( isset ( $thisLogevent[ $thisRowItem ] ) ) {			$row .= '1';		  } else {			$row .= '0';		  }	    } else {                  if ( isset ( $thisLogevent[$thisRowItem] ) ) {                        // If it's an array (e.g. tag array), implode it                        if ( is_array ( $thisLogevent[$thisRowItem] ) ) {                              $thisLogevent[$thisRowItem] = implode ( $thisLogevent[$thisRowItem] ); }                       // If it's a string field, escape it                        if ( in_array ( $thisRowItem, $stringFields ) ) { $thisLogevent[$thisRowItem] = "'". $con->real_escape_string ( $thisLogevent[$thisRowItem] ). "'";                       }                        $row .= $thisLogevent[$thisRowItem]; } else { $row .= $defaultFields[] }           }      }      $row .= ')'; } $row .= ';'; echo $row;

$con->query ( $row ); $con->close;