Index: branches/Maps0.8/includes/services/GoogleMaps3/Maps_GoogleMaps3DispPoint.php |
— | — | @@ -11,17 +11,17 @@ |
12 | 12 | final class MapsGoogleMaps3DispPoint extends MapsBasePointMap { |
13 | 13 | |
14 | 14 | /** |
15 | | - * @see MapsBaseMap::addSpecificMapHTML |
| 15 | + * @see MapsBasePointMap::getMapHTML() |
16 | 16 | */ |
17 | | - public function addSpecificMapHTML( Parser $parser ) { |
| 17 | + public function getMapHTML( array $params, Parser $parser ) { |
18 | 18 | return Html::element( |
19 | 19 | 'div', |
20 | 20 | array( |
21 | 21 | 'id' => $this->service->getMapId(), |
22 | | - 'style' => "width: $this->width; height: $this->height; background-color: #cccccc; overflow: hidden;" |
| 22 | + 'style' => "width: {$params['width']}; height: {$params['height']}; background-color: #cccccc; overflow: hidden;", |
23 | 23 | ), |
24 | | - null |
| 24 | + wfMsg( 'maps-loading-map' ) |
25 | 25 | ); |
26 | 26 | } |
27 | 27 | |
28 | | -} |
\ No newline at end of file |
| 28 | +} |
Index: branches/Maps0.8/includes/services/GoogleMaps3/Maps_GoogleMaps3DispMap.php |
— | — | @@ -23,4 +23,4 @@ |
24 | 24 | ); |
25 | 25 | } |
26 | 26 | |
27 | | -} |
\ No newline at end of file |
| 27 | +} |
Index: branches/Maps0.8/includes/services/YahooMaps/Maps_YahooMapsDispPoint.php |
— | — | @@ -11,17 +11,17 @@ |
12 | 12 | class MapsYahooMapsDispPoint extends MapsBasePointMap { |
13 | 13 | |
14 | 14 | /** |
15 | | - * @see MapsBaseMap::addSpecificMapHTML |
| 15 | + * @see MapsBasePointMap::getMapHTML() |
16 | 16 | */ |
17 | | - public function addSpecificMapHTML( Parser $parser ) { |
| 17 | + public function getMapHTML( array $params, Parser $parser ) { |
18 | 18 | return Html::element( |
19 | 19 | 'div', |
20 | 20 | array( |
21 | 21 | 'id' => $this->service->getMapId(), |
22 | | - 'style' => "width: $this->width; height: $this->height; background-color: #cccccc; overflow: hidden;", |
| 22 | + 'style' => "width: {$params['width']}; height: {$params['height']}; background-color: #cccccc; overflow: hidden;", |
23 | 23 | ), |
24 | 24 | wfMsg( 'maps-loading-map' ) |
25 | 25 | ); |
26 | 26 | } |
27 | 27 | |
28 | | -} |
\ No newline at end of file |
| 28 | +} |
Index: branches/Maps0.8/includes/services/OpenLayers/Maps_OpenLayersDispPoint.php |
— | — | @@ -11,17 +11,17 @@ |
12 | 12 | class MapsOpenLayersDispPoint extends MapsBasePointMap { |
13 | 13 | |
14 | 14 | /** |
15 | | - * @see MapsBaseMap::addSpecificMapHTML |
| 15 | + * @see MapsBasePointMap::getMapHTML() |
16 | 16 | */ |
17 | | - public function addSpecificMapHTML( Parser $parser ) { |
| 17 | + public function addSpecificMapHTML( array $params, Parser $parser ) { |
18 | 18 | return Html::element( |
19 | 19 | 'div', |
20 | 20 | array( |
21 | 21 | 'id' => $this->service->getMapId(), |
22 | | - 'style' => "width: $this->width; height: $this->height; background-color: #cccccc; overflow: hidden;", |
| 22 | + 'style' => "width: {$params['width']}; height: {$params['height']}; background-color: #cccccc; overflow: hidden;", |
23 | 23 | ), |
24 | 24 | wfMsg( 'maps-loading-map' ) |
25 | 25 | ); |
26 | 26 | } |
27 | 27 | |
28 | | -} |
\ No newline at end of file |
| 28 | +} |
Index: branches/Maps0.8/includes/services/OpenLayers/Maps_OpenLayersDispMap.php |
— | — | @@ -29,8 +29,6 @@ |
30 | 30 | |
31 | 31 | /** |
32 | 32 | * @see MapsBaseMap::getMapHTML |
33 | | - * |
34 | | - * @since 0.7.3 |
35 | 33 | */ |
36 | 34 | public function getMapHTML( array $params, Parser $parser ) { |
37 | 35 | return Html::element( |
— | — | @@ -43,4 +41,4 @@ |
44 | 42 | ); |
45 | 43 | } |
46 | 44 | |
47 | | -} |
\ No newline at end of file |
| 45 | +} |
Index: branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMapsDispMap.php |
— | — | @@ -16,10 +16,8 @@ |
17 | 17 | public function getMapHTML( array $params, Parser $parser ) { |
18 | 18 | $mapName = $this->service->getMapId(); |
19 | 19 | |
20 | | - $output = ''; |
| 20 | + $output = $this->service->getOverlayOutput( $mapName, $params['overlays'], $params['controls'] ); |
21 | 21 | |
22 | | - $this->service->addOverlayOutput( $output, $mapName, $params['overlays'], $params['controls'] ); |
23 | | - |
24 | 22 | return $output . Html::element( |
25 | 23 | 'div', |
26 | 24 | array( |
— | — | @@ -30,4 +28,4 @@ |
31 | 29 | ); |
32 | 30 | } |
33 | 31 | |
34 | | -} |
\ No newline at end of file |
| 32 | +} |
Index: branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMaps.php |
— | — | @@ -272,14 +272,16 @@ |
273 | 273 | /** |
274 | 274 | * Adds the needed output for the overlays control. |
275 | 275 | * |
276 | | - * @param string $output |
277 | 276 | * @param string $mapName |
278 | 277 | * @param string $overlays |
279 | 278 | * @param string $controls |
280 | 279 | * |
281 | 280 | * FIXME: layer onload function kills maps for some reason |
| 281 | + * TODO: integrate this properly with Validator |
| 282 | + * |
| 283 | + * @return string |
282 | 284 | */ |
283 | | - public function addOverlayOutput( &$output, $mapName, $overlays, $controls ) { |
| 285 | + public function getOverlayOutput( $mapName, $overlays, $controls ) { |
284 | 286 | global $egMapsGMapOverlays, $egMapsGoogleOverlLoaded; |
285 | 287 | |
286 | 288 | // Check to see if there is an overlays control. |
— | — | @@ -307,7 +309,7 @@ |
308 | 310 | $overlayHtml = ''; |
309 | 311 | $onloadFunctions = array(); |
310 | 312 | |
311 | | - $output .= Html::rawElement( |
| 313 | + return Html::rawElement( |
312 | 314 | 'div', |
313 | 315 | array( |
314 | 316 | 'class' => 'outer-more', |
Index: branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMapsDispPoint.php |
— | — | @@ -10,25 +10,22 @@ |
11 | 11 | */ |
12 | 12 | final class MapsGoogleMapsDispPoint extends MapsBasePointMap { |
13 | 13 | |
14 | | - protected function initSpecificParamInfo( array &$parameters ) { |
15 | | - } |
16 | | - |
17 | 14 | /** |
18 | | - * @see MapsBaseMap::addSpecificMapHTML |
| 15 | + * @see MapsBasePointMap::getMapHTML |
19 | 16 | */ |
20 | | - public function addSpecificMapHTML( Parser $parser ) { |
| 17 | + public function getMapHTML( array $params, Parser $parser ) { |
21 | 18 | $mapName = $this->service->getMapId(); |
22 | 19 | |
23 | | - $this->service->addOverlayOutput( $this->output, $mapName, $this->overlays, $this->controls ); |
| 20 | + $output = $this->service->getOverlayOutput( $mapName, $params['overlays'], $params['controls'] ); |
24 | 21 | |
25 | | - return Html::element( |
| 22 | + return $output . Html::element( |
26 | 23 | 'div', |
27 | 24 | array( |
28 | 25 | 'id' => $mapName, |
29 | | - 'style' => "width: $this->width; height: $this->height; background-color: #cccccc; overflow: hidden;", |
| 26 | + 'style' => "width: {$params['width']}; height: {$params['height']}; background-color: #cccccc; overflow: hidden;", |
30 | 27 | ), |
31 | 28 | wfMsg( 'maps-loading-map' ) |
32 | 29 | ); |
33 | 30 | } |
34 | 31 | |
35 | | -} |
\ No newline at end of file |
| 32 | +} |
Index: branches/Maps0.8/includes/services/OSM/Maps_OSMDispMap.php |
— | — | @@ -34,4 +34,4 @@ |
35 | 35 | ); |
36 | 36 | } |
37 | 37 | |
38 | | -} |
\ No newline at end of file |
| 38 | +} |
Index: branches/Maps0.8/includes/parserHooks/Maps_DisplayPoint.php |
— | — | @@ -141,7 +141,7 @@ |
142 | 142 | // Get an instance of the class handling the current parser hook and service. |
143 | 143 | $mapClass = $service->getFeatureInstance( 'display_point' ); |
144 | 144 | |
145 | | - return $mapClass->getMapHtml( $parameters, $this->parser ); |
| 145 | + return $mapClass->renderMap( $parameters, $this->parser ); |
146 | 146 | } |
147 | 147 | |
148 | 148 | /** |
— | — | @@ -168,4 +168,4 @@ |
169 | 169 | return wfMsg( 'maps-displaypoint-description' ); |
170 | 170 | } |
171 | 171 | |
172 | | -} |
\ No newline at end of file |
| 172 | +} |
Index: branches/Maps0.8/includes/features/Maps_BasePointMap.php |
— | — | @@ -17,38 +17,25 @@ |
18 | 18 | */ |
19 | 19 | protected $service; |
20 | 20 | |
21 | | - protected $centreLat, $centreLon; |
22 | | - protected $markerJs; |
23 | | - |
24 | | - protected $output = ''; |
| 21 | + protected $markerData = array(); |
25 | 22 | |
26 | | - protected $markerString; |
| 23 | + /** |
| 24 | + * Returns the HTML to display the map. |
| 25 | + * |
| 26 | + * @since 0.8 |
| 27 | + * |
| 28 | + * @param array $params |
| 29 | + * @param $parser |
| 30 | + * |
| 31 | + * @return string |
| 32 | + */ |
| 33 | + protected abstract function getMapHTML( array $params, Parser $parser ); |
27 | 34 | |
28 | | - private $specificParameters = false; |
29 | | - private $markerData = array(); |
30 | | - |
31 | 35 | public function __construct( iMappingService $service ) { |
32 | 36 | $this->service = $service; |
33 | 37 | } |
34 | 38 | |
35 | 39 | /** |
36 | | - * Sets the map properties as class fields. |
37 | | - * |
38 | | - * @param array $mapProperties |
39 | | - */ |
40 | | - protected function setMapProperties( array $mapProperties ) { |
41 | | - foreach ( $mapProperties as $paramName => $paramValue ) { |
42 | | - if ( !property_exists( __CLASS__, $paramName ) ) { |
43 | | - $this-> { $paramName } = $paramValue; |
44 | | - } |
45 | | - else { |
46 | | - // If this happens in any way, it could be a big vunerability, so throw an exception. |
47 | | - throw new Exception( 'Attempt to override a class field during map property assignment. Field name: ' . $paramName ); |
48 | | - } |
49 | | - } |
50 | | - } |
51 | | - |
52 | | - /** |
53 | 40 | * Returns the specific parameters by first checking if they have been initialized yet, |
54 | 41 | * doing to work if this is not the case, and then returning them. |
55 | 42 | * |
— | — | @@ -81,19 +68,17 @@ |
82 | 69 | * |
83 | 70 | * @return html |
84 | 71 | */ |
85 | | - public final function getMapHtml( array $params, Parser $parser ) { |
86 | | - $this->setMapProperties( $params ); |
87 | | - |
88 | | - $this->setMarkerData(); |
| 72 | + public final function renderMap( array $params, Parser $parser ) { |
| 73 | + $this->setMarkerData( $params ); |
89 | 74 | |
90 | | - $this->setCentre(); |
| 75 | + $this->setCentre( $params ); |
91 | 76 | |
92 | 77 | // TODO |
93 | | - if ( count( $this->markerData ) <= 1 && $this->zoom == 'null' ) { |
| 78 | + /*if ( count( $this->markerData ) <= 1 && $this->zoom == 'null' ) { |
94 | 79 | $this->zoom = $this->service->getDefaultZoom(); |
95 | | - } |
| 80 | + }*/ |
96 | 81 | |
97 | | - $this->addSpecificMapHTML( $parser ); |
| 82 | + $output = $this->getMapHTML( $params, $parser ) . $this->getJSON( $params, $parser ); |
98 | 83 | |
99 | 84 | global $wgTitle; |
100 | 85 | if ( $wgTitle->getNamespace() == NS_SPECIAL ) { |
— | — | @@ -104,10 +89,45 @@ |
105 | 90 | $this->service->addDependencies( $parser ); |
106 | 91 | } |
107 | 92 | |
108 | | - return $this->output; |
| 93 | + return $output; |
109 | 94 | } |
110 | 95 | |
111 | 96 | /** |
| 97 | + * Returns the JSON with the maps data. |
| 98 | + * |
| 99 | + * @since 0.8 |
| 100 | + * |
| 101 | + * @param array $params |
| 102 | + * @param Parser $parser |
| 103 | + * |
| 104 | + * @return string |
| 105 | + */ |
| 106 | + protected function getJSON( array $params, Parser $parser ) { |
| 107 | + $object = $this->getJSONObject( $params, $parser ); |
| 108 | + |
| 109 | + if ( $object === false ) { |
| 110 | + return ''; |
| 111 | + } |
| 112 | + |
| 113 | + // TODO |
| 114 | + return Html::inlineScript( "maps=[]; maps['{$this->service->getName()}']=[]; maps['{$this->service->getName()}'].push(" . json_encode( $object ) . ')' ); |
| 115 | + } |
| 116 | + |
| 117 | + /** |
| 118 | + * Returns a PHP object to encode to JSON with the map data. |
| 119 | + * |
| 120 | + * @since 0.8 |
| 121 | + * |
| 122 | + * @param array $params |
| 123 | + * @param Parser $parser |
| 124 | + * |
| 125 | + * @return mixed |
| 126 | + */ |
| 127 | + protected function getJSONObject( array $params, Parser $parser ) { |
| 128 | + return $params; |
| 129 | + } |
| 130 | + |
| 131 | + /** |
112 | 132 | * Fills the $markerData array with the locations and their meta data. |
113 | 133 | */ |
114 | 134 | private function setMarkerData() { |
— | — | @@ -170,7 +190,7 @@ |
171 | 191 | * Sets the $centre_lat and $centre_lon fields. |
172 | 192 | * Note: this needs to be done AFTRE the maker coordinates are set. |
173 | 193 | */ |
174 | | - protected function setCentre() { |
| 194 | + protected function setCentre( array &$params ) { |
175 | 195 | global $egMapsDefaultMapCentre; |
176 | 196 | |
177 | 197 | if ( $this->centre === false ) { |
— | — | @@ -186,7 +206,7 @@ |
187 | 207 | $this->centreLon = 'null'; |
188 | 208 | } |
189 | 209 | else { |
190 | | - $this->setCentreToDefault(); |
| 210 | + $this->setCentreToDefault( $params ); |
191 | 211 | } |
192 | 212 | |
193 | 213 | } |
— | — | @@ -199,7 +219,7 @@ |
200 | 220 | $this->centreLon = Xml::escapeJsString( $this->centre['lon'] ); |
201 | 221 | } |
202 | 222 | else { // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used. |
203 | | - $this->setCentreToDefault(); |
| 223 | + $this->setCentreToDefault( $params ); |
204 | 224 | } |
205 | 225 | } |
206 | 226 | |
— | — | @@ -211,7 +231,7 @@ |
212 | 232 | * |
213 | 233 | * @since 0.7 |
214 | 234 | */ |
215 | | - protected function setCentreToDefault() { |
| 235 | + protected function setCentreToDefault( array &$params ) { |
216 | 236 | global $egMapsDefaultMapCentre; |
217 | 237 | |
218 | 238 | $centre = MapsGeocoders::attemptToGeocode( $egMapsDefaultMapCentre, $this->geoservice, $this->service->getName() ); |
— | — | @@ -220,6 +240,7 @@ |
221 | 241 | throw new Exception( 'Failed to parse the default centre for the map. Please check the value of $egMapsDefaultMapCentre.' ); |
222 | 242 | } |
223 | 243 | else { |
| 244 | + //$params['centre'] = |
224 | 245 | $this->centreLat = Xml::escapeJsString( $centre['lat'] ); |
225 | 246 | $this->centreLon = Xml::escapeJsString( $centre['lon'] ); |
226 | 247 | } |
Index: branches/Maps0.8/includes/features/Maps_BaseMap.php |
— | — | @@ -59,7 +59,7 @@ |
60 | 60 | * Handles the request from the parser hook by doing the work that's common for all |
61 | 61 | * mapping services, calling the specific methods and finally returning the resulting output. |
62 | 62 | * |
63 | | - * @since 0.7.3 |
| 63 | + * @since 0.8 |
64 | 64 | * |
65 | 65 | * @param array $params |
66 | 66 | * @param Parser $parser |
— | — | @@ -67,20 +67,14 @@ |
68 | 68 | * @return html |
69 | 69 | */ |
70 | 70 | public final function renderMap( array $params, Parser $parser ) { |
71 | | - global $egMapsUseRL; |
72 | | - |
73 | 71 | $this->setCentre( $params ); |
74 | 72 | |
75 | 73 | if ( $params['zoom'] == 'null' ) { |
76 | 74 | $params['zoom'] = $this->service->getDefaultZoom(); |
77 | 75 | } |
78 | 76 | |
79 | | - $output = $this->getMapHTML( $params, $parser ); |
| 77 | + $output = $this->getMapHTML( $params, $parser ) . $this->getJSON( $params, $parser ); |
80 | 78 | |
81 | | - if ( $egMapsUseRL ) { |
82 | | - $output .= $this->getJSON( $params, $parser ); |
83 | | - } |
84 | | - |
85 | 79 | global $wgTitle; |
86 | 80 | if ( $wgTitle->getNamespace() == NS_SPECIAL ) { |
87 | 81 | global $wgOut; |
— | — | @@ -130,6 +124,10 @@ |
131 | 125 | |
132 | 126 | /** |
133 | 127 | * Translates the coordinates field to the centre field and makes sure it's set to it's default when invalid. |
| 128 | + * |
| 129 | + * @since 0.8 |
| 130 | + * |
| 131 | + * @param array &$params |
134 | 132 | */ |
135 | 133 | protected function setCentre( array &$params ) { |
136 | 134 | // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used. |