From fc5e54e7216798b50195cfdae261f78bd7f6c77c Mon Sep 17 00:00:00 2001 From: Tim Starling Date: Mon, 22 Dec 2003 03:51:30 +0000 Subject: [PATCH] Miscellaneous scripts --- maintenance/attribute.php | 145 +++++++++++++++++++++++++++++++++++++ maintenance/changeuser.sql | 12 +++ maintenance/rcdumper.php | 80 ++++++++++++++++++++ 3 files changed, 237 insertions(+) create mode 100644 maintenance/attribute.php create mode 100644 maintenance/changeuser.sql create mode 100755 maintenance/rcdumper.php diff --git a/maintenance/attribute.php b/maintenance/attribute.php new file mode 100644 index 0000000000..5b5ed4b5b1 --- /dev/null +++ b/maintenance/attribute.php @@ -0,0 +1,145 @@ + \n"; + exit; +} + +$lang = $argv[1]; +$source = $argv[2]; +$dest = $argv[3]; + +# Initialisation + +$wgCommandLineMode = true; +$DP = "../includes"; + +$sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":"; +ini_set( "include_path", "$IP$sep$include_path" ); + +include_once( "/apache/htdocs/$lang/w/LocalSettings.php" ); +include_once( "Setup.php" ); + +$wgTitle = Title::newFromText( "Changing attribution script" ); +set_time_limit(0); +$wgCommandLineMode = true; + +$eSource = wfStrencode( $source ); +$eDest = wfStrencode( $dest ); + +# Get user id +$res = wfQuery( "SELECT user_id FROM user WHERE user_name='$eDest'", DB_READ ); +$row = wfFetchObject( $res ); +if ( !$row ) { + print "Warning: the target name \"$dest\" does not exist"; + $uid = 0; +} else { + $uid = $row->user_id; +} + +# Initialise files +$logfile = fopen( "attribute.log", "w" ); +$sqlfile = fopen( "attribute.sql", "w" ); + +fwrite( $logfile, "* $source → $dest\n" ); + +fwrite( $sqlfile, +"-- Changing attribution SQL file +-- Generated with attribute.php +-- $source -> $dest ($uid) +"); + +# Get old entries +print "Getting old entries"; + +$res = wfQuery( "SELECT old_namespace, old_title, old_id, old_timestamp FROM old WHERE old_user_text='$eSource'", DB_READ ); +$row = wfFetchObject( $res ); + +if ( $row ) { +/* + if ( $row->old_title=='Votes_for_deletion' && $row->old_namespace == 4 ) { + # We don't have that long + break; + } +*/ + fwrite( $logfile, "**Old IDs: " ); + fwrite( $sqlfile, "UPDATE old SET old_user=$uid, old_user_text='$eDest' WHERE old_id IN (\n" ); + + for ( $first=true; $row; $row = wfFetchObject( $res ) ) { + $ns = $wgLang->getNsText( $row->old_namespace ); + if ( $ns ) { + $fullTitle = "$ns:{$row->old_title}"; + } else { + $fullTitle = $row->old_title; + } + $url = "http://$lang.wikipedia.org/w/wiki.phtml?title=" . urlencode( $fullTitle ); + $eTitle = wfStrencode( $row->old_title ); +/* + # Find previous entry + $lastres = wfQuery( "SELECT old_id FROM old WHERE + old_title='$eTitle' AND old_namespace={$row->old_namespace} AND + old_timestamp<'{$row->old_timestamp}' ORDER BY inverse_timestamp LIMIT 1", DB_READ ); + $lastrow = wfFetchObject( $lastres ); + if ( $lastrow ) { + $last = $lastrow->old_id; + $url .= "&diff={$row->old_id}&oldid=$last"; + } else {*/ + $url .= "&oldid={$row->old_id}"; +# } + + # Output + fwrite( $sqlfile, " " ); + if ( $first ) { + $first = false; + } else { + fwrite( $sqlfile, ", " ); + fwrite( $logfile, ", " ); + } + + fwrite( $sqlfile, "{$row->old_id} -- $url\n" ); + fwrite( $logfile, "[$url {$row->old_id}]" ); + + print "."; + } + fwrite( $sqlfile, ");\n" ); + fwrite( $logfile, "\n" ); +} +print "\n"; + +# Get cur entries +print "Getting cur entries"; +$res = wfQuery( "SELECT cur_title, cur_namespace, cur_timestamp, cur_id FROM cur WHERE cur_user_text='$eSource'", + DB_READ ); +$row = wfFetchObject( $res ); +if ( $row ) { + fwrite( $sqlfile, "\n\nUPDATE cur SET cur_user=$uid, cur_user_text='$eDest' WHERE cur_id IN(\n" ); + fwrite( $logfile, "**Cur entries:\n" ); + for ( $first=true; $row; $row = wfFetchObject( $res ) ) { + $ns = $wgLang->getNsText( $row->cur_namespace ); + if ( $ns ) { + $fullTitle = "$ns:{$row->cur_title}"; + } else { + $fullTitle = $row->cur_title; + } + $url = "http://$lang.wikipedia.org/wiki/" . urlencode($fullTitle); + if ( $first ) { + fwrite( $sqlfile, " " ); + $first = false; + } else { + fwrite( $sqlfile, " , " ); + } + fwrite( $sqlfile, "{$row->cur_id} -- $url\n" ); + fwrite( $logfile, "***[[$fullTitle]] {$row->cur_timestamp}\n" ); + print "."; + } + fwrite( $sqlfile, ");\n" ); +} +print "\n"; + +fclose( $sqlfile ); +fclose( $logfile ); + +?> diff --git a/maintenance/changeuser.sql b/maintenance/changeuser.sql new file mode 100644 index 0000000000..f6e5cf8921 --- /dev/null +++ b/maintenance/changeuser.sql @@ -0,0 +1,12 @@ +set @oldname = 'At18'; +set @newname = 'Alfio'; + +update low_priority user set user_name=@newname where user_name=@oldname; +update low_priority user_newtalk set user_ip=@newname where user_ip=@oldname; +update low_priority cur set cur_user_text=@newname where cur_user_text=@oldname; +update low_priority old set old_user_text=@newname where old_user_text=@oldname; +update low_priority archive set ar_user_text=@newname where ar_user_text=@oldname; +update low_priority ipblocks set ipb_address=@newname where ipb_address=@oldname; +update low_priority oldimage set oi_user_text=@newname where oi_user_text=@oldname; +update low_priority recentchanges set rc_user_text=@newname where rc_user_text=@oldname; + diff --git a/maintenance/rcdumper.php b/maintenance/rcdumper.php new file mode 100755 index 0000000000..a90497d852 --- /dev/null +++ b/maintenance/rcdumper.php @@ -0,0 +1,80 @@ +rc_timestamp; + +while (1) { + $res = wfQuery( "SELECT * FROM recentchanges WHERE rc_timestamp>'$oldTimestamp' ORDER BY rc_timestamp", DB_READ ); + while ( $row = wfFetchObject( $res ) ) { + $ns = $wgLang->getNsText( $row->rc_namespace ) ; + if ( $ns ) { + $title = "$ns:{$row->rc_title}"; + } else { + $title = $row->rc_title; + } + /*if ( strlen( $row->rc_comment ) > 50 ) { + $comment = substr( $row->rc_comment, 0, 50 ); + } else {*/ + $comment = $row->rc_comment; +// } + $bad = array("\n", "\r"); + $empty = array("", ""); + $comment = str_replace($bad, $empty, $comment); + $title = str_replace($bad, $empty, $title); + $user = str_replace($bad, $empty, $row->rc_user_text); + $url = "http://$lang.wikipedia.org/wiki/" . urlencode($title); + + if ( $patterns ) { + foreach ( $patterns as $pattern ) { + if ( preg_match( $pattern, $comment ) ) { + print chr(7); + break; + } + } + } + print( "$url ($user) $comment\n" ); + $oldTimestamp = $row->rc_timestamp; + } + sleep(5); +} + +exit(); + +?> -- 2.20.1