update pod2x to use Mediawiki module instead of WWW:::Mediawiki::Client. whew, that...
[freeside.git] / bin / pod2x
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my $mw_username = 'ivan';
6 chomp( my $mw_password = `cat .mw-password` );
7
8 my $site_perl = "./FS";
9 #my $html = "Freeside:1.7:Documentation:Developer";
10 my $html = "Freeside:1.9:Documentation:Developer";
11
12 foreach my $dir (
13   $html,
14   map "$html/$_", qw( bin FS FS/UI FS/part_export FS/part_pkg
15                       FS/part_event FS/part_event/Condition FS/part_event/Action
16                       FS/ClientAPI FS/Cron FS/Misc FS/Report FS/Report/Table
17                       FS/TicketSystem FS/UI
18                       FS/SelfService
19                     )
20 ) {
21   -d $dir or mkdir $dir;
22 }
23
24 $|=1;
25
26 die "Can't find $site_perl" unless -d $site_perl;
27 #die "Can't find $catman" unless -d $catman;
28 -d $html or mkdir $html;
29
30 my $count = 0;
31
32 #make some useless links
33 foreach my $file (
34   glob("$site_perl/bin/freeside-*"),
35 ) {
36   next if $file =~ /\.pod$/;
37   #symlink $file, "$file.pod"; # or die "link $file to $file.pod: $!";
38   #system("cp $file $file.pod");
39   -e "$file.pod" or system("cp $file $file.pod");
40 }
41
42 #just for filename_to_pagename for now
43 use WWW::Mediawiki::Client;
44 my $mvs = WWW::Mediawiki::Client->new(
45             'host'           => 'www.freeside.biz',
46             'wiki_path'      => 'mediawiki/index.php',
47             'username'       => $mw_username,
48             'password'       => $mw_password,
49             #'commit_message' => 'import from POD'
50           );
51 #$mvs->do_login;
52
53 use MediaWiki;
54
55 my $c = MediaWiki->new;
56 # $is_ok = $c->setup("config.ini");
57 $c->setup({
58   'bot' => { 'user' => $mw_username, 'pass' => $mw_password },
59   'wiki' => {
60     'host' => 'www.freeside.biz',
61     'path' => 'mediawiki',
62   }
63 }) or die "Mediawiki->setup failed";
64
65 #Also, the 'wiki' section may specify the 'ssl' key (boolean 0/1) if the server uses an SSL connection. Section 'tmp' and key 'msgcache' specify path to the MediaWiki messages cache.
66 #Options 'has_query' and 'has_filepath' in 'wiki' section enable experimental optimized interfaces. Set has_query to 1 if there is query.php extension (this should reduce traffic usage and servers load). Set has_filepath to 1 if there is Special:Filepath page in target wiki (affects only filepath() and download() functions).
67
68 my @files;
69 if ( @ARGV ) {
70   @files = @ARGV;
71 } else {
72   @files = (
73     glob("$site_perl/*.pm"),
74     glob("$site_perl/*/*.pm"),
75     glob("$site_perl/*/*/*.pm"),
76     glob("$site_perl/*/*/*/*.pm"),
77     glob("$site_perl/bin/*.pod"),
78     glob("./fs_selfservice/FS-SelfService/*.pm"),
79     glob("./fs_selfservice/FS-SelfService/*/*.pm"),
80   );
81
82 }
83
84 foreach my $file (@files) {
85   next if $file =~ /(^|\/)blib\//;
86   next if $file =~ /(^|\/)CVS\//;
87   #$file =~ /\/([\w\-]+)\.pm$/ or die "oops file $file";
88   my $name;
89   if ( $file =~ /fs_\w+\/FS\-\w+\/(.*)\.pm$/ ) {
90     $name = "FS/$1";
91   } elsif ( $file =~ /$site_perl\/(.*)\.(pm|pod)$/ ) {
92     $name = $1;
93   } else {
94     die "oops file $file";
95   }
96
97   #exit if $count++ == 10;
98
99   my $htmlroot = join('/', map '..',1..(scalar($file =~ tr/\///)-2)) || '.';
100
101   system "pod2wiki  --style mediawiki $file >$html/$name.rawwiki";
102
103   if ( -e "$html/$name.rawwiki" ) {
104     print "processing $name\n";
105   } else {
106     print "skipping $name\n";
107     next;
108   };
109
110 #  $mvs->do_update("$html/$name.wiki");
111
112
113   my $text = '';
114   open(RAW, "<$html/$name.rawwiki") or die $!;
115   while (<RAW>) {
116     s/\[\[([^#p][^\]]*)\]\]/"[[$html\/". w_e($1). "|$1]]"/ge;
117     $text .= $_;
118   }
119   close RAW;
120
121   my $pagename = $mvs->filename_to_pagename("$html/$name.wiki");
122   #print " uploading to $pagename\n";
123
124   $c->text( $pagename, $text );
125
126 }
127
128 sub w_e {
129   my $s = shift;
130   $s =~ s/_/ /g;
131   $s =~ s/::/\//g;
132   $s =~ s/^freeside-/bin\/freeside-/g;
133   $s;
134 }
135
136
137 ##  system "pod2text $file >$catman/$name.txt"; 
138 ##
139 #  system "pod2html --podroot=$site_perl --podpath=./FS:./FS/UI:.:./bin --norecurse --htmlroot=$htmlroot $file >$html/$name.html";
140 #  #system "pod2html --podroot=$site_perl --htmlroot=$htmlroot $file >$html/$name.html";
141 ##  system "pod2html $file >$html/$name.html";
142 ##
143
144 #remove the useless links
145 unlink glob("$site_perl/bin/*.pod");
146