r65327 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r65326‎ | r65327 | r65328 >
Date:15:10, 20 April 2010
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Follow up to r65307
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /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 (deleted) (history)
  • /trunk/extensions/Maps/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php (modified) (history)
  • /trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.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/Maps_ParserFunctions.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_iDisplayFunction.php (deleted) (history)
  • /trunk/extensions/Maps/ParserFunctions/Maps_iMapFeature.php (added) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.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/Maps_MapFeature.php
@@ -1,128 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * File holding class MapsMapFeature.
6 - *
7 - * @file Maps_MapFeature.php
8 - * @ingroup Maps
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if ( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -/**
18 - * MapsMapFeature bundles base functionallity for all general mapping feature classes.
19 - *
20 - * @ingroup Maps
21 - *
22 - * @author Jeroen De Dauw
23 - *
24 - * TODO: refactor this and subclasses to follow mw conventions and simply have a better design pattern.
25 - */
26 -abstract class MapsMapFeature {
27 -
28 - /**
29 - * Set the map service specific element name and the javascript function handling the displaying of an address
30 - */
31 - protected abstract function setMapSettings();
32 -
33 - /**
34 - * Map service specific map count and loading of dependencies
35 - */
36 - protected abstract function doMapServiceLoad();
37 -
38 - /**
39 - * Adds the HTML specific to the mapping service to the output
40 - */
41 - protected abstract function addSpecificMapHTML( Parser $parser );
42 -
43 - public $serviceName;
44 -
45 - protected $elementNr;
46 - protected $elementNamePrefix;
47 -
48 - protected $mapName;
49 -
50 - protected $centreLat, $centreLon;
51 -
52 - protected $output = '';
53 -
54 - protected $spesificParameters = false;
55 - protected $featureParameters = false;
56 -
57 - /**
58 - * Sets the map properties as class fields.
59 - *
60 - * @param array $mapProperties
61 - * @param string $className
62 - */
63 - protected function setMapProperties( array $mapProperties, $className ) {
64 - foreach ( $mapProperties as $paramName => $paramValue ) {
65 - if ( !property_exists( $className, $paramName ) ) {
66 - $this-> { $paramName } = $paramValue;
67 - }
68 - else {
69 - // If this happens in any way, it could be a big vunerability, so throw an exception.
70 - throw new Exception( 'Attempt to override a class field during map property assignment. Field name: ' . $paramName );
71 - }
72 - }
73 - }
74 -
75 - /**
76 - * Sets the $mapName field, using the $elementNamePrefix and $elementNr.
77 - */
78 - protected function setMapName() {
79 - $this->mapName = $this->elementNamePrefix . '_' . $this->elementNr;
80 - }
81 -
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, $egMapsMapWidth, $egMapsMapHeight;
94 -
95 - return array(
96 - 'service' => array(
97 - 'criteria' => array(
98 - 'in_array' => $egMapsAvailableServices
99 - ),
100 - ),
101 - 'geoservice' => array(
102 - 'criteria' => array(
103 - 'in_array' => $egMapsAvailableGeoServices
104 - ),
105 - 'default' => $egMapsDefaultGeoService
106 - ),
107 - 'zoom' => array(
108 - 'type' => 'integer',
109 - 'criteria' => array(
110 - 'not_empty' => array()
111 - )
112 - ),
113 - 'width' => array(
114 - 'criteria' => array(
115 - 'is_map_dimension' => array( 'width' ),
116 - ),
117 - 'default' => $egMapsMapWidth,
118 - 'output-type' => array( 'mapdimension', 'width', $egMapsMapWidth )
119 - ),
120 - 'height' => array(
121 - 'criteria' => array(
122 - 'is_map_dimension' => array( 'height' ),
123 - ),
124 - 'default' => $egMapsMapHeight,
125 - 'output-type' => array( 'mapdimension', 'height', $egMapsMapHeight )
126 - ),
127 - );
128 - }
129 -}
\ No newline at end of file
Index: trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3DispPoint.php
@@ -24,21 +24,7 @@
2525
2626 public $serviceName = MapsGoogleMaps3::SERVICE_NAME;
2727
28 - /**
29 - * @see MapsBaseMap::setMapSettings()
30 - *
31 - */
32 - protected function setMapSettings() {
33 - global $egMapsGMaps3Zoom, $egMapsGMaps3Prefix;
34 -
35 - $this->elementNamePrefix = $egMapsGMaps3Prefix;
36 - $this->defaultZoom = $egMapsGMaps3Zoom;
37 -
38 - $this->markerStringFormat = 'getGMaps3MarkerData(lat, lon, \'title\', \'label\', "icon")';
39 -
40 - $this->spesificParameters = array(
41 - );
42 - }
 28+ protected $markerStringFormat = 'getGMaps3MarkerData(lat, lon, \'title\', \'label\', "icon")';
4329
4430 /**
4531 * @see MapsBaseMap::doMapServiceLoad()
@@ -58,21 +44,26 @@
5945 *
6046 */
6147 public function addSpecificMapHTML( Parser $parser ) {
 48+ global $egMapsGMaps3Prefix, $egGMaps3OnThisPage;
 49+
 50+ $mapName = $egMapsGMaps3Prefix . '_' . $egGMaps3OnThisPage;
 51+
6252 $this->output .= Html::element(
6353 'div',
6454 array(
65 - 'id' => $this->mapName,
 55+ 'id' => $mapName,
6656 'width' => $this->width,
6757 'height' => $this->height
6858 ),
6959 null
7060 );
7161
72 - $wgOut->addInlineScript( <<<EOT
 62+ $parser->getOutput()->addHeadItem(
 63+ Html::inlineScript( <<<EOT
7364 addOnloadHook(
7465 function() {
7566 initGMap3(
76 - "$this->mapName",
 67+ '$mapName',
7768 {
7869 zoom: $this->zoom,
7970 lat: $this->centreLat,
@@ -85,6 +76,7 @@
8677 }
8778 );
8879 EOT
 80+ )
8981 );
9082 }
9183
Index: trunk/extensions/Maps/GoogleMaps3/Maps_GoogleMaps3DispMap.php
@@ -23,20 +23,6 @@
2424 final class MapsGoogleMaps3DispMap extends MapsBaseMap {
2525
2626 public $serviceName = MapsGoogleMaps3::SERVICE_NAME;
27 -
28 - /**
29 - * @see MapsBaseMap::setMapSettings()
30 - *
31 - */
32 - protected function setMapSettings() {
33 - global $egMapsGMaps3Zoom, $egMapsGMaps3Prefix;
34 -
35 - $this->elementNamePrefix = $egMapsGMaps3Prefix;
36 - $this->defaultZoom = $egMapsGMaps3Zoom;
37 -
38 - $this->spesificParameters = array(
39 - );
40 - }
4127
4228 /**
4329 * @see MapsBaseMap::doMapServiceLoad()
@@ -56,21 +42,26 @@
5743 *
5844 */
5945 public function addSpecificMapHTML( Parser $parser ) {
 46+ global $egMapsGMaps3Prefix, $egGMaps3OnThisPage;
 47+
 48+ $mapName = $egMapsGMaps3Prefix . '_' . $egGMaps3OnThisPage;
 49+
6050 $this->output .= Html::element(
6151 'div',
6252 array(
63 - 'id' => $this->mapName,
 53+ 'id' => $mapName,
6454 'width' => $this->width,
6555 'height' => $this->height
6656 ),
6757 null
6858 );
6959
70 - $wgOut->addInlineScript( <<<EOT
 60+ $parser->getOutput()->addHeadItem(
 61+ Html::inlineScript( <<<EOT
7162 addOnloadHook(
7263 function() {
7364 initGMap3(
74 - "$this->mapName",
 65+ '$mapName',
7566 {
7667 zoom: $this->zoom,
7768 lat: $this->centreLat,
@@ -83,6 +74,7 @@
8475 }
8576 );
8677 EOT
 78+ )
8779 );
8880 }
8981
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php
@@ -22,20 +22,9 @@
2323
2424 public $serviceName = MapsOpenLayers::SERVICE_NAME;
2525
 26+ protected $markerStringFormat = 'getOLMarkerData(lon, lat, \'title\', \'label\', "icon")';
 27+
2628 /**
27 - * @see MapsBaseMap::setMapSettings()
28 - *
29 - */
30 - protected function setMapSettings() {
31 - global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix;
32 -
33 - $this->elementNamePrefix = $egMapsOpenLayersPrefix;
34 - $this->defaultZoom = $egMapsOpenLayersZoom;
35 -
36 - $this->markerStringFormat = 'getOLMarkerData(lon, lat, \'title\', \'label\', "icon")';
37 - }
38 -
39 - /**
4029 * @see MapsBaseMap::doMapServiceLoad()
4130 *
4231 */
@@ -53,12 +42,16 @@
5443 *
5544 */
5645 public function addSpecificMapHTML( Parser $parser ) {
 46+ global $egMapsOpenLayersPrefix, $egOpenLayersOnThisPage;
 47+
5748 $layerItems = MapsOpenLayers::createLayersStringAndLoadDependencies( $this->output, $this->layers );
5849
 50+ $mapName = $egMapsOpenLayersPrefix . '_' . $egOpenLayersOnThisPage;
 51+
5952 $this->output .= Html::element(
6053 'div',
6154 array(
62 - 'id' => $this->mapName,
 55+ 'id' => $mapName,
6356 'style' => "width: $this->width; height: $this->height; background-color: #cccccc;",
6457 ),
6558 wfMsg('maps-loading-map')
@@ -69,7 +62,7 @@
7063 addOnloadHook(
7164 function() {
7265 initOpenLayer(
73 - '$this->mapName',
 66+ '$mapName',
7467 $this->centreLon,
7568 $this->centreLat,
7669 $this->zoom,
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php
@@ -18,16 +18,6 @@
1919 public $serviceName = MapsOpenLayers::SERVICE_NAME;
2020
2121 /**
22 - * @see MapsBaseMap::setMapSettings()
23 - */
24 - protected function setMapSettings() {
25 - global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix;
26 -
27 - $this->elementNamePrefix = $egMapsOpenLayersPrefix;
28 - $this->defaultZoom = $egMapsOpenLayersZoom;
29 - }
30 -
31 - /**
3222 * @see MapsBaseMap::doMapServiceLoad()
3323 */
3424 protected function doMapServiceLoad() {
@@ -43,23 +33,27 @@
4434 * @see MapsBaseMap::addSpecificMapHTML()
4535 */
4636 public function addSpecificMapHTML( Parser $parser ) {
 37+ global $egMapsOpenLayersPrefix, $egOpenLayersOnThisPage;
 38+
4739 $layerItems = MapsOpenLayers::createLayersStringAndLoadDependencies( $this->output, $this->layers );
 40+
 41+ $mapName = $egMapsOpenLayersPrefix . '_' . $egOpenLayersOnThisPage;
4842
4943 $this->output .= Html::element(
5044 'div',
5145 array(
52 - 'id' => $this->mapName,
 46+ 'id' => $mapName,
5347 'style' => "width: $this->width; height: $this->height; background-color: #cccccc;",
5448 ),
5549 wfMsg('maps-loading-map')
5650 );
5751
58 - $parser->getOutput()->addHeadItem(
 52+ $parser->getOutput()->addHeadItem(
5953 Html::inlineScript( <<<EOT
6054 addOnloadHook(
6155 function() {
6256 initOpenLayer(
63 - '$this->mapName',
 57+ '$mapName',
6458 $this->centreLon,
6559 $this->centreLat,
6660 $this->zoom,
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php
@@ -61,31 +61,31 @@
6262 private static function initializeParams() {
6363 global $egMapsServices, $egMapsOLLayers, $egMapsOLControls, $egMapsOpenLayersZoom;
6464
 65+ $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
 66+ 'controls' => array(
 67+ 'type' => array( 'string', 'list' ),
 68+ 'criteria' => array(
 69+ 'in_array' => self::getControlNames()
 70+ ),
 71+ 'default' => $egMapsOLControls,
 72+ 'output-type' => array( 'list', ',', '\'' )
 73+ ),
 74+ 'layers' => array(
 75+ 'type' => array( 'string', 'list' ),
 76+ 'criteria' => array(
 77+ 'in_array' => self::getLayerNames( true )
 78+ ),
 79+ 'default' => $egMapsOLLayers,
 80+ 'output-types' => array(
 81+ 'unique_items',
 82+ 'olgroups',
 83+ array( 'filtered_array', self::getLayerNames() ),
 84+ )
 85+ ),
 86+ );
 87+
6588 $egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['default'] = $egMapsOpenLayersZoom;
66 - $egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['criteria']['in_range'] = array( 0, 19 );
67 -
68 - $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
69 - 'controls' => array(
70 - 'type' => array( 'string', 'list' ),
71 - 'criteria' => array(
72 - 'in_array' => self::getControlNames()
73 - ),
74 - 'default' => $egMapsOLControls,
75 - 'output-type' => array( 'list', ',', '\'' )
76 - ),
77 - 'layers' => array(
78 - 'type' => array( 'string', 'list' ),
79 - 'criteria' => array(
80 - 'in_array' => self::getLayerNames( true )
81 - ),
82 - 'default' => $egMapsOLLayers,
83 - 'output-types' => array(
84 - 'unique_items',
85 - 'olgroups',
86 - array( 'filtered_array', self::getLayerNames() ),
87 - )
88 - ),
89 - );
 89+ $egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['criteria']['in_range'] = array( 0, 19 );
9090 }
9191
9292 /**
@@ -97,15 +97,15 @@
9898 */
9999 public static function getControlNames() {
100100 return array(
101 - 'argparser', 'attribution', 'button', 'dragfeature', 'dragpan',
102 - 'drawfeature', 'editingtoolbar', 'getfeature', 'keyboarddefaults', 'layerswitcher',
103 - 'measure', 'modifyfeature', 'mousedefaults', 'mouseposition', 'mousetoolbar',
104 - 'navigation', 'navigationhistory', 'navtoolbar', 'overviewmap', 'pan',
105 - 'panel', 'panpanel', 'panzoom', 'panzoombar', 'autopanzoom', 'permalink',
106 - 'scale', 'scaleline', 'selectfeature', 'snapping', 'split',
107 - 'wmsgetfeatureinfo', 'zoombox', 'zoomin', 'zoomout', 'zoompanel',
108 - 'zoomtomaxextent'
109 - );
 101+ 'argparser', 'attribution', 'button', 'dragfeature', 'dragpan',
 102+ 'drawfeature', 'editingtoolbar', 'getfeature', 'keyboarddefaults', 'layerswitcher',
 103+ 'measure', 'modifyfeature', 'mousedefaults', 'mouseposition', 'mousetoolbar',
 104+ 'navigation', 'navigationhistory', 'navtoolbar', 'overviewmap', 'pan',
 105+ 'panel', 'panpanel', 'panzoom', 'panzoombar', 'autopanzoom', 'permalink',
 106+ 'scale', 'scaleline', 'selectfeature', 'snapping', 'split',
 107+ 'wmsgetfeatureinfo', 'zoombox', 'zoomin', 'zoomout', 'zoompanel',
 108+ 'zoomtomaxextent'
 109+ );
110110 }
111111
112112 /**
Index: trunk/extensions/Maps/ParserFunctions/Maps_iDisplayFunction.php
@@ -1,23 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * File holding interface iDisplayFunction.
6 - *
7 - * @file Maps_iDisplayFunction.php
8 - * @ingroup Maps
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if ( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -/**
18 - * Interface that should be implemented by all display_ parser functions.
19 - *
20 - * @author Jeroen De Dauw
21 - */
22 -interface iDisplayFunction {
23 - public function displayMap( Parser &$parser, array $params );
24 -}
\ No newline at end of file
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
@@ -21,48 +21,80 @@
2222 * @ingroup Maps
2323 *
2424 * @author Jeroen De Dauw
 25+ *
 26+ * TODO: fix zoom - should default to 'null' when no value given and multiple points
2527 */
26 -abstract class MapsBasePointMap extends MapsMapFeature implements iDisplayFunction {
 28+abstract class MapsBasePointMap implements iMapFeature {
2729
 30+ public $serviceName;
 31+
 32+ protected $centreLat, $centreLon;
 33+
 34+ protected $output = '';
 35+
 36+ protected $spesificParameters = false;
 37+ protected $featureParameters = false;
 38+
2839 private $markerData = array();
2940 protected $markerString;
3041
3142 /**
 43+ * Sets the map properties as class fields.
 44+ *
 45+ * @param array $mapProperties
 46+ */
 47+ protected function setMapProperties( array $mapProperties ) {
 48+ foreach ( $mapProperties as $paramName => $paramValue ) {
 49+ if ( !property_exists( __CLASS__, $paramName ) ) {
 50+ $this-> { $paramName } = $paramValue;
 51+ }
 52+ else {
 53+ // If this happens in any way, it could be a big vunerability, so throw an exception.
 54+ throw new Exception( 'Attempt to override a class field during map property assignment. Field name: ' . $paramName );
 55+ }
 56+ }
 57+ }
 58+
 59+ /**
3260 * @return array
 61+ */
 62+ public function getSpecificParameterInfo() {
 63+ return array();
 64+ }
 65+
 66+ /**
 67+ * @return array
3368 */
3469 public function getFeatureParameters() {
3570 global $egMapsDefaultServices, $egMapsDefaultTitle, $egMapsDefaultLabel;
3671
37 - return array_merge(
38 - parent::getFeatureParameters(),
39 - array(
40 - 'service' => array(
41 - 'default' => $egMapsDefaultServices['display_point']
 72+ return array(
 73+ 'service' => array(
 74+ 'default' => $egMapsDefaultServices['display_point']
 75+ ),
 76+ 'centre' => array(
 77+ 'aliases' => array( 'center' ),
 78+ ),
 79+ 'title' => array(
 80+ 'default' => $egMapsDefaultTitle
 81+ ),
 82+ 'label' => array(
 83+ 'default' => $egMapsDefaultLabel
 84+ ),
 85+ 'icon' => array(
 86+ 'criteria' => array(
 87+ 'not_empty' => array()
 88+ )
 89+ ),
 90+ 'coordinates' => array(
 91+ 'required' => true,
 92+ 'type' => array( 'string', 'list', ';' ),
 93+ 'aliases' => array( 'coords', 'location', 'locations' ),
 94+ 'criteria' => array(
 95+ 'are_locations' => array()
4296 ),
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 - 'coordinates' => array(
58 - 'required' => true,
59 - 'type' => array( 'string', 'list', ';' ),
60 - 'aliases' => array( 'coords', 'location', 'locations' ),
61 - 'criteria' => array(
62 - 'are_locations' => array()
63 - ),
64 - 'output-type' => 'coordinateSets',
65 - ),
66 - )
 97+ 'output-type' => 'coordinateSets',
 98+ ),
6799 );
68100 }
69101
@@ -75,23 +107,17 @@
76108 *
77109 * @return html
78110 */
79 - public final function displayMap( Parser &$parser, array $params ) {
80 - $this->setMapSettings();
81 -
 111+ public final function displayMap( Parser &$parser, array $params ) {
82112 $this->featureParameters = MapsDisplayPoint::$parameters;
83113
84114 $this->doMapServiceLoad();
85115
86 - parent::setMapProperties( $params, __CLASS__ );
 116+ $this->setMapProperties( $params );
87117
88 - $this->setMapName();
89 -
90118 $this->setMarkerData( $parser );
91119
92120 $this->createMarkerString();
93121
94 - $this->setZoom();
95 -
96122 $this->setCentre();
97123
98124 $this->addSpecificMapHTML( $parser );
@@ -100,23 +126,6 @@
101127 }
102128
103129 /**
104 - * Sets the zoom level to the provided value. When no zoom is provided, set
105 - * it to the default when there is only one location, or the best fitting soom when
106 - * there are multiple locations.
107 - *
108 - */
109 - private function setZoom() {
110 - if ( strlen( $this->zoom ) < 1 ) {
111 - if ( count( $this->markerData ) > 1 ) {
112 - $this->zoom = 'null';
113 - }
114 - else {
115 - $this->zoom = $this->defaultZoom;
116 - }
117 - }
118 - }
119 -
120 - /**
121130 * Fills the $markerData array with the locations and their meta data.
122131 *
123132 * @param unknown_type $parser
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
@@ -22,29 +22,59 @@
2323 *
2424 * @author Jeroen De Dauw
2525 */
26 -abstract class MapsBaseMap extends MapsMapFeature implements iDisplayFunction {
 26+abstract class MapsBaseMap implements iMapFeature {
2727
 28+ public $serviceName;
 29+
 30+ protected $centreLat, $centreLon;
 31+
 32+ protected $output = '';
 33+
 34+ protected $spesificParameters = false;
 35+ protected $featureParameters = false;
 36+
2837 /**
 38+ * Sets the map properties as class fields.
 39+ *
 40+ * @param array $mapProperties
 41+ */
 42+ protected function setMapProperties( array $mapProperties ) {
 43+ foreach ( $mapProperties as $paramName => $paramValue ) {
 44+ if ( !property_exists( __CLASS__, $paramName ) ) {
 45+ $this-> { $paramName } = $paramValue;
 46+ }
 47+ else {
 48+ // If this happens in any way, it could be a big vunerability, so throw an exception.
 49+ throw new Exception( 'Attempt to override a class field during map property assignment. Field name: ' . $paramName );
 50+ }
 51+ }
 52+ }
 53+
 54+ /**
2955 * @return array
 56+ */
 57+ public function getSpecificParameterInfo() {
 58+ return array();
 59+ }
 60+
 61+ /**
 62+ * @return array
3063 */
3164 public function getFeatureParameters() {
3265 global $egMapsDefaultServices;
3366
34 - return array_merge(
35 - parent::getFeatureParameters(),
36 - array(
37 - 'service' => array(
38 - 'default' => $egMapsDefaultServices['display_map']
 67+ return array(
 68+ 'service' => array(
 69+ 'default' => $egMapsDefaultServices['display_map']
 70+ ),
 71+ 'coordinates' => array(
 72+ 'required' => true,
 73+ 'aliases' => array( 'coords', 'location', 'locations' ),
 74+ 'criteria' => array(
 75+ 'is_location' => array()
3976 ),
40 - 'coordinates' => array(
41 - 'required' => true,
42 - 'aliases' => array( 'coords', 'location', 'locations' ),
43 - 'criteria' => array(
44 - 'is_location' => array()
45 - ),
46 - 'output-type' => 'coordinateSet',
47 - ),
48 - )
 77+ 'output-type' => 'coordinateSet',
 78+ ),
4979 );
5080 }
5181
@@ -58,18 +88,12 @@
5989 * @return html
6090 */
6191 public final function displayMap( Parser &$parser, array $params ) {
62 - $this->setMapSettings();
63 -
6492 $this->featureParameters = MapsDisplayMap::$parameters;
6593
6694 $this->doMapServiceLoad();
6795
68 - parent::setMapProperties( $params, __CLASS__ );
 96+ $this->setMapProperties( $params );
6997
70 - $this->setMapName();
71 -
72 - $this->setZoom();
73 -
7498 $this->setCentre();
7599
76100 $this->addSpecificMapHTML( $parser );
@@ -78,16 +102,6 @@
79103 }
80104
81105 /**
82 - * Sets the zoom level to the provided value. When no zoom is provided, set
83 - * it to the default when there is only one location, or the best fitting soom when
84 - * there are multiple locations.
85 - *
86 - */
87 - private function setZoom() {
88 - if ( empty( $this->zoom ) ) $this->zoom = $this->defaultZoom;
89 - }
90 -
91 - /**
92106 * Sets the $centre_lat and $centre_lon fields.
93107 */
94108 private function setCentre() {
Index: trunk/extensions/Maps/ParserFunctions/Maps_iMapFeature.php
@@ -0,0 +1,34 @@
 2+<?php
 3+
 4+/**
 5+ * File holding interface iMapFeature.
 6+ *
 7+ * @file Maps_iMapFeature.php
 8+ * @ingroup Maps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ */
 12+
 13+if ( !defined( 'MEDIAWIKI' ) ) {
 14+ die( 'Not an entry point.' );
 15+}
 16+
 17+/**
 18+ * Interface that should be implemented by all mapping feature classes.
 19+ *
 20+ * @author Jeroen De Dauw
 21+ */
 22+interface iMapFeature {
 23+ function displayMap( Parser &$parser, array $params );
 24+
 25+ /**
 26+ * Map service specific map count and loading of dependencies.
 27+ */
 28+ function doMapServiceLoad();
 29+
 30+ /**
 31+ * Adds the HTML specific to the mapping service to the output.
 32+ */
 33+ function addSpecificMapHTML( Parser $parser );
 34+}
 35+
Property changes on: trunk/extensions/Maps/ParserFunctions/Maps_iMapFeature.php
___________________________________________________________________
Name: svn:eol-style
136 + native
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -24,8 +24,6 @@
2525 */
2626 final class MapsParserFunctions {
2727
28 - public static $parameters = array();
29 -
3028 /**
3129 * Initialize the parser functions feature. This function handles the parser function hook,
3230 * and will load the required classes.
@@ -33,7 +31,7 @@
3432 public static function initialize() {
3533 global $egMapsDir, $egMapsFeatures;
3634
37 - include_once $egMapsDir . 'ParserFunctions/Maps_iDisplayFunction.php';
 35+ include_once $egMapsDir . 'ParserFunctions/Maps_iMapFeature.php';
3836
3937 // This runs a small hook that enables parser functions to run initialization code.
4038 foreach ( $egMapsFeatures['pf'] as $hook ) {
@@ -66,7 +64,7 @@
6765 foreach( $args as $arg ) {
6866 $split = explode( '=', $arg );
6967 $name = strtolower( trim( array_shift( $split ) ) );
70 - if ( count( $split ) > 1 && self::inParamAliases( $name, 'service', self::$parameters ) ) {
 68+ if ( count( $split ) > 1 && self::inParamAliases( $name, 'service', MapsMapper::getCommonParameters() ) ) {
7169 if ( !$setService ) {
7270 $service = implode( '=', $split );
7371 $parameters = 'service=' . $service;
@@ -90,7 +88,7 @@
9189 * again overidden by the service parameters (the ones spesific to the service),
9290 * and finally by the spesific parameters (the ones spesific to a service-feature combination).
9391 */
94 - $parameterInfo = array_merge( self::$parameters, $mapClass->getFeatureParameters() );
 92+ $parameterInfo = array_merge( MapsMapper::getCommonParameters(), $mapClass->getFeatureParameters() );
9593 $parameterInfo = array_merge( $parameterInfo, $egMapsServices[$service]['parameters'] );
9694 $parameterInfo = array_merge( $parameterInfo, $mapClass->getSpecificParameterInfo() );
9795
Index: trunk/extensions/Maps/Maps.php
@@ -84,7 +84,6 @@
8585
8686 // Autoload the general classes
8787 $wgAutoloadClasses['MapsCoordinateParser'] = $egMapsDir . 'Maps_CoordinateParser.php';
88 - $wgAutoloadClasses['MapsMapFeature'] = $egMapsDir . 'Maps_MapFeature.php';
8988 $wgAutoloadClasses['MapsMapper'] = $egMapsDir . 'Maps_Mapper.php';
9089
9190 wfLoadExtensionMessages( 'Maps' );
Index: trunk/extensions/Maps/Maps_Mapper.php
@@ -201,6 +201,49 @@
202202 public static function geocoderIsAvailable() {
203203 global $wgAutoloadClasses;
204204 return array_key_exists( 'MapsGeocoder', $wgAutoloadClasses );
 205+ }
 206+
 207+ /**
 208+ * This function returns the definitions for the parameters used by every map feature.
 209+ *
 210+ * @return array
 211+ */
 212+ public static function getCommonParameters() {
 213+ global $egMapsAvailableServices, $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsMapWidth, $egMapsMapHeight;
 214+
 215+ return array(
 216+ 'service' => array(
 217+ 'criteria' => array(
 218+ 'in_array' => $egMapsAvailableServices
 219+ ),
 220+ ),
 221+ 'geoservice' => array(
 222+ 'criteria' => array(
 223+ 'in_array' => $egMapsAvailableGeoServices
 224+ ),
 225+ 'default' => $egMapsDefaultGeoService
 226+ ),
 227+ 'zoom' => array(
 228+ 'type' => 'integer',
 229+ 'criteria' => array(
 230+ 'not_empty' => array()
 231+ )
 232+ ),
 233+ 'width' => array(
 234+ 'criteria' => array(
 235+ 'is_map_dimension' => array( 'width' ),
 236+ ),
 237+ 'default' => $egMapsMapWidth,
 238+ 'output-type' => array( 'mapdimension', 'width', $egMapsMapWidth )
 239+ ),
 240+ 'height' => array(
 241+ 'criteria' => array(
 242+ 'is_map_dimension' => array( 'height' ),
 243+ ),
 244+ 'default' => $egMapsMapHeight,
 245+ 'output-type' => array( 'mapdimension', 'height', $egMapsMapHeight )
 246+ ),
 247+ );
205248 }
206249
207250 }
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php
@@ -23,7 +23,7 @@
2424 final class MapsGoogleMapsDispMap extends MapsBaseMap {
2525
2626 public $serviceName = MapsGoogleMaps::SERVICE_NAME;
27 -
 27+
2828 public function getSpecificParameterInfo() {
2929 global $egMapsGMapOverlays;
3030 // TODO: it'd be cool to have this static so it can be cheched in order to only init it once.
@@ -40,19 +40,9 @@
4141 }
4242
4343 /**
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 - /**
5444 * @see MapsBaseMap::doMapServiceLoad()
5545 */
56 - protected function doMapServiceLoad() {
 46+ public function doMapServiceLoad() {
5747 global $egGoogleMapsOnThisPage;
5848
5949 MapsGoogleMaps::addGMapDependencies( $this->output );
@@ -65,22 +55,26 @@
6656 * @see MapsBaseMap::addSpecificMapHTML()
6757 */
6858 public function addSpecificMapHTML( Parser $parser ) {
69 - MapsGoogleMaps::addOverlayOutput( $this->output, $this->mapName, $this->overlays, $this->controls );
 59+ global $egMapsGoogleMapsPrefix, $egGoogleMapsOnThisPage;
7060
 61+ $mapName = $egMapsGoogleMapsPrefix . '_' . $egGoogleMapsOnThisPage;
 62+
 63+ MapsGoogleMaps::addOverlayOutput( $this->output, $mapName, $this->overlays, $this->controls );
 64+
7165 $this->output .= Html::element(
7266 'div',
7367 array(
74 - 'id' => $this->mapName,
 68+ 'id' => $mapName,
7569 'style' => "width: $this->width; height: $this->height; background-color: #cccccc;",
7670 ),
77 - wfMsg('maps-loading-map')
 71+ wfMsg( 'maps-loading-map' )
7872 );
7973
8074 $parser->getOutput()->addHeadItem(
8175 Html::inlineScript( <<<EOT
8276 addOnloadHook(
8377 function() {
84 - initializeGoogleMap('$this->mapName',
 78+ initializeGoogleMap('$mapName',
8579 {
8680 lat: $this->centreLat,
8781 lon: $this->centreLon,
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
@@ -64,9 +64,6 @@
6565
6666 $allowedTypes = self::getTypeNames();
6767
68 - $egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['default'] = $egMapsGoogleMapsZoom;
69 - $egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['criteria']['in_range'] = array( 0, 20 );
70 -
7168 $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
7269 'controls' => array(
7370 'type' => array( 'string', 'list' ),
@@ -100,6 +97,9 @@
10198 'output-type' => 'boolstr'
10299 ),
103100 );
 101+
 102+ $egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['default'] = $egMapsGoogleMapsZoom;
 103+ $egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['criteria']['in_range'] = array( 0, 20 );
104104 }
105105
106106 // http://code.google.com/apis/maps/documentation/reference.html#GMapType.G_NORMAL_MAP
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php
@@ -24,6 +24,8 @@
2525
2626 public $serviceName = MapsGoogleMaps::SERVICE_NAME;
2727
 28+ protected $markerStringFormat = 'getGMarkerData(lat, lon, \'title\', \'label\', "icon")';
 29+
2830 public function getSpecificParameterInfo() {
2931 global $egMapsGMapOverlays;
3032 // TODO: it'd be cool to have this static so it can be cheched in order to only init it once.
@@ -38,25 +40,11 @@
3941 );
4042 return $this->spesificParameters;
4143 }
42 -
 44+
4345 /**
44 - * @see MapsBaseMap::setMapSettings()
45 - *
46 - */
47 - protected function setMapSettings() {
48 - global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix;
49 -
50 - $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
51 - $this->defaultZoom = $egMapsGoogleMapsZoom;
52 -
53 - $this->markerStringFormat = 'getGMarkerData(lat, lon, \'title\', \'label\', "icon")';
54 - }
55 -
56 - /**
5746 * @see MapsBaseMap::doMapServiceLoad()
58 - *
5947 */
60 - protected function doMapServiceLoad() {
 48+ public function doMapServiceLoad() {
6149 global $egGoogleMapsOnThisPage;
6250
6351 MapsGoogleMaps::addGMapDependencies( $this->output );
@@ -67,18 +55,21 @@
6856
6957 /**
7058 * @see MapsBaseMap::addSpecificMapHTML()
71 - *
7259 */
7360 public function addSpecificMapHTML( Parser $parser ) {
74 - MapsGoogleMaps::addOverlayOutput( $this->output, $this->mapName, $this->overlays, $this->controls );
 61+ global $egMapsGoogleMapsPrefix, $egGoogleMapsOnThisPage;
7562
 63+ $mapName = $egMapsGoogleMapsPrefix . '_' . $egGoogleMapsOnThisPage;
 64+
 65+ MapsGoogleMaps::addOverlayOutput( $this->output, $mapName, $this->overlays, $this->controls );
 66+
7667 $this->output .= Html::element(
7768 'div',
7869 array(
79 - 'id' => $this->mapName,
 70+ 'id' => $mapName,
8071 'style' => "width: $this->width; height: $this->height; background-color: #cccccc;",
8172 ),
82 - wfMsg('maps-loading-map')
 73+ wfMsg( 'maps-loading-map' )
8374 );
8475
8576 $parser->getOutput()->addHeadItem(
@@ -86,7 +77,7 @@
8778 <<<EOT
8879 addOnloadHook(
8980 function() {
90 - initializeGoogleMap('$this->mapName',
 81+ initializeGoogleMap('$mapName',
9182 {
9283 lat: $this->centreLat,
9384 lon: $this->centreLon,
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php
@@ -22,18 +22,7 @@
2323
2424 public $serviceName = MapsYahooMaps::SERVICE_NAME;
2525
26 - /**
27 - * @see MapsBaseMap::setFormInputSettings()
28 - *
29 - */
30 - protected function setMapSettings() {
31 - global $egMapsYahooMapsZoom, $egMapsYahooMapsPrefix;
32 -
33 - $this->elementNamePrefix = $egMapsYahooMapsPrefix;
34 - $this->defaultZoom = $egMapsYahooMapsZoom;
35 -
36 - $this->markerStringFormat = 'getYMarkerData(lat, lon, \'title\', \'label\', "icon")';
37 - }
 26+ protected $markerStringFormat = 'getYMarkerData(lat, lon, \'title\', \'label\', "icon")';
3827
3928 /**
4029 * @see MapsBaseMap::doMapServiceLoad()
@@ -53,10 +42,14 @@
5443 *
5544 */
5645 public function addSpecificMapHTML( Parser $parser ) {
 46+ global $egMapsYahooMapsPrefix, $egYahooMapsOnThisPage;
 47+
 48+ $mapName = $egMapsYahooMapsPrefix . '_' . $egYahooMapsOnThisPage;
 49+
5750 $this->output .= Html::element(
5851 'div',
5952 array(
60 - 'id' => $this->mapName,
 53+ 'id' => $mapName,
6154 'style' => "width: $this->width; height: $this->height; background-color: #cccccc;",
6255 ),
6356 wfMsg('maps-loading-map')
@@ -67,7 +60,7 @@
6861 addOnloadHook(
6962 function() {
7063 initializeYahooMap(
71 - '$this->mapName',
 64+ '$mapName',
7265 $this->centreLat,
7366 $this->centreLon,
7467 $this->zoom,
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php
@@ -18,21 +18,9 @@
1919 public $serviceName = MapsYahooMaps::SERVICE_NAME;
2020
2121 /**
22 - * @see MapsBaseMap::setFormInputSettings()
23 - *
24 - */
25 - protected function setMapSettings() {
26 - global $egMapsYahooMapsZoom, $egMapsYahooMapsPrefix;
27 -
28 - $this->elementNamePrefix = $egMapsYahooMapsPrefix;
29 - $this->defaultZoom = $egMapsYahooMapsZoom;
30 - }
31 -
32 - /**
3322 * @see MapsBaseMap::doMapServiceLoad()
34 - *
3523 */
36 - protected function doMapServiceLoad() {
 24+ public function doMapServiceLoad() {
3725 global $egYahooMapsOnThisPage;
3826
3927 MapsYahooMaps::addYMapDependencies( $this->output );
@@ -43,13 +31,16 @@
4432
4533 /**
4634 * @see MapsBaseMap::addSpecificMapHTML()
47 - *
4835 */
4936 public function addSpecificMapHTML( Parser $parser ) {
 37+ global $egMapsYahooMapsPrefix, $egYahooMapsOnThisPage;
 38+
 39+ $mapName = $egMapsYahooMapsPrefix . '_' . $egYahooMapsOnThisPage;
 40+
5041 $this->output .= Html::element(
5142 'div',
5243 array(
53 - 'id' => $this->mapName,
 44+ 'id' => $mapName,
5445 'style' => "width: $this->width; height: $this->height; background-color: #cccccc;",
5546 ),
5647 wfMsg('maps-loading-map')
@@ -60,7 +51,7 @@
6152 addOnloadHook(
6253 function() {
6354 initializeYahooMap(
64 - '$this->mapName',
 55+ '$mapName',
6556 $this->centreLat,
6657 $this->centreLon,
6758 $this->zoom,
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php
@@ -62,50 +62,50 @@
6363
6464 $allowedTypes = MapsYahooMaps::getTypeNames();
6565
 66+ $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
 67+ 'controls' => array(
 68+ 'type' => array( 'string', 'list' ),
 69+ 'criteria' => array(
 70+ 'in_array' => self::getControlNames()
 71+ ),
 72+ 'default' => $egMapsYMapControls,
 73+ 'output-type' => array( 'list', ',', '\'' )
 74+ ),
 75+ 'type' => array (
 76+ 'aliases' => array( 'map-type', 'map type' ),
 77+ 'criteria' => array(
 78+ 'in_array' => $allowedTypes
 79+ ),
 80+ 'default' => $egMapsYahooMapsType, // FIXME: default value should not be used when not present in types parameter.
 81+ 'output-type' => 'ymaptype'
 82+ ),
 83+ 'types' => array (
 84+ 'type' => array( 'string', 'list' ),
 85+ 'aliases' => array( 'map-types', 'map types' ),
 86+ 'criteria' => array(
 87+ 'in_array' => $allowedTypes
 88+ ),
 89+ 'default' => $egMapsYahooMapsTypes,
 90+ 'output-types' => array( 'ymaptypes', 'list' )
 91+ ),
 92+ 'autozoom' => array(
 93+ 'type' => 'boolean',
 94+ 'aliases' => array( 'auto zoom', 'mouse zoom', 'mousezoom' ),
 95+ 'default' => $egMapsYahooAutozoom,
 96+ 'output-type' => 'boolstr'
 97+ ),
 98+ );
 99+
66100 $egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['default'] = $egMapsYahooMapsZoom;
67 - $egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['criteria']['in_range'] = array( 1, 13 );
68 -
69 - $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
70 - 'controls' => array(
71 - 'type' => array( 'string', 'list' ),
72 - 'criteria' => array(
73 - 'in_array' => self::getControlNames()
74 - ),
75 - 'default' => $egMapsYMapControls,
76 - 'output-type' => array( 'list', ',', '\'' )
77 - ),
78 - 'type' => array (
79 - 'aliases' => array( 'map-type', 'map type' ),
80 - 'criteria' => array(
81 - 'in_array' => $allowedTypes
82 - ),
83 - 'default' => $egMapsYahooMapsType, // FIXME: default value should not be used when not present in types parameter.
84 - 'output-type' => 'ymaptype'
85 - ),
86 - 'types' => array (
87 - 'type' => array( 'string', 'list' ),
88 - 'aliases' => array( 'map-types', 'map types' ),
89 - 'criteria' => array(
90 - 'in_array' => $allowedTypes
91 - ),
92 - 'default' => $egMapsYahooMapsTypes,
93 - 'output-types' => array( 'ymaptypes', 'list' )
94 - ),
95 - 'autozoom' => array(
96 - 'type' => 'boolean',
97 - 'aliases' => array( 'auto zoom', 'mouse zoom', 'mousezoom' ),
98 - 'default' => $egMapsYahooAutozoom,
99 - 'output-type' => 'boolstr'
100 - ),
101 - );
 101+ $egMapsServices[self::SERVICE_NAME]['parameters']['zoom']['criteria']['in_range'] = array( 1, 13 );
102102 }
103103
104104 // http://developer.yahoo.com/maps/ajax
105105 private static $mapTypes = array(
106 - 'normal' => 'YAHOO_MAP_REG',
107 - 'satellite' => 'YAHOO_MAP_SAT',
108 - 'hybrid' => 'YAHOO_MAP_HYB',
109 - );
 106+ 'normal' => 'YAHOO_MAP_REG',
 107+ 'satellite' => 'YAHOO_MAP_SAT',
 108+ 'hybrid' => 'YAHOO_MAP_HYB',
 109+ );
110110
111111 /**
112112 * Returns the names of all supported map types.

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r65307Follow up to r65108 - Fixed coordinate handling for display_map and display_p...jeroendedauw12:37, 20 April 2010

Status & tagging log