Revision: 43476
Author:   siebrand
Date:     2008-11-14 07:18:56 +0000 (Fri, 14 Nov 2008)

Log Message:
-----------
Update for slippy map. Merged with 
http://svn.openstreetmap.org/applications/utils/wiki-extensions/SlippyMap-local/

Modified Paths:
--------------
    trunk/extensions/SlippyMap/SlippyMap.class.php

Added Paths:
-----------
    trunk/extensions/SlippyMap/reset-button.png
    trunk/extensions/SlippyMap/wikicode-button.png

Modified: trunk/extensions/SlippyMap/SlippyMap.class.php
===================================================================
--- trunk/extensions/SlippyMap/SlippyMap.class.php      2008-11-14 06:38:07 UTC 
(rev 43475)
+++ trunk/extensions/SlippyMap/SlippyMap.class.php      2008-11-14 07:18:56 UTC 
(rev 43476)
@@ -43,10 +43,25 @@
 
        # The callback function for converting the input text to HTML output
        static function parse( $input, $argv ) {
-               global $wgMapOfServiceUrl, $wgSlippyMapVersion;
+               global $wgScriptPath, $wgMapOfServiceUrl, $wgSlippyMapVersion;
 
                wfLoadExtensionMessages( 'SlippyMap' );
 
+               //Support old style parameters from $input
+               //Parse the pipe separated name value pairs (e.g. 
'aaa=bbb|ccc=ddd')
+               //With the new syntax we expect nothing in the $input, so this 
will result in '' values
+               $oldStyleParamStrings=explode('|',$input);
+               foreach ($oldStyleParamStrings as $oldStyleParamString) {
+                       $oldStyleParamString = trim($oldStyleParamString);
+                       $eqPos = strpos($oldStyleParamString,"=");
+                       if ($eqPos===false) {
+                               $oldStyleParams[$oldStyleParamString] = "true";
+                       } else {
+                               
$oldStyleParams[substr($oldStyleParamString,0,$eqPos)] = 
trim(htmlspecialchars(substr($oldStyleParamString,$eqPos+1)));
+                       }
+               }
+
+               //Receive new style args: <slippymap aaa=bbb 
ccc=ddd></slippymap>
                if ( isset( $argv['lat'] ) ) {
                        $lat            = $argv['lat'];
                } else {
@@ -100,12 +115,16 @@
                if (substr($width,-2)=='px')    $width = (int) 
substr($width,0,-2);
                if (substr($height,-2)=='px')   $height = (int) 
substr($height,0,-2);
 
-
-               if ( trim( $input ) != '' ) {
-                       $showkml = true;
+               if (trim($input)!='' && sizeof($oldStyleParamStrings)<3) {
+                       $error = 'slippymap tag contents. Were you trying to 
input KML? KML support '.
+                                'is disactivated on the OSM wiki pending 
discussions about wiki syntax';
+                       $showkml = false;
                } else {
                        $showkml = false;
                }
+
+               if ($marker) $error = 'marker support is disactivated on the 
OSM wiki pending discussions about wiki syntax';
+
                //Check required parameters values are provided
                if ( $lat==''  ) $error .= wfMsg( 'slippymap_latmissing' );
                if ( $lon==''  ) $error .= wfMsg( 'slippymap_lonmissing' );
@@ -171,32 +190,49 @@
                } else {
                        //HTML output for the slippy map.
                        //Note that this must all be output on one line (no 
linefeeds)
-                       //otherwise MediaWiki adds <BR> tags, which is bad in 
the middle of block of javascript.
+                       //otherwise MediaWiki adds <BR> tags, which is bad in 
the middle of a block of javascript.
                        //There are other ways of fixing this, but not for 
MediaWiki v4
                        //(See 
http://www.mediawiki.org/wiki/Manual:Tag_extensions#How_can_I_avoid_modification_of_my_extension.27s_HTML_output.3F)
 
-                       $output = '<script type="text/javascript"> var 
osm_fully_loaded=false;';
 
-                       // defer loading of the javascript. Since the script is 
quite bit, it would delay
-                       // page loading and rendering dramatically
-                       $output .= 'addOnloadHook( function() { ' .
-                               '       var sc = 
document.createElement("script");' .
-                               '       sc.src = 
"http://www.openlayers.org/api/OpenLayers.js";;' .
-                               '       document.body.appendChild( sc );' .
-                               '       var sc = 
document.createElement("script");' .
-                               '       sc.src = 
"http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SlippyMap/OpenStreetMap.js?view=co&;'
 . $wgSlippyMapVersion . '";'.
-                               '       document.body.appendChild( sc );' .
-                               '} );';
+                       $output  = '<!-- slippy map -->';
 
+                       //This inline stylesheet defines how the two extra 
buttons look, and where they are positioned.
+                       $output .= "<style> .buttonsPanel div { float:left; 
display:block; position:relative; left:50px; margin-left:3px; margin-top:7px; 
width:36px;  height:19px; }</style>\n";
+                       $output .= "<style> .buttonsPanel 
.getWikiCodeButtonItemInactive { width:36px; height:19px; 
background-image:url('" . $wgScriptPath . 
"/extensions/SlippyMap/wikicode-button.png'); }</style>\n";
+                       $output .= "<style> .buttonsPanel 
.resetButtonItemInactive       { width:36px; height:19px; 
background-image:url('" . $wgScriptPath . 
"/extensions/SlippyMap/reset-button.png'); }</style>\n";
+
+
+                       $output .= "<!-- bring in the OpenLayers javascript 
library -->";
+                       $output .= "<script 
src=\"http://openlayers.org/api/OpenLayers.js\";></script> ";
+
+                       $output .= "<!-- bring in the OpenStreetMap OpenLayers 
layers. ";
+                       $output .= "     Using this hosted file will make sure 
we are kept up ";
+                       $output .= "     to date with any necessary changes --> 
";
+                       $output .= "<script 
src=\"http://openstreetmap.org/openlayers/OpenStreetMap.js\";></script> ";
+
+                       $output .= '<script type="text/javascript">';
+
                        $output .= "var lon= ${lon}; var lat= ${lat}; var zoom= 
${zoom}; var lonLat;";
 
                        $output .= 'var map; ';
 
                        $output .= 'addOnloadHook( slippymap_init ); ';
 
+
+                       $output .= 'function slippymap_resetPosition() {';
+                       $output .= '    map.setCenter(lonLat, zoom);';
+                       $output .= '}';
+
+                       $output .= 'function slippymap_getWikicode() {';
+                       $output .= '    LL = 
map.getCenter().transform(map.getProjectionObject(), new 
OpenLayers.Projection("EPSG:4326"));';
+                       $output .= '    Z = map.getZoom(); ';
+                       $output .= '    size = map.getSize();';
+
+                       $output .= '    prompt( "' . wfMsg('slippymap_code') 
.'", "<slippymap h="+size.h+" w="+size.w+" z="+Z+" lat="+LL.lat+" 
lon="+LL.lon+" layer=mapnik marker=1></slippymap>" ); ';
+                       $output .= '}';
+
                        $output .= 'function slippymap_init() { ';
-                       $output .= '    if (!osm_fully_loaded) { 
window.setTimeout("slippymap_init()",500); return 0; } ' ;
-
                        $output .= '    map = new OpenLayers.Map("map", { ';
                        $output .= '            controls:[ ';
                        $output .= '                    new 
OpenLayers.Control.Navigation(), ';
@@ -221,48 +257,44 @@
 
                        if ( $marker ) {
                                $output .= 'var markers = new 
OpenLayers.Layer.Markers( "Markers" ); ' .
-                                       '   map.addLayer(markers); ' .
-                                       '   var size = new 
OpenLayers.Size(20,34); ' .
-                                       '   var offset = new 
OpenLayers.Pixel(-(size.w/2), -size.h); ' .
-                                       "   var icon = new 
OpenLayers.Icon('http://boston.openguides.org/markers/YELLOW.png',size,offset);"
 .
-                                       '   markers.addMarker(new 
OpenLayers.Marker( lonLat,icon)); ';
+                               '   map.addLayer(markers); ' .
+                               '   var size = new OpenLayers.Size(20,34); ' .
+                               '   var offset = new 
OpenLayers.Pixel(-(size.w/2), -size.h); ' .
+                               "   var icon = new 
OpenLayers.Icon('http://boston.openguides.org/markers/YELLOW.png',size,offset);"
 .
+                               '   markers.addMarker(new OpenLayers.Marker( 
lonLat,icon)); ';
                        }
 
                        if ( $showkml ) {
-                               $input = str_replace(
-                                       array( '%',   "\n" , "'"  , '"'  , '<'  
, '>'  , ' '   ),
-                                       array( '%25', '%0A', '%27', '%22', 
'%3C', '%3E', '%20' ),
-                                       $input
-                               );
+                               $input = str_replace( array( '%',   "\n" , "'"  
, '"'  , '<'  , '>'  , ' '   ),
+                               array( '%25', '%0A', '%27', '%22', '%3C', 
'%3E', '%20' ), $input );
                                $output .= 'var vector = new 
OpenLayers.Layer.Vector("Vector Layer"); ' .
-                                       '   map.addLayer(vector); ' .
-                                       '   kml = new OpenLayers.Format.KML( { 
"internalProjection": map.baseLayer.projection, ' .
-                                       '                                      
"externalProjection": epsg4326, ' .
-                                       '                                      
"extractStyles": true, ' .
-                                       '                                      
"extractAttributes": true } ); ' .
-                                       "   features = 
kml.read(unescape('$input')); " .
-                                       '   vector.addFeatures( features ); ';
+                               '   map.addLayer(vector); ' .
+                               '   kml = new OpenLayers.Format.KML( { 
"internalProjection": map.baseLayer.projection, ' .
+                               '                                      
"externalProjection": epsg4326, ' .
+                               '                                      
"extractStyles": true, ' .
+                               '                                      
"extractAttributes": true } ); ' .
+                               "   features = kml.read(unescape('$input')); " .
+                               '   vector.addFeatures( features ); ';
                        }
 
                        $output .= '    map.setCenter (lonLat, zoom); ';
+                       $output .= '    var getWikiCodeButton = new 
OpenLayers.Control.Button({title: "' . wfMsg('slippymap_button_code') . '", 
displayClass: "getWikiCodeButton", trigger: slippymap_getWikicode}); ';
+                       $output .= '    var resetButton = new 
OpenLayers.Control.Button({title: "' . wfMsg('slippymap_resetview') . '", 
displayClass: "resetButton", trigger: slippymap_resetPosition}); ';
+                       $output .= '    var panel = new 
OpenLayers.Control.Panel( { displayClass: "buttonsPanel"}); ';
+                       $output .= '    panel.addControls([getWikiCodeButton, 
resetButton]); ';
+                       $output .= '    map.addControl(panel); ';
                        $output .= '} ';
 
-                       $output .= 'function slippymap_getWikicode() {';
-                       $output .= '    LL = 
map.getCenter().transform(map.getProjectionObject(), new 
OpenLayers.Projection("EPSG:4326"));';
-                       $output .= '    Z = map.getZoom(); ';
-                       $output .= '    size = map.getSize();';
 
-                       $output .= '    prompt( "' . wfMsg('slippymap_code') 
.'", "<slippymap h="+size.h+" w="+size.w+" z="+Z+" lat="+LL.lat+" 
lon="+LL.lon+" layer=mapnik marker=1></slippymap>" ); ';
-                       $output .= '}';
-
                        $output .= "</script> ";
 
-                       $output .= '<div class="map">';
                        $output .= "<div style=\"width: {$width}px; 
height:{$height}px; border-style:solid; border-width:1px; 
border-color:lightgrey;\" id=\"map\">";
                        $output .= "<noscript><a 
href=\"http://www.openstreetmap.org/?lat=$lat&lon=$lon&zoom=$zoom\"; title=\"See 
this map on OpenStreetMap.org\" style=\"text-decoration:none\">";
                        $output .= "<img 
src=\"".$wgMapOfServiceUrl."lat=${lat}&long=${lon}&z=${zoom}&w=${width}&h=${height}&format=jpeg\"
 width=\"${width}\" height=\"${height}\" border=\"0\"><br/>";
                        $output .= '</a></noscript>';
-                       $output .= '</div><div id="postmap"><input 
type="button" value="' . wfMsg('slippymap_resetview') . '" 
onmousedown="map.setCenter(lonLat, zoom);" /><input type="button" value="' . 
wfMsg('slippymap_button_code') . '" onmousedown="slippymap_getWikicode();" 
/></div></div>';
+                       $output .= '</div>';
+
+                       if (sizeof($oldStyleParamStrings) >2 )  $output .= 
'<div style="font-size:0.8em;"><i>please change to <a 
href="http://wiki.openstreetmap.org/index.php/Slippy_Map_MediaWiki_Extension";>new
 syntax</a></i></div>';
                }
                return $output;
        }

Added: trunk/extensions/SlippyMap/reset-button.png
===================================================================
(Binary files differ)


Property changes on: trunk/extensions/SlippyMap/reset-button.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Added: trunk/extensions/SlippyMap/wikicode-button.png
===================================================================
(Binary files differ)


Property changes on: trunk/extensions/SlippyMap/wikicode-button.png
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream



_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to