array( "method" => "GET", "header" => "Accept-Encoding: gzip" ) ) ) ;
$page = file_get_contents ( $request_url, false, $context ) ;
# ungzip if needed
if ( $page && substr( $page , 0, 3 ) == "\x1f\x8b\x08" ) {
return gzinflate ( substr($page, 10, -8) ) ;
} else {
return $page ;
}
}
# Get everything we need to run
$lang = fix_language_code ( get_request ( 'language' , 'en' ) , '' ) ;
if ( ! $lang ) {
header("HTTP/1.1 400 Bad Request");
print "No language given" ;
exit ;
}
$theparams = htmlspecialchars ( get_request ( 'params' , '' ) ) ;
if ( $theparams == '' ) {
header("HTTP/1.1 400 Bad Request");
print "No parameters given (
¶ms=
is empty or missing)" ;
exit ;
}
# Using REFERER as a last resort for pagename
preg_match("/https?:\/\/[^\/]+\/?(?:wiki\/|w\/index.php\?.*?title=)([^&?#{|}\[\]]+)/", ( $_SERVER['HTTP_REFERER'] ? $_SERVER['HTTP_REFERER'] : '' ), $ref_match );
$r_pagename = get_request( 'pagename', ( $ref_match ? urldecode( $ref_match[1] ) : '' ) ) ;
$r_title = get_request( 'title', str_replace( '_', ' ', $r_pagename ) ) ;
$r_pagename = htmlspecialchars ( $r_pagename ) ;
$r_title = htmlspecialchars ( $r_title ) ;
# Initilize Map Sources
$md = new map_sources ( $theparams , "Some title" ) ;
if (($e = $md->p->get_error()) != "") {
header("HTTP/1.1 400 Bad Request");
print "
" . htmlspecialchars( $e ) . "
";
exit ;
}
# (auto-)detect region
$region_name = false ;
$globe = '';
$nlzoom = '';
foreach ( $md->p->pieces AS $k => $v ) {
if ( substr ( $v , 0 , 7 ) == "region:" )
$region_name = strtoupper ( substr ( $v , 7 ) ) ;
else if ( substr ( $v , 0 , 6) == "globe:" )
$globe = strtolower ( substr ( $v , 6 ) );
else if ( substr ( $v , 0 , 5) == "zoom:" )
$nlzoom = strtolower ( substr ( $v , 5 ) );
}
$lat = $md->p->make_minsec($md->p->latdeg);
$lon = $md->p->make_minsec($md->p->londeg);
if ( $region_name === false && ! ( $globe != '' && $globe != 'earth' ) ) {
$url = "http://toolserver.org/~para/region.php?tsv&lat=" . $lat['deg'] . "&long=" . $lon['deg'] ;
$ctx = stream_context_create(array('http' => array('timeout' => 5)));
$region = @explode ( "\t" , file_get_contents ( $url , 0 , $ctx ) ) ;
if ( count ( $region ) > 2 ) {
array_shift ( $region ) ;
array_shift ( $region ) ;
if ( count ( $region ) > 0 ) {
$region_name = strtoupper ( array_shift ( $region ) ) ;
if ( $region_name != "" ) $md->p->pieces[] = "region:" . $region_name ;
}
}
}
$region_name = array_shift ( explode ( '-' , $region_name ) ) ;
$region_name = array_shift ( explode ( '_' , $region_name ) ) ;
# Read template
#$pagename = get_request ( "altpage" , "Template:GeoTemplate" ) ;
$pagename = "Template:GeoTemplate" ;
if ( $globe != '' && $globe != 'earth' ) {
$pagename .= '/' . str_replace ( "&", "%26", $globe ) ;
}
if ( ! get_request ( 'project' , '' ) ) {
$request_url = "http://{$lang}.wikipedia.org/w/index.php?title=$pagename&useskin=monobook" . strftime ( "&nocache=%Y%m%d%H" ) ;
} else {
$request_url = "http://meta.wikimedia.org/w/index.php?title=$pagename/" . get_request ( 'project' , '' ) . "&useskin=monobook" . strftime ( "&nocache=%Y%m%d%H" ) ;
$lang = 'meta' ;
}
$page = @get_html ( $request_url ) ;
if ( $page === false || $page == '' ) {
# fall back to to English Wikipedia
$page = @get_html ( "http://en.wikipedia.org/w/index.php?title=$pagename&uselang=$lang&useskin=monobook" . strftime ( "&nocache=%Y%m%d%H" ) ) ;
}
if ( $page === false || $page == '' ) {
header("HTTP/1.1 502 Bad Gateway");
print "" ;
print "
502 Bad Gateway" ;
print "Failed to open
{$request_url}." ;
print "" ;
exit ;
}
$page = str_replace ( ' href="/w' , " href=\"//{$lang}.wikipedia.org/w" , $page ) ;
$actions = str_replace ( 'id="p-cactions"', '', get_div_section ( $page, "p-cactions" ) ) ;
$languages = preg_replace_callback ( '/ href="\/\/([a-z\-]+)\.wikipedia\.org\/wiki\/[^"]*/', create_function(
'$match',
'global $theparams, $r_pagename;return " href=\"" . make_link ( $match[1] , $theparams , $r_pagename );'
), get_div_section ( $page, "p-lang" ) ) ;
# Remove edit links
do {
$op = $page ;
$p = explode ( '
' , array_pop ( $p ) , 2 ) ;
$page .= array_pop ( $p ) ;
} while ( $op != $page ) ;
# Build the page
if ( strpos ( $page , '' ) ) {
$page = array_pop ( explode ( '' , $page , 2 ) ) ;
$page = array_shift ( explode ( '' , $page , 2 ) ) ;
} else {
$page = array_pop ( explode ( '' , $page , 2 ) ) ;
$page = array_shift ( explode ( '' , $page , 2 ) ) ;
}
# XXX There should be failsafe branch here
$md->thetext = $page ;
$page = $md->build_output () ;
# Ugly hacks
$page = str_replace ( '{nztmeasting}' , '0' , $page ) ;
$page = str_replace ( '{nztmnorthing}' , '0' , $page ) ;
# Localized services
$locmaps = get_div_section ( $page, 'GEOTEMPLATE-'.$region_name );
$locinsert = get_div_section ( $page, 'GEOTEMPLATE-LOCAL' );
if($locmaps && $locinsert){
$page = str_replace ( $locmaps, '', $page ) ;
$page = str_replace ( $locinsert, $locmaps, $page ) ;
$page = str_replace ( get_div_section ( $page, 'GEOTEMPLATE-REGIONS' ), '', $page ) ;
}
# FIXME better titles
$mytitle = "GeoHack" ;
if ( $r_title ) $mytitle = $mytitle." - ".$r_title ;
elseif ( $r_pagename ) $mytitle = $mytitle." - ".str_replace('_', ' ', $r_pagename ) ;
elseif ($lat && $lon ) $mytitle = $mytitle." (".$lat['deg']."; ".$lon['deg'].")" ;
# Headers
header('Cache-Control: max-age=86400'); # expire after 24 hours
# Output
print '
'.$mytitle.'
' ;
if ( $nlzoom ) {
print '
Waarschuwing:
op deze pagina word de verouderde parameter "zoom" gebruikt, in plaats
daarvan zou "scale" of "dim" gebruikt moeten worden
' ;
}
print $page ;
print '
';
$logo = array( # Away from the sun
'sun' => '//upload.wikimedia.org/wikipedia/commons/thumb/a/a4/The_Sun_by_the_Atmospheric_Imaging_Assembly_of_NASA%27s_Solar_Dynamics_Observatory_-_20100801.jpg/150px-The_Sun_by_the_Atmospheric_Imaging_Assembly_of_NASA%27s_Solar_Dynamics_Observatory_-_20100801.jpg',
'mercury' => '//upload.wikimedia.org/wikipedia/commons/thumb/3/30/Mercury_in_color_-_Prockter07_centered.jpg/150px-Mercury_in_color_-_Prockter07_centered.jpg',
'venus' => '//upload.wikimedia.org/wikipedia/commons/thumb/5/51/Venus-real.jpg/150px-Venus-real.jpg',
'' => '//upload.wikimedia.org/wikipedia/commons/thumb/9/97/The_Earth_seen_from_Apollo_17.jpg/150px-The_Earth_seen_from_Apollo_17.jpg',
'earth' => '//upload.wikimedia.org/wikipedia/commons/thumb/9/97/The_Earth_seen_from_Apollo_17.jpg/150px-The_Earth_seen_from_Apollo_17.jpg',
'moon' => '//upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Full_Moon_Luc_Viatour.jpg/150px-Full_Moon_Luc_Viatour.jpg',
'mars' => '//upload.wikimedia.org/wikipedia/commons/thumb/7/76/Mars_Hubble.jpg/166px-Mars_Hubble.jpg',
# Moons of Mars
'phobos' => '//upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Phobos_colour_2008.jpg/150px-Phobos_colour_2008.jpg',
'deimos' => '//upload.wikimedia.org/wikipedia/commons/thumb/8/8d/Deimos-MRO.jpg/150px-Deimos-MRO.jpg',
# Asteroid belt
'ceres' => '//upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Ceres_optimized.jpg/150px-Ceres_optimized.jpg',
'jupiter' => '//upload.wikimedia.org/wikipedia/commons/thumb/5/5a/Jupiter_by_Cassini-Huygens.jpg/150px-Jupiter_by_Cassini-Huygens.jpg',
# Moons of Jupiter
'ganymede' => '//upload.wikimedia.org/wikipedia/commons/thumb/7/7a/Noaa_ganymede.jpg/150px-Noaa_ganymede.jpg',
'callisto' => '//upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Callisto.jpg/150px-Callisto.jpg',
'io' => '//upload.wikimedia.org/wikipedia/commons/thumb/7/7b/Io_highest_resolution_true_color.jpg/150px-Io_highest_resolution_true_color.jpg',
'europa' => '//upload.wikimedia.org/wikipedia/commons/thumb/5/54/Europa-moon.jpg/150px-Europa-moon.jpg',
'amalthea' => '//upload.wikimedia.org/wikipedia/commons/thumb/4/44/Amalthea_Voyager-1.gif/150px-Amalthea_Voyager-1.gif',
'thebe' => '//upload.wikimedia.org/wikipedia/commons/thumb/1/1b/Thebe.jpg/150px-Thebe.jpg',
'saturn' => '//upload.wikimedia.org/wikipedia/commons/thumb/c/c7/Saturn_during_Equinox.jpg/200px-Saturn_during_Equinox.jpg',
# Moons of Saturn
'mimas' => '//upload.wikimedia.org/wikipedia/commons/thumb/d/da/Mimas_moon.jpg/150px-Mimas_moon.jpg',
'enceladus'=> '//upload.wikimedia.org/wikipedia/commons/thumb/c/c5/PIA08409_North_Polar_Region_of_Enceladus.jpg/180px-PIA08409_North_Polar_Region_of_Enceladus.jpg',
'tethys' => '//upload.wikimedia.org/wikipedia/commons/thumb/0/01/PIA07738_Tethys_mosaic_contrast-enhanced.jpg/150px-PIA07738_Tethys_mosaic_contrast-enhanced.jpg',
'dione' => '//upload.wikimedia.org/wikipedia/commons/thumb/6/6e/Dione3_cassini_big.jpg/150px-Dione3_cassini_big.jpg',
'rhea' => '//upload.wikimedia.org/wikipedia/commons/thumb/a/ab/PIA07763_Rhea_full_globe5.jpg/150px-PIA07763_Rhea_full_globe5.jpg',
'titan' => '//upload.wikimedia.org/wikipedia/commons/thumb/8/84/Titan_in_natural_color_Cassini.jpg/150px-Titan_in_natural_color_Cassini.jpg',
'hyperion' => '//upload.wikimedia.org/wikipedia/commons/thumb/9/94/Hyperion_true.jpg/150px-Hyperion_true.jpg',
'iapetus' => '//upload.wikimedia.org/wikipedia/commons/thumb/9/9a/Iapetus_mosaic_color.jpg/140px-Iapetus_mosaic_color.jpg',
'phoebe' => '//upload.wikimedia.org/wikipedia/commons/thumb/2/24/Phoebe_13-06-2004.jpg/180px-Phoebe_13-06-2004.jpg',
'janus' => '//upload.wikimedia.org/wikipedia/commons/thumb/6/62/PIA12714_Janus_crop.jpg/150px-PIA12714_Janus_crop.jpg',
'epimetheus'=>'//upload.wikimedia.org/wikipedia/commons/thumb/4/4a/Epimetheus.jpg/150px-Epimetheus.jpg',
'uranus' => '//upload.wikimedia.org/wikipedia/commons/thumb/3/3d/Uranus2.jpg/150px-Uranus2.jpg',
# Moons of Uranus
'ariel' => '//upload.wikimedia.org/wikipedia/commons/thumb/5/59/Ariel_%28moon%29.jpg/140px-Ariel_%28moon%29.jpg',
'umbriel' => '//upload.wikimedia.org/wikipedia/commons/thumb/5/50/Umbriel_%28moon%29.jpg/150px-Umbriel_%28moon%29.jpg',
'titania' => '//upload.wikimedia.org/wikipedia/commons/thumb/a/a2/Titania_%28moon%29_color_cropped.jpg/135px-Titania_%28moon%29_color_cropped.jpg',
'oberon' => '//upload.wikimedia.org/wikipedia/commons/thumb/0/09/Voyager_2_picture_of_Oberon.jpg/150px-Voyager_2_picture_of_Oberon.jpg',
'miranda' => '//upload.wikimedia.org/wikipedia/commons/thumb/d/d0/Miranda.jpg/140px-Miranda.jpg',
'puck' => '//upload.wikimedia.org/wikipedia/commons/thumb/b/b6/Puck.png/150px-Puck.png',
'neptune' => '//upload.wikimedia.org/wikipedia/commons/thumb/0/06/Neptune.jpg/150px-Neptune.jpg',
# Moons of Neptune
'triton' => '//upload.wikimedia.org/wikipedia/commons/thumb/a/a6/Triton_moon_mosaic_Voyager_2_%28large%29.jpg/150px-Triton_moon_mosaic_Voyager_2_%28large%29.jpg',
'nereid' => '//upload.wikimedia.org/wikipedia/commons/b/b0/Nereid-Voyager2.jpg',
'proteus' => '//upload.wikimedia.org/wikipedia/commons/thumb/8/83/Proteus_%28Voyager_2%29.jpg/150px-Proteus_%28Voyager_2%29.jpg',
# Pluto
'pluto' => '//upload.wikimedia.org/wikipedia/commons/thumb/a/ac/Hst_pluto_cropped.png/150px-Hst_pluto_cropped.png',
# Special
'osm' => '//wiki.openstreetmap.org/Wiki.png');
print '
';
print $actions;
print '
';
print $languages;
print '
'; # //wikitech.wikimedia.org/w/images/c/cf/Labslogo_thumb.png
print '
' ;
?>