User:Leucosticte/bots/MirrorPushBot.php

 * version 1.0.1 * * 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 */

// "r" (repeat) Three options: -ro (onetime), -rd (continuous, using defaults), // r $usage = 'Usage: php mirrorpushbot.php [-r]' . "\n"; $options = getopt( 'r:'); $allowableOptions['r'] = array( 'o', 'd', ); if ( !isset ( $options['r'] ) ) {     $options['r'] = 'o'; // Default to onetime } 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'); // Get the passwords $passwordFile = 'inclubot_passwords.php'; if ( !file_exists ( $passwordFile ) ) { die ( "File $passwordFile does not exist\n" ); } include( 'inclubot_passwords.php' ); // Get the defaults $defaultsFile = 'inclubot_defaults.php'; if ( !file_exists ( $defaultsFile ) ) { die ( "File $defaultsFile does not exist\n" ); } include( 'inclubot_defaults.php' ); $wiki     = new wikipedia; $wiki->url = $localWikiUrl;

// Database $db = new mysqli( $host, $dbUser, $dbPass ); if ( !$db ) { die( 'Could not connect: ' . mysql_error); } $db->select_db ( "$dbName" ); if ( !$db ) { die( "Could not select $dbName" ); } $wiki->login( $pushUser, $pushPass ); $token = urlencode ( $wiki->getedittoken );

$mbRet = $db->query( "SELECT * FROM mb_rc_queue WHERE mbrcq_push_timestamp=''" ); if ( !$mbRet ) { die ( "No rows found\n" ); } $row = $mbRet->fetch_assoc; // Just do one row for testing purposes if ( $row['mbrcq_rc_type'] == 'edit' or $row['mbrcq_rc_type'] == 'new' ) { $pushMapping = array(           'pageid' => 'mbrcq_rc_cur_id',            'text' => 'mbrcq_text', // This doesn't actually exist; it'll be supplied through a                  // separate query            'summary' => 'mbrcq_rc_comment',            'minor' => 'mbrcq_rc_minor',            'bot' => 'mbrcq_rc_bot',            'title' => 'mbrcq_rc_title',            'namespace' => 'mbrcq_rc_namespace',            'contentmodel' => 'mbrcq_content_model',            'rcid' => 'mbrcq_rc_id',            'revid' => 'mbrcq_rc_thisoldid',            'user' => 'mbrcq_rc_user_text',            'userid' => 'mbrcq_rc_user',            'timestamp' => 'mbrcq_rc_timestamp',            'tags' => 'mbrcq_tags',      ); $mbRet = $db->query( "SELECT mbt_text FROM mb_text WHERE mbt_id="           . $row['mbrcq_text_id'] . "" ); if ( !$mbRet ) { die ( "No rows found for mbrcq_id " . $row['mbrcq_id'] . ", mbrcq_text_id "                 . $row['mbrcq_text_id'] . "\n" ); }     $textRow = $mbRet->fetch_assoc; if ( !$textRow ) { die ( "No rows, or empty row, found for mbrcq_id " . $row['mbrcq_id']                 . ", mbrcq_text_id "                  . $row['mbrcq_text_id'] . "\n" ); }     #echo "strlen ". strlen( $textRow['mbt_text'] ); #die; #$row['mbrcq_text'] = $textRow['mbt_text']; $data = array( 'text' => $textRow['mbt_text'] ); #$row['mbrcq_text'] = substr( $textRow['mbt_text'], 0, 7000 ); $query = "?action=mirroredit&format=php&token=$token"; } elseif( $row['mbrcq_rc_type'] == 'create' ) { $pushMapping = array(           'user' => 'mbrcq_rc_user_text',            'userid' => 'mbrcq_rc_user',            'timestamp' => 'mbrcq_rc_timestamp',            'rcid' => 'mbrcq_rc_id',            'logid' => 'mbrcq_rc_logid',      ); } $canBeZero = array(     'namespace',      'userid',      'text' ); foreach( $pushMapping as $pushMappingKey => $pushMappingValue ) { if ( $row[$pushMappingValue] || in_array( $pushMappingKey, $canBeZero ) ) { $query .= "&$pushMappingKey=". ( urlencode( $row[$pushMappingValue] ) ); #$query .= "&$pushMappingKey=". $row[$pushMappingValue]; echo "strlen ". $pushMappingKey. " " . strlen( urlencode( $row[$pushMappingValue] ) ). "\n"; } } echo "strlen ". strlen( $query ). "\n"; $localRet = $wiki->query ( $query, $data,     array( 'Content-Type: application/x-www-form-urlencoded' ), false ); // POST, serialize var_dump ( $localRet ); if ( !$localRet ) { die ( "Nothing was returned\n" ); } if ( isset( $localRet['error' ] ) ) { die( "The $localWikiName API returned an error message on mbrcq_id " . $row['mbrcq_id'] . "!\n" ); } // TODO: Get the timestamp from the API!
 * 1) die;

$db->query ( "UPDATE mb_rc_queue SET mbrcq_push_timestamp=" . $localRet['newtimestamp']     . ", mbrcq_push_user="      . $localRet['userid'] . " WHERE mbrcq_rcid=" . $row['mbrcq_rc_id'] );