1 Subject: [PATCH] git-remote-mediawiki: skip not found media
3 When fetching media, if a suitable revision of an image for a page
4 cannot be found using an imageinfo query, it's skipped without
7 Provide the same behavior when actually fetching the image if the
8 result of the fetch is an HTTP 404 (not found) or 403 (Forbidden)
11 HTTP result codes other than 403 and 404 will continue to abort the
12 fetch in the same manner as they have done before.
14 Signed-off-by: Kyle J. McKay <mackyle@gmail.com>
17 contrib/mw-to-git/git-remote-mediawiki.perl | 12 +++++++-----
18 1 file changed, 7 insertions(+), 5 deletions(-)
20 diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
21 index a6657140..32ed2706 100755
22 --- a/contrib/mw-to-git/git-remote-mediawiki.perl
23 +++ b/contrib/mw-to-git/git-remote-mediawiki.perl
24 @@ -494,14 +494,15 @@ sub get_mw_mediafile_for_page_revision {
25 # If not defined it means there is no revision of the file for
27 if (defined($file->{imageinfo})) {
28 - $mediafile{title} = $filename;
30 my $fileinfo = pop(@{$file->{imageinfo}});
31 - $mediafile{timestamp} = $fileinfo->{timestamp};
32 # Mediawiki::API's download function doesn't support https URLs
33 # and can't download old versions of files.
34 - print {*STDERR} "\tDownloading file $mediafile{title}, version $mediafile{timestamp}\n";
35 - $mediafile{content} = download_mw_mediafile($fileinfo->{url});
36 + print {*STDERR} "\tDownloading file $filename, version $$fileinfo{timestamp}\n";
37 + if (defined(my $mediacontent = download_mw_mediafile($fileinfo->{url}))) {
38 + $mediafile{title} = $filename;
39 + $mediafile{timestamp} = $fileinfo->{timestamp};
40 + $mediafile{content} = $mediacontent;
45 @@ -521,6 +522,7 @@ sub download_mw_mediafile {
46 print {*STDERR} "Error downloading mediafile from :\n";
47 print {*STDERR} "URL: ${download_url}\n";
48 print {*STDERR} 'Server response: ' . $response->code . q{ } . $response->message . "\n";
49 + return undef if $response->code eq '404' || $response->code eq '403';