DokuWiki

It's better when it's simple

User Tools

Site Tools


Sidebar

Translations of this page?:

Learn about DokuWiki

Advanced Use

Corporate Use

Our Community


Follow us on Facebook, Twitter and other social networks.

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/&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: 2010-03-04 07:30 by 164.67.235.79