summaryrefslogtreecommitdiff
path: root/upload-wiki.pl
diff options
context:
space:
mode:
authorDennis Roczek <dennisroczek@libreoffice.org>2015-06-09 03:54:20 +0200
committerAdolfo Jayme Barrientos <fitojb@ubuntu.com>2015-07-07 14:48:16 +0000
commitf36f2883973e4ba6d59ee8d0d9b3e98273aa1c44 (patch)
treede214e2dff0e4c45c35920f639d8fe362b3f3976 /upload-wiki.pl
parent5aad108719014b52c9aba6be407ed553d0095a66 (diff)
improving upload script
Change-Id: I8f7bc5973f988af29b0a07ad3ac066f93bebe5e6 Reviewed-on: https://gerrit.libreoffice.org/16198 Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com> Tested-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Diffstat (limited to 'upload-wiki.pl')
-rwxr-xr-xupload-wiki.pl51
1 files changed, 41 insertions, 10 deletions
diff --git a/upload-wiki.pl b/upload-wiki.pl
index a42d809342..f49c7393c2 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";
+ }
}
}