#!/usr/bin/perl use strict; use Getopt::Long; use lib qw; use BerkeleyDB; our $VERSION = do{my @r=(q$Revision: 1.2 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; my %opt = ( db => q, ); GetOptions ( 'database-dir=s' => \$opt{db}, 'input-file=s' => \$opt{src}, 'output-file=s' => \$opt{output}, ); $opt{output} ||= $opt{db} . q; $opt{src} ||= $opt{db} . q; print STDERR "Reading $opt{src}...\n"; open my $src, '<', $opt{src} or die "$0: $opt{src}: $!"; local $/ = undef; print STDERR "Output: $opt{output}\n"; require SuikaWiki::DB::Hash; my %db; my $out = new SuikaWiki::DB::Hash constructor => sub { tie %db, 'BerkeleyDB::Hash', -Filename => $opt{output}, -Flags => DB_CREATE, -Mode => 0644; \%db; }; my $source = scalar <$src>; $source =~ s!^\#\?SuikaWikiMetaInfo/0.9[^\x02]*\x02!!; my $i = 0; for my $old (map {[split /\x1F/, $_, 2]} split /\x1E/, $source) { my $page = [split m#//#, $old->[0]]; my %referer = map {split /\x09/, 2} split /\x0A/, $out->get ('referer', $page); my %newref = split /"/, $old->[1]; for (grep {$_} keys %newref) { $referer{$_} += $newref{$_} if $_ and $newref{$_}; } $out->set ('referer', $page => join "\x0A", map {$_ . "\x09" . $referer{$_}} keys %referer); print STDERR '*' unless ++$i % 10; print STDERR "\n" unless $i % 500; } close $src; $out->close; print STDERR "\n"; =head1 NAME referer2to3.pl - SuikaWiki: Converting SuikaWiki 2 Referer Database into SuikaWiki 3 Referer Database =head1 SYNOPSIS referer2to3.pl [--database-dir=] [--input-file=] [--output-file=] =head1 DESCRIPTION C converts SuikaWiki 2 referer database into SuikaWiki 3 database. SuikaWiki 2 stores received HTTP Referer information into SuikaWikiMetaInfo/0.9 database in wiki database directory. Referer module of SuikaWiki 3 stores them, in default configuration, into BerkeleyDB with different sub-format, so convertion required to upgrade to SuikaWiki 3. This script is part of SuikaWiki. =head1 OPTIONS =over 4 =item --database-dir=I (Default: C<./wikidata>) Wiki database directory. This option only used when either C<--input-file> or C<--output-file> option is not specified. =item --input-file=I (Default: C/page/mt--52656665726572.dat>) Source (SuikaWiki 2) referer database file. =item --output-file=I (Default: C/page/referer.db>) New (SuikaWiki 3 BerkeleyDB) referer database file. =back =head1 SEE ALSO C, SuikaWiki:WikiPlugin . =head1 LICENSE Copyright 2004 Wakaba . All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # $Date: 2004/03/11 08:06:26 $