summaryrefslogtreecommitdiff
path: root/helpcontent2/upload-wiki.pl
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2010-11-26 10:05:54 +0100
committerJan Holesovsky <kendy@suse.cz>2010-11-26 10:05:54 +0100
commit5e07f686b79957baef3fa979c7ec2730878ef9a8 (patch)
tree5567d7f7dc994fbf1c8dcc915ecb9c55a730dd11 /helpcontent2/upload-wiki.pl
parent3d16ea3ade84c9940269ece9f5321b46059d60ca (diff)
wikihelp: upload-wiki.pl, tool to publish the generated wiki.
Diffstat (limited to 'helpcontent2/upload-wiki.pl')
-rwxr-xr-xhelpcontent2/upload-wiki.pl75
1 files changed, 75 insertions, 0 deletions
diff --git a/helpcontent2/upload-wiki.pl b/helpcontent2/upload-wiki.pl
new file mode 100755
index 000000000..1531b216e
--- /dev/null
+++ b/helpcontent2/upload-wiki.pl
@@ -0,0 +1,75 @@
+#!/usr/bin/perl -w
+
+use MediaWiki::API;
+use File::Find();
+use File::Slurp;
+
+# help
+sub usage {
+ print <<EOM;
+upload-wiki.pl - Uploads the wiki/ subdir to a real wiki installation.
+
+You need a wikisetup.txt in this directory, to be able to authentificate you.
+The content should be:
+
+wiki=<url of the api.php on the wiki>
+name=<the user name>
+password=<the appropriate password>
+
+EOM
+ exit 1;
+}
+
+# first of all, read the configuration from wikisetup.txt
+my ( $url, $name, $password );
+open( IN, "wikisetup.txt" ) || usage();
+while ( my $line = <IN> ) {
+ if ( $line =~ /^([^=]*)=(.*)$/ ) {
+ my $k = $1;
+ my $v = $2;
+ chomp $k;
+ chomp $v;
+ if ( $k eq 'wiki' ) {
+ $url = $v;
+ }
+ elsif ( $k eq 'name' ) {
+ $name = $v;
+ }
+ elsif ( $k eq 'password' ) {
+ $password = $v;
+ }
+ }
+}
+close( IN );
+
+if ( !defined( $url ) || !defined( $name ) || !defined( $password ) ) {
+ usage();
+}
+
+# initialize the wiki
+my $mw = MediaWiki::API->new();
+$mw->{config}->{api_url} = $url;
+
+# log in to the wiki
+$mw->login( { lgname => $name, lgpassword => $password } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
+
+# upload the articles
+sub upload_article {
+ -f || return;
+
+ my $pagename = $File::Find::name;
+ $pagename =~ s/^wiki\///;
+ my $text = read_file( $_ );
+
+ print "Uploading '$pagename'\n";
+ $mw->edit( {
+ action => 'edit',
+ title => $pagename,
+ text => $text } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
+}
+File::Find::find( {wanted => \&upload_article}, 'wiki/' );
+
+# clean up
+$mw->logout();
+
+# vim:set shiftwidth=4 softtabstop=4 expandtab: