r64989 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r64988‎ | r64989 | r64990 >
Date:15:16, 13 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.6 - refactored a bunch of stuff and further implemented #geodistance and #finddestination
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3DispMap.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3DispPoint.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_MapFeature.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispMap.php (modified) (history)
  • /trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3DispPoint.php
@@ -75,8 +75,8 @@
7676 "$this->mapName",
7777 {
7878 zoom: $this->zoom,
79 - lat: $this->centre_lat,
80 - lon: $this->centre_lon,
 79+ lat: $this->centreLat,
 80+ lon: $this->centreLon,
8181 types: [],
8282 mapTypeId: $this->type
8383 },
Index: trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3DispMap.php
@@ -73,8 +73,8 @@
7474 "$this->mapName",
7575 {
7676 zoom: $this->zoom,
77 - lat: $this->centre_lat,
78 - lon: $this->centre_lon,
 77+ lat: $this->centreLat,
 78+ lon: $this->centreLon,
7979 types: [],
8080 mapTypeId: $this->type
8181 },
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php
@@ -70,8 +70,8 @@
7171 function() {
7272 initOpenLayer(
7373 '$this->mapName',
74 - $this->centre_lon,
75 - $this->centre_lat,
 74+ $this->centreLon,
 75+ $this->centreLat,
7676 $this->zoom,
7777 [$layerItems],
7878 [$this->controls],
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php
@@ -63,8 +63,8 @@
6464 function() {
6565 initOpenLayer(
6666 '$this->mapName',
67 - $this->centre_lon,
68 - $this->centre_lat,
 67+ $this->centreLon,
 68+ $this->centreLat,
6969 $this->zoom,
7070 [$layerItems],
7171 [$this->controls],
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
@@ -157,14 +157,14 @@
158158 if ( empty( $this->centre ) ) {
159159 if ( count( $this->markerData ) == 1 ) {
160160 // If centre is not set and there is exactelly one marker, use it's coordinates.
161 - $this->centre_lat = Xml::escapeJsString( $this->markerData[0]['lat'] );
162 - $this->centre_lon = Xml::escapeJsString( $this->markerData[0]['lon'] );
 161+ $this->centreLat = Xml::escapeJsString( $this->markerData[0]['lat'] );
 162+ $this->centreLon = Xml::escapeJsString( $this->markerData[0]['lon'] );
163163 }
164164 elseif ( count( $this->markerData ) > 1 ) {
165165 // If centre is not set and there are multiple markers, set the values to null,
166166 // to be auto determined by the JS of the mapping API.
167 - $this->centre_lat = 'null';
168 - $this->centre_lon = 'null';
 167+ $this->centreLat = 'null';
 168+ $this->centreLon = 'null';
169169 }
170170 else {
171171 // If centre is not set and there are no markers, use the default latitude and longitutde.
@@ -176,8 +176,8 @@
177177
178178 // If the centre is not false, it will be a valid coordinate, which can be used to set the latitude and longitutde.
179179 if ( $this->centre ) {
180 - $this->centre_lat = Xml::escapeJsString( $this->centre['lat'] );
181 - $this->centre_lon = Xml::escapeJsString( $this->centre['lon'] );
 180+ $this->centreLat = Xml::escapeJsString( $this->centre['lat'] );
 181+ $this->centreLon = Xml::escapeJsString( $this->centre['lon'] );
182182 }
183183 else { // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used.
184184 $this->setCentreDefaults();
@@ -190,7 +190,7 @@
191191 */
192192 private function setCentreDefaults() {
193193 global $egMapsMapLat, $egMapsMapLon;
194 - $this->centre_lat = $egMapsMapLat;
195 - $this->centre_lon = $egMapsMapLon;
 194+ $this->centreLat = $egMapsMapLat;
 195+ $this->centreLon = $egMapsMapLon;
196196 }
197197 }
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
@@ -69,16 +69,16 @@
7070 private function setCentre() {
7171 if ( empty( $this->coordinates ) ) { // If centre is not set, use the default latitude and longitutde.
7272 global $egMapsMapLat, $egMapsMapLon;
73 - $this->centre_lat = $egMapsMapLat;
74 - $this->centre_lon = $egMapsMapLon;
 73+ $this->centreLat = $egMapsMapLat;
 74+ $this->centreLon = $egMapsMapLon;
7575 }
7676 else { // If a centre value is set, geocode when needed and use it.
7777 $this->coordinates = MapsGeocoder::attemptToGeocode( $this->coordinates, $this->geoservice, $this->serviceName );
7878
7979 // If the centre is not false, it will be a valid coordinate, which can be used to set the latitude and longitutde.
8080 if ( $this->coordinates ) {
81 - $this->centre_lat = Xml::escapeJsString( $this->coordinates['lat'] );
82 - $this->centre_lon = Xml::escapeJsString( $this->coordinates['lon'] );
 81+ $this->centreLat = Xml::escapeJsString( $this->coordinates['lat'] );
 82+ $this->centreLon = Xml::escapeJsString( $this->coordinates['lon'] );
8383 }
8484 else { // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used.
8585 $this->setCentreDefaults();
Index: trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php
@@ -56,43 +56,28 @@
5757
5858 // We already know the $parser.
5959 array_shift( $args );
60 -
61 - // Default parameter assignment, to allow for nameless syntax.
62 - $defaultParams = array( 'location1', 'location2' );
63 - $parameters = array();
6460
65 - // Determine all parameter names and value, and take care of default (nameless)
66 - // parameters, by turning them into named ones.
67 - foreach( $args as $arg ) {
68 - $parts = explode( '=', $arg );
69 - if ( count( $parts ) == 1 ) {
70 - if ( count( $defaultParams ) > 0 ) {
71 - $defaultParam = array_shift( $defaultParams );
72 - $parameters[$defaultParam] = trim( $parts[0] );
73 - }
74 - } else {
75 - $name = strtolower( trim( array_shift( $parts ) ) );
76 - $parameters[$name] = trim( implode( $parts ) );
77 - }
78 - }
 61+ $manager = new ValidatorManager();
7962
80 - $parameterInfo = array(
81 - 'location1' => array(
82 - 'required' => true
 63+ $parameters = $manager->manageMapparameters(
 64+ $parameters,
 65+ array(
 66+ 'location1' => array(
 67+ 'required' => true
 68+ ),
 69+ 'location2' => array(
 70+ 'required' => true
 71+ ),
8372 ),
84 - 'location2' => array(
85 - 'required' => true
86 - ),
 73+ array( 'location1', 'location2' )
8774 );
8875
89 - $manager = new ValidatorManager();
90 -
91 - $parameters = $manager->manageMapparameters( $parameters, $parameterInfo );
92 -
9376 $doCalculation = $parameters !== false;
9477
9578 if ( $doCalculation ) {
96 - if ( self::geocoderIsAvailable() ) {
 79+ $canGeocode = self::geocoderIsAvailable();
 80+
 81+ if ( $canGeocode ) {
9782 $start = MapsGeocoder::attemptToGeocode( $parameters['location1'] );
9883 $end = MapsGeocoder::attemptToGeocode( $parameters['location2'] );
9984 } else {
@@ -108,25 +93,33 @@
10994 $output .= '<br />' . $errorList;
11095 }
11196 } else {
112 - $errorList = '';
 97+ global $egValidatorFatalLevel;
11398
114 - if ( !$start ) {
115 - $errorList .= wfMsgExt( 'maps-invalid-coordinates', array( 'parsemag' ), $parameters['location1'] );
 99+ $fails = array();
 100+ if ( !$start ) $fails[] = $parameters['location1'];
 101+ if ( !$end ) $fails[] = $parameters['location2'];
 102+
 103+ switch ( $egValidatorFatalLevel ) {
 104+ case Validator_ERRORS_NONE:
 105+ $output = '';
 106+ break;
 107+ case Validator_ERRORS_WARN:
 108+ $output = '<b>' . wfMsgExt( 'validator_warning_parameters', array( 'parsemag' ), count( $fails ) ) . '</b>';
 109+ break;
 110+ case Validator_ERRORS_SHOW: default:
 111+ global $wgLang;
 112+
 113+ if ( $canGeocode ) {
 114+ $output = htmlspecialchars( wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $fails ), count( $fails ) ) );
 115+ } else {
 116+ $output = htmlspecialchars( wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $fails ), count( $fails ) ) );
 117+ }
 118+ break;
116119 }
117 -
118 - if ( !$end ) {
119 - if ( $errorList != '' ) $errorList .= '<br />';
120 - $errorList .= wfMsgExt( 'maps-invalid-coordinates', array( 'parsemag' ), $parameters['location2'] );
121 - }
122 -
123 - $output = $errorList;
124120 }
125121 } else {
126122 // One of the parameters is not provided, so display an error message.
127 - // If the error level is Validator_ERRORS_MINIMAL, show the Validator_ERRORS_WARN message since
128 - // the function could not do any work, otherwise use the error level as it is.
129 - global $egValidatorErrorLevel;
130 - $output = $manager->getErrorList( $egValidatorErrorLevel == Validator_ERRORS_MINIMAL ? Validator_ERRORS_WARN : $egValidatorErrorLevel );
 123+ $output = $manager->getErrorList();
131124 }
132125
133126 return array( $output, 'noparse' => true, 'isHTML' => true );
@@ -139,49 +132,101 @@
140133 * @param Parser $parser
141134 */
142135 public static function renderFindDestination( Parser &$parser ) {
 136+ global $egMapsAvailableServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsAvailableCoordNotations;
 137+ global $egMapsCoordinateNotation, $egMapsAllowCoordsGeocoding, $egMapsCoordinateDirectional;
 138+
143139 $args = func_get_args();
144140
145141 // We already know the $parser.
146142 array_shift( $args );
147 -
148 - // Default parameter assignment, to allow for nameless syntax.
149 - $defaultParams = array( 'location', 'bearing', 'distance' );
150 - $parameters = array();
151143
152 - // Determine all parameter names and value, and take care of default (nameless)
153 - // parameters, by turning them into named ones.
154 - foreach( $args as $arg ) {
155 - $parts = explode( '=', $arg );
156 - if ( count( $parts ) == 1 ) {
157 - if ( count( $defaultParams ) > 0 ) {
158 - $defaultParam = array_shift( $defaultParams );
159 - $parameters[$defaultParam] = trim( $parts[0] );
160 - }
161 - } else {
162 - $name = strtolower( trim( array_shift( $parts ) ) );
163 - $parameters[$name] = trim( implode( $parts ) );
164 - }
165 - }
 144+ $manager = new ValidatorManager();
166145
167 - $parameterInfo = array(
168 - 'location' => array(
169 - 'required' => true
 146+ $parameters = $manager->manageMapparameters(
 147+ $parameters,
 148+ array(
 149+ 'location' => array(
 150+ 'required' => true
 151+ ),
 152+ 'bearing' => array(
 153+ 'type' => 'float',
 154+ 'required' => true
 155+ ),
 156+ 'distance' => array(
 157+ 'type' => 'float',
 158+ 'required' => true
 159+ ),
 160+ 'mappingservice' => array(
 161+ 'criteria' => array(
 162+ 'in_array' => $egMapsAvailableServices
 163+ ),
 164+ 'default' => false
 165+ ),
 166+ 'service' => array(
 167+ 'criteria' => array(
 168+ 'in_array' => $egMapsAvailableGeoServices
 169+ ),
 170+ 'default' => $egMapsDefaultGeoService
 171+ ),
 172+ 'format' => array(
 173+ 'criteria' => array(
 174+ 'in_array' => $egMapsAvailableCoordNotations
 175+ ),
 176+ 'aliases' => array(
 177+ 'notation'
 178+ ),
 179+ 'default' => $egMapsCoordinateNotation
 180+ ),
 181+ 'allowcoordinates' => array(
 182+ 'type' => 'boolean',
 183+ 'default' => $egMapsAllowCoordsGeocoding
 184+ ),
 185+ 'directional' => array(
 186+ 'type' => 'boolean',
 187+ 'default' => $egMapsCoordinateDirectional
 188+ ),
170189 ),
171 - 'bearing' => array(
172 - 'required' => true
173 - ),
174 - 'distance' => array(
175 - 'required' => true
176 - ),
177 - );
 190+ array( 'location', 'bearing', 'distance' )
 191+ );
178192
179 - $manager = new ValidatorManager();
180 -
181 - $parameters = $manager->manageMapparameters( $parameters, $parameterInfo );
182 -
183193 $doCalculation = $parameters !== false;
184194
185 - // TODO
 195+ if ( $doCalculation ) {
 196+ $canGeocode = self::geocoderIsAvailable();
 197+
 198+ if ( $canGeocode ) {
 199+ $location = MapsGeocoder::attemptToGeocode( $parameters['location'] );
 200+ } else {
 201+ $location = MapsCoordinateParser::parseCoordinates( $parameters['location'] );
 202+ }
 203+
 204+ if ( $location ) {
 205+ $destination = self::findDestination( $location, $parameters['bearing'], $parameters['distance'] );
 206+ } else {
 207+ global $egValidatorFatalLevel;
 208+ switch ( $egValidatorFatalLevel ) {
 209+ case Validator_ERRORS_NONE:
 210+ $output = '';
 211+ break;
 212+ case Validator_ERRORS_WARN:
 213+ $output = '<b>' . wfMsgExt( 'validator_warning_parameters', array( 'parsemag' ), 1 ) . '</b>';
 214+ break;
 215+ case Validator_ERRORS_SHOW: default:
 216+ // Show an error that the location could not be geocoded or the coordinates where not recognized.
 217+ if ( $canGeocode ) {
 218+ $output = htmlspecialchars( wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $parameters['location'] ) );
 219+ } else {
 220+ $output = htmlspecialchars( wfMsgExt( 'maps-invalid-coordinates', array( 'parsemag' ), $parameters['location'] ) );
 221+ }
 222+ break;
 223+ }
 224+ }
 225+ } else {
 226+ // Either required parameters are missing, or there are errors while having a strict error level.
 227+ $output = $manager->getErrorList();
 228+ }
 229+
 230+ return array( $output, 'noparse' => true, 'isHTML' => true );
186231 }
187232
188233 /**
Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php
@@ -2,10 +2,6 @@
33
44 /**
55 * This file contains the registration functions for the following parser functions:
6 - *
7 - * {{#geocode:<Address>|<param1>=<value1>|<param2>=<value2>}}
8 - * {{#geocodelat:<Address>|<param1>=<value1>|<param2>=<value2>}}
9 - * {{#geocodelng:<Address>|<param1>=<value1>|<param2>=<value2>}}
106 *
117 * @file Maps_GeocodeFunctions.php
128 * @ingroup Maps
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -114,16 +114,19 @@
115115
116116 if ( $egValidatorErrorLevel >= Validator_ERRORS_WARN ) {
117117 if ( count( $coordFails ) > 0 ) {
 118+ // TODO: escaping
118119 $output .= '<i>' . wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
119120 }
120121
121122 if ( count( $geoFails ) > 0 ) {
 123+ // TODO: escaping
122124 $output .= '<i>' . wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>';
123125 }
124126 }
125127 }
126128 elseif ( $egValidatorErrorLevel >= Validator_ERRORS_MINIMAL ) {
127129 if ( $coords == '' && ( count( $geoFails ) > 0 || count( $coordFails ) > 0 ) ) {
 130+ // TODO: escaping
128131 if ( count( $coordFails ) > 0 ) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
129132 if ( count( $geoFails ) > 0 ) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>';
130133 $output .= '<i>' . wfMsg( 'maps_map_cannot_be_displayed' ) . '</i>';
Index: trunk/extensions/Maps/Maps.php
@@ -33,7 +33,7 @@
3434 echo '<b>Warning:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.';
3535 }
3636 else {
37 - define( 'Maps_VERSION', '0.6 a12' );
 37+ define( 'Maps_VERSION', '0.6 a13' );
3838
3939 // The different coordinate notations.
4040 define( 'Maps_COORDS_FLOAT', 'float' );
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispMap.php
@@ -77,8 +77,8 @@
7878 mode: '$this->mode',
7979 layer: 'osm-like',
8080 locale: '$this->lang',
81 - lat: $this->centre_lat,
82 - lon: $this->centre_lon,
 81+ lat: $this->centreLat,
 82+ lon: $this->centreLon,
8383 zoom: $this->zoom,
8484 markers: [],
8585 controls: [$this->controls]
@@ -130,10 +130,10 @@
131131 $staticType = $mode['handler'];
132132 $staticOptions = $mode['options'];
133133
134 - $static = new $staticType( $this->centre_lat, $this->centre_lon, $this->zoom, $this->width, $this->height, $this->lang, $staticOptions );
 134+ $static = new $staticType( $this->centreLat, $this->centreLon, $this->zoom, $this->width, $this->height, $this->lang, $staticOptions );
135135 $rendering_url = $static->getUrl();
136136
137 - $alt = wfMsg( 'maps_centred_on', $this->centre_lat, $this->centre_lon );
 137+ $alt = wfMsg( 'maps_centred_on', $this->centreLat, $this->centreLon );
138138 $title = $this->activatable ? wfMsg( 'maps_click_to_activate' ) : $alt;
139139
140140 $image = array(
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php
@@ -62,8 +62,8 @@
6363 {
6464 layer: 'osm-like',
6565 locale: '$this->lang',
66 - lat: $this->centre_lat,
67 - lon: $this->centre_lon,
 66+ lat: $this->centreLat,
 67+ lon: $this->centreLon,
6868 zoom: $this->zoom,
6969 markers: [$this->markerString],
7070 controls: [$this->controls]
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php
@@ -80,8 +80,8 @@
8181 function() {
8282 initializeGoogleMap('$this->mapName',
8383 {
84 - lat: $this->centre_lat,
85 - lon: $this->centre_lon,
 84+ lat: $this->centreLat,
 85+ lon: $this->centreLon,
8686 zoom: $this->zoom,
8787 type: $this->type,
8888 types: [$this->types],
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php
@@ -83,8 +83,8 @@
8484 function() {
8585 initializeGoogleMap('$this->mapName',
8686 {
87 - lat: $this->centre_lat,
88 - lon: $this->centre_lon,
 87+ lat: $this->centreLat,
 88+ lon: $this->centreLon,
8989 zoom: $this->zoom,
9090 type: $this->type,
9191 types: [$this->types],
Index: trunk/extensions/Maps/Maps_MapFeature.php
@@ -19,6 +19,8 @@
2020 * @ingroup Maps
2121 *
2222 * @author Jeroen De Dauw
 23+ *
 24+ * TODO: refactor this and subclasses to follow mw conventions and simply have a better design pattern.
2325 */
2426 abstract class MapsMapFeature {
2527
@@ -46,8 +48,8 @@
4749
4850 protected $mapName;
4951
50 - protected $centre_lat;
51 - protected $centre_lon;
 52+ protected $centreLat;
 53+ protected $centreLon;
5254
5355 protected $output = '';
5456 protected $errorList;
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php
@@ -68,8 +68,8 @@
6969 function() {
7070 initializeYahooMap(
7171 '$this->mapName',
72 - $this->centre_lat,
73 - $this->centre_lon,
 72+ $this->centreLat,
 73+ $this->centreLon,
7474 $this->zoom,
7575 $this->type,
7676 [$this->types],
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php
@@ -61,8 +61,8 @@
6262 function() {
6363 initializeYahooMap(
6464 '$this->mapName',
65 - $this->centre_lat,
66 - $this->centre_lon,
 65+ $this->centreLat,
 66+ $this->centreLon,
6767 $this->zoom,
6868 $this->type,
6969 [$this->types],

Follow-up revisions

RevisionCommit summaryAuthorDate
r64992Follow up to r64989 - bugfixjeroendedauw15:38, 13 April 2010
r64998Follow up to r64989, fixed some bugs and used new code from Validatorjeroendedauw17:37, 13 April 2010

Status & tagging log