Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit fed56c0

Browse files
Perdugitster
authored andcommitted
git-remote-mediawiki: put non-trivial numeric values in constants.
Non-trivial numeric values (e.g., different from 0, 1 and 2) are placed in constants at the top of the code to be easily modifiable and to make more sense Signed-off-by: Célestin Matte <[email protected]> Signed-off-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aeb95ee commit fed56c0

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

contrib/mw-to-git/git-remote-mediawiki.perl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@
4242

4343
use constant EMPTY => q{};
4444

45+
# Number of pages taken into account at once in submodule get_mw_page_list
46+
use constant SLICE_SIZE => 50;
47+
48+
# Number of linked mediafile to get at once in get_linked_mediafiles
49+
# The query is split in small batches because of the MW API limit of
50+
# the number of links to be returned (500 links max).
51+
use constant BATCH_SIZE => 10;
52+
53+
use constant HTTP_CODE_OK => 200;
54+
4555
my $remotename = $ARGV[0];
4656
my $url = $ARGV[1];
4757

@@ -229,13 +239,13 @@ sub get_mw_page_list {
229239
my $pages = shift;
230240
my @some_pages = @$page_list;
231241
while (@some_pages) {
232-
my $last_page = 50;
242+
my $last_page = SLICE_SIZE;
233243
if ($#some_pages < $last_page) {
234244
$last_page = $#some_pages;
235245
}
236246
my @slice = @some_pages[0..$last_page];
237247
get_mw_first_pages(\@slice, $pages);
238-
@some_pages = @some_pages[51..$#some_pages];
248+
@some_pages = @some_pages[(SLICE_SIZE + 1)..$#some_pages];
239249
}
240250
return;
241251
}
@@ -385,9 +395,7 @@ sub get_linked_mediafiles {
385395
my $pages = shift;
386396
my @titles = map { $_->{title} } values(%{$pages});
387397

388-
# The query is split in small batches because of the MW API limit of
389-
# the number of links to be returned (500 links max).
390-
my $batch = 10;
398+
my $batch = BATCH_SIZE;
391399
while (@titles) {
392400
if ($#titles < $batch) {
393401
$batch = $#titles;
@@ -469,7 +477,7 @@ sub download_mw_mediafile {
469477
my $download_url = shift;
470478

471479
my $response = $mediawiki->{ua}->get($download_url);
472-
if ($response->code == 200) {
480+
if ($response->code == HTTP_CODE_OK) {
473481
return $response->decoded_content;
474482
} else {
475483
print {*STDERR} "Error downloading mediafile from :\n";

0 commit comments

Comments
 (0)