summaryrefslogtreecommitdiff
path: root/contrib/mw-to-git/git-remote-mediawiki.perl
diff options
context:
space:
mode:
authorKevin <kevin@ki-ai.org>2017-11-06 21:19:47 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-11-07 00:45:55 (GMT)
commit5d9798ae622bc51a877a93cae25c53c062854401 (patch)
tree279c04a17aece524cab504816b68408148bf7f61 /contrib/mw-to-git/git-remote-mediawiki.perl
parentcb5918aa0d50f50e83787f65c2ddc3dcb10159fe (diff)
downloadgit-5d9798ae622bc51a877a93cae25c53c062854401.zip
git-5d9798ae622bc51a877a93cae25c53c062854401.tar.gz
git-5d9798ae622bc51a877a93cae25c53c062854401.tar.bz2
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>
Diffstat (limited to 'contrib/mw-to-git/git-remote-mediawiki.perl')
-rwxr-xr-xcontrib/mw-to-git/git-remote-mediawiki.perl25
1 files changed, 25 insertions, 0 deletions
diff --git a/contrib/mw-to-git/git-remote-mediawiki.perl b/contrib/mw-to-git/git-remote-mediawiki.perl
index e7f857c..5ffb575 100755
--- a/contrib/mw-to-git/git-remote-mediawiki.perl
+++ b/contrib/mw-to-git/git-remote-mediawiki.perl
@@ -63,6 +63,10 @@ chomp(@tracked_pages);
my @tracked_categories = split(/[ \n]/, run_git("config --get-all remote.${remotename}.categories"));
chomp(@tracked_categories);
+# Just like @tracked_categories, but for MediaWiki namespaces.
+my @tracked_namespaces = split(/[ \n]/, run_git("config --get-all remote.${remotename}.namespaces"));
+chomp(@tracked_namespaces);
+
# Import media files on pull
my $import_media = run_git("config --get --bool remote.${remotename}.mediaimport");
chomp($import_media);
@@ -256,6 +260,23 @@ sub get_mw_tracked_categories {
return;
}
+sub get_mw_tracked_namespaces {
+ my $pages = shift;
+ foreach my $local_namespace (@tracked_namespaces) {
+ my $mw_pages = $mediawiki->list( {
+ action => 'query',
+ list => 'allpages',
+ apnamespace => get_mw_namespace_id($local_namespace),
+ aplimit => 'max' } )
+ || die $mediawiki->{error}->{code} . ': '
+ . $mediawiki->{error}->{details} . "\n";
+ foreach my $page (@{$mw_pages}) {
+ $pages->{$page->{title}} = $page;
+ }
+ }
+ return;
+}
+
sub get_mw_all_pages {
my $pages = shift;
# No user-provided list, get the list of pages from the API.
@@ -319,6 +340,10 @@ sub get_mw_pages {
$user_defined = 1;
get_mw_tracked_categories(\%pages);
}
+ if (@tracked_namespaces) {
+ $user_defined = 1;
+ get_mw_tracked_namespaces(\%pages);
+ }
if (!$user_defined) {
get_mw_all_pages(\%pages);
}