r36981 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r36980‎ | r36981 | r36982 >
Date:13:44, 3 July 2008
Author:raymond
Status:old
Tags:
Comment:
* Add $wgSlippyMapVersion to help update caches when OpenStreetMap.js is changed
* Localize button messages
* Avoid PHP notice for depreciated parameter 'long'
* Use class=error for errormessages
* Kill whitespaces
Modified paths:
  • /trunk/extensions/SlippyMap/SlippyMap.class.php (modified) (history)
  • /trunk/extensions/SlippyMap/SlippyMap.i18n.php (modified) (history)
  • /trunk/extensions/SlippyMap/SlippyMap.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SlippyMap/SlippyMap.i18n.php
@@ -34,6 +34,8 @@
3535 'slippymap_osmlink' => 'http://www.openstreetmap.org/?lat=%1&lon=%2&zoom=%3', # do not translate or duplicate this message to other languages
3636 'slippymap_osmtext' => 'See this map on OpenStreetMap.org',
3737 'slippymap_code' => 'Wikicode for this map view:',
 38+ 'slippymap_button_code' => 'Get wikicode',
 39+ 'slippymap_resetview' => 'Reset view',
3840 'slippymap_license' => 'OpenStreetMap - CC-BY-SA-2.0', # do not translate or duplicate this message to other languages
3941 );
4042
@@ -60,12 +62,14 @@
6163 'slippymap_lonbig' => "Die geografische Länge darf nicht größer als 180 sein",
6264 'slippymap_lonsmall' => "Die geografische Länge darf nicht kleiner als -180 sein",
6365 'slippymap_zoomsmall' => "Der Zoomwert darf nicht negativ sein",
64 - 'slippymap_zoom18' => "Der Zoomwert (z) kann nicht größer als 17 sein. Beachte, dass diese MediaWiki-Erweiterung die OpenStreetMap 'Osmarender'-Karte einbindet, die nicht höher als Zoom 17 geht. Die Mapnik-Karte ist auf openstreetmap.org verfügbar und geht bis Zoom 18.",
65 - 'slippymap_zoombig' => "Der Zoomwert (z) kann nicht größer als 17 sein.",
 66+ 'slippymap_zoom18' => "Der Zoomwert (z) darf nicht größer als 17 sein. Beachte, dass diese MediaWiki-Erweiterung die OpenStreetMap 'Osmarender'-Karte einbindet, die nicht höher als Zoom 17 geht. Die Mapnik-Karte ist auf openstreetmap.org verfügbar und geht bis Zoom 18.",
 67+ 'slippymap_zoombig' => "Der Zoomwert (z) darf nicht größer als 17 sein.",
6668 'slippymap_invalidlayer' => "Ungültiger 'layer'-Wert „%1“",
6769 'slippymap_code' => 'Wikitext für diese Kartenansicht:',
6870 'slippymap_maperror' => "Kartenfehler:",
6971 'slippymap_osmtext' => 'Diese Karte auf OpenStreetMap.org ansehen',
 72+ 'slippymap_button_code' => 'Zeige Wikicode',
 73+ 'slippymap_resetview' => 'Zurücksetzen',
7074 );
7175
7276 /** French (Français)
Index: trunk/extensions/SlippyMap/SlippyMap.php
@@ -33,6 +33,8 @@
3434 $wgAutoloadClasses['SlippyMap'] = dirname( __FILE__ ) . '/SlippyMap.class.php';
3535 $wgExtensionMessagesFiles['SlippyMap'] = dirname( __FILE__ ) . "/SlippyMap.i18n.php";
3636
 37+ # Bump this when updating OpenStreetMap.js to help update caches
 38+ $wgSlippyMapVersion = 1;
3739
3840 function wfslippymap() {
3941 global $wgParser, $wgMapOfServiceUrl;
Index: trunk/extensions/SlippyMap/SlippyMap.class.php
@@ -24,8 +24,8 @@
2525
2626 # The callback function for converting the input text to HTML output
2727 function parse( $input ) {
28 - global $wgMapOfServiceUrl;
29 -
 28+ global $wgMapOfServiceUrl, $wgSlippyMapVersion;
 29+
3030 wfLoadExtensionMessages( 'SlippyMap' );
3131
3232 //Parse pipe separated name value pairs (e.g. 'aaa=bbb|ccc=ddd')
@@ -39,7 +39,7 @@
4040 $params[substr($paramString,0,$eqPos)] = trim(htmlspecialchars(substr($paramString,$eqPos+1)));
4141 }
4242 }
43 -
 43+
4444 $lat = $params['lat'];
4545 $lon = $params['lon'];
4646 $zoom = $params['z'];
@@ -47,28 +47,28 @@
4848 $height = $params['h'];
4949 $layer = $params['layer'];
5050 $marker = $params['marker'];
51 -
 51+
5252 $error="";
53 -
 53+
5454 //default values (meaning these parameters can be missed out)
5555 if ($width=='') $width ='450';
5656 if ($height=='') $height='320';
5757 if ($layer=='') $layer='mapnik';
58 -
 58+
5959 if ($zoom=='') $zoom = $params['zoom']; //see if they used 'zoom' rather than 'z' (and allow it)
6060
6161 $marker = ( $marker != '' && $marker != '0' );
62 -
 62+
6363 //trim off the 'px' on the end of pixel measurement numbers (ignore if present)
6464 if (substr($width,-2)=='px') $width = substr($width,0,-2);
6565 if (substr($height,-2)=='px') $height = substr($height,0,-2);
66 -
 66+
6767 //Check required parameters values are provided
6868 if ($lat=='') $error .= wfMsg( 'slippymap_latmissing' );
6969 if ($lon=='') $error .= wfMsg( 'slippymap_lonmissing' );
7070 if ($zoom=='') $error .= wfMsg( 'slippymap_zoommissing' );
71 - if ($params['long']!='') $error .= wfMsg( 'slippymap_longdepreciated' );
72 -
 71+ if ( isset( $params['long'] ) ) $error .= wfMsg( 'slippymap_longdepreciated' );
 72+
7373 if ($error=='') {
7474 //no errors so far. Now check the values
7575 if (!is_numeric($width)) {
@@ -105,10 +105,10 @@
106106 $error = wfMsg( 'slippymap_zoombig' );
107107 }
108108 }
109 -
 109+
110110 //Find the tile server URL to use. Note that we could allow the user to override that with
111111 //*any* tile server URL for more flexibility, but that might be a security concern.
112 -
 112+
113113 $layer = strtolower($layer);
114114 $layerObjectDef = '';
115115 if ($layer=='osmarender') {
@@ -120,12 +120,11 @@
121121 } else {
122122 $error = wfMsg( 'slippymap_invalidlayer', htmlspecialchars($layer) );
123123 }
124 -
125 -
 124+
126125 if ($error!="") {
127126 //Something was wrong. Spew the error message and input text.
128127 $output = '';
129 - $output .= "<font color=\"red\"><b>". wfMsg( 'slippymap_maperror' ). "</b> " . $error . "</font><br>";
 128+ $output .= "<span class=\"error\">". wfMsg( 'slippymap_maperror' ) . ' ' . $error . "</span><br />";
130129 $output .= htmlspecialchars($input);
131130 } else {
132131 //HTML output for the slippy map.
@@ -133,7 +132,7 @@
134133 //otherwise MediaWiki adds <BR> tags, which is bad in the middle of block of javascript.
135134 //There are other ways of fixing this, but not for MediaWiki v4
136135 //(See http://www.mediawiki.org/wiki/Manual:Tag_extensions#How_can_I_avoid_modification_of_my_extension.27s_HTML_output.3F)
137 -
 136+
138137 $output = '<script type="text/javascript"> var osm_fully_loaded=false;';
139138
140139 // defer loading of the javascript. Since the script is quite bit, it would delay
@@ -143,22 +142,19 @@
144143 ' sc.src = "http://openlayers.org/api/OpenLayers.js";' .
145144 ' document.body.appendChild( sc );' .
146145 ' var sc = document.createElement("script");' .
147 - ' sc.src = "http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SlippyMap/OpenStreetMap.js?view=co";'.
 146+ ' sc.src = "http://svn.wikimedia.org/viewvc/mediawiki/trunk/extensions/SlippyMap/OpenStreetMap.js?view=co&' . $wgSlippyMapVersion . '";'.
148147 ' document.body.appendChild( sc );' .
149148 '} );';
150149
151 -
152 -
153 -
154150 $output .= "var lon= $lon; var lat= $lat; var zoom= $zoom; var lonLat;";
155 -
 151+
156152 $output .= 'var map; ';
157 -
 153+
158154 $output .= 'function lonLatToMercator(ll) { ';
159155 $output .= ' var lon = ll.lon * 20037508.34 / 180; ';
160156 $output .= ' var lat = Math.log (Math.tan ((90 + ll.lat) * Math.PI / 360)) / (Math.PI / 180); ';
161157 $output .= ' lat = lat * 20037508.34 / 180; ';
162 -
 158+
163159 $output .= ' return new OpenLayers.LonLat(lon, lat); ';
164160 $output .= '} ';
165161
@@ -170,32 +166,31 @@
171167 $output .= ' lat = lat * 180 / Math.PI;';
172168 $output .= ' return new OpenLayers.LonLat(lon, lat); ';
173169 $output .= ' } ';
174 -
 170+
175171 $output .= 'addOnloadHook( slippymap_init ); ';
176 -
 172+
177173 $output .= 'function slippymap_init() { ';
178174 $output .= ' if (!osm_fully_loaded) { window.setTimeout("slippymap_init()",500); return 0; } ' ;
179 -
 175+
180176 $output .= ' map = new OpenLayers.Map("map", { ';
181177 $output .= ' controls:[ ';
182178 $output .= ' new OpenLayers.Control.Navigation(), ';
183 -
 179+
184180 if ($height>320) {
185181 //Add the zoom bar control, except if the map is only little
186182 $output .= ' new OpenLayers.Control.PanZoomBar(),';
187183 } else if ( $height > 140 ) {
188184 $output .= ' new OpenLayers.Control.PanZoom(),';
189185 }
190 -
 186+
191187 $output .= ' new OpenLayers.Control.Attribution()], ';
192188 $output .= ' maxExtent: new OpenLayers.Bounds(-20037508.34,-20037508.34,20037508.34,20037508.34), ';
193189 $output .= " maxResolution:156543.0399, units:'meters', projection: \"EPSG:900913\"} ); ";
194 -
195 -
 190+
196191 $output .= " layer = new " . $layerObjectDef;
197 -
 192+
198193 $output .= " map.addLayer(layer); ";
199 -
 194+
200195 $output .= " lonLat = lonLatToMercator(new OpenLayers.LonLat(lon, lat)); ";
201196
202197 if ( $marker ) {
@@ -206,10 +201,10 @@
207202 " var icon = new OpenLayers.Icon('http://boston.openguides.org/markers/YELLOW.png',size,offset);" .
208203 ' markers.addMarker(new OpenLayers.Marker( lonLat,icon)); ';
209204 }
210 -
 205+
211206 $output .= " map.setCenter (lonLat, zoom); ";
212207 $output .= " postmap = document.getElementById('postmap'); ";
213 - $output .= " postmap.innerHTML = '<input type=\"button\" value=\"Reset view\" onmousedown=\"map.setCenter(lonLat, zoom);\" /><input type=\"button\" value=\"Get wikicode\" onmousedown=\"slippymap_getWikicode();\" \>'; ";
 208+ $output .= " postmap.innerHTML = '<input type=\"button\" value=\"" . wfMsg( 'slippymap_resetview' ) . "\" onmousedown=\"map.setCenter(lonLat, zoom);\" /><input type=\"button\" value=\"" . wfMsg( 'slippymap_button_code' ) . "\" onmousedown=\"slippymap_getWikicode();\" \>'; ";
214209 $output .= "} ";
215210
216211 $output .= 'function slippymap_getWikicode() {';
@@ -218,18 +213,15 @@
219214
220215 $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>" ); ';
221216 $output .= '}';
222 -
 217+
223218 $output .= "</script> ";
224 -
225 -
 219+
226220 $output .= '<div class="map">';
227221 $output .= "<div style=\"width: {$width}px; height:{$height}px; border-style:solid; border-width:1px; border-color:lightgrey;\" id=\"map\">";
228222 $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\">";
229223 $output .= "<img src=\"".$wgMapOfServiceUrl."lat=$lat&long=$lon&z=$zoom&w=$width&h=$height&format=jpeg\" width=\"$width\" height=\"$height\" border=\"0\"><br/>";
230224 $output .= '<span style="font-size:60%; background-color:white; position:relative; top:-15px; ">OpenStreetMap - CC-BY-SA-2.0</span>';
231225 $output .= '</a></noscript></div><div id="postmap"></div></div>';
232 -
233 -
234226 }
235227 return $output;
236228 }

Status & tagging log