1. Summary
  2. Files
  3. Support
  4. Report Spam
  5. Create account
  6. Log in

Username mapping tool for MediaWiki export

SourceForge.net provides MediaWiki service as part of our Hosted Apps offering. Some projects have an existing MediaWiki install which they want to move to SourceForge.net. Our MediaWiki service does support import, but there is a pitfall. When you have an external MediaWiki install, that install probably has usernames which do not map to SourceForge.net user accounts. We provide this page as instructions for realigning your MediaWiki install against the SourceForge.net user accounts of your developer team.

Data conversion may be performed as follows:

  1. Export the page from your existing MediaWiki install.
  2. Save the perl script, as shown below, in a file named mediawiki-convert.pl
  3. Run the script below, as follows, to process and modify all included usernames to their matching SourceForge.net user account:$ ./mediawiki-convert.pl EXPORT_FILENAME > NEW_EXPORT_FILENAME
  4. Import the data to your new MediaWiki install at SourceForge.net.

Should a problem be noted with the user mapping it can be fixed by deleting the page and running this convert script as documented or by manually tweaking the contents of the XML file.

#!/usr/bin/perl -w
 
my %users;
my $text;
 
# Store stdin and process for usernames
 
open(FH, $ARGV[0])
  or die "Cannot open $ARGV[0]\n";
 
while(<FH>) {
  $text .= $_;
 
  if($_ =~ m/<username>(.+)<\/username>/) {
    $users{$1} = '';
  }
}
 
close(FH);
 
# Prompt for replacement values
 
print STDERR "
You will now be prompted with a set of usernames, respond with
the name of the SourceForge.net user that should be mapped to
the username in question:\n";
 
foreach(keys(%users)) {
  print STDERR "$_: ";
  my $tmp = <STDIN>;
  chomp($tmp);
  $tmp = lc($tmp);
  $tmp = ucfirst($tmp);
  $users{$_} = $tmp;
}
 
foreach(keys(%users)) {
  $text =~ s/<username>$_<\/username>/<username>$users{$_}<\/username>/gs;
}
 
print $text;

Getting Help