Gracefully handle template errors; Add diagnostics

main
parent 5574f14e6f
commit 2739dffa1d
  1. 5
      MWTemplate.pm
  2. 10
      wiki-tile.pl

@ -5,9 +5,14 @@ use v5.30;
use feature "signatures";
no warnings "experimental::signatures";
my $DEBUG = 1;
sub Parse($input, $template_name)
{
# say STDERR "Looking for $template_name in:";
# say STDERR $input;
my ($contents) = $input =~ /\{\{ \s* $template_name \s* \| (.*) \}\}/sx;
return 0 unless $contents;
my @params = split /\|/, $contents;
my @positional_params;
my %named_params;

@ -76,6 +76,8 @@ foreach my $page (values %{$region_query_results->{query}{pages}})
next if $page->{title} =~ /^Category:/;
my $region = $grid->make_region($page->{title});
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $region_template_name);
next unless $parsed_template;
say STDERR "Processing region: $page->{title}";
$region->{defaults}{colour} = $parsed_template->{named_params}{colour};
if($regiondir)
{
@ -114,6 +116,8 @@ foreach my $page (values %{$subregion_query_results->{query}{pages}})
{
next if $page->{title} =~ /^Category:/;
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $subregion_template_name);
next unless $parsed_template;
say STDERR "Processing subregion: $page->{title}";
my $subregion = $grid->make_region($page->{title});
$subregion->{defaults}{colour} = $parsed_template->{named_params}{colour};
if($regiondir)
@ -139,6 +143,7 @@ foreach my $page (values %{$background_query_results->{query}{pages}})
{
if($page->{imageinfo})
{
say STDERR "Processing image: $page->{title}";
foreach my $region (@{$background_pages{$page->{title}}})
{
$region->{defaults}{image} = $page->{imageinfo}[0]{url};
@ -161,6 +166,7 @@ foreach my $page (values %{$tile_query_results->{query}{pages}})
{
my $content = $page->{revisions}[0]{'*'};
my ($region_name) = $page->{title} =~ /(.*)\/Tiles/;
say STDERR "Processing tiles for: $region_name";
my $region = $grid->{regions}{$region_name};
foreach my $coords (split /;/, $content)
{
@ -188,6 +194,8 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
{
next if $page->{title} =~ /^Category:/;
my $parsed_template = MWTemplate::Parse($page->{revisions}[0]{'*'}, $location_template_name);
next unless $parsed_template;
say STDERR "Processing location: $page->{title}";
my $location = $grid->make_region($page->{title});
$location->{defaults}{colour} = $parsed_template->{named_params}{colour};
@ -209,7 +217,6 @@ foreach my $page (values %{$location_query_results->{query}{pages}})
$location_with_context->{defaults}{colour} = $location->{defaults}{colour};
}
# The below regex is a whitespace forgiving version of /^(-?\d+),(-?\d+)/, an int pair
if($parsed_template->{positional_params}[0] =~ $coords_regex)
{
$location->make_tile_at($1,$2);
@ -257,6 +264,7 @@ foreach my $site_page_ref (values %{$site_query_results->{query}{pages}})
my $site_url = $site_page_ref->{canonicalurl};
my $site_content = $site_page_ref->{revisions}[0]{'*'};
my $parsed_template = MWTemplate::Parse($site_content, $site_template_name);
next unless $parsed_template;
my ($nw,$sw) = split /,/, $parsed_template->{named_params}{coords};
my $imageinfo_query_results = $mw->api({ action => 'query',

Loading…
Cancel
Save