[Libreoffice-commits] help.git: upload-wiki.pl

Dennis Roczek dennisroczek at libreoffice.org
Tue Jul 7 07:48:46 PDT 2015


 upload-wiki.pl |   51 +++++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 41 insertions(+), 10 deletions(-)

New commits:
commit f36f2883973e4ba6d59ee8d0d9b3e98273aa1c44
Author: Dennis Roczek <dennisroczek at libreoffice.org>
Date:   Tue Jun 9 03:54:20 2015 +0200

    improving upload script
    
    Change-Id: I8f7bc5973f988af29b0a07ad3ac066f93bebe5e6
    Reviewed-on: https://gerrit.libreoffice.org/16198
    Reviewed-by: Adolfo Jayme Barrientos <fitojb at ubuntu.com>
    Tested-by: Adolfo Jayme Barrientos <fitojb at ubuntu.com>

diff --git a/upload-wiki.pl b/upload-wiki.pl
index a42d809..f49c739 100755
--- a/upload-wiki.pl
+++ b/upload-wiki.pl
@@ -11,6 +11,7 @@ use MediaWiki::API;
 use File::Find();
 use File::Slurp;
 use Getopt::Std;
+use Digest::SHA1 qw(sha1 sha1_hex sha1_base64);
 
 # help
 sub usage {
@@ -153,9 +154,12 @@ File::Find::find( {wanted => \&upload_article}, 'wiki/' );
 # upload the images
 if ( $upload_images ) {
     open( IN, "images.txt" ) || usage();
+    my $imagename = '';
+    my $imageuploadmsg = '';
+    my $image = '';    
     while ( my $line = <IN> ) {
         chomp( $line );
-        $fname = "images/$line";
+        my $fname = "images/$line";
         if ( ! -f $fname ) {
             print "Image '$fname' not found, skipped.\n";
             next;
@@ -163,19 +167,46 @@ if ( $upload_images ) {
         if ( ! $fname =~ /\.(png|gif|jpg|jpeg)$/ ) {
             print "Image '$line' ignored, not a jpg/png/gif.\n";
             next;
-        }
-
-        my $imagename = $line;
+        }        
+        
+        $imagename = $line;
         if ( $line =~ /\/([^\/]*)$/ ) {
             $imagename = $1;
         }
-        my $image = read_file( $fname );
-
-        print "Uploading image '$imagename'\n";
-        $mw->upload( {
-                title => $imagename,
-                summary => 'Initial upload.',
+        sub upload_file_to_mw {
+            $mw->upload( {
+                title => 'File:'.$imagename,
+                summary => $imageuploadmsg,
                 data => $image } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details};
+        }
+        
+        $image = read_file( $fname );
+
+        # don't reupload an image if it is already present - otherwise it only bloats the wiki
+        my $imagesha1 = sha1_hex($image);
+        # get the sha1 request directly from the wiki
+        my $mwquery = $mw->api( {
+            action => 'query',
+            prop => 'imageinfo',
+            iiprop => 'sha1',
+            titles => 'File:'.$imagename } );        
+        my $mwimagesha1 = "";
+        #FIXME: bad style, this foreach should konsist only ONE imageid --> do that nicelier
+        foreach my $imageid (keys $mwquery->{'query'}{'pages'}) {
+            $mwimagesha1 = $mwquery->{'query'}{'pages'}{$imageid}{'imageinfo'}->[0]->{'sha1'};
+        }
+        
+        if (($imagesha1 ne $mwimagesha1) and ($mwimagesha1 ne '')) {
+            print "Updating image '$imagename', sha1 is different from already uploaded image.\n";
+            $imageuploadmsg = 'Updating image.';
+            upload_file_to_mw();
+        } elsif ($mwimagesha1 eq '') {
+            print "Initial upload of  image '$imagename'\n";
+            $imageuploadmsg = 'Initial upload.';
+            upload_file_to_mw();
+        } else {
+            print "Skipping image '$imagename', sha1 identially to already uploaded image.\n";
+        }
     }
 }
 


More information about the Libreoffice-commits mailing list