User:Leucosticte/MPushB

 * * 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., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * http://www.gnu.org/copyleft/gpl.html */ // "q" (queue) Three options: -qrc, -qrev, qus // "r" (repeat) Three options: -ro (onetime), -rd (continuous, using defaults), // r $usage = 'Usage: php mirrorpushbot.php -q' . '[-r]' . "\n"; $options = getopt( 'q:r:'); $allowableOptions['q'] = array( 'rc', 'rev', 'us' ); $allowableOptions['r'] = array( 'o', 'd', ); if ( !isset ( $options['q'] ) ) {     die ( $usage ); } if ( !isset ( $options['r'] ) ) {      $options['r'] = 'o'; // Default to onetime } if ( !in_array ( $options[ 'q' ], $allowableOptions['q'] ) ) {      die ( $usage ); } if ( !in_array ( $options[ 'r' ], $allowableOptions['r'] ) ) {      if ( !is_int ( $options['r'] ) ) { // Microseconds option            die ( $usage );      } else {            $sleepMicroseconds = $options['r'];      } }

/* Setup my classes. */ include('botclasses.php'); $wiki     = new wikipedia; $wiki->url = $localWikiUrl;

// Database $db = new mysqli( $host, $dbUser, $dbPass, $dbName ); if ( !$db ) { die( 'Could not connect: ' . mysql_error); }

// Get new users // TODO What about when the result is failure or something of the like? // TODO iteration, w/ command line options $ret = $db->query( "SELECT * FROM mb_rc_queue WHERE mbrcq_rc_logtype='newusers' "     . "AND mbrcq_push_result=''" ); if ( !$ret ) { die ( "No unpushed newusers rows found\n" ); } $row = $ret->fetch_assoc; // Just do one row for testing purposes $row = $ret->fetch_assoc; // Just do one row for testing purposes $row = $ret->fetch_assoc; // Just do one row for testing purposes var_dump ( $row );

$wiki->login($pushUser,$pushPass); $token = $wiki->getedittoken ; unset($pass); $fields = array(     'rcid' => 'mbrcq_rc_id',      'logid' => 'mbrcq_rc_logid',      'pageid' => 'mbrcq_rc_cur_id',      'pagenamespace' => 'mbrcq_rc_namespace',      'pagetitle' => 'mbrcq_rc_title',      'type' => 'mbrcq_rc_logtype',      'logaction' => 'mbrcq_rc_log_action',      'user' => 'mbrcq_rc_user_text',      'userid' => 'mbrcq_rc_user',      'timestamp' => 'mbrcq_rc_timestamp',      'comment' => 'mbrcq_rc_comment',      'tags' => 'mbrcq_tags' ); $query = '?action=createaccount&format=php'; foreach ( $fields as $key => $value ) { if ( isset ( $row[ $value ] ) ) { $query .= '&'. $key. '=' . $row[ $value ]; } } $ret = $wiki->query ( '?action=createaccount&format=php'     . '&rcid=' . $row['mbrcq_rc_id']      . '&logid=' . $row['mbrcq_rc_logid']      . '&pageid=' . $row['mbrcq_rc_cur_id']      . '&pagenamespace=' . $row['mbrcq_rc_namespace']      . '&pagetitle=' . $row['mbrcq_rc_title']      . '&type=' . $row['mbrcq_rc_logtype']      . '&logaction=' . $row['mbrcq_rc_log_action']      . '&user=' . $row['mbrcq_rc_user_text']      . '&userid=' . $row['mbrcq_rc_user']      . '&timestamp=' . $row['mbrcq_rc_timestamp']      . '&comment=' . $row['mbrcq_rc_comment']      . '&tags=' . $row['mbrcq_tags']      . '&token=' . $token     , true ); // Post var_dump ( $ret ); $db->query ( "UPDATE mb_rc_queue SET mbrcq_push_result=" . $ret['result'] . ", mbrcq_push_user="     . $ret['userid'] . " WHERE mbrcq_rcid=" . $row['mbrcq_rc_id'] );