X-Git-Url: http://git.cyclocoop.org/?a=blobdiff_plain;f=maintenance%2Fattribute.php;h=d885fd286e77fd6a498ee2f5bbf57da808ade052;hb=48d5b739e940857c7a2c95f113ecc2e9c60a78b9;hp=5b5ed4b5b112e4a5f27e50b9ced2c31de8088368;hpb=fc5e54e7216798b50195cfdae261f78bd7f6c77c;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/attribute.php b/maintenance/attribute.php index 5b5ed4b5b1..d885fd286e 100644 --- a/maintenance/attribute.php +++ b/maintenance/attribute.php @@ -1,38 +1,36 @@ - \n"; + if ( $wgWikiFarm ) { + print "Usage: php attribute.php \n"; + } else { + print "Usage: php attribute.php \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" ); +$source = $args[0]; +$dest = $args[1]; -$wgTitle = Title::newFromText( "Changing attribution script" ); -set_time_limit(0); -$wgCommandLineMode = true; - -$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; @@ -41,8 +39,8 @@ if ( !$row ) { } # Initialise files -$logfile = fopen( "attribute.log", "w" ); -$sqlfile = fopen( "attribute.sql", "w" ); +$logfile = fopen( "attribute.log", "a" ); +$sqlfile = fopen( "attribute.sql", "a" ); fwrite( $logfile, "* $source → $dest\n" ); @@ -52,11 +50,13 @@ fwrite( $sqlfile, -- $source -> $dest ($uid) "); +$omitTitle = "Wikipedia:Changing_attribution_for_an_edit"; + # Get old entries -print "Getting 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 ) { /* @@ -68,27 +68,20 @@ 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}"; } else { $fullTitle = $row->old_title; } + if ( $fullTitle == $omitTitle ) { + continue; + } + + 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, " " ); @@ -102,28 +95,29 @@ if ( $row ) { 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 ); +print "\n\nCur entries\n\n"; + +$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}"; } else { $fullTitle = $row->cur_title; } + if ( $fullTitle == $omitTitle ) { + continue; + } $url = "http://$lang.wikipedia.org/wiki/" . urlencode($fullTitle); if ( $first ) { fwrite( $sqlfile, " " ); @@ -133,7 +127,7 @@ if ( $row ) { } fwrite( $sqlfile, "{$row->cur_id} -- $url\n" ); fwrite( $logfile, "***[[$fullTitle]] {$row->cur_timestamp}\n" ); - print "."; + print "$fullTitle\n"; } fwrite( $sqlfile, ");\n" ); }