r65108 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65107‎ | r65108 | r65109 >
Date:06:33, 16 April 2010
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
Changes for 0.6 - doing big rewrite of the maping classes and MapsParserFunctions. not completely finished, esp SM has not been adapted and will not work with this version
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/Maps.i18n.magic.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_MapFeature.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Settings.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Coordinates/Maps_Coordinates.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.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)

Diff [purge]

Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php
@@ -19,7 +19,6 @@
2020
2121 /**
2222 * @see MapsBaseMap::setMapSettings()
23 - *
2423 */
2524 protected function setMapSettings() {
2625 global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix;
@@ -30,7 +29,6 @@
3130
3231 /**
3332 * @see MapsBaseMap::doMapServiceLoad()
34 - *
3533 */
3634 protected function doMapServiceLoad() {
3735 global $egOpenLayersOnThisPage;
@@ -43,7 +41,6 @@
4442
4543 /**
4644 * @see MapsBaseMap::addSpecificMapHTML()
47 - *
4845 */
4946 public function addSpecificMapHTML( Parser $parser ) {
5047 $layerItems = MapsOpenLayers::createLayersStringAndLoadDependencies( $this->output, $this->layers );
Index: trunk/extensions/Maps/Maps.i18n.magic.php
@@ -3,13 +3,12 @@
44 $magicWords = array();
55
66 $magicWords['en'] = array(
 7+ 'display_map' => array( 0, 'display_map' ),
78 'display_point' => array( 0, 'display_point' ),
89 'display_points' => array( 0, 'display_points' ),
9 - 'display_address' => array( 0, 'display_address' ),
10 - 'display_addresses' => array( 0, 'display_addresses' ),
1110 'geocode' => array( 0, 'geocode' ),
1211 'geocodelat' => array( 0, 'geocodelat' ),
13 - 'geocodelng' => array( 0, 'geocodelng' ),
 12+ 'geocodelon' => array( 0, 'geocodelon' ),
1413 );
1514
1615 $magicWords['ar'] = array(
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php
@@ -16,7 +16,9 @@
1717 $wgAutoloadClasses['MapsDisplayPoint'] = $egMapsDir . 'ParserFunctions/DisplayPoint/Maps_DisplayPoint.php';
1818 $wgAutoloadClasses['MapsBasePointMap'] = $egMapsDir . 'ParserFunctions/DisplayPoint/Maps_BasePointMap.php';
1919
20 -$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic';
 20+if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) {
 21+ $wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic';
 22+}
2123 $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint';
2224
2325 $egMapsFeatures['pf'][] = 'MapsDisplayPoint::initialize';
@@ -52,7 +54,6 @@
5355 public static $parameters = array();
5456
5557 public static function initialize() {
56 - self::initializeParams();
5758 }
5859
5960 /**
@@ -67,32 +68,4 @@
6869 return MapsParserFunctions::getMapHtml( $parser, $args, 'display_point' );
6970 }
7071
71 - private static function initializeParams() {
72 - global $egMapsDefaultCentre, $egMapsDefaultTitle, $egMapsDefaultLabel, $egMapsDefaultServices;
73 -
74 - self::$parameters = array_merge(
75 - MapsParserFunctions::$parameters,
76 - array(
77 - 'service' => array(
78 - 'default' => $egMapsDefaultServices['display_map']
79 - ),
80 - 'centre' => array(
81 - 'aliases' => array( 'center' ),
82 - 'default' => $egMapsDefaultCentre
83 - ),
84 - 'title' => array(
85 - 'default' => $egMapsDefaultTitle
86 - ),
87 - 'label' => array(
88 - 'default' => $egMapsDefaultLabel
89 - ),
90 - 'icon' => array(
91 - 'criteria' => array(
92 - 'not_empty' => array()
93 - )
94 - ),
95 - )
96 - );
97 - }
98 -
9972 }
\ No newline at end of file
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
@@ -22,12 +22,42 @@
2323 *
2424 * @author Jeroen De Dauw
2525 */
26 -abstract class MapsBasePointMap extends MapsMapFeature implements iDisplayFunction {
 26+abstract class MapsBasePointMap extends MapsMapFeature implements iDisplayFunction {
2727
2828 private $markerData = array();
2929 protected $markerString;
3030
3131 /**
 32+ * @return array
 33+ */
 34+ public function getFeatureParameters() {
 35+ global $egMapsDefaultServices, $egMapsDefaultTitle, $egMapsDefaultLabel;
 36+
 37+ return array_merge(
 38+ parent::getFeatureParameters(),
 39+ array(
 40+ 'service' => array(
 41+ 'default' => $egMapsDefaultServices['display_point']
 42+ ),
 43+ 'centre' => array(
 44+ 'aliases' => array( 'center' ),
 45+ ),
 46+ 'title' => array(
 47+ 'default' => $egMapsDefaultTitle
 48+ ),
 49+ 'label' => array(
 50+ 'default' => $egMapsDefaultLabel
 51+ ),
 52+ 'icon' => array(
 53+ 'criteria' => array(
 54+ 'not_empty' => array()
 55+ )
 56+ ),
 57+ )
 58+ );
 59+ }
 60+
 61+ /**
3262 * Handles the request from the parser hook by doing the work that's common for all
3363 * mapping services, calling the specific methods and finally returning the resulting output.
3464 *
@@ -40,24 +70,24 @@
4171 $this->setMapSettings();
4272
4373 $this->featureParameters = MapsDisplayPoint::$parameters;
44 -
45 - if ( parent::manageMapProperties( $params, __CLASS__ ) ) {
46 - $this->doMapServiceLoad();
4774
48 - $this->setMapName();
49 -
50 - $this->setMarkerData( $parser );
51 -
52 - $this->createMarkerString();
53 -
54 - $this->setZoom();
55 -
56 - $this->setCentre();
57 -
58 - $this->addSpecificMapHTML( $parser );
59 - }
 75+ $this->doMapServiceLoad();
 76+
 77+ parent::setMapProperties( $params, __CLASS__ );
6078
61 - return $this->output . $this->errorList;
 79+ $this->setMapName();
 80+
 81+ $this->setMarkerData( $parser );
 82+
 83+ $this->createMarkerString();
 84+
 85+ $this->setZoom();
 86+
 87+ $this->setCentre();
 88+
 89+ $this->addSpecificMapHTML( $parser );
 90+
 91+ return $this->output;
6292 }
6393
6494 /**
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php
@@ -16,7 +16,9 @@
1717 $wgAutoloadClasses['MapsDisplayMap'] = $egMapsDir . 'ParserFunctions/DisplayMap/Maps_DisplayMap.php';
1818 $wgAutoloadClasses['MapsBaseMap'] = $egMapsDir . 'ParserFunctions/DisplayMap/Maps_BaseMap.php';
1919
20 -$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic';
 20+if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) {
 21+ $wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic';
 22+}
2123 $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap';
2224
2325 $egMapsFeatures['pf'][] = 'MapsDisplayMap::initialize';
@@ -51,7 +53,6 @@
5254 public static $parameters = array();
5355
5456 public static function initialize() {
55 - self::initializeParams();
5657 }
5758
5859 /**
@@ -65,18 +66,5 @@
6667 $args = func_get_args();
6768 return MapsParserFunctions::getMapHtml( $parser, $args, 'display_map' );
6869 }
69 -
70 - private static function initializeParams() {
71 - global $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsDefaultServices;
72 -
73 - self::$parameters = array_merge(
74 - MapsParserFunctions::$parameters,
75 - array(
76 - 'service' => array(
77 - 'default' => $egMapsDefaultServices['display_map']
78 - ),
79 - )
80 - );
81 - }
8270
8371 }
\ No newline at end of file
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
@@ -25,6 +25,22 @@
2626 abstract class MapsBaseMap extends MapsMapFeature implements iDisplayFunction {
2727
2828 /**
 29+ * @return array
 30+ */
 31+ public function getFeatureParameters() {
 32+ global $egMapsDefaultServices;
 33+
 34+ return array_merge(
 35+ parent::getFeatureParameters(),
 36+ array(
 37+ 'service' => array(
 38+ 'default' => $egMapsDefaultServices['display_map']
 39+ )
 40+ )
 41+ );
 42+ }
 43+
 44+ /**
2945 * Handles the request from the parser hook by doing the work that's common for all
3046 * mapping services, calling the specific methods and finally returning the resulting output.
3147 *
@@ -38,19 +54,19 @@
3955
4056 $this->featureParameters = MapsDisplayMap::$parameters;
4157
42 - if ( parent::manageMapProperties( $params, __CLASS__ ) ) {
43 - $this->doMapServiceLoad();
44 -
45 - $this->setMapName();
46 -
47 - $this->setZoom();
48 -
49 - $this->setCentre();
50 -
51 - $this->addSpecificMapHTML( $parser );
52 - }
 58+ $this->doMapServiceLoad();
 59+
 60+ parent::setMapProperties( $params, __CLASS__ );
5361
54 - return $this->output . $this->errorList;
 62+ $this->setMapName();
 63+
 64+ $this->setZoom();
 65+
 66+ $this->setCentre();
 67+
 68+ $this->addSpecificMapHTML( $parser );
 69+
 70+ return $this->output;
5571 }
5672
5773 /**
@@ -81,7 +97,10 @@
8298 $this->centreLon = Xml::escapeJsString( $this->coordinates['lon'] );
8399 }
84100 else { // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used.
85 - $this->setCentreDefaults();
 101+ // TODO: Some warning this failed would be nice here.
 102+ global $egMapsMapLat, $egMapsMapLon;
 103+ $this->centreLat = $egMapsMapLat;
 104+ $this->centreLon = $egMapsMapLon;
86105 }
87106 }
88107 }
Index: trunk/extensions/Maps/ParserFunctions/GeoFunctions/Maps_GeoFunctions.php
@@ -19,7 +19,9 @@
2020 // The approximate radius of the earth in km.
2121 define( 'Maps_EARTH_RADIUS', 20000 / M_PI );
2222
23 -$wgHooks['LanguageGetMagic'][] = 'efMapsGeoFunctionsMagic';
 23+if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) {
 24+ $wgHooks['LanguageGetMagic'][] = 'efMapsGeoFunctionsMagic';
 25+}
2426 $wgHooks['ParserFirstCallInit'][] = 'efMapsGeoFunctions';
2527
2628 /**
Index: trunk/extensions/Maps/ParserFunctions/Geocode/Maps_GeocodeFunctions.php
@@ -14,7 +14,9 @@
1515 die( 'Not an entry point.' );
1616 }
1717
18 -$wgHooks['LanguageGetMagic'][] = 'efMapsGeoFunctionMagic';
 18+if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) {
 19+ $wgHooks['LanguageGetMagic'][] = 'efMapsGeoFunctionMagic';
 20+}
1921 $wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterGeoFunctions';
2022
2123 /**
Index: trunk/extensions/Maps/ParserFunctions/Coordinates/Maps_Coordinates.php
@@ -14,7 +14,9 @@
1515 die( 'Not an entry point.' );
1616 }
1717
18 -$wgHooks['LanguageGetMagic'][] = 'efMapsCoordinatesMagic';
 18+if ( version_compare( $wgVersion, '1.16alpha', '<' ) ) {
 19+ $wgHooks['LanguageGetMagic'][] = 'efMapsCoordinatesMagic';
 20+}
1921 $wgHooks['ParserFirstCallInit'][] = 'efMapsCoordinatesFunction';
2022
2123 /**
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -7,8 +7,6 @@
88 * @ingroup Maps
99 *
1010 * @author Jeroen De Dauw
11 - *
12 - * TODO: clean up this stuff (goes together with refactoring MapsMapFeature and it's subclasses).
1311 */
1412
1513 if ( !defined( 'MEDIAWIKI' ) ) {
@@ -37,8 +35,6 @@
3836
3937 include_once $egMapsDir . 'ParserFunctions/Maps_iDisplayFunction.php';
4038
41 - self::initializeParams();
42 -
4339 // This runs a small hook that enables parser functions to run initialization code.
4440 foreach ( $egMapsFeatures['pf'] as $hook ) {
4541 call_user_func( $hook );
@@ -49,23 +45,6 @@
5046
5147 private static function initializeParams() {
5248 global $egMapsAvailableServices, $egMapsDefaultServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
53 -
54 - self::$parameters = array(
55 - 'service' => array(
56 - 'criteria' => array(
57 - 'in_array' => $egMapsAvailableServices
58 - ),
59 - ),
60 - 'coordinates' => array(
61 - 'aliases' => array( 'coords', 'location', 'locations' ),
62 - ),
63 - 'geoservice' => array(
64 - 'criteria' => array(
65 - 'in_array' => $egMapsAvailableGeoServices
66 - ),
67 - 'default' => $egMapsDefaultGeoService
68 - ),
69 - );
7049 }
7150
7251 /**
@@ -77,197 +56,68 @@
7857 *
7958 * @return array
8059 */
81 - public static function getMapHtml( Parser &$parser, array $params, $parserFunction ) {
82 - global $wgLang, $egValidatorErrorLevel, $egValidatorFatalLevel;
 60+ public static function getMapHtml( Parser &$parser, array $args, $parserFunction ) {
 61+ global $wgLang, $egValidatorErrorLevel, $egValidatorFatalLevel, $egMapsServices;
8362
84 - array_shift( $params ); // We already know the $parser.
85 -
86 - $map = array();
87 - $coordFails = array();
 63+ array_shift( $args ); // We already know the $parser.
8864
89 - $paramInfo = array_merge( MapsMapper::getMainParams(), self::$parameters );
90 -
91 - $geoFails = self::changeAddressesToCoords( $params, $paramInfo, $parserFunction );
 65+ $parameters = array();
 66+ $setService = false;
9267
93 - // Go through all parameters, split their names and values, and put them in the $map array.
94 - foreach ( $params as $param ) {
95 - $split = explode( '=', $param );
96 - if ( count( $split ) > 1 ) {
97 - $paramName = strtolower( trim( array_shift( $split ) ) );
98 - $paramValue = trim( implode( $split ) );
99 - if ( $paramName != '' && $paramValue != '' ) {
100 - $map[$paramName] = $paramValue;
101 - if ( self::inParamAliases( $paramName, 'coordinates', $paramInfo ) ) $coordFails = self::filterInvalidCoords( $map[$paramName] );
102 - }
103 - }
104 - else { // Default parameter (without name).
105 - $split[0] = trim( $split[0] );
106 - if ( $split[0] != '' ) $map['coordinates'] = $split[0];
107 - }
108 - }
109 -
110 - $coords = self::getParamValue( 'coordinates', $map, $paramInfo );
111 -
112 - if ( $coords ) {
113 - $mapClass = self::getParserClassInstance( $map['service'], $parserFunction );
114 -
115 - // Call the function according to the map service to get the HTML output.
116 - $output = $mapClass->displayMap( $parser, $map );
117 -
118 - if ( $egValidatorErrorLevel >= Validator_ERRORS_WARN ) {
119 - if ( count( $coordFails ) > 0 ) {
120 - $output .= '<i>' . htmlspecialchars( wfMsgExt( 'maps_unrecognized_coords_for', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) ) . '</i>';
121 - }
122 -
123 - if ( count( $geoFails ) > 0 ) {
124 - $output .= '<i>' . htmlspecialchars( wfMsgExt( 'maps_geocoding_failed_for', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) ) . '</i>';
125 - }
126 - }
127 - }
128 - elseif ( $egValidatorFatalLevel >= Validator_ERRORS_NONE ) {
129 - if ( $coords == '' && ( count( $geoFails ) > 0 || count( $coordFails ) > 0 ) ) {
130 - if ( count( $coordFails ) > 0 ) $output = '<i>' . wfMsgExt( 'maps_unrecognized_coords', array( 'parsemag' ), $wgLang->listToText( $coordFails ), count( $coordFails ) ) . '</i>';
131 - if ( count( $geoFails ) > 0 ) $output = '<i>' . wfMsgExt( 'maps_geocoding_failed', array( 'parsemag' ), $wgLang->listToText( $geoFails ), count( $geoFails ) ) . '</i>';
132 - $output .= '<i>' . htmlspecialchars( wfMsg( 'maps_map_cannot_be_displayed' ) ) . '</i>';
133 - }
134 - else {
135 - $output = '<i>' . htmlspecialchars( wfMsg( 'maps_coordinates_missing' ) ) . '</i>';
136 - }
137 - }
138 -
139 - // Return the result.
140 - return array( $output, 'noparse' => true, 'isHTML' => true );
141 - }
142 -
143 - /**
144 - * Filters all non coordinate valus from a coordinate string,
145 - * and returns an array containing all filtered out values.
146 - *
147 - * @param string $coordList
148 - * @param string $delimeter
149 - *
150 - * @return array
151 - */
152 - public static function filterInvalidCoords( &$coordList, $delimeter = ';' ) {
153 - $coordFails = array();
154 - $validCoordinates = array();
155 - $coordinateSets = explode( $delimeter, $coordList );
156 -
157 - // Loop through all the provided coordinates. If they are valid, format their parsed values
158 - // to non-directional floats, and add them to the valid array, else add them to the fails array.
159 - foreach ( $coordinateSets as $coordinates ) {
160 - $parsedCoords = MapsCoordinateParser::parseCoordinates( $coordinates );
161 -
162 - if ( $parsedCoords ) { // Will be false when parsing failed.
163 - $validCoordinates[] = MapsCoordinateParser::formatCoordinates( $parsedCoords, Maps_COORDS_FLOAT, false );
 68+ foreach( $args as $arg ) {
 69+ $split = explode( '=', $arg );
 70+ $name = strtolower( trim( array_shift( $split ) ) );
 71+ if ( count( $split ) > 1 && self::inParamAliases( $name, 'service', self::$parameters ) ) {
 72+ if ( !$setService ) {
 73+ $service = implode( '=', $split );
 74+ $parameters = 'service=' . $service;
 75+ $setService = true;
 76+ }
 77+ } else {
 78+ $parameters[] = $arg;
16479 }
165 - else {
166 - $coordFails[] = $coordinates;
167 - }
16880 }
16981
170 - $coordList = implode( $delimeter, $validCoordinates );
171 - return $coordFails;
172 - }
173 -
174 - /**
175 - * Changes the values of the address or addresses parameter into coordinates
176 - * in the provided array. Returns an array containing the addresses that
177 - * could not be geocoded.
178 - *
179 - * Also ensures the service parameter is valid.
180 - *
181 - * @param array $params
182 - *
183 - * @return array
184 - */
185 - private static function changeAddressesToCoords( &$params, array $paramInfo, $parserFunction ) {
186 - global $egMapsDefaultService;
187 -
188 - $fails = array();
 82+ $service = MapsMapper::getValidService( $setService ? $service : '', $parserFunction );
18983
190 - // Get the service and geoservice from the parameters, since they are needed to geocode addresses.
191 - for ( $i = 0; $i < count( $params ); $i++ ) {
192 - $split = explode( '=', $params[$i] );
193 - if ( self::inParamAliases( strtolower( trim( $split[0] ) ), 'service', $paramInfo ) && count( $split ) > 1 ) {
194 - $service = trim( $split[1] );
195 - }
196 - else if ( strtolower( trim( $split[0] ) ) == 'geoservice' && count( $split ) > 1 ) {
197 - $geoservice = trim( $split[1] );
198 - }
199 - }
200 -
201 - // Make sure the service and geoservice are valid.
202 - if ( !isset( $service ) ) $service = '';
203 - $service = MapsMapper::getValidService( $service, $parserFunction );
 84+ // TODO: hook into Validator for main parameter validation, geocoding and coordinate parsing
20485
205 - if ( ! isset( $geoservice ) ) $geoservice = '';
 86+ $mapClass = new $egMapsServices[$service]['features'][$parserFunction]();
20687
207 - $setService = false;
 88+ $manager = new ValidatorManager();
20889
209 - // Go over all parameters.
210 - for ( $i = 0; $i < count( $params ); $i++ ) {
211 - $split = explode( '=', $params[$i] );
212 - $isAddress = ( strtolower( trim( $split[0] ) ) == 'address' || strtolower( trim( $split[0] ) ) == 'addresses' ) && count( $split ) > 1;
213 - $isDefault = count( $split ) == 1;
214 -
215 - // If a parameter is either the default (no name), or an addresses list, extract all locations.
216 - if ( $isAddress || $isDefault ) {
217 -
218 - $address_srting = $split[count( $split ) == 1 ? 0 : 1];
219 - $addresses = explode( ';', $address_srting );
220 -
221 - $coordinates = array();
222 -
223 - // Go over every location and attempt to geocode it.
224 - foreach ( $addresses as $address ) {
225 - $args = explode( '~', $address );
226 - $args[0] = trim( $args[0] );
227 -
228 - if ( strlen( $args[0] ) > 0 ) {
229 - $coords = MapsGeocoder::attemptToGeocodeToString( $args[0], $geoservice, $service, $isDefault );
230 -
231 - if ( $coords ) {
232 - $args[0] = $coords;
233 - $coordinates[] = implode( '~', $args );
234 - }
235 - else {
236 - $fails[] = $args[0];
237 - }
238 - }
239 - }
240 -
241 - // Add the geocoded result back to the parameter list.
242 - $params[$i] = implode( ';', $coordinates );
243 -
244 - } else if ( self::inParamAliases( strtolower( trim( $split[0] ) ), 'service', $paramInfo ) && count( $split ) > 1 ) {
245 - $params[$i] = "service=$service";
246 - $setService = true;
247 - }
248 - }
249 -
250 - if ( !$setService ) {
251 - $params[] = "service=$service";
252 - }
 90+ /*
 91+ * Assembliy of the allowed parameters and their information.
 92+ * The main parameters (the ones that are shared by everything) are overidden
 93+ * by the feature parameters (the ones spesific to a feature). The result is then
 94+ * again overidden by the service parameters (the ones spesific to the service),
 95+ * and finally by the spesific parameters (the ones spesific to a service-feature combination).
 96+ */
 97+ $parameterInfo = array_merge( MapsMapper::getMainParams(), self::$parameters );
 98+ $parameterInfo = array_merge( $parameterInfo, $mapClass->getFeatureParameters() );
 99+ $parameterInfo = array_merge( $parameterInfo, $egMapsServices[$service]['parameters'] );
 100+ $parameterInfo = array_merge( $parameterInfo, $mapClass->getSpecificParameterInfo() );
253101
254 - return $fails;
 102+ $parameters = $manager->manageParameters(
 103+ $parameters,
 104+ $parameterInfo,
 105+ array( 'coordinates' )
 106+ );
 107+
 108+ $displayMap = $parameters !== false;
 109+
 110+ if ( $displayMap ) {
 111+ // Call the function according to the map service to get the HTML output.
 112+ $output = $mapClass->displayMap( $parser, $parameters ) . $manager->getErrorList();
 113+ } else {
 114+ // TODO: add errors to output depending on validator fatal level
 115+ }
 116+
 117+ // Return the result.
 118+ return array( $output, 'noparse' => true, 'isHTML' => true );
255119 }
256120
257121 /**
258 - * Returns an instance of the class supporting the spesified mapping service for
259 - * the also spesified parser function.
260 - *
261 - * @param string $service
262 - * @param string $parserFunction
263 - *
264 - * @return MapsMapFeature
265 - */
266 - public static function getParserClassInstance( $service, $parserFunction ) {
267 - global $egMapsServices;
268 - return new $egMapsServices[$service]['features'][$parserFunction]();
269 - }
270 -
271 - /**
272122 * Gets if a provided name is present in the aliases array of a parameter
273123 * name in the $mainParams array.
274124 *
@@ -287,59 +137,4 @@
288138
289139 return $equals;
290140 }
291 -
292 - /**
293 - * Gets if a parameter is present as key in the $stack. Also checks for
294 - * the presence of aliases in the $mainParams array unless specified not to.
295 - *
296 - * @param string $paramName
297 - * @param array $stack
298 - * @param array $paramInfo Contains meta data, including aliases, of the possible parameters.
299 - * @param boolean $checkForAliases
300 - *
301 - * @return boolean
302 - */
303 - public static function paramIsPresent( $paramName, array $stack, array $paramInfo = array(), $checkForAliases = true ) {
304 - $isPresent = array_key_exists( $paramName, $stack );
305 -
306 - if ( !$isPresent && $checkForAliases && array_key_exists( 'aliases', $paramInfo[$paramName] ) ) {
307 - foreach ( $paramInfo[$paramName]['aliases'] as $alias ) {
308 - if ( array_key_exists( $alias, $stack ) ) {
309 - $isPresent = true;
310 - break;
311 - }
312 - }
313 - }
314 -
315 - return $isPresent;
316 - }
317 -
318 - /**
319 - * Returns the value of a parameter represented as key in the $stack.
320 - * Also checks for the presence of aliases in the $mainParams array
321 - * and returns the value of the alies unless specified not to. When
322 - * no array key name match is found, false will be returned.
323 - *
324 - * @param string $paramName
325 - * @param array $stack The values to search through
326 - * @param array $paramInfo Contains meta data, including aliases, of the possible parameters.
327 - * @param boolean $checkForAliases
328 - *
329 - * @return the parameter value or false
330 - */
331 - private static function getParamValue( $paramName, array $stack, array $paramInfo = array(), $checkForAliases = true ) {
332 - $paramValue = false;
333 -
334 - if ( array_key_exists( $paramName, $stack ) ) $paramValue = $stack[$paramName];
335 -
336 - if ( $checkForAliases ) {
337 - foreach ( $paramInfo[$paramName]['aliases'] as $alias ) {
338 - if ( array_key_exists( $alias, $stack ) ) $paramValue = $stack[$alias];
339 - break;
340 - }
341 - }
342 -
343 - return $paramValue;
344 - }
345 -
346141 }
\ No newline at end of file
Index: trunk/extensions/Maps/Maps.php
@@ -62,8 +62,12 @@
6363 // Include the settings file.
6464 require_once( $egMapsDir . 'Maps_Settings.php' );
6565
66 - $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php';
 66+ $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.php';
6767
 68+ if( version_compare( $wgVersion, '1.16alpha', '>=' ) ) {
 69+ $wgExtensionMessagesFiles['Maps'] = $egMapsDir . 'Maps.i18n.magic.php';
 70+ }
 71+
6872 // Register the initialization function of Maps.
6973 $wgExtensionFunctions[] = 'efMapsSetup';
7074
Index: trunk/extensions/Maps/Maps_Mapper.php
@@ -14,22 +14,16 @@
1515 }
1616
1717 final class MapsMapper {
18 -
19 - /**
20 - * Array holding the parameters that are not spesific to a mapping service,
21 - * their aliases, criteria and default value.
22 - *
23 - * @var array
24 - */
25 - private static $mainParams;
2618
 19+ private static $mainParams;
 20+
2721 public static function initializeMainParams() {
2822 global $egMapsSizeRestrictions, $egMapsMapWidth, $egMapsMapHeight;
2923
3024 Validator::addOutputFormat( 'mapdimension', array( __CLASS__, 'setMapDimension' ) );
31 - Validator::addValidationFunction( 'is_map_dimension', array( __CLASS__, 'isMapDimension' ) );
32 -
33 - self::$mainParams = array (
 25+ Validator::addValidationFunction( 'is_map_dimension', array( __CLASS__, 'isMapDimension' ) );
 26+
 27+ self::$mainParams = array(
3428 'zoom' => array(
3529 'type' => 'integer',
3630 'criteria' => array(
@@ -49,10 +43,10 @@
5044 ),
5145 'default' => $egMapsMapHeight,
5246 'output-type' => array( 'mapdimension', 'height', $egMapsMapHeight )
53 - ),
 47+ ),
5448 );
5549 }
56 -
 50+
5751 /**
5852 * Returns the main parameters array.
5953 *
@@ -60,7 +54,7 @@
6155 */
6256 public static function getMainParams() {
6357 return self::$mainParams;
64 - }
 58+ }
6559
6660 /**
6761 * Returns a valid service. When an invalid service is provided, the default one will be returned.
@@ -68,7 +62,6 @@
6963 *
7064 * @param string $service
7165 * @param string $feature
72 - * @param string $subfeature
7366 *
7467 * @return string
7568 */
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php
@@ -24,30 +24,33 @@
2525
2626 public $serviceName = MapsGoogleMaps::SERVICE_NAME;
2727
28 - /**
29 - * @see MapsBaseMap::setMapSettings()
30 - *
31 - */
32 - protected function setMapSettings() {
33 - global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix, $egMapsGMapOverlays;
34 -
35 - $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
36 - $this->defaultZoom = $egMapsGoogleMapsZoom;
37 -
 28+ public function getSpecificParameterInfo() {
 29+ global $egMapsGMapOverlays;
 30+ // TODO: it'd be cool to have this static so it can be cheched in order to only init it once.
3831 $this->spesificParameters = array(
3932 'overlays' => array(
4033 'type' => array( 'string', 'list' ),
4134 'criteria' => array(
4235 'is_google_overlay' => array()
43 - ),
 36+ ),
4437 'default' => $egMapsGMapOverlays,
45 - ),
 38+ ),
4639 );
 40+ return $this->spesificParameters;
4741 }
4842
4943 /**
 44+ * @see MapsBaseMap::setMapSettings()
 45+ */
 46+ protected function setMapSettings() {
 47+ global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix;
 48+
 49+ $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
 50+ $this->defaultZoom = $egMapsGoogleMapsZoom;
 51+ }
 52+
 53+ /**
5054 * @see MapsBaseMap::doMapServiceLoad()
51 - *
5255 */
5356 protected function doMapServiceLoad() {
5457 global $egGoogleMapsOnThisPage;
@@ -60,7 +63,6 @@
6164
6265 /**
6366 * @see MapsBaseMap::addSpecificMapHTML()
64 - *
6567 */
6668 public function addSpecificMapHTML( Parser $parser ) {
6769 MapsGoogleMaps::addOverlayOutput( $this->output, $this->mapName, $this->overlays, $this->controls );
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php
@@ -24,27 +24,32 @@
2525
2626 public $serviceName = MapsGoogleMaps::SERVICE_NAME;
2727
 28+ public function getSpecificParameterInfo() {
 29+ global $egMapsGMapOverlays;
 30+ // TODO: it'd be cool to have this static so it can be cheched in order to only init it once.
 31+ $this->spesificParameters = array(
 32+ 'overlays' => array(
 33+ 'type' => array( 'string', 'list' ),
 34+ 'criteria' => array(
 35+ 'is_google_overlay' => array()
 36+ ),
 37+ 'default' => $egMapsGMapOverlays,
 38+ ),
 39+ );
 40+ return $this->spesificParameters;
 41+ }
 42+
2843 /**
2944 * @see MapsBaseMap::setMapSettings()
3045 *
3146 */
3247 protected function setMapSettings() {
33 - global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix, $egMapsGMapOverlays;
 48+ global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix;
3449
3550 $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
3651 $this->defaultZoom = $egMapsGoogleMapsZoom;
3752
3853 $this->markerStringFormat = 'getGMarkerData(lat, lon, \'title\', \'label\', "icon")';
39 -
40 - $this->spesificParameters = array(
41 - 'overlays' => array(
42 - 'type' => array( 'string', 'list' ),
43 - 'criteria' => array(
44 - 'is_google_overlay' => array()
45 - ),
46 - 'default' => $egMapsGMapOverlays,
47 - ),
48 - );
4954 }
5055
5156 /**
Index: trunk/extensions/Maps/Maps_MapFeature.php
@@ -40,70 +40,32 @@
4141 protected abstract function addSpecificMapHTML( Parser $parser );
4242
4343 public $serviceName;
44 -
45 - protected $defaultZoom;
4644
4745 protected $elementNr;
4846 protected $elementNamePrefix;
4947
5048 protected $mapName;
5149
52 - protected $centreLat;
53 - protected $centreLon;
 50+ protected $centreLat, $centreLon;
5451
5552 protected $output = '';
56 - protected $errorList;
 53+
 54+ protected $spesificParameters = false;
 55+ protected $featureParameters = false;
5756
58 - protected $featureParameters = array();
59 - protected $spesificParameters = array();
60 -
6157 /**
62 - * Validates and corrects the provided map properties, and the sets them as class fields.
63 - *
64 - * @param array $mapProperties
65 - * @param string $className
66 - *
67 - * @return boolean Indicates whether the map should be shown or not.
68 - */
69 - protected final function manageMapProperties( array $mapProperties, $className ) {
70 - global $egMapsServices;
71 -
72 - /*
73 - * Assembliy of the allowed parameters and their information.
74 - * The main parameters (the ones that are shared by everything) are overidden
75 - * by the feature parameters (the ones spesific to a feature). The result is then
76 - * again overidden by the service parameters (the ones spesific to the service),
77 - * and finally by the spesific parameters (the ones spesific to a service-feature combination).
78 - */
79 - $parameterInfo = array_merge( MapsMapper::getMainParams(), $this->featureParameters );
80 - $parameterInfo = array_merge( $parameterInfo, $egMapsServices[$this->serviceName]['parameters'] );
81 - $parameterInfo = array_merge( $parameterInfo, $this->spesificParameters );
82 -
83 - $manager = new ValidatorManager();
84 -
85 - $result = $manager->manageParameters( $mapProperties, $parameterInfo );
86 -
87 - $showMap = $result !== false;
88 -
89 - if ( $showMap ) $this->setMapProperties( $result, $className );
90 -
91 - $this->errorList = $manager->getErrorList();
92 -
93 - return $showMap;
94 - }
95 -
96 - /**
9758 * Sets the map properties as class fields.
9859 *
9960 * @param array $mapProperties
10061 * @param string $className
10162 */
102 - private function setMapProperties( array $mapProperties, $className ) {
 63+ protected function setMapProperties( array $mapProperties, $className ) {
10364 foreach ( $mapProperties as $paramName => $paramValue ) {
104 - if ( ! property_exists( $className, $paramName ) ) {
 65+ if ( !property_exists( $className, $paramName ) ) {
10566 $this-> { $paramName } = $paramValue;
10667 }
10768 else {
 69+ // If this happens in any way, it could be a big vunerability, so throw an exception.
10870 throw new Exception( 'Attempt to override a class field during map property assignment. Field name: ' . $paramName );
10971 }
11072 }
@@ -116,4 +78,34 @@
11779 $this->mapName = $this->elementNamePrefix . '_' . $this->elementNr;
11880 }
11981
 82+ /**
 83+ * @return array
 84+ */
 85+ public function getSpecificParameterInfo() {
 86+ return array();
 87+ }
 88+
 89+ /**
 90+ * @return array
 91+ */
 92+ public function getFeatureParameters() {
 93+ global $egMapsAvailableServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
 94+
 95+ return array(
 96+ 'service' => array(
 97+ 'criteria' => array(
 98+ 'in_array' => $egMapsAvailableServices
 99+ ),
 100+ ),
 101+ 'coordinates' => array(
 102+ 'aliases' => array( 'coords', 'location', 'locations' ),
 103+ ),
 104+ 'geoservice' => array(
 105+ 'criteria' => array(
 106+ 'in_array' => $egMapsAvailableGeoServices
 107+ ),
 108+ 'default' => $egMapsDefaultGeoService
 109+ ),
 110+ );
 111+ }
120112 }
\ No newline at end of file
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -152,11 +152,6 @@
153153 $egMapsMapLat = '1';
154154 $egMapsMapLon = '1';
155155
156 -# String. The default centre for a map. Must be in floating point notation.
157 -# This value will override the smart behaviour when multiple markers are present when set.
158 -# This value will only be used when the user does not provide one.
159 -$egMapsDefaultCentre = '';
160 -
161156 # Strings. The default content for all pop-ups. This value will only be used when the user does not provide one.
162157 $egMapsDefaultTitle = '';
163158 $egMapsDefaultLabel = '';

Follow-up revisions

RevisionCommit summaryAuthorDate
r65275Follow up to r65108 - Fixed smart geocoding in display_map and display_point(s)jeroendedauw12:52, 19 April 2010
r65307Follow up to r65108 - Fixed coordinate handling for display_map and display_p...jeroendedauw12:37, 20 April 2010

Comments

#Comment by Raymond (talk | contribs)   20:49, 16 April 2010

Something wrong on translatewiki with this revision:

"" is not a valid magic thingie for "coordinates"

Extension disabled for now.

#Comment by Jeroen De Dauw (talk | contribs)   06:56, 17 April 2010

Oh oops. I forgot to change something there. Can take some time to fix.

#Comment by Jeroen De Dauw (talk | contribs)   17:36, 27 April 2010

This issue has been fixed

#Comment by Raymond (talk | contribs)   19:10, 27 April 2010

Now I get

"" is not a valid magic thingie for "display_map"
#Comment by Jeroen De Dauw (talk | contribs)   20:00, 27 April 2010

When do you get this?

#Comment by Raymond (talk | contribs)   20:02, 27 April 2010

Today, running r65581 on translatewiki after I enabling the Maps extension (now disabled again). See #mediawiki-i18n channel

Status & tagging log