1 |
#!/usr/bin/perl |
2 |
use strict; |
3 |
use Getopt::Long; |
4 |
use lib qw<lib ../lib>; |
5 |
use BerkeleyDB; |
6 |
our $VERSION = do{my @r=(q$Revision: 1.1 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
7 |
|
8 |
my %opt = ( |
9 |
db => q<wikidata>, |
10 |
); |
11 |
GetOptions ( |
12 |
'database-dir=s' => \$opt{db}, |
13 |
'input-file=s' => \$opt{src}, |
14 |
'output-file=s' => \$opt{output}, |
15 |
); |
16 |
|
17 |
$opt{output} ||= $opt{db} . q</page/referer.db>; |
18 |
$opt{src} ||= $opt{db} . q</page/mt--52656665726572.dat>; |
19 |
|
20 |
print STDERR "Reading $opt{src}...\n"; |
21 |
open my $src, '<', $opt{src} or die "$0: $opt{src}: $!"; |
22 |
local $/ = undef; |
23 |
|
24 |
print STDERR "Output: $opt{output}\n"; |
25 |
require SuikaWiki::DB::Hash; |
26 |
my %db; |
27 |
my $out = new SuikaWiki::DB::Hash constructor => sub { |
28 |
tie %db, 'BerkeleyDB::Hash', |
29 |
-Filename => $opt{output}, |
30 |
-Flags => DB_CREATE, |
31 |
-Mode => 0644; |
32 |
\%db; |
33 |
}; |
34 |
|
35 |
my $source = scalar <$src>; |
36 |
$source =~ s!^\#\?SuikaWikiMetaInfo/0.9[^\x02]*\x02!!; |
37 |
|
38 |
my $i = 0; |
39 |
for my $old (map {[split /\x1F/, $_, 2]} split /\x1E/, $source) { |
40 |
my $page = [split m#//#, $old->[0]]; |
41 |
my %referer = map {split /\x09/, 2} split /\x0A/, $out->get ('referer', $page); |
42 |
my %newref = split /"/, $old->[1]; |
43 |
for (grep {$_} keys %newref) { |
44 |
$referer{$_} += $newref{$_} if $_ and $newref{$_}; |
45 |
} |
46 |
$out->set ('referer', $page |
47 |
=> join "\x0A", map {$_ . "\x09" . $referer{$_}} keys %referer); |
48 |
|
49 |
print STDERR '*' unless ++$i % 10; |
50 |
print STDERR "\n" unless $i % 500; |
51 |
} |
52 |
|
53 |
close $src; |
54 |
$out->close; |
55 |
|
56 |
print STDERR "\n"; |
57 |
|
58 |
=head1 NAME |
59 |
|
60 |
referer2to3.pl - SuikaWiki: Converting SuikaWiki 2 Referer Database into SuikaWiki 3 Referer Database |
61 |
|
62 |
=head1 SYNOPSIS |
63 |
|
64 |
referer2to3.pl [--database-dir=<dir>] [--input-file=<file>] [--output-file=<file>] |
65 |
|
66 |
=head1 DESCRIPTION |
67 |
|
68 |
C<referer2to3.pl> converts SuikaWiki 2 referer database into SuikaWiki 3 |
69 |
database. SuikaWiki 2 stores received HTTP Referer information |
70 |
into SuikaWikiMetaInfo/0.9 database in wiki database directory. |
71 |
Referer module of SuikaWiki 3 stores them, in default configuration, |
72 |
into BerkeleyDB with different sub-format, so convertion required |
73 |
to upgrade to SuikaWiki 3. |
74 |
|
75 |
This script is part of SuikaWiki. |
76 |
|
77 |
=head1 OPTIONS |
78 |
|
79 |
=over 4 |
80 |
|
81 |
=item --database-dir=I<database-dir> (Default: C<./wikidata>) |
82 |
|
83 |
Wiki database directory. This option only used when either |
84 |
C<--input-file> or C<--output-file> option is not specified. |
85 |
|
86 |
=item --input-file=I<file> (Default: C<I<database-dir>/page/mt--52656665726572.dat>) |
87 |
|
88 |
Source (SuikaWiki 2) referer database file. |
89 |
|
90 |
=item --output-file=I<file> (Default: C<I<database-dir>/page/referer.db>) |
91 |
|
92 |
New (SuikaWiki 3 BerkeleyDB) referer database file. |
93 |
|
94 |
=back |
95 |
|
96 |
=head1 SEE ALSO |
97 |
|
98 |
C<SuikaWiki::Plugin>, SuikaWiki:WikiPlugin |
99 |
<http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiPlugin>. |
100 |
|
101 |
=head1 LICENSE |
102 |
|
103 |
Copyright 2004 Wakaba <w@suika.fam.cx>. All rights reserved. |
104 |
|
105 |
This program is free software; you can redistribute it and/or |
106 |
modify it under the same terms as Perl itself. |
107 |
|
108 |
=cut |
109 |
|
110 |
1; # $Date: 2004/03/11 04:04:06 $ |