Fix for r47482: put the RELEASE-NOTES entry in the "bug fixes" section and not the...
[mediawiki.git] / maintenance / attribute.php
blob63f194356240a49b1d75dea7a893f8f7083640ea
1 <?php
2 /**
3 * Script for re-attributing edits
4 * Use reassingEdits.php
6 * @file
7 * @ingroup Maintenance
8 */
10 /** */
11 require_once( "commandLine.inc" );
13 # Parameters
14 if ( count( $args ) < 2 ) {
15 print "Not enough parameters\n";
16 if ( $wgWikiFarm ) {
17 print "Usage: php attribute.php <language> <site> <source> <destination>\n";
18 } else {
19 print "Usage: php attribute.php <source> <destination>\n";
21 exit;
24 $source = $args[0];
25 $dest = $args[1];
27 $dbr = wfGetDB( DB_SLAVE );
28 extract( $dbr->tableNames( 'page', 'revision','user' ));
29 $eSource = $dbr->strencode( $source );
30 $eDest = $dbr->strencode( $dest );
32 # Get user id
33 $res = $dbr->query( "SELECT user_id FROM $user WHERE user_name='$eDest'" );
34 $row = $dbr->fetchObject( $res );
35 if ( !$row ) {
36 print "Warning: the target name \"$dest\" does not exist";
37 $uid = 0;
38 } else {
39 $uid = $row->user_id;
42 # Initialise files
43 $logfile = fopen( "attribute.log", "a" );
44 $sqlfile = fopen( "attribute.sql", "a" );
46 fwrite( $logfile, "* $source &rarr; $dest\n" );
48 fwrite( $sqlfile,
49 "-- Changing attribution SQL file
50 -- Generated with attribute.php
51 -- $source -> $dest ($uid)
52 ");
54 $omitTitle = "Wikipedia:Changing_attribution_for_an_edit";
56 # Get revisions
57 print "\nPage revisions\n\n";
59 $res = $dbr->query( "SELECT page_namespace, page_title, rev_id, rev_timestamp
60 FROM $revision,$page
61 WHERE rev_user_text='$eSource' and rev_page=page_id" );
62 $row = $dbr->fetchObject( $res );
64 if ( $row ) {
66 if ( $row->old_title=='Votes_for_deletion' && $row->old_namespace == 4 ) {
67 # We don't have that long
68 break;
71 fwrite( $logfile, "**Revision IDs: " );
72 fwrite( $sqlfile, "UPDATE $revision SET rev_user=$uid, rev_user_text='$eDest' WHERE rev_id IN (\n" );
74 for ( $first=true; $row; $row = $dbr->fetchObject( $res ) ) {
75 $title = Title::makeTitle( $row->page_namespace, $row->page_title );
76 $fullTitle = $title->getPrefixedDbKey();
77 if ( $fullTitle == $omitTitle ) {
78 continue;
81 print "$fullTitle\n";
82 $url = $title->getFullUrl( "oldid={$row->rev_id}" );
84 # Output
85 fwrite( $sqlfile, " " );
86 if ( $first ) {
87 $first = false;
88 } else {
89 fwrite( $sqlfile, ", " );
90 fwrite( $logfile, ", " );
93 fwrite( $sqlfile, "{$row->rev_id} -- $url\n" );
94 fwrite( $logfile, "[$url {$row->rev_id}]" );
97 fwrite( $sqlfile, ");\n" );
98 fwrite( $logfile, "\n" );
101 print "\n";
103 fclose( $sqlfile );
104 fclose( $logfile );