|
63 | 63 | my @tracked_categories = split(/[ \n]/, run_git("config --get-all remote.${remotename}.categories"));
|
64 | 64 | chomp(@tracked_categories);
|
65 | 65 |
|
| 66 | +# Just like @tracked_categories, but for MediaUncyclo 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 | + |
66 | 71 | # Import media files on pull
|
67 | 72 | my $import_media = run_git("config --get --bool remote.${remotename}.mediaimport");
|
68 | 73 | chomp($import_media);
|
@@ -256,6 +261,31 @@ sub get_mw_tracked_categories {
|
256 | 261 | return;
|
257 | 262 | }
|
258 | 263 |
|
| 264 | +sub get_mw_tracked_namespaces { |
| 265 | + my $pages = shift; |
| 266 | + foreach my $local_namespace (sort @tracked_namespaces) { |
| 267 | + my ($namespace_id, $mw_pages); |
| 268 | + if ($local_namespace eq "(Main)") { |
| 269 | + $namespace_id = 0; |
| 270 | + } else { |
| 271 | + $namespace_id = get_mw_namespace_id($local_namespace); |
| 272 | + } |
| 273 | + next if $namespace_id < 0; # virtual namespaces don't support allpages |
| 274 | + $mw_pages = $mediawiki->list( { |
| 275 | + action => 'query', |
| 276 | + list => 'allpages', |
| 277 | + apnamespace => $namespace_id, |
| 278 | + aplimit => 'max' } ) |
| 279 | + || die $mediawiki->{error}->{code} . ': ' |
| 280 | + . $mediawiki->{error}->{details} . "\n"; |
| 281 | + print {*STDERR} "$#{$mw_pages} found in namespace $local_namespace ($namespace_id)\n"; |
| 282 | + foreach my $page (@{$mw_pages}) { |
| 283 | + $pages->{$page->{title}} = $page; |
| 284 | + } |
| 285 | + } |
| 286 | + return; |
| 287 | +} |
| 288 | + |
259 | 289 | sub get_mw_all_pages {
|
260 | 290 | my $pages = shift;
|
261 | 291 | # No user-provided list, get the list of pages from the API.
|
@@ -319,6 +349,10 @@ sub get_mw_pages {
|
319 | 349 | $user_defined = 1;
|
320 | 350 | get_mw_tracked_categories(\%pages);
|
321 | 351 | }
|
| 352 | + if (@tracked_namespaces) { |
| 353 | + $user_defined = 1; |
| 354 | + get_mw_tracked_namespaces(\%pages); |
| 355 | + } |
322 | 356 | if (!$user_defined) {
|
323 | 357 | get_mw_all_pages(\%pages);
|
324 | 358 | }
|
@@ -1308,7 +1342,9 @@ sub get_mw_namespace_id {
|
1308 | 1342 | my $id;
|
1309 | 1343 |
|
1310 | 1344 | if (!defined $ns) {
|
1311 |
| - print {*STDERR} "No such namespace ${name} on MediaUncyclo.\n"; |
| 1345 | + my @namespaces = sort keys %namespace_id; |
| 1346 | + for (@namespaces) { s/ /_/g; } |
| 1347 | + print {*STDERR} "No such namespace ${name} on MediaUncyclo, known namespaces: @namespaces\n"; |
1312 | 1348 | $ns = {is_namespace => 0};
|
1313 | 1349 | $namespace_id{$name} = $ns;
|
1314 | 1350 | }
|
|
0 commit comments