Created
May 19, 2012 10:50
-
-
Save DamianZaremba/2730447 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
include 'wikibot.classes.php'; | |
$wpapi = new wikipediaapi; | |
$wpapi->login( 'ClueBot_NG', 'passwordhere' ); | |
function mysql_reconnect() { | |
if( !@mysql_ping() ) { | |
mysql_connect( 'bots-sql2', 'cb', 'passwordhere' ); | |
mysql_select_db( 'cluebotbig' ); | |
} | |
} | |
$continue = null; | |
$id = False; | |
$count = 0; | |
while( ($id == False || $id > 936592) ) { | |
$contribs = $wpapi->usercontribs( 'ClueBot_NG', 5000, $continue ); | |
foreach( $contribs as $edit ) { | |
if( $id == False ) { | |
$id = $edit['revid']; | |
} | |
if( $edit['revid'] > $id ) { | |
$id = $edit['revid']; | |
} | |
if( !is_array( $edit ) || !isset( $edit['comment'] ) ) { | |
continue; | |
} | |
if( preg_match( '/^Reverting possible vandalism by \[\[Special:Contributions\/.+\|(.+)\]\] to version by (.+)\. False positive\? \[\[User:ClueBot NG\/FalsePositives\|Report it\]\]\. Thanks, \[\[User:ClueBot NG\|ClueBot NG\]\]\. \((.+)\) \(Bot\)$/', $edit['comment'], $matches ) ) { | |
$ruser = $matches[1]; | |
$oruser = $matches[2]; | |
$cbng_id = $matches[3]; | |
mysql_reconnect(); | |
$res = mysql_query( | |
'SELECT * FROM `vandalism` WHERE `id` = "' . mysql_real_escape_string( $cbng_id ) . '" AND ' . | |
'(`user` = "" OR `article` = "" OR `diff` = "" OR `new_id` = 0)' | |
); | |
if( mysql_num_rows( $res ) > 0 ) { | |
$revs = $wpapi->revisions( $edit['title'], $count=3, $dir='older', $content=False, $revid=$edit['revid'] ); | |
$rev = $revs[1]; | |
$rev2 = $revs[2]; | |
if( !is_array( $rev ) || !is_array( $rev2 ) ) { | |
continue; | |
} | |
$query = 'UPDATE `vandalism` SET'; | |
$query .= ' `article` = "' . mysql_real_escape_string( $edit['title'] ) . '",'; | |
$query .= ' `user` = "' . mysql_real_escape_string( $rev['user'] ) . '",'; | |
$query .= ' `diff` = "' . mysql_real_escape_string( 'http://en.wikipedia.org/w/index.php?diff=' . $rev['revid'] . '&oldid=' . $rev2['revid'] ) . '",'; | |
$query .= ' `new_id` = "' . mysql_real_escape_string( $rev['revid'] ) . '",'; | |
$query .= ' `old_id` = "' . mysql_real_escape_string( $rev2['revid'] ) . '"'; | |
$query .= ' WHERE `id` = "' . mysql_real_escape_string( $cbng_id ) . '" AND'; | |
$query .= ' (`user` = "" OR `article` = "" OR `diff` = "" OR `new_id` = 0 OR `old_id` = 0)'; | |
if( mysql_query( $query ) ) { | |
print "Updated " . $cbng_id . "\n"; | |
$count++; | |
} | |
} | |
} | |
} | |
} | |
print $count . " updated\n"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment