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.2 $=~/\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-dir=s' => \$opt{output}, |
15 |
); |
16 |
|
17 |
$opt{output} ||= $opt{db} . q</page/>; |
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::FileSystem::Count; |
26 |
my $out = SuikaWiki::DB::FileSystem::Count->new |
27 |
(base_directory => $opt{output}, |
28 |
directory_suffix => '.ns', |
29 |
file_suffix => '.ref', |
30 |
auto_mkdir => 1); |
31 |
|
32 |
my $source = scalar <$src>; |
33 |
$source =~ s!^\#\?SuikaWikiMetaInfo/0.9[^\x02]*\x02!!; |
34 |
|
35 |
my $i = 0; |
36 |
for my $old (map {[split /\x1F/, $_, 2]} split /\x1E/, $source) { |
37 |
my $page = [split m#//#, $old->[0]]; |
38 |
my $referer = $out->get ('referer', $page); |
39 |
my %newref = split /"/, $old->[1]; |
40 |
for (grep {$_} keys %newref) { |
41 |
$referer->{$_} += $newref{$_} if $_ and $newref{$_}; |
42 |
} |
43 |
$out->set ('referer', $page => $referer); |
44 |
|
45 |
print STDERR '*' unless ++$i % 10; |
46 |
print STDERR "\n" unless $i % 500; |
47 |
} |
48 |
|
49 |
close $src; |
50 |
$out->close; |
51 |
|
52 |
print STDERR "\n"; |
53 |
|
54 |
=head1 NAME |
55 |
|
56 |
referer2to3.pl - SuikaWiki: Converting SuikaWiki 2 Referer Database into SuikaWiki 3 Referer Database |
57 |
|
58 |
=head1 SYNOPSIS |
59 |
|
60 |
referer2to3.pl [--database-dir=<dir>] [--input-file=<file>] [--output-dir=<dir>] |
61 |
|
62 |
=head1 DESCRIPTION |
63 |
|
64 |
C<referer2to3.pl> converts SuikaWiki 2 referer database into SuikaWiki 3 |
65 |
database. SuikaWiki 2 stores received HTTP Referer information |
66 |
into SuikaWikiMetaInfo/0.9 database in wiki database directory. |
67 |
Referer module of SuikaWiki 3 stores them, in default configuration, |
68 |
into BerkeleyDB with different sub-format, so convertion required |
69 |
to upgrade to SuikaWiki 3. |
70 |
|
71 |
This script is part of SuikaWiki. |
72 |
|
73 |
=head1 OPTIONS |
74 |
|
75 |
=over 4 |
76 |
|
77 |
=item --database-dir=I<database-dir> (Default: C<./wikidata>) |
78 |
|
79 |
Wiki database directory. This option only used when either |
80 |
C<--input-file> or C<--output-file> option is not specified. |
81 |
|
82 |
=item --input-file=I<file> (Default: C<I<database-dir>/page/mt--52656665726572.dat>) |
83 |
|
84 |
Source (SuikaWiki 2) referer database file. |
85 |
|
86 |
=item --output-dir=I<dir> (Default: C<I<database-dir>/page/>) |
87 |
|
88 |
New (SuikaWiki 3 BerkeleyDB) referer database directory. |
89 |
|
90 |
=back |
91 |
|
92 |
=head1 SEE ALSO |
93 |
|
94 |
C<SuikaWiki::Plugin>, SuikaWiki:WikiPlugin |
95 |
<http://suika.fam.cx/~wakaba/-temp/wiki/wiki?WikiPlugin>. |
96 |
|
97 |
=head1 LICENSE |
98 |
|
99 |
Copyright 2004 Wakaba <w@suika.fam.cx>. All rights reserved. |
100 |
|
101 |
This program is free software; you can redistribute it and/or |
102 |
modify it under the same terms as Perl itself. |
103 |
|
104 |
=cut |
105 |
|
106 |
1; # $Date: 2004/03/11 08:06:26 $ |