+
+my $mvs = WWW::Mediawiki::Client->new(
+ 'host' => 'www.freeside.biz',
+ 'wiki_path' => 'mediawiki/index.php',
+ 'username' => $mw_username,
+ 'password' => $mw_password,
+ #'commit_message' => 'import from POD'
+ );
+
+$mvs->do_login;
+
+my @files;
+if ( @ARGV ) {
+ @files = @ARGV;
+} else {
+ @files = (
+ glob("$site_perl/*.pm"),
+ glob("$site_perl/*/*.pm"),
+ glob("$site_perl/*/*/*.pm"),
+ glob("$site_perl/*/*/*/*.pm"),
+ glob("$site_perl/bin/*.pod"),
+ glob("./fs_selfservice/FS-SelfService/*.pm"),
+ glob("./fs_selfservice/FS-SelfService/*/*.pm"),
+ );
+
+}
+
+foreach my $file (@files) {
+ next if $file =~ /(^|\/)blib\//;
+ next if $file =~ /(^|\/)CVS\//;
+ #$file =~ /\/([\w\-]+)\.pm$/ or die "oops file $file";
+ my $name;
+ if ( $file =~ /fs_\w+\/FS\-\w+\/(.*)\.pm$/ ) {
+ $name = "FS/$1";
+ } elsif ( $file =~ /$site_perl\/(.*)\.(pm|pod)$/ ) {
+ $name = $1;
+ } else {
+ die "oops file $file";
+ }
+
+ #exit if $count++ == 10;
+
+ my $htmlroot = join('/', map '..',1..(scalar($file =~ tr/\///)-2)) || '.';
+
+ system "pod2wiki --style mediawiki $file >$html/$name.rawwiki";
+
+ if ( -e "$html/$name.rawwiki" ) {
+ print "processing $name\n";
+ } else {
+ print "skipping $name\n";
+ next;
+ };
+
+ $mvs->do_update("$html/$name.wiki");
+
+ open(RAW, "<$html/$name.rawwiki") or die $!;
+ open(WIKI,">$html/$name.wiki" ) or die $!;
+ while (<RAW>) {
+ s/\[\[([^#p][^\]]*)\]\]/"[[$html\/". w_e($1). "|$1]]"/ge;
+ print WIKI $_;
+ }
+ close RAW;
+ close WIKI;
+
+ print " uploading to ". $mvs->filename_to_pagename("$html/$name.wiki"). "\n";
+ $mvs->commit_message( 'import from POD' );
+ $mvs->do_commit("$html/$name.wiki");
+
+}
+
+sub w_e {
+ my $s = shift;
+ $s =~ s/_/ /g;
+ $s =~ s/::/\//g;
+ $s =~ s/^freeside-/bin\/freeside-/g;
+ $s;
+}
+
+
+## system "pod2text $file >$catman/$name.txt";
+##
+# system "pod2html --podroot=$site_perl --podpath=./FS:./FS/UI:.:./bin --norecurse --htmlroot=$htmlroot $file >$html/$name.html";
+# #system "pod2html --podroot=$site_perl --htmlroot=$htmlroot $file >$html/$name.html";
+## system "pod2html $file >$html/$name.html";
+##
+
+#remove the useless links
+unlink glob("$site_perl/bin/*.pod");
+