Main Page | Namespace List | Class Hierarchy | Class List | File List | Class Members | File Members | Related Pages

attribute.php

Go to the documentation of this file.
00001 <?php 00002 # Script for re-attributing edits 00003 require_once( "commandLine.inc" ); 00004 00005 # Parameters 00006 if ( count( $args ) < 2 ) { 00007 print "Not enough parameters\n"; 00008 if ( $wgWikiFarm ) { 00009 print "Usage: php attribute.php <language> <site> <source> <destination>\n"; 00010 } else { 00011 print "Usage: php attribute.php <source> <destination>\n"; 00012 } 00013 exit; 00014 } 00015 00016 $source = $args[0]; 00017 $dest = $args[1]; 00018 00019 $eSource = wfStrencode( $source ); 00020 $eDest = wfStrencode( $dest ); 00021 00022 # Get user id 00023 $res = wfQuery( "SELECT user_id FROM user WHERE user_name='$eDest'", DB_READ ); 00024 $row = wfFetchObject( $res ); 00025 if ( !$row ) { 00026 print "Warning: the target name \"$dest\" does not exist"; 00027 $uid = 0; 00028 } else { 00029 $uid = $row->user_id; 00030 } 00031 00032 # Initialise files 00033 $logfile = fopen( "attribute.log", "a" ); 00034 $sqlfile = fopen( "attribute.sql", "a" ); 00035 00036 fwrite( $logfile, "* $source &rarr; $dest\n" ); 00037 00038 fwrite( $sqlfile, 00039 "-- Changing attribution SQL file 00040 -- Generated with attribute.php 00041 -- $source -> $dest ($uid) 00042 "); 00043 00044 $omitTitle = "Wikipedia:Changing_attribution_for_an_edit"; 00045 00046 # Get old entries 00047 print "\nOld entries\n\n"; 00048 00049 $res = wfQuery( "SELECT old_namespace, old_title, old_id, old_timestamp FROM old WHERE old_user_text='$eSource'", DB_READ ); 00050 $row = wfFetchObject( $res ); 00051 00052 if ( $row ) { 00053 /* 00054 if ( $row->old_title=='Votes_for_deletion' && $row->old_namespace == 4 ) { 00055 # We don't have that long 00056 break; 00057 } 00058 */ 00059 fwrite( $logfile, "**Old IDs: " ); 00060 fwrite( $sqlfile, "UPDATE old SET old_user=$uid, old_user_text='$eDest' WHERE old_id IN (\n" ); 00061 00062 for ( $first=true; $row; $row = wfFetchObject( $res ) ) { 00063 $ns = $wgLang->getNsText( $row->old_namespace ); 00064 if ( $ns ) { 00065 $fullTitle = "$ns:{$row->old_title}"; 00066 } else { 00067 $fullTitle = $row->old_title; 00068 } 00069 if ( $fullTitle == $omitTitle ) { 00070 continue; 00071 } 00072 00073 print "$fullTitle\n"; 00074 $url = "http://$lang.wikipedia.org/w/wiki.phtml?title=" . urlencode( $fullTitle ); 00075 $eTitle = wfStrencode( $row->old_title ); 00076 /* 00077 # Find previous entry 00078 $lastres = wfQuery( "SELECT old_id FROM old WHERE 00079 old_title='$eTitle' AND old_namespace={$row->old_namespace} AND 00080 old_timestamp<'{$row->old_timestamp}' ORDER BY inverse_timestamp LIMIT 1", DB_READ ); 00081 $lastrow = wfFetchObject( $lastres ); 00082 if ( $lastrow ) { 00083 $last = $lastrow->old_id; 00084 $url .= "&diff={$row->old_id}&oldid=$last"; 00085 } else {*/ 00086 $url .= "&oldid={$row->old_id}"; 00087 # } 00088 00089 # Output 00090 fwrite( $sqlfile, " " ); 00091 if ( $first ) { 00092 $first = false; 00093 } else { 00094 fwrite( $sqlfile, ", " ); 00095 fwrite( $logfile, ", " ); 00096 } 00097 00098 fwrite( $sqlfile, "{$row->old_id} -- $url\n" ); 00099 fwrite( $logfile, "[$url {$row->old_id}]" ); 00100 00101 } 00102 fwrite( $sqlfile, ");\n" ); 00103 fwrite( $logfile, "\n" ); 00104 } 00105 00106 # Get cur entries 00107 print "\n\nCur entries\n\n"; 00108 00109 $res = wfQuery( "SELECT cur_title, cur_namespace, cur_timestamp, cur_id FROM cur WHERE cur_user_text='$eSource'", 00110 DB_READ ); 00111 $row = wfFetchObject( $res ); 00112 if ( $row ) { 00113 fwrite( $sqlfile, "\n\nUPDATE cur SET cur_user=$uid, cur_user_text='$eDest' WHERE cur_id IN(\n" ); 00114 fwrite( $logfile, "**Cur entries:\n" ); 00115 for ( $first=true; $row; $row = wfFetchObject( $res ) ) { 00116 $ns = $wgLang->getNsText( $row->cur_namespace ); 00117 if ( $ns ) { 00118 $fullTitle = "$ns:{$row->cur_title}"; 00119 } else { 00120 $fullTitle = $row->cur_title; 00121 } 00122 if ( $fullTitle == $omitTitle ) { 00123 continue; 00124 } 00125 $url = "http://$lang.wikipedia.org/wiki/" . urlencode($fullTitle); 00126 if ( $first ) { 00127 fwrite( $sqlfile, " " ); 00128 $first = false; 00129 } else { 00130 fwrite( $sqlfile, " , " ); 00131 } 00132 fwrite( $sqlfile, "{$row->cur_id} -- $url\n" ); 00133 fwrite( $logfile, "***[[$fullTitle]] {$row->cur_timestamp}\n" ); 00134 print "$fullTitle\n"; 00135 } 00136 fwrite( $sqlfile, ");\n" ); 00137 } 00138 print "\n"; 00139 00140 fclose( $sqlfile ); 00141 fclose( $logfile ); 00142 00143 ?>

Generated on Tue Jun 29 23:40:02 2004 for Mediawiki by doxygen 1.3.7