r80825 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r80824‎ | r80825 | r80826 >
Date:18:34, 23 January 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
a bunch of refactoring, stuff probably rather broken now
Modified paths:
  • /branches/Maps0.8/includes/features/Maps_BaseMap.php (modified) (history)
  • /branches/Maps0.8/includes/features/Maps_BasePointMap.php (modified) (history)
  • /branches/Maps0.8/includes/parserHooks/Maps_DisplayPoint.php (modified) (history)
  • /branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMapsDispMap.php (modified) (history)
  • /branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMapsDispPoint.php (modified) (history)
  • /branches/Maps0.8/includes/services/GoogleMaps3/Maps_GoogleMaps3DispMap.php (modified) (history)
  • /branches/Maps0.8/includes/services/GoogleMaps3/Maps_GoogleMaps3DispPoint.php (modified) (history)
  • /branches/Maps0.8/includes/services/OSM/Maps_OSMDispMap.php (modified) (history)
  • /branches/Maps0.8/includes/services/OpenLayers/Maps_OpenLayersDispMap.php (modified) (history)
  • /branches/Maps0.8/includes/services/OpenLayers/Maps_OpenLayersDispPoint.php (modified) (history)
  • /branches/Maps0.8/includes/services/YahooMaps/Maps_YahooMapsDispPoint.php (modified) (history)

Diff [purge]

Index: branches/Maps0.8/includes/services/GoogleMaps3/Maps_GoogleMaps3DispPoint.php
@@ -11,17 +11,17 @@
1212 final class MapsGoogleMaps3DispPoint extends MapsBasePointMap {
1313
1414 /**
15 - * @see MapsBaseMap::addSpecificMapHTML
 15+ * @see MapsBasePointMap::getMapHTML()
1616 */
17 - public function addSpecificMapHTML( Parser $parser ) {
 17+ public function getMapHTML( array $params, Parser $parser ) {
1818 return Html::element(
1919 'div',
2020 array(
2121 '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;",
2323 ),
24 - null
 24+ wfMsg( 'maps-loading-map' )
2525 );
2626 }
2727
28 -}
\ No newline at end of file
 28+}
Index: branches/Maps0.8/includes/services/GoogleMaps3/Maps_GoogleMaps3DispMap.php
@@ -23,4 +23,4 @@
2424 );
2525 }
2626
27 -}
\ No newline at end of file
 27+}
Index: branches/Maps0.8/includes/services/YahooMaps/Maps_YahooMapsDispPoint.php
@@ -11,17 +11,17 @@
1212 class MapsYahooMapsDispPoint extends MapsBasePointMap {
1313
1414 /**
15 - * @see MapsBaseMap::addSpecificMapHTML
 15+ * @see MapsBasePointMap::getMapHTML()
1616 */
17 - public function addSpecificMapHTML( Parser $parser ) {
 17+ public function getMapHTML( array $params, Parser $parser ) {
1818 return Html::element(
1919 'div',
2020 array(
2121 '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;",
2323 ),
2424 wfMsg( 'maps-loading-map' )
2525 );
2626 }
2727
28 -}
\ No newline at end of file
 28+}
Index: branches/Maps0.8/includes/services/OpenLayers/Maps_OpenLayersDispPoint.php
@@ -11,17 +11,17 @@
1212 class MapsOpenLayersDispPoint extends MapsBasePointMap {
1313
1414 /**
15 - * @see MapsBaseMap::addSpecificMapHTML
 15+ * @see MapsBasePointMap::getMapHTML()
1616 */
17 - public function addSpecificMapHTML( Parser $parser ) {
 17+ public function addSpecificMapHTML( array $params, Parser $parser ) {
1818 return Html::element(
1919 'div',
2020 array(
2121 '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;",
2323 ),
2424 wfMsg( 'maps-loading-map' )
2525 );
2626 }
2727
28 -}
\ No newline at end of file
 28+}
Index: branches/Maps0.8/includes/services/OpenLayers/Maps_OpenLayersDispMap.php
@@ -29,8 +29,6 @@
3030
3131 /**
3232 * @see MapsBaseMap::getMapHTML
33 - *
34 - * @since 0.7.3
3533 */
3634 public function getMapHTML( array $params, Parser $parser ) {
3735 return Html::element(
@@ -43,4 +41,4 @@
4442 );
4543 }
4644
47 -}
\ No newline at end of file
 45+}
Index: branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMapsDispMap.php
@@ -16,10 +16,8 @@
1717 public function getMapHTML( array $params, Parser $parser ) {
1818 $mapName = $this->service->getMapId();
1919
20 - $output = '';
 20+ $output = $this->service->getOverlayOutput( $mapName, $params['overlays'], $params['controls'] );
2121
22 - $this->service->addOverlayOutput( $output, $mapName, $params['overlays'], $params['controls'] );
23 -
2422 return $output . Html::element(
2523 'div',
2624 array(
@@ -30,4 +28,4 @@
3129 );
3230 }
3331
34 -}
\ No newline at end of file
 32+}
Index: branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMaps.php
@@ -272,14 +272,16 @@
273273 /**
274274 * Adds the needed output for the overlays control.
275275 *
276 - * @param string $output
277276 * @param string $mapName
278277 * @param string $overlays
279278 * @param string $controls
280279 *
281280 * FIXME: layer onload function kills maps for some reason
 281+ * TODO: integrate this properly with Validator
 282+ *
 283+ * @return string
282284 */
283 - public function addOverlayOutput( &$output, $mapName, $overlays, $controls ) {
 285+ public function getOverlayOutput( $mapName, $overlays, $controls ) {
284286 global $egMapsGMapOverlays, $egMapsGoogleOverlLoaded;
285287
286288 // Check to see if there is an overlays control.
@@ -307,7 +309,7 @@
308310 $overlayHtml = '';
309311 $onloadFunctions = array();
310312
311 - $output .= Html::rawElement(
 313+ return Html::rawElement(
312314 'div',
313315 array(
314316 'class' => 'outer-more',
Index: branches/Maps0.8/includes/services/GoogleMaps/Maps_GoogleMapsDispPoint.php
@@ -10,25 +10,22 @@
1111 */
1212 final class MapsGoogleMapsDispPoint extends MapsBasePointMap {
1313
14 - protected function initSpecificParamInfo( array &$parameters ) {
15 - }
16 -
1714 /**
18 - * @see MapsBaseMap::addSpecificMapHTML
 15+ * @see MapsBasePointMap::getMapHTML
1916 */
20 - public function addSpecificMapHTML( Parser $parser ) {
 17+ public function getMapHTML( array $params, Parser $parser ) {
2118 $mapName = $this->service->getMapId();
2219
23 - $this->service->addOverlayOutput( $this->output, $mapName, $this->overlays, $this->controls );
 20+ $output = $this->service->getOverlayOutput( $mapName, $params['overlays'], $params['controls'] );
2421
25 - return Html::element(
 22+ return $output . Html::element(
2623 'div',
2724 array(
2825 '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;",
3027 ),
3128 wfMsg( 'maps-loading-map' )
3229 );
3330 }
3431
35 -}
\ No newline at end of file
 32+}
Index: branches/Maps0.8/includes/services/OSM/Maps_OSMDispMap.php
@@ -34,4 +34,4 @@
3535 );
3636 }
3737
38 -}
\ No newline at end of file
 38+}
Index: branches/Maps0.8/includes/parserHooks/Maps_DisplayPoint.php
@@ -141,7 +141,7 @@
142142 // Get an instance of the class handling the current parser hook and service.
143143 $mapClass = $service->getFeatureInstance( 'display_point' );
144144
145 - return $mapClass->getMapHtml( $parameters, $this->parser );
 145+ return $mapClass->renderMap( $parameters, $this->parser );
146146 }
147147
148148 /**
@@ -168,4 +168,4 @@
169169 return wfMsg( 'maps-displaypoint-description' );
170170 }
171171
172 -}
\ No newline at end of file
 172+}
Index: branches/Maps0.8/includes/features/Maps_BasePointMap.php
@@ -17,38 +17,25 @@
1818 */
1919 protected $service;
2020
21 - protected $centreLat, $centreLon;
22 - protected $markerJs;
23 -
24 - protected $output = '';
 21+ protected $markerData = array();
2522
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 );
2734
28 - private $specificParameters = false;
29 - private $markerData = array();
30 -
3135 public function __construct( iMappingService $service ) {
3236 $this->service = $service;
3337 }
3438
3539 /**
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 - /**
5340 * Returns the specific parameters by first checking if they have been initialized yet,
5441 * doing to work if this is not the case, and then returning them.
5542 *
@@ -81,19 +68,17 @@
8269 *
8370 * @return html
8471 */
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 );
8974
90 - $this->setCentre();
 75+ $this->setCentre( $params );
9176
9277 // TODO
93 - if ( count( $this->markerData ) <= 1 && $this->zoom == 'null' ) {
 78+ /*if ( count( $this->markerData ) <= 1 && $this->zoom == 'null' ) {
9479 $this->zoom = $this->service->getDefaultZoom();
95 - }
 80+ }*/
9681
97 - $this->addSpecificMapHTML( $parser );
 82+ $output = $this->getMapHTML( $params, $parser ) . $this->getJSON( $params, $parser );
9883
9984 global $wgTitle;
10085 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
@@ -104,10 +89,45 @@
10590 $this->service->addDependencies( $parser );
10691 }
10792
108 - return $this->output;
 93+ return $output;
10994 }
11095
11196 /**
 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+ /**
112132 * Fills the $markerData array with the locations and their meta data.
113133 */
114134 private function setMarkerData() {
@@ -170,7 +190,7 @@
171191 * Sets the $centre_lat and $centre_lon fields.
172192 * Note: this needs to be done AFTRE the maker coordinates are set.
173193 */
174 - protected function setCentre() {
 194+ protected function setCentre( array &$params ) {
175195 global $egMapsDefaultMapCentre;
176196
177197 if ( $this->centre === false ) {
@@ -186,7 +206,7 @@
187207 $this->centreLon = 'null';
188208 }
189209 else {
190 - $this->setCentreToDefault();
 210+ $this->setCentreToDefault( $params );
191211 }
192212
193213 }
@@ -199,7 +219,7 @@
200220 $this->centreLon = Xml::escapeJsString( $this->centre['lon'] );
201221 }
202222 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 );
204224 }
205225 }
206226
@@ -211,7 +231,7 @@
212232 *
213233 * @since 0.7
214234 */
215 - protected function setCentreToDefault() {
 235+ protected function setCentreToDefault( array &$params ) {
216236 global $egMapsDefaultMapCentre;
217237
218238 $centre = MapsGeocoders::attemptToGeocode( $egMapsDefaultMapCentre, $this->geoservice, $this->service->getName() );
@@ -220,6 +240,7 @@
221241 throw new Exception( 'Failed to parse the default centre for the map. Please check the value of $egMapsDefaultMapCentre.' );
222242 }
223243 else {
 244+ //$params['centre'] =
224245 $this->centreLat = Xml::escapeJsString( $centre['lat'] );
225246 $this->centreLon = Xml::escapeJsString( $centre['lon'] );
226247 }
Index: branches/Maps0.8/includes/features/Maps_BaseMap.php
@@ -59,7 +59,7 @@
6060 * Handles the request from the parser hook by doing the work that's common for all
6161 * mapping services, calling the specific methods and finally returning the resulting output.
6262 *
63 - * @since 0.7.3
 63+ * @since 0.8
6464 *
6565 * @param array $params
6666 * @param Parser $parser
@@ -67,20 +67,14 @@
6868 * @return html
6969 */
7070 public final function renderMap( array $params, Parser $parser ) {
71 - global $egMapsUseRL;
72 -
7371 $this->setCentre( $params );
7472
7573 if ( $params['zoom'] == 'null' ) {
7674 $params['zoom'] = $this->service->getDefaultZoom();
7775 }
7876
79 - $output = $this->getMapHTML( $params, $parser );
 77+ $output = $this->getMapHTML( $params, $parser ) . $this->getJSON( $params, $parser );
8078
81 - if ( $egMapsUseRL ) {
82 - $output .= $this->getJSON( $params, $parser );
83 - }
84 -
8579 global $wgTitle;
8680 if ( $wgTitle->getNamespace() == NS_SPECIAL ) {
8781 global $wgOut;
@@ -130,6 +124,10 @@
131125
132126 /**
133127 * 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
134132 */
135133 protected function setCentre( array &$params ) {
136134 // If it's false, the coordinate was invalid, or geocoding failed. Either way, the default's should be used.

Follow-up revisions

RevisionCommit summaryAuthorDate
r80826Follow up to r80825jeroendedauw18:35, 23 January 2011
r80836follow up to r80825jeroendedauw21:50, 23 January 2011

Status & tagging log