tips:wakka2doku
wakka2doku.pl
This script helps you to get started when converting data from an existing WakkaWiki to DokuWiki. You still need to edit some of the generated files to display correctly in DokuWiki but its better than nothing .
#!/usr/bin/perl use DBI; use Data::Dumper; # Database stuff $driver = "mysql"; $database = "wakka"; $hostname = "localhost"; $user = "username"; $password = "secret"; $dsn = "DBI:$driver:database=$database;host=$hostname"; $dbh = DBI->connect($dsn, $user, $password); $SELECT = "SELECT tag, body FROM wakka_pages WHERE latest = 'Y' AND comment_on = ''"; $result = $dbh->selectall_arrayref($SELECT); #build page hash %pages; for (my $row=0; defined($result->[$row][0]); $row++){ $pages{$result->[$row][0]} = $result->[$row][1]; } @names = keys(%pages); while (my ($page,$body) = each(%pages) ){ my @codes; for (my $i=0; $body =~ m/%%(.*?)%%/s; $i++){ $body =~ s/%%(.*?)%%/fooooooooooooooooo$i/s; $codes[$i] = $1; } $body =~ s/{{autoindex}}//sg; # dokuwiki creates tocs it self #$body =~ s/''(.*?)''/(($1))/sg; # remarks to footnotes $body =~ s/''(.*?)''/$1/sg; # remove remarks $body =~ s/""(.*?)""/<nowiki>$1<\/nowiki>/sg; # non parsed $body =~ s/##(.*?)##/''$1''/sg; # inline code $body =~ s/\[\[([^\[\]]+?)\s([^\[\]]+?)\]\]/\[\[$1\|$2\]\]/sg; # links with titles $body =~ s/\{img="(.*?)"}/{{$1}}/sg; # images $body =~ s/^(\t| +)-/$1\*/mg; # unordered lists $body =~ s/^(\t| +)\d\)/$1-/mg; # ordered lists #entities $body =~ s/"/"/sg; $body =~ s/&/&/sg; #do CamelCase links to existing pages foreach $name (@names){ $body =~ s/([^\w\[])(\Q$name\E)([^\w\]])/$1\[\[$2\]\]$3/sg; } #reinsert code foreach my $i (0 .. $#codes){ $c = $codes[$i]; $body =~ s/fooooooooooooooooo$i/<code>$c<\/code>/s; } $page = lc($page); open(FILE,">$page.txt") ||die("could not write '$page.txt'"); print FILE $body; close FILE; } $dbh->disconnect();
tips/wakka2doku.txt · Last modified: 2018-04-30 20:51 by Aleksandr