Miscellaneous scripts
authorTim Starling <tstarling@users.mediawiki.org>
Mon, 22 Dec 2003 03:51:30 +0000 (03:51 +0000)
committerTim Starling <tstarling@users.mediawiki.org>
Mon, 22 Dec 2003 03:51:30 +0000 (03:51 +0000)
maintenance/attribute.php [new file with mode: 0644]
maintenance/changeuser.sql [new file with mode: 0644]
maintenance/rcdumper.php [new file with mode: 0755]

diff --git a/maintenance/attribute.php b/maintenance/attribute.php
new file mode 100644 (file)
index 0000000..5b5ed4b
--- /dev/null
@@ -0,0 +1,145 @@
+<?
+
+# Parameters
+
+if ($argc < 4) {
+       print "Not enough parameters\n";
+       print "Usage: php attribute.php <lang> <source> <destination>\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 &rarr; $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 (file)
index 0000000..f6e5cf8
--- /dev/null
@@ -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 (executable)
index 0000000..a90497d
--- /dev/null
@@ -0,0 +1,80 @@
+<?
+
+$wgCommandLineMode = true;
+
+$sep = strchr( $include_path = ini_get( "include_path" ), ";" ) ? ";" : ":";
+if ( $argv[1] ) {
+       $lang = $argv[1];
+       $settingsFile = "/apache/htdocs/{$argv[1]}/w/LocalSettings.php";
+       $newpath = "/apache/common/php$sep";
+} else {
+       $settingsFile = "../LocalSettings.php";
+       $newpath = "";
+}
+
+if ( $argv[2] ) {
+       print $argv[2] . "\n";
+       $patterns = explode( ",", $argv[2]);
+} else {
+       $patterns = false;
+}
+
+if ( ! is_readable( $settingsFile ) ) {
+       print "A copy of your installation's LocalSettings.php\n" .
+         "must exist in the source directory.\n";
+       exit();
+}
+
+$wgCommandLineMode = true;
+$DP = "../includes";
+include_once( $settingsFile );
+
+ini_set( "include_path", "$newpath$IP$sep$include_path" );
+
+include_once( "Setup.php" );
+$wgTitle = Title::newFromText( "RC dumper" );
+$wgCommandLineMode = true;
+set_time_limit(0);
+
+$res = wfQuery( "SELECT rc_timestamp FROM recentchanges ORDER BY rc_timestamp DESC LIMIT 1", DB_READ ); 
+$row = wfFetchObject( $res );
+$oldTimestamp = $row->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();
+
+?>