1 |
#!/usr/bin/perl -w |
2 |
|
3 |
use DBI; |
4 |
|
5 |
my $sql = qq{ |
6 |
select |
7 |
pagename, content, lastmodified::abstime, author |
8 |
from wiki |
9 |
-- where author != 'The PhpWiki programming team' |
10 |
order by lastmodified |
11 |
}; |
12 |
my $dump_dir = './dump/'; |
13 |
my $st_dir = './st/'; |
14 |
|
15 |
my $connect = "DBI:Pg:dbname=phpwiki"; |
16 |
|
17 |
my $dbh = DBI->connect($connect,"","") || die $DBI::errstr; |
18 |
$sth = $dbh->prepare($sql) || die $dbh->errstr(); |
19 |
$sth->execute() || die $sth->errstr(); |
20 |
|
21 |
while (my($page,$content,$last_change,$author) = $sth->fetchrow_array() ) { |
22 |
print "exporting: $page\n"; |
23 |
|
24 |
my $path = $page; |
25 |
$path =~ s!/+!_!g; |
26 |
|
27 |
open(my $out, '>', "$dump_dir/${path}.wiki") || die "can't open $out_dir/$path: $!"; |
28 |
print $out $content; |
29 |
close($out); |
30 |
|
31 |
# headings |
32 |
$content =~ s/^!\s*(.*?)$/^ $1/mg; |
33 |
$content =~ s/^!!\s*(.*?)$/^^ $1/mg; |
34 |
$content =~ s/^!!!\s*(.*?)$/^^^ $1/mg; |
35 |
$content =~ s/^!!!!\s*(.*?)$/^^^^ $1/mg; |
36 |
$content =~ s/^!!!!!\s*(.*?)$/^^^^^ $1/mg; |
37 |
|
38 |
$content =~ s/!([A-Z]\w+)/$1/mg; |
39 |
|
40 |
$content =~ s!''(.*?)''!/$1/!mg; |
41 |
$content =~ s!__(.*?)__!*$1*!mg; |
42 |
|
43 |
$content =~ s!\[\s*(.+?)\s*[\s\|]\s*((http://|mailto:)\S+)\s*\]!"$1"<$2>!mg; |
44 |
$content =~ s!\[\s*(http://\S+)\s*[\s\|]\s*(.+?)\s*\]!"$2"<$1>!mg; |
45 |
|
46 |
my $seen; |
47 |
my $out; |
48 |
foreach (split(/[\n\r]/, $content)) { |
49 |
if ( |
50 |
( ! /^\s+/ && $seen->{space} ) # end of space preformat |
51 |
|| |
52 |
( /^\s+\S+/ && ! $seen->{space} ) # begin of space preformat |
53 |
) { |
54 |
|
55 |
$out .= ".pre\n"; |
56 |
$seen->{space} = not $seen->{space}; |
57 |
} |
58 |
$out .= "$_\n"; |
59 |
} |
60 |
|
61 |
$out .= ".pre\n" if ($seen->{space}); |
62 |
|
63 |
$content = $out; |
64 |
|
65 |
$content =~ s/\.pre[\n\r]+\.pre//sg; |
66 |
|
67 |
$content .= "\n----\nLast modified $last_change by $author\n"; |
68 |
|
69 |
open(my $out, '>', "$st_dir/${path}.wiki") || die "can't open $out_dir/$path: $!"; |
70 |
print $out $content; |
71 |
close($out); |
72 |
} |