4a3e800d8f734f0cfba9b8d532cd991f5bbf2faa
[freeside.git] / bin / pod2x
1 #!/usr/bin/perl -w
2
3 use strict;
4 use WWW::Mediawiki::Client;
5 #sub WWW::Mediawiki::Client::pagename_to_url {
6 #    my ($self, $name, $action) = @_;
7 #    WWW::Mediawiki::Client::URLConstructionException->throw(
8 #            error => 'No action supplied.',
9 #        ) unless $action;
10 #    WWW::Mediawiki::Client::URLConstructionException->throw(
11 #            error => "Page name $name ends with '.wiki'.",
12 #        ) if $name =~ /.wiki$/;
13 #    my $char = $self->space_substitute;
14 #    $name =~ s/ /$char/;
15 #    my $lang = $self->language_code;
16 #    my $host = $self->host;
17 #    $host =~ s/__LANG__/$lang/g;
18 #    my $wiki_path = $self->wiki_path;
19 #    $wiki_path =~ s/__LANG__/$lang/g;
20 #    my $protocol = $self->protocol;
21 #    return "$protocol://$host/$wiki_path?" . ACTION . "=$action&" . TITLE . "=$name" . '&wpRecreate=1';
22 #}
23
24 my $mw_username = 'ivan';
25 chomp( my $mw_password = `cat .mw-password` );
26
27 my $site_perl = "./FS";
28 #my $html = "Freeside:1.7:Documentation:Developer";
29 my $html = "Freeside:1.9:Documentation:Developer";
30
31 foreach my $dir (
32   $html,
33   map "$html/$_", qw( bin FS FS/UI FS/part_export FS/part_pkg
34                       FS/part_event FS/part_event/Condition FS/part_event/Action
35                       FS/ClientAPI FS/Cron FS/Misc FS/Report FS/Report/Table
36                       FS/TicketSystem FS/UI
37                     )
38 ) {
39   -d $dir or mkdir $dir;
40 }
41
42 $|=1;
43
44 die "Can't find $site_perl" unless -d $site_perl;
45 #die "Can't find $catman" unless -d $catman;
46 -d $html or mkdir $html;
47
48 my $count = 0;
49
50 #make some useless links
51 foreach my $file (
52   glob("$site_perl/bin/freeside-*"),
53 ) {
54   next if $file =~ /\.pod$/;
55   #symlink $file, "$file.pod"; # or die "link $file to $file.pod: $!";
56   #system("cp $file $file.pod");
57   -e "$file.pod" or system("cp $file $file.pod");
58 }
59
60 my $mvs = WWW::Mediawiki::Client->new(
61             'host'           => 'www.sisd.com',
62             'wiki_path'      => 'mediawiki/index.php',
63             'username'       => $mw_username,
64             'password'       => $mw_password,
65             #'commit_message' => 'import from POD'
66           );
67
68 $mvs->do_login;
69
70 foreach my $file (
71   glob("$site_perl/*.pm"),
72   glob("$site_perl/*/*.pm"),
73   glob("$site_perl/*/*/*.pm"),
74   glob("$site_perl/*/*/*/*.pm"),
75   glob("$site_perl/bin/*.pod"),
76   glob("./fs_selfservice/FS-SelfService/*.pm"),
77   glob("./fs_selfservice/FS-SelfService/*/*.pm"),
78 ) {
79   next if $file =~ /(^|\/)blib\//;
80   next if $file =~ /(^|\/)CVS\//;
81   #$file =~ /\/([\w\-]+)\.pm$/ or die "oops file $file";
82   my $name;
83   if ( $file =~ /fs_\w+\/FS\-\w+\/(.*)\.pm$/ ) {
84     $name = "FS/$1";
85   } elsif ( $file =~ /$site_perl\/(.*)\.(pm|pod)$/ ) {
86     $name = $1;
87   } else {
88     die "oops file $file";
89   }
90
91   #exit if $count++ == 10;
92
93   my $htmlroot = join('/', map '..',1..(scalar($file =~ tr/\///)-2)) || '.';
94
95   system "pod2wiki  --style mediawiki $file >$html/$name.rawwiki";
96
97   if ( -e "$html/$name.rawwiki" ) {
98     print "processing $name\n";
99   } else {
100     print "skipping $name\n";
101     next;
102   };
103
104   $mvs->do_update("$html/$name.wiki");
105
106   open(RAW, "<$html/$name.rawwiki") or die $!;
107   open(WIKI,">$html/$name.wiki"   ) or die $!;
108   while (<RAW>) {
109     s/\[\[([^#][^\]]*)\]\]/"[[$html\/". w_e($1). "|$1]]"/ge;
110     print WIKI $_;
111   }
112   close RAW;
113   close WIKI;
114
115   print "  uploading to ". $mvs->filename_to_pagename("$html/$name.wiki"). "\n";
116   $mvs->commit_message( 'import from POD' );
117   $mvs->do_commit("$html/$name.wiki");
118
119 }
120
121 sub w_e {
122   my $s = shift;
123   $s =~ s/_/ /g;
124   $s =~ s/::/\//g;
125   $s =~ s/^freeside-/bin\/freeside-/g;
126   $s;
127 }
128
129
130 ##  system "pod2text $file >$catman/$name.txt"; 
131 ##
132 #  system "pod2html --podroot=$site_perl --podpath=./FS:./FS/UI:.:./bin --norecurse --htmlroot=$htmlroot $file >$html/$name.html";
133 #  #system "pod2html --podroot=$site_perl --htmlroot=$htmlroot $file >$html/$name.html";
134 ##  system "pod2html $file >$html/$name.html";
135 ##
136
137 #remove the useless links
138 unlink glob("$site_perl/bin/*.pod");
139