Skip to content

Commit 5c22d53

Browse files
committed
Merge branch 'ab/mediawiki-namespace'
The remote-helper for talking to MediaWiki has been updated to work with mediawiki namespaces. * ab/mediawiki-namespace: remote-mediawiki: show progress while fetching namespaces remote-mediawiki: process namespaces in order remote-mediawiki: support fetching from (Main) namespace remote-mediawiki: skip virtual namespaces remote-mediawiki: show known namespace choices on failure remote-mediawiki: allow fetching namespaces with spaces remote-mediawiki: add namespace support
2 parents 905f16d + 94c9acb commit 5c22d53

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

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

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@
6363
my @tracked_categories = split(/[ \n]/, run_git("config --get-all remote.${remotename}.categories"));
6464
chomp(@tracked_categories);
6565

66+
# Just like @tracked_categories, but for MediaWiki namespaces.
67+
my @tracked_namespaces = split(/[ \n]/, run_git("config --get-all remote.${remotename}.namespaces"));
68+
for (@tracked_namespaces) { s/_/ /g; }
69+
chomp(@tracked_namespaces);
70+
6671
# Import media files on pull
6772
my $import_media = run_git("config --get --bool remote.${remotename}.mediaimport");
6873
chomp($import_media);
@@ -256,6 +261,32 @@ sub get_mw_tracked_categories {
256261
return;
257262
}
258263

264+
sub get_mw_tracked_namespaces {
265+
my $pages = shift;
266+
foreach my $local_namespace (sort @tracked_namespaces) {
267+
my $namespace_id;
268+
if ($local_namespace eq "(Main)") {
269+
$namespace_id = 0;
270+
} else {
271+
$namespace_id = get_mw_namespace_id($local_namespace);
272+
}
273+
# virtual namespaces don't support allpages
274+
next if !defined($namespace_id) || $namespace_id < 0;
275+
my $mw_pages = $mediawiki->list( {
276+
action => 'query',
277+
list => 'allpages',
278+
apnamespace => $namespace_id,
279+
aplimit => 'max' } )
280+
|| die $mediawiki->{error}->{code} . ': '
281+
. $mediawiki->{error}->{details} . "\n";
282+
print {*STDERR} "$#{$mw_pages} found in namespace $local_namespace ($namespace_id)\n";
283+
foreach my $page (@{$mw_pages}) {
284+
$pages->{$page->{title}} = $page;
285+
}
286+
}
287+
return;
288+
}
289+
259290
sub get_mw_all_pages {
260291
my $pages = shift;
261292
# No user-provided list, get the list of pages from the API.
@@ -319,6 +350,10 @@ sub get_mw_pages {
319350
$user_defined = 1;
320351
get_mw_tracked_categories(\%pages);
321352
}
353+
if (@tracked_namespaces) {
354+
$user_defined = 1;
355+
get_mw_tracked_namespaces(\%pages);
356+
}
322357
if (!$user_defined) {
323358
get_mw_all_pages(\%pages);
324359
}
@@ -1308,7 +1343,8 @@ sub get_mw_namespace_id {
13081343
my $id;
13091344

13101345
if (!defined $ns) {
1311-
print {*STDERR} "No such namespace ${name} on MediaWiki.\n";
1346+
my @namespaces = map { s/ /_/g; $_; } sort keys %namespace_id;
1347+
print {*STDERR} "No such namespace ${name} on MediaWiki, known namespaces: @namespaces\n";
13121348
$ns = {is_namespace => 0};
13131349
$namespace_id{$name} = $ns;
13141350
}

0 commit comments

Comments
 (0)