DokuWiki

It's better when it's simple

User Tools

Site Tools


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 ;-).

Note 2023: It also works with WikkaWiki (now dead) but you need to remove: AND comment_on = ''

#!/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/&quot;/"/sg;
  $body =~ s/&amp;/&/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: 2023-06-29 23:50 by 62.235.238.209

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki