Add tests for the just-fixed bug 553, and broken cases regarding
[lhc/web/wiklou.git] / maintenance / attribute.php
index 56c2d2a..7220a85 100644 (file)
@@ -1,38 +1,36 @@
 <?php
+/**
+ * Script for re-attributing edits
+ *
+ * @package MediaWiki
+ * @subpackage Maintenance
+ */
 
-# Parameters
+/** */
+require_once( "commandLine.inc" );
 
-if ($argc < 4) {
+# Parameters
+if ( count( $args ) < 2 ) {
        print "Not enough parameters\n";
-       print "Usage: php attribute.php <lang> <source> <destination>\n";
+       if ( $wgWikiFarm ) {
+               print "Usage: php attribute.php <language> <site> <source> <destination>\n";
+       } else {
+               print "Usage: php attribute.php <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" );
-
-require_once( "/apache/htdocs/$lang/w/LocalSettings.php" );
-require_once( "Setup.php" );
-
-$wgTitle = Title::newFromText( "Changing attribution script" );
-set_time_limit(0);
-$wgCommandLineMode = true;
+$source = $args[0];
+$dest = $args[1];
 
-$eSource = wfStrencode( $source );
-$eDest = wfStrencode( $dest );
+$dbr =& wfGetDB( DB_SLAVE );
+extract( $dbr->tableNames( 'cur','old','user' );
+$eSource = $dbr->strencode( $source );
+$eDest = $dbr->strencode( $dest );
 
 # Get user id
-$res = wfQuery( "SELECT user_id FROM user WHERE user_name='$eDest'", DB_READ );
-$row = wfFetchObject( $res );
+$res = $dbr->query( "SELECT user_id FROM $user WHERE user_name='$eDest'" );
+$row = $dbr->fetchObject( $res );
 if ( !$row ) {
        print "Warning: the target name \"$dest\" does not exist";
        $uid = 0;
@@ -57,8 +55,8 @@ $omitTitle = "Wikipedia:Changing_attribution_for_an_edit";
 # Get old entries
 print "\nOld entries\n\n";
 
-$res = wfQuery( "SELECT old_namespace, old_title, old_id, old_timestamp FROM old WHERE old_user_text='$eSource'", DB_READ );
-$row = wfFetchObject( $res );
+$res = $dbr->query( "SELECT old_namespace, old_title, old_id, old_timestamp FROM $old WHERE old_user_text='$eSource'" );
+$row = $dbr->fetchObject( $res );
 
 if ( $row ) {
 /*
@@ -70,7 +68,7 @@ if ( $row ) {
        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 ) ) {
+       for ( $first=true; $row; $row = $dbr->fetchObject( $res ) ) {
                $ns = $wgLang->getNsText( $row->old_namespace );
                if ( $ns ) {
                        $fullTitle = "$ns:{$row->old_title}";
@@ -83,19 +81,7 @@ if ( $row ) {
 
                print "$fullTitle\n";
                $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}";
-#              }
+               $url .= "&oldid={$row->old_id}";
                
                # Output
                fwrite( $sqlfile, "      " );
@@ -117,13 +103,12 @@ if ( $row ) {
 # Get cur entries
 print "\n\nCur entries\n\n";
 
-$res = wfQuery( "SELECT cur_title, cur_namespace, cur_timestamp, cur_id FROM cur WHERE cur_user_text='$eSource'",
-       DB_READ );
-$row = wfFetchObject( $res );
+$res = $dbr->query( "SELECT cur_title, cur_namespace, cur_timestamp, cur_id FROM $cur WHERE cur_user_text='$eSource'" );
+$row = $dbr->fetchObject( $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 ) ) {
+       for ( $first=true; $row; $row = $dbr->fetchObject( $res ) ) {
                $ns = $wgLang->getNsText( $row->cur_namespace );
                if ( $ns ) {
                        $fullTitle = "$ns:{$row->cur_title}";