MoinMoin/Filter

For converting MoinMoin wikitext to MediaWiki wikitext, Dan Littlejohn's mm2mw.pl Perl script is the least-worst option.

Below is a version of Filter that includes a few more syntax conversions and also converts simple tables. Feel free to enhance.

The original version of the code on this page is by Dan Littlejohn with patches by Tyler Drake. A license was not given in the original file (though it was made available at no cost to all); David Gerard contacted Mr Littlejohn to ask, but got no response. It's not GFDL.

sub Filter {
 * 1) Filter
 * 2) filters lines to correct syntax
 * 3) args: 1) infile - file to have words converted
 * 4) args: 2) outfile - file to output
 * 1) args: 1) infile - file to have words converted
 * 2) args: 2) outfile - file to output
 * 1) args: 2) outfile - file to output

my $this = shift; my $args = { infile => " ", outfile => " ", @_,			# Override previous attributes };	my $infile = $args->{infile}; my $outfile = $args->{outfile};

my @slashparts; my $filename; my @spaceparts; my $name;

my $is_table = 0;

open(INFILE, "<$infile"); open(OUTFILE, ">$outfile"); while (){

##########               # line skips #               next if /^$/;       # remove unneeded header lines

##########               # regexp substitutions #

# list convert - 1st layer #               s/^ \*(.*?)/\*$1/g;

# list convert - 2nd layer #               s/^  \*(.*?)/\*\*$1/g;

# list convert - 3rd layer #               s/^   \*(.*?)/\*\*\*$1/g;

# list convert - 4th layer #               s/^    \*(.*?)/\*\*\*\*$1/g;

# list convert - 5th layer #               s/^     \*(.*?)/\*\*\*\*\*$1/g;

# list convert - numerical #               s/^ 1.(.*?)/\#$1/g;

# link convert - BR -> #               s/\[\[BR\]\]/\/g;

# link convert superscripted - ^ * ^ -> * #               s/\^(.*?)\^/\$1\<\/sup\>/g;

# link convert subscripted - ,, * ,, -> * #               s/\,\,(.*?)\,\,/\$1\<\/sub\>/g;

# link convert smaller - ~- * -~ -> * #               s/\~-(.*?)-\~/\$1\<\/small\>/g;

# link convert larger - ~+ * +~ -> * #               s/\~\+(.*?)\+\~/\$1\<\/big\>/g;

# link convert - [# * ] -> * #               s/\[\#(.*?)\]/\[\[\#$1\]\]/g;

# link convert - [" * "] -> * #               s/\[\"(.*?)\"\]/\[\[$1\]\]/g;

# link convert - [: * ] -> * #               s/\[\:(.*?)\]/\[\[$1\]\]/g;

# link convert - __ * __ -> * #               s/__(.*?)__/\$1\<\/u\>/g;

# link convert - ` * ` -> #               s/`(.*?)`/\$1\<\/tt\>/g;

# link convert - -> # (if on same line) #               s/\{\{\{(.*?)\}\}\}/\$1\<\/nowiki\>\<\/code\>/g;

# link convert - on different line)                #                s/\{\{\{(.*?)/\\$1/g;

# link convert - * }}} ->  * <\pre><\nowiki> # (if on same line) #               s/(.*?)\}\}\}/$1\<\/nowiki\><\/pre\>/g;

# strikethrough convert #               s/--\((.*?)\)--/\$1\<\/s\>/g;

# link convert - [wiki:cat * ] -> * #               $this->ConvertWikiLinks(line=>\$_);

# convert CamelCase links #               $this->ConvertCamelLinks(line=>\$_);

# link convert - /CommentPage -> Talk:PageName #               @slashparts = split(/\//,$infile); my $filename = $slashparts[$#slashparts]; @spaceparts = split(/(?=[A-Z])/,$filename); $name = join(" ",@spaceparts); s/\/CommentPage/\[\[Talk:$name\]\]/g;

# Convert definition lists #               # Partially built out, but not implemented #               # MM has term, colon, colon, space, definition # MW has semicolon, space, term, space, colon, space, definition # s/(.*)\:\:\s(.*)/\;\s$1\s\:\s$2/g;

##########               # deletions #

# `` - don't need these (ex Myth``Blog on front page) #               s/``//g;

##########               # tables #

# start of table/row? if(/^\|\|/) { if($is_table == 0) { # start of table $is_table = 1; s/^\|\|/\n\{\|border=1 cellpadding=1 cellspacing=0\|\n\|/; }                       else { # start of row s/^\|\|/\n\|-\n\|/; }                       }                else { # end of table? # (i.e. in a table and the line doesn't start '||') if ($is_table == 1) { $is_table = 0; s/(.*)$/$1\n\|\}\n/; }                       }

# end of row (we just zap that) s/\|\|\s+$//;

# all other '||' are just cell indicators s/\|\|/\n\|/g;

print OUTFILE "$_"; }

# source text ended with unclosed table print OUTFILE "\n\|\}\n" if ($is_table == 1);

close OUTFILE; close INFILE; }