remote-mediawiki: add namespace support

This introduces a new remote.origin.namespaces argument that is a space-separated list of namespaces. The list of pages extract is then taken from all the specified namespaces. Reviewed-by: Antoine Beaupré <anarcat@debian.org> Signed-off-by: Antoine Beaupré <anarcat@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kevin committed Nov 6, 2017 at 16:19 UTC 5d9798ae622bc51a877a93cae25c53c062854401
1 file changed +25
contrib/mw-to-git/git-remote-mediawiki.perl
+25
@@ -63,6 +63,10 @@ chomp(@tracked_pages);
63 my @tracked_categories = split(/[ \n]/, run_git("config --get-all remote.${remotename}.categories"));
64 chomp(@tracked_categories);
65
66 +# Just like @tracked_categories, but for MediaWiki namespaces.
67 +my @tracked_namespaces = split(/[ \n]/, run_git("config --get-all remote.${remotename}.namespaces"));
68 +chomp(@tracked_namespaces);
69 +
70 # Import media files on pull
71 my $import_media = run_git("config --get --bool remote.${remotename}.mediaimport");
72 chomp($import_media);
@@ -256,6 +260,23 @@ sub get_mw_tracked_categories {
260 return;
261 }
262
263 +sub get_mw_tracked_namespaces {
264 + my $pages = shift;
265 + foreach my $local_namespace (@tracked_namespaces) {
266 + my $mw_pages = $mediawiki->list( {
267 + action => 'query',
268 + list => 'allpages',
269 + apnamespace => get_mw_namespace_id($local_namespace),
270 + aplimit => 'max' } )
271 + || die $mediawiki->{error}->{code} . ': '
272 + . $mediawiki->{error}->{details} . "\n";
273 + foreach my $page (@{$mw_pages}) {
274 + $pages->{$page->{title}} = $page;
275 + }
276 + }
277 + return;
278 +}
279 +
280 sub get_mw_all_pages {
281 my $pages = shift;
282 # No user-provided list, get the list of pages from the API.
@@ -319,6 +340,10 @@ sub get_mw_pages {
340 $user_defined = 1;
341 get_mw_tracked_categories(\%pages);
342 }
343 + if (@tracked_namespaces) {
344 + $user_defined = 1;
345 + get_mw_tracked_namespaces(\%pages);
346 + }
347 if (!$user_defined) {
348 get_mw_all_pages(\%pages);
349 }