summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@suse.cz>2010-12-03 13:33:28 +0100
committerJan Holesovsky <kendy@suse.cz>2010-12-03 13:33:28 +0100
commit15b1b660a11a0f2d05341e1181d93f89c21add18 (patch)
treedc6b5137654ee0954115d369bda2a5b29e9e43c1
parent28f9f37cce7fef09df98d9cdd30e2328777607d1 (diff)
wikihelp: Uploading of images.
-rwxr-xr-xhelpcontent2/to-wiki/wikiconv2.py28
-rwxr-xr-xhelpcontent2/upload-wiki.pl64
2 files changed, 83 insertions, 9 deletions
diff --git a/helpcontent2/to-wiki/wikiconv2.py b/helpcontent2/to-wiki/wikiconv2.py
index fa191484c1..8dbb5bb132 100755
--- a/helpcontent2/to-wiki/wikiconv2.py
+++ b/helpcontent2/to-wiki/wikiconv2.py
@@ -20,6 +20,9 @@ hid_lst = {}
# names
redirects = []
+# to collect images that we will up-load later
+images = set()
+
# list of elements that we can directly convert to wiki text
replace_element = \
{'start':{'br': '<br/>',
@@ -424,7 +427,11 @@ class Image(ElementBase):
self.alttext = self.alttext + data
def get_all(self):
- wikitext = "[[Image:"+self.src+"|border|"+self.align+"|"
+ global images
+ images.add(self.src)
+
+ name = self.src[self.src.rfind('/') + 1:]
+ wikitext = "[[Image:"+name+"|border|"+self.align+"|"
if len(self.width):
wikitext = wikitext + self.width+"x"+self.height+"|"
wikitext = wikitext + self.alttext+"]]"
@@ -1084,11 +1091,22 @@ for title in titles:
time.sleep(0.1)
+# set of the images used here
+print 'Writing the collection of images to "images.txt"...'
+file = open('images.txt', "w")
+for image in images:
+ file.write('%s\n'% image)
+file.close()
+
# generate the redirects
-print "Generating the redirects..."
+print 'Generating the redirects...'
for redir in redirects:
- file = open('wiki/%s'% redir[0], "w")
- file.write('#REDIRECT [[%s]]\n'% redir[1])
- file.close()
+ fname = 'wiki/%s'% redir[0]
+ try:
+ file = open(fname, "w")
+ file.write('#REDIRECT [[%s]]\n'% redir[1])
+ file.close()
+ except:
+ sys.stderr.write('Unable to write "%s".\n'%'wiki/%s'% fname)
# vim:set shiftwidth=4 softtabstop=4 expandtab:
diff --git a/helpcontent2/upload-wiki.pl b/helpcontent2/upload-wiki.pl
index 1531b216e1..74861a8436 100755
--- a/helpcontent2/upload-wiki.pl
+++ b/helpcontent2/upload-wiki.pl
@@ -13,16 +13,30 @@ 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>
+upload=<url of the Special:Upload page>
name=<the user name>
password=<the appropriate password>
+upload-wiki.pl operates on the output of help-to-wiki.py, needing particularly
+these:
+
+wiki/ - directory with all the pages generated out of the help .xhp files
+images.txt - list of the images used in help
+
+Additionally you need:
+
+images/ - directory with an unpack of images_tango.zip
+
EOM
exit 1;
}
# first of all, read the configuration from wikisetup.txt
-my ( $url, $name, $password );
-open( IN, "wikisetup.txt" ) || usage();
+my ( $url, $upload_url, $name, $password );
+if ( ! open( IN, "wikisetup.txt" ) ) {
+ print "Missing wikisetup.txt\n\n";
+ usage();
+}
while ( my $line = <IN> ) {
if ( $line =~ /^([^=]*)=(.*)$/ ) {
my $k = $1;
@@ -32,6 +46,9 @@ while ( my $line = <IN> ) {
if ( $k eq 'wiki' ) {
$url = $v;
}
+ elsif ( $k eq 'upload' ) {
+ $upload_url = $v;
+ }
elsif ( $k eq 'name' ) {
$name = $v;
}
@@ -42,13 +59,25 @@ while ( my $line = <IN> ) {
}
close( IN );
-if ( !defined( $url ) || !defined( $name ) || !defined( $password ) ) {
+if ( !defined( $url ) || !defined( $upload_url ) || !defined( $name ) || !defined( $password ) ) {
+ print "wikisetup.txt does not contain all the info.\n\n";
+ usage();
+}
+
+if ( ! -d 'wiki' || ! -f 'images.txt' ) {
+ print "Missing the wiki/ subdir or images.txt, re-run help-to-wiki.py.\n\n";
+ usage();
+}
+
+if ( ! -d 'images' ) {
+ print "Missing images/ subdir - mkdir images ; cd images ; unzip /path/to/images_tango.zip\n\n";
usage();
}
# initialize the wiki
my $mw = MediaWiki::API->new();
$mw->{config}->{api_url} = $url;
+$mw->{config}->{upload_url} = $upload_url;
# log in to the wiki
$mw->login( { lgname => $name, lgpassword => $password } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
@@ -61,7 +90,7 @@ sub upload_article {
$pagename =~ s/^wiki\///;
my $text = read_file( $_ );
- print "Uploading '$pagename'\n";
+ print "Uploading page '$pagename'\n";
$mw->edit( {
action => 'edit',
title => $pagename,
@@ -69,6 +98,33 @@ sub upload_article {
}
File::Find::find( {wanted => \&upload_article}, 'wiki/' );
+# upload the images
+open( IN, "images.txt" ) || usage();
+while ( my $line = <IN> ) {
+ chomp( $line );
+ $fname = "images/$line";
+ if ( ! -f $fname ) {
+ print "Image '$fname' not found, skipped.\n";
+ next;
+ }
+ if ( ! $fname =~ /\.(png|gif|jpg|jpeg)$/ ) {
+ print "Image '$line' ignored, not a jpg/png/gif.\n";
+ next;
+ }
+
+ my $imagename = $line;
+ if ( $line =~ /\/([^\/]*)$/ ) {
+ $imagename = $1;
+ }
+ my $image = read_file( $fname );
+
+ print "Uploading image '$imagename'\n";
+ $mw->upload( {
+ title => $imagename,
+ summary => 'Initial upload.',
+ data => $image } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
+}
+
# clean up
$mw->logout();