/[socialtext-import]/phpwiki/phpwiki-dump.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /phpwiki/phpwiki-dump.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Mon Nov 20 18:43:09 2006 UTC (17 years, 4 months ago) by dpavlin
File MIME type: text/plain
File size: 1850 byte(s)
fix pages with names

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 # markup
41 $content =~ s!''(.*?)''!/$1/!mg;
42 $content =~ s!__(.*?)__!*$1*!mg;
43
44 # links to url
45 $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 # page links with names
49 $content =~ s!\[\s*([\w\s]+)\s*\|\s*(\w+)\s*\]!"$1"[$2]!mg;
50
51 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 }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26