#!/usr/bin/env perl use MediaWiki::API; use Switch; use strict; use URI::Escape; use Geo::KML; my $filename = '/var/www/mediawiki/ShadowMap/ours.kml'; my $out = &create_styles; my $kml = Geo::KML->new(version => '2.2.0'); my $mw = MediaWiki::API->new(); $mw->{config}->{api_url} = 'https://jackpoint.obscuritus.ca/api.php'; my $articles = $mw->list ( { action => 'query', list => 'categorymembers', cmtitle => 'Category:Locations', cmlimit => 'max' } ) || die $mw->{error}->{code} . ': ' . $mw->{error}->{details}; foreach (@{$articles}) { my $name = $_->{title}; my $lat; my $long; my $desc; my $page = $mw->get_page( { title => $name } ); if($page->{'*'} =~ m/.*Template:Location.*/){ my @locs = split /\|/ , $&; foreach(@locs) { my @tokens = split(/=/, $_); $tokens[1] =~ s/\}//g; switch($tokens[0]) { case "Latitude" { $lat = $tokens[1] } case "Longitude" { $long = $tokens[1] } case "Notes" { $desc = $tokens[1] } } } } my $coord = $long . ',' . $lat; if( $lat && $long){ push(@{$out->{Document}->{AbstractFeatureGroup}}, append_placemark($name, $desc, $coord)); } } $kml->writeKML($out, $filename); sub append_placemark { my($name, $desc, $coord) = @_; return { Placemark => { Point => { coordinates => $coord, }, styleUrl =>'#jackpoint-logo', name => "$name", description => $desc } }; } sub create_styles { return { Document => { AbstractStyleSelectorGroup => [ { Style => { IconStyle => { Icon => { href => 'https://jackpoint.obscuritus.ca/images/logo.jpg' }, }, LabelStyle => { scale => '0' }, id => 'jackpoint-logo' } } ], } }; }