r43459 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r43458‎ | r43459 | r43460 >
Date:17:41, 13 November 2008
Author:siebrand
Status:old
Tags:
Comment:
* remove indent level
* remove need for an additional dirname()
* some formatting fixes
* put authors in an array

No functional changes
Modified paths:
  • /trunk/extensions/SlippyMap/SlippyMap.class.php (modified) (history)
  • /trunk/extensions/SlippyMap/SlippyMap.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SlippyMap/SlippyMap.php
@@ -1,18 +1,18 @@
22 <?php
33 # OpenStreetMap SlippyMap - MediaWiki extension
4 -#
 4+#
55 # This defines what happens when <slippymap> tag is placed in the wikitext
6 -#
 6+#
77 # 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.
99 #
1010 # 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>
1212 #
1313 # Tile images are not cached local to the wiki.
1414 # To acheive this (remove the OSM dependency) you might set up a squid proxy,
1515 # and modify the requests URLs here accordingly.
16 -#
 16+#
1717 # This file should be placed in the mediawiki 'extensions' directory
1818 # ...and then it needs to be 'included' within LocalSettings.php
1919 #
@@ -38,34 +38,35 @@
3939 #
4040
4141
42 -if( defined( 'MEDIAWIKI' ) ) {
43 - $wgExtensionFunctions[] = 'wfslippymap';
 42+if (!defined('MEDIAWIKI'))
 43+ die();
4444
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 &lt;slippymap&gt; tag to display an OpenLayers slippy map. Maps are from [http://openstreetmap.org openstreetmap.org]',
52 - 'descriptionmsg' => 'slippymap_desc',
53 - );
 45+$wgExtensionFunctions[] = 'wfslippymap';
5446
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 &lt;slippymap&gt; tag to display an OpenLayers slippy map. Maps are from [http://openstreetmap.org openstreetmap.org]',
 54+ 'descriptionmsg' => 'slippymap_desc',
 55+);
5756
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';
6060
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;
7163
 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/?";
7273 }
Index: trunk/extensions/SlippyMap/SlippyMap.class.php
@@ -1,18 +1,18 @@
22 <?php
33 # OpenStreetMap SlippyMap - MediaWiki extension
4 -#
 4+#
55 # This defines what happens when <slippymap> tag is placed in the wikitext
6 -#
 6+#
77 # 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.
99 #
1010 # 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>
1212 #
1313 # Tile images are not cached local to the wiki.
1414 # To acheive this (remove the OSM dependency) you might set up a squid proxy,
1515 # and modify the requests URLs here accordingly.
16 -#
 16+#
1717 # This file should be placed in the mediawiki 'extensions' directory
1818 # ...and then it needs to be 'included' within LocalSettings.php
1919 #
@@ -37,9 +37,7 @@
3838 # @addtogroup Extensions
3939 #
4040
41 -
4241 class SlippyMap {
43 -
4442 function SlippyMap() {
4543 }
4644
@@ -49,37 +47,37 @@
5048
5149 wfLoadExtensionMessages( 'SlippyMap' );
5250
53 - if ( isset( $argv['lat'] ) ) {
 51+ if ( isset( $argv['lat'] ) ) {
5452 $lat = $argv['lat'];
5553 } else {
5654 $lat = '';
5755 }
58 - if ( isset( $argv['lon'] ) ) {
 56+ if ( isset( $argv['lon'] ) ) {
5957 $lon = $argv['lon'];
6058 } else {
6159 $lon = '';
6260 }
63 - if ( isset( $argv['z'] ) ) {
 61+ if ( isset( $argv['z'] ) ) {
6462 $zoom = $argv['z'];
6563 } else {
6664 $zoom = '';
6765 }
68 - if ( isset( $argv['w'] ) ) {
 66+ if ( isset( $argv['w'] ) ) {
6967 $width = $argv['w'];
7068 } else {
7169 $width = '';
7270 }
73 - if ( isset( $argv['h'] ) ) {
 71+ if ( isset( $argv['h'] ) ) {
7472 $height = $argv['h'];
7573 } else {
7674 $height = '';
7775 }
78 - if ( isset( $argv['layer'] ) ) {
 76+ if ( isset( $argv['layer'] ) ) {
7977 $layer = $argv['layer'];
8078 } else {
8179 $layer = '';
8280 }
83 - if ( isset( $argv['marker'] ) ) {
 81+ if ( isset( $argv['marker'] ) ) {
8482 $marker = $argv['marker'];
8583 } else {
8684 $marker = '';
@@ -88,9 +86,9 @@
8987 $error='';
9088
9189 //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';
9593
9694 if ($zoom=='' && isset( $argv['zoom'] ) ) {
9795 $zoom = $argv['zoom']; //see if they used 'zoom' rather than 'z' (and allow it)
@@ -114,7 +112,7 @@
115113 if ( $zoom=='' ) $error .= wfMsg( 'slippymap_zoommissing' );
116114
117115 if ($error=='') {
118 - //no errors so far. Now check the values
 116+ //no errors so far. Now check the values
119117 if (!is_numeric($width)) {
120118 $error = wfMsg( 'slippymap_widthnan', $width );
121119 } else if (!is_numeric($height)) {
@@ -155,7 +153,7 @@
156154
157155 $layer = strtolower($layer);
158156 $layerObjectDef = '';
159 - if ($layer=='osmarender') {
 157+ if ($layer=='osmarender') {
160158 $layerObjectDef = 'OpenLayers.Layer.OSM.Osmarender("Osmarender"); ';
161159 } elseif ($layer=='mapnik') {
162160 $layerObjectDef = 'OpenLayers.Layer.OSM.Mapnik("Mapnik"); ';
@@ -182,13 +180,13 @@
183181 // defer loading of the javascript. Since the script is quite bit, it would delay
184182 // page loading and rendering dramatically
185183 $output .= 'addOnloadHook( function() { ' .
186 - ' var sc = document.createElement("script");' .
 184+ ' var sc = document.createElement("script");' .
187185 ' 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+ '} );';
193191
194192 $output .= "var lon= ${lon}; var lat= ${lat}; var zoom= ${zoom}; var lonLat;";
195193
@@ -205,7 +203,7 @@
206204
207205 if ($height>320) {
208206 //Add the zoom bar control, except if the map is only little
209 - $output .= ' new OpenLayers.Control.PanZoomBar(),';
 207+ $output .= ' new OpenLayers.Control.PanZoomBar(),';
210208 } else if ( $height > 140 ) {
211209 $output .= ' new OpenLayers.Control.PanZoom(),';
212210 }
@@ -223,16 +221,19 @@
224222
225223 if ( $marker ) {
226224 $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)); ';
232230 }
233231
234232 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+ );
237238 $output .= 'var vector = new OpenLayers.Layer.Vector("Vector Layer"); ' .
238239 ' map.addLayer(vector); ' .
239240 ' kml = new OpenLayers.Format.KML( { "internalProjection": map.baseLayer.projection, ' .
@@ -247,7 +248,7 @@
248249 $output .= '} ';
249250
250251 $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"));';
252253 $output .= ' Z = map.getZoom(); ';
253254 $output .= ' size = map.getSize();';
254255

Status & tagging log