Index: trunk/extensions/SlippyMap/SlippyMap.php |
— | — | @@ -1,18 +1,18 @@ |
2 | 2 | <?php |
3 | 3 | # OpenStreetMap SlippyMap - MediaWiki extension |
4 | | -# |
| 4 | +# |
5 | 5 | # This defines what happens when <slippymap> tag is placed in the wikitext |
6 | | -# |
| 6 | +# |
7 | 7 | # We show a map based on the lat/lon/zoom data passed in. This extension brings in |
8 | | -# the OpenLayers javascript, to show a slippy map. |
| 8 | +# the OpenLayers javascript, to show a slippy map. |
9 | 9 | # |
10 | 10 | # Usage example: |
11 | | -# <slippymap lat=51.485 lon=-0.15 z=11 w=300 h=200 layer=osmarender></slippymap> |
| 11 | +# <slippymap lat=51.485 lon=-0.15 z=11 w=300 h=200 layer=osmarender></slippymap> |
12 | 12 | # |
13 | 13 | # Tile images are not cached local to the wiki. |
14 | 14 | # To acheive this (remove the OSM dependency) you might set up a squid proxy, |
15 | 15 | # and modify the requests URLs here accordingly. |
16 | | -# |
| 16 | +# |
17 | 17 | # This file should be placed in the mediawiki 'extensions' directory |
18 | 18 | # ...and then it needs to be 'included' within LocalSettings.php |
19 | 19 | # |
— | — | @@ -38,34 +38,35 @@ |
39 | 39 | # |
40 | 40 | |
41 | 41 | |
42 | | -if( defined( 'MEDIAWIKI' ) ) { |
43 | | - $wgExtensionFunctions[] = 'wfslippymap'; |
| 42 | +if (!defined('MEDIAWIKI')) |
| 43 | + die(); |
44 | 44 | |
45 | | - $wgExtensionCredits['parserhook'][] = array( |
46 | | - 'name' => 'OpenStreetMap Slippy Map', |
47 | | - 'author' => '[http://harrywood.co.uk Harry Wood], Jens Frank', |
48 | | - 'svn-date' => '$LastChangedDate$', |
49 | | - 'svn-revision' => '$LastChangedRevision$', |
50 | | - 'url' => 'http://wiki.openstreetmap.org/index.php/Slippy_Map_MediaWiki_Extension', |
51 | | - 'description' => 'Allows the use of the <slippymap> tag to display an OpenLayers slippy map. Maps are from [http://openstreetmap.org openstreetmap.org]', |
52 | | - 'descriptionmsg' => 'slippymap_desc', |
53 | | - ); |
| 45 | +$wgExtensionFunctions[] = 'wfslippymap'; |
54 | 46 | |
55 | | - $wgAutoloadClasses['SlippyMap'] = dirname( __FILE__ ) . '/SlippyMap.class.php'; |
56 | | - $wgExtensionMessagesFiles['SlippyMap'] = dirname( __FILE__ ) . "/SlippyMap.i18n.php"; |
| 47 | +$wgExtensionCredits['parserhook'][] = array( |
| 48 | + 'name' => 'OpenStreetMap Slippy Map', |
| 49 | + 'author' => array( '[http://harrywood.co.uk Harry Wood]', 'Jens Frank' ), |
| 50 | + 'svn-date' => '$LastChangedDate$', |
| 51 | + 'svn-revision' => '$LastChangedRevision$', |
| 52 | + 'url' => 'http://wiki.openstreetmap.org/index.php/Slippy_Map_MediaWiki_Extension', |
| 53 | + 'description' => 'Allows the use of the <slippymap> tag to display an OpenLayers slippy map. Maps are from [http://openstreetmap.org openstreetmap.org]', |
| 54 | + 'descriptionmsg' => 'slippymap_desc', |
| 55 | +); |
57 | 56 | |
58 | | - # Bump this when updating OpenStreetMap.js to help update caches |
59 | | - $wgSlippyMapVersion = 1; |
| 57 | +$dir = dirname(__FILE__) . '/'; |
| 58 | +$wgAutoloadClasses['SlippyMap'] = $dir . 'SlippyMap.class.php'; |
| 59 | +$wgExtensionMessagesFiles['SlippyMap'] = $dir . 'SlippyMap.i18n.php'; |
60 | 60 | |
61 | | - function wfslippymap() { |
62 | | - global $wgParser, $wgMapOfServiceUrl; |
63 | | - # register the extension with the WikiText parser |
64 | | - # the first parameter is the name of the new tag. |
65 | | - # In this case it defines the tag <slippymap> ... </slippymap> |
66 | | - # the second parameter is the callback function for |
67 | | - # processing the text between the tags |
68 | | - $wgParser->setHook( 'slippymap', array( 'SlippyMap', 'parse' ) ); |
69 | | - $wgMapOfServiceUrl = "http://osm-tah-cache.firefishy.com/~ojw/MapOf/?"; |
70 | | - } |
| 61 | +# Bump this when updating OpenStreetMap.js to help update caches |
| 62 | +$wgSlippyMapVersion = 1; |
71 | 63 | |
| 64 | +function wfslippymap() { |
| 65 | + global $wgParser, $wgMapOfServiceUrl; |
| 66 | + # register the extension with the WikiText parser |
| 67 | + # the first parameter is the name of the new tag. |
| 68 | + # In this case it defines the tag <slippymap> ... </slippymap> |
| 69 | + # the second parameter is the callback function for |
| 70 | + # processing the text between the tags |
| 71 | + $wgParser->setHook( 'slippymap', array( 'SlippyMap', 'parse' ) ); |
| 72 | + $wgMapOfServiceUrl = "http://osm-tah-cache.firefishy.com/~ojw/MapOf/?"; |
72 | 73 | } |
Index: trunk/extensions/SlippyMap/SlippyMap.class.php |
— | — | @@ -1,18 +1,18 @@ |
2 | 2 | <?php |
3 | 3 | # OpenStreetMap SlippyMap - MediaWiki extension |
4 | | -# |
| 4 | +# |
5 | 5 | # This defines what happens when <slippymap> tag is placed in the wikitext |
6 | | -# |
| 6 | +# |
7 | 7 | # We show a map based on the lat/lon/zoom data passed in. This extension brings in |
8 | | -# the OpenLayers javascript, to show a slippy map. |
| 8 | +# the OpenLayers javascript, to show a slippy map. |
9 | 9 | # |
10 | 10 | # Usage example: |
11 | | -# <slippymap lat=51.485 lon=-0.15 z=11 w=300 h=200 layer=osmarender marker=0></slippymap> |
| 11 | +# <slippymap lat=51.485 lon=-0.15 z=11 w=300 h=200 layer=osmarender marker=0></slippymap> |
12 | 12 | # |
13 | 13 | # Tile images are not cached local to the wiki. |
14 | 14 | # To acheive this (remove the OSM dependency) you might set up a squid proxy, |
15 | 15 | # and modify the requests URLs here accordingly. |
16 | | -# |
| 16 | +# |
17 | 17 | # This file should be placed in the mediawiki 'extensions' directory |
18 | 18 | # ...and then it needs to be 'included' within LocalSettings.php |
19 | 19 | # |
— | — | @@ -37,9 +37,7 @@ |
38 | 38 | # @addtogroup Extensions |
39 | 39 | # |
40 | 40 | |
41 | | - |
42 | 41 | class SlippyMap { |
43 | | - |
44 | 42 | function SlippyMap() { |
45 | 43 | } |
46 | 44 | |
— | — | @@ -49,37 +47,37 @@ |
50 | 48 | |
51 | 49 | wfLoadExtensionMessages( 'SlippyMap' ); |
52 | 50 | |
53 | | - if ( isset( $argv['lat'] ) ) { |
| 51 | + if ( isset( $argv['lat'] ) ) { |
54 | 52 | $lat = $argv['lat']; |
55 | 53 | } else { |
56 | 54 | $lat = ''; |
57 | 55 | } |
58 | | - if ( isset( $argv['lon'] ) ) { |
| 56 | + if ( isset( $argv['lon'] ) ) { |
59 | 57 | $lon = $argv['lon']; |
60 | 58 | } else { |
61 | 59 | $lon = ''; |
62 | 60 | } |
63 | | - if ( isset( $argv['z'] ) ) { |
| 61 | + if ( isset( $argv['z'] ) ) { |
64 | 62 | $zoom = $argv['z']; |
65 | 63 | } else { |
66 | 64 | $zoom = ''; |
67 | 65 | } |
68 | | - if ( isset( $argv['w'] ) ) { |
| 66 | + if ( isset( $argv['w'] ) ) { |
69 | 67 | $width = $argv['w']; |
70 | 68 | } else { |
71 | 69 | $width = ''; |
72 | 70 | } |
73 | | - if ( isset( $argv['h'] ) ) { |
| 71 | + if ( isset( $argv['h'] ) ) { |
74 | 72 | $height = $argv['h']; |
75 | 73 | } else { |
76 | 74 | $height = ''; |
77 | 75 | } |
78 | | - if ( isset( $argv['layer'] ) ) { |
| 76 | + if ( isset( $argv['layer'] ) ) { |
79 | 77 | $layer = $argv['layer']; |
80 | 78 | } else { |
81 | 79 | $layer = ''; |
82 | 80 | } |
83 | | - if ( isset( $argv['marker'] ) ) { |
| 81 | + if ( isset( $argv['marker'] ) ) { |
84 | 82 | $marker = $argv['marker']; |
85 | 83 | } else { |
86 | 84 | $marker = ''; |
— | — | @@ -88,9 +86,9 @@ |
89 | 87 | $error=''; |
90 | 88 | |
91 | 89 | //default values (meaning these parameters can be missed out) |
92 | | - if ($width=='') $width ='450'; |
93 | | - if ($height=='') $height='320'; |
94 | | - if ($layer=='') $layer='mapnik'; |
| 90 | + if ($width=='') $width ='450'; |
| 91 | + if ($height=='') $height='320'; |
| 92 | + if ($layer=='') $layer='mapnik'; |
95 | 93 | |
96 | 94 | if ($zoom=='' && isset( $argv['zoom'] ) ) { |
97 | 95 | $zoom = $argv['zoom']; //see if they used 'zoom' rather than 'z' (and allow it) |
— | — | @@ -114,7 +112,7 @@ |
115 | 113 | if ( $zoom=='' ) $error .= wfMsg( 'slippymap_zoommissing' ); |
116 | 114 | |
117 | 115 | if ($error=='') { |
118 | | - //no errors so far. Now check the values |
| 116 | + //no errors so far. Now check the values |
119 | 117 | if (!is_numeric($width)) { |
120 | 118 | $error = wfMsg( 'slippymap_widthnan', $width ); |
121 | 119 | } else if (!is_numeric($height)) { |
— | — | @@ -155,7 +153,7 @@ |
156 | 154 | |
157 | 155 | $layer = strtolower($layer); |
158 | 156 | $layerObjectDef = ''; |
159 | | - if ($layer=='osmarender') { |
| 157 | + if ($layer=='osmarender') { |
160 | 158 | $layerObjectDef = 'OpenLayers.Layer.OSM.Osmarender("Osmarender"); '; |
161 | 159 | } elseif ($layer=='mapnik') { |
162 | 160 | $layerObjectDef = 'OpenLayers.Layer.OSM.Mapnik("Mapnik"); '; |
— | — | @@ -182,13 +180,13 @@ |
183 | 181 | // defer loading of the javascript. Since the script is quite bit, it would delay |
184 | 182 | // page loading and rendering dramatically |
185 | 183 | $output .= 'addOnloadHook( function() { ' . |
186 | | - ' var sc = document.createElement("script");' . |
| 184 | + ' var sc = document.createElement("script");' . |
187 | 185 | ' sc.src = "http://www.openlayers.org/api/OpenLayers.js";' . |
188 | | - ' document.body.appendChild( sc );' . |
189 | | - ' var sc = document.createElement("script");' . |
190 | | - ' sc.src = "http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SlippyMap/OpenStreetMap.js?view=co&' . $wgSlippyMapVersion . '";'. |
191 | | - ' document.body.appendChild( sc );' . |
192 | | - '} );'; |
| 186 | + ' document.body.appendChild( sc );' . |
| 187 | + ' var sc = document.createElement("script");' . |
| 188 | + ' sc.src = "http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SlippyMap/OpenStreetMap.js?view=co&' . $wgSlippyMapVersion . '";'. |
| 189 | + ' document.body.appendChild( sc );' . |
| 190 | + '} );'; |
193 | 191 | |
194 | 192 | $output .= "var lon= ${lon}; var lat= ${lat}; var zoom= ${zoom}; var lonLat;"; |
195 | 193 | |
— | — | @@ -205,7 +203,7 @@ |
206 | 204 | |
207 | 205 | if ($height>320) { |
208 | 206 | //Add the zoom bar control, except if the map is only little |
209 | | - $output .= ' new OpenLayers.Control.PanZoomBar(),'; |
| 207 | + $output .= ' new OpenLayers.Control.PanZoomBar(),'; |
210 | 208 | } else if ( $height > 140 ) { |
211 | 209 | $output .= ' new OpenLayers.Control.PanZoom(),'; |
212 | 210 | } |
— | — | @@ -223,16 +221,19 @@ |
224 | 222 | |
225 | 223 | if ( $marker ) { |
226 | 224 | $output .= 'var markers = new OpenLayers.Layer.Markers( "Markers" ); ' . |
227 | | - ' map.addLayer(markers); ' . |
228 | | - ' var size = new OpenLayers.Size(20,34); ' . |
229 | | - ' var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); ' . |
230 | | - " var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/YELLOW.png',size,offset);" . |
231 | | - ' markers.addMarker(new OpenLayers.Marker( lonLat,icon)); '; |
| 225 | + ' map.addLayer(markers); ' . |
| 226 | + ' var size = new OpenLayers.Size(20,34); ' . |
| 227 | + ' var offset = new OpenLayers.Pixel(-(size.w/2), -size.h); ' . |
| 228 | + " var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/YELLOW.png',size,offset);" . |
| 229 | + ' markers.addMarker(new OpenLayers.Marker( lonLat,icon)); '; |
232 | 230 | } |
233 | 231 | |
234 | 232 | if ( $showkml ) { |
235 | | - $input = str_replace( array( '%', "\n" , "'" , '"' , '<' , '>' , ' ' ), |
236 | | - array( '%25', '%0A', '%27', '%22', '%3C', '%3E', '%20' ), $input ); |
| 233 | + $input = str_replace( |
| 234 | + array( '%', "\n" , "'" , '"' , '<' , '>' , ' ' ), |
| 235 | + array( '%25', '%0A', '%27', '%22', '%3C', '%3E', '%20' ), |
| 236 | + $input |
| 237 | + ); |
237 | 238 | $output .= 'var vector = new OpenLayers.Layer.Vector("Vector Layer"); ' . |
238 | 239 | ' map.addLayer(vector); ' . |
239 | 240 | ' kml = new OpenLayers.Format.KML( { "internalProjection": map.baseLayer.projection, ' . |
— | — | @@ -247,7 +248,7 @@ |
248 | 249 | $output .= '} '; |
249 | 250 | |
250 | 251 | $output .= 'function slippymap_getWikicode() {'; |
251 | | - $output .= ' LL = map.getCenter().transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));'; |
| 252 | + $output .= ' LL = map.getCenter().transform(map.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));'; |
252 | 253 | $output .= ' Z = map.getZoom(); '; |
253 | 254 | $output .= ' size = map.getSize();'; |
254 | 255 | |