From 5e07f686b79957baef3fa979c7ec2730878ef9a8 Mon Sep 17 00:00:00 2001 From: Jan Holesovsky Date: Fri, 26 Nov 2010 10:05:54 +0100 Subject: wikihelp: upload-wiki.pl, tool to publish the generated wiki. --- helpcontent2/.gitignore | 1 + helpcontent2/upload-wiki.pl | 75 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 helpcontent2/.gitignore create mode 100755 helpcontent2/upload-wiki.pl (limited to 'helpcontent2') diff --git a/helpcontent2/.gitignore b/helpcontent2/.gitignore new file mode 100644 index 0000000000..0ff7b08b34 --- /dev/null +++ b/helpcontent2/.gitignore @@ -0,0 +1 @@ +/wikisetup.txt diff --git a/helpcontent2/upload-wiki.pl b/helpcontent2/upload-wiki.pl new file mode 100755 index 0000000000..1531b216e1 --- /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 < +name= +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 = ) { + 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: -- cgit