User:George Drummond/SpecialGoogleEarth.php

THIS IS AN ALPHA RELEASE. ]]> ';	$output .= "\n"; return $output; }

function addPolyline( $polyline, $color ){ $output .= "\n Polyline \n				 ".GME_POLYLINE_OPACITY.ltrim($color, "#")." 				 ".GME_POLYLINE_WIDTH."     				 1 clampedToGround\n"; //Might want to change this later on. $output .= " \n"; $output .= implode("\n", $polyline); $output .= "\n \n\n\n"; return $output; }

/* * * Map maker, taken from google maps extension * */ function makeMap( $map ) { $lines = preg_split("/[\r\n]+/", $map); $doAddMarker = false; $marker_count = 0; // Just name markers numerically for now, starting at 1 foreach($lines as $line) { if (preg_match("/^(#[0-9a-fA-F]{6})/", $line, $matches)) { //if ($wgGoogleMapsEnablePaths) { if (isset($color)) { // i.e., we were just making a path, so dump and reset $polyline $output .= addPolyline($polyline, $color); $polyline = array; }				$color = $matches[1]; //}		}		elseif (preg_match('/^\/([^\\\\]+)\\\\ *(.*)$/', $line, $matches)) { $tab_description = renderWikiText( $matches[2] ); $description .=" ".$matches[1]." ".$tab_description; $doAddMarker = true; // we want a marker there if it has tabs } 		elseif (preg_match("/^(?:\(([.a-zA-Z0-9_-]*?)\) *)?([^,]+), *([^ ,]+)(?:, (.+))?/", $line, $matches)) { if ($doAddMarker) { // first create the previous marker, now that we have all the tab/caption info $output .= addMarker($lat, $lon, $icon, $description, $marker_count); $doAddMarker = false; }			$icon = $matches[1]; $lat = $matches[2]; $lon = $matches[3]; $description = addslashes(renderWikiText($matches[4])); // This parse function above lets us insert wiki markup into the map markers. //}			if (is_numeric($lat) && is_numeric($lon)) { if ($icon || $caption || !isset($color)) { // we don't actually put down a marker for anonymous points along a path $doAddMarker = true; $marker_count++; }				// If we're making a path, record the location and move on. if (isset($color)) { $polyline[] = "{$lon}, {$lat}"; }			}		}	}	if( isset($color) ) // Close polylines $output .= addPolyline( $polyline, $color ); if ($doAddMarker) { // we've been waiting $output .= addMarker($lat, $lon, $icon, $description, $marker_count); }

return $output; }

/* * * KML maker * */ function makeKml( $page_title, $old_text ){ global $wgOut, $wgRequest; if(preg_match("/(]*>)([^<]*)(<\/googlemap>)/", $old_text)){ preg_match_all("/]+)>*([^<]+)<\/googlemap>/", $old_text, $source); $maps = $source[2]; $maps_attributes = $source[1]; $map_number = $wgRequest->getText( 'map_number', $par ); $output = ""; $output .= xml_header( $page_title );

if( $map_number != "" && is_numeric($map_number) && $map_number <= count($maps) ) { $output .= makeMap( $maps["$map_number"] ); }		elseif( !$map_number ){ // if no map is requested then just display all $i = 0; // Maps dont have any title at the moment. Lets just label them numerically for now, starting at 1. foreach($maps as $map){ preg_match("#name=\"(.*?)\"#s",$maps_attributes[$i], $title_tag); if( $title_tag[0] = "" || !$title_tag[0] ){ $title = "Map ".($i+1); }				else { $title = $title_tag[1]; } $output .= "\n <![CDATA[".$title."]]> \n"; $output .= makeMap( $map ); $output .= ""; $i++; }		}		else {// Map number isnt found on this page. $wgOut->setPageTitle( wfMsg( 'ge-title' ) ); // If no map is found on page $wgOut->addWikiText( "=== We couldn't find that map number on the page that you requested ===" ); GoogleEarthForm; return true; }		$output .= "\n"; $output .= " "; // Output mime type now $wgOut->disable; mime_type( $page_title ); echo $output; }	else { $wgOut->setPageTitle( wfMsg( 'ge-title' ) ); // If no map is found on page $wgOut->addWikiText( wfMsg( 'ge-nomapfound' ) ); GoogleEarthForm; } }