1 |
dpavlin |
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 |
dpavlin |
2 |
|
40 |
|
|
# markup |
41 |
dpavlin |
1 |
$content =~ s!''(.*?)''!/$1/!mg; |
42 |
|
|
$content =~ s!__(.*?)__!*$1*!mg; |
43 |
|
|
|
44 |
dpavlin |
2 |
# links to url |
45 |
dpavlin |
1 |
$content =~ s!\[\s*(.+?)\s*[\s\|]\s*((http://|mailto:)\S+)\s*\]!"$1"<$2>!mg; |
46 |
|
|
$content =~ s!\[\s*(http://\S+)\s*[\s\|]\s*(.+?)\s*\]!"$2"<$1>!mg; |
47 |
|
|
|
48 |
dpavlin |
2 |
# page links with names |
49 |
|
|
$content =~ s!\[\s*([\w\s]+)\s*\|\s*(\w+)\s*\]!"$1"[$2]!mg; |
50 |
|
|
|
51 |
dpavlin |
1 |
my $seen; |
52 |
|
|
my $out; |
53 |
|
|
foreach (split(/[\n\r]/, $content)) { |
54 |
|
|
if ( |
55 |
|
|
( ! /^\s+/ && $seen->{space} ) # end of space preformat |
56 |
|
|
|| |
57 |
|
|
( /^\s+\S+/ && ! $seen->{space} ) # begin of space preformat |
58 |
|
|
) { |
59 |
|
|
|
60 |
|
|
$out .= ".pre\n"; |
61 |
|
|
$seen->{space} = not $seen->{space}; |
62 |
|
|
} |
63 |
|
|
$out .= "$_\n"; |
64 |
|
|
} |
65 |
|
|
|
66 |
|
|
$out .= ".pre\n" if ($seen->{space}); |
67 |
|
|
|
68 |
|
|
$content = $out; |
69 |
|
|
|
70 |
|
|
$content =~ s/\.pre[\n\r]+\.pre//sg; |
71 |
|
|
|
72 |
|
|
$content .= "\n----\nLast modified $last_change by $author\n"; |
73 |
|
|
|
74 |
|
|
open(my $out, '>', "$st_dir/${path}.wiki") || die "can't open $out_dir/$path: $!"; |
75 |
|
|
print $out $content; |
76 |
|
|
close($out); |
77 |
|
|
} |