r59531 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59530‎ | r59531 | r59532 >
Date:21:27, 28 November 2009
Author:jeroendedauw
Status:deferred (Comments)
Tags:
Comment:
Changes for 0.5. Rewrote parameter handling and added strict validation. http://www.mediawiki.org/wiki/Extension:Maps/Future#Maps_0.5
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/GoogleMaps/Maps_GoogleMapsUtils.php (deleted) (history)
  • /trunk/extensions/Maps/Maps.i18n.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_ParamManager.php (added) (history)
  • /trunk/extensions/Maps/Maps_ParamValidator.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Settings.php (modified) (history)
  • /trunk/extensions/Maps/Maps_ValidationFunctions.php (added) (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/OpenLayers/Maps_OpenLayersUtils.php (deleted) (history)
  • /trunk/extensions/Maps/OpenStreetMap/Maps_OSM.php (modified) (history)
  • /trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispMap.php (modified) (history)
  • /trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/OpenStreetMap/Maps_OSMUtils.php (deleted) (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/Maps_ParserFunctions.php (modified) (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)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMapsUtils.php (deleted) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps_MapFeature.php
@@ -37,9 +37,7 @@
3838 */
3939 protected abstract function addSpecificMapHTML();
4040
41 - public $serviceName;
42 -
43 - protected $defaultParams = array();
 41+ public $serviceName;
4442
4543 protected $defaultZoom;
4644
@@ -52,32 +50,62 @@
5351 protected $centre_lon;
5452
5553 protected $output = '';
56 - protected $errors = array();
 54+ protected $errorList;
5755
 56+ protected $featureParameters = array();
 57+ protected $spesificParameters = array();
 58+
5859 /**
5960 * Validates and corrects the provided map properties, and the sets them as class fields.
6061 *
6162 * @param array $mapProperties
6263 * @param string $className
 64+ *
 65+ * @return boolean Indicates whether the map should be shown or not.
6366 */
64 - protected function manageMapProperties(array $mapProperties, $className) {
65 - global $egMapsServices;
66 - //$egMapsErrorLevel
67 - // TODO: implement strict parameter validation, put errors in array.
68 - $mapProperties = MapsMapper::getValidParams($mapProperties, $egMapsServices[$this->serviceName]['parameters']);
69 - $mapProperties = MapsMapper::setDefaultParValues($mapProperties, $this->defaultParams);
 67+ protected final function manageMapProperties(array $mapProperties, $className) {
 68+ global $egMapsServices, $egMapsErrorLevel;
7069
71 - // Go through the array with map parameters and create new variables
72 - // with the name of the key and value of the item if they don't exist on class level yet.
 70+ /*
 71+ * Assembliy of the allowed parameters and their information.
 72+ * The main parameters (the ones that are shared by everything) are overidden
 73+ * by the feature parameters (the ones spesific to a feature). The result is then
 74+ * again overidden by the service parameters (the ones spesific to the service),
 75+ * and finally by the spesific parameters (the ones spesific to a service-feature combination).
 76+ */
 77+ $parameterInfo = array_merge(MapsMapper::getMainParams(), $this->featureParameters);
 78+ $parameterInfo = array_merge($parameterInfo, $egMapsServices[$this->serviceName]['parameters']);
 79+ $parameterInfo = array_merge($parameterInfo, $this->spesificParameters);
 80+
 81+ $manager = new MapsParamManager();
 82+
 83+ $result = $manager->manageMapparameters($mapProperties, $parameterInfo);
 84+
 85+ $showMap = $result !== false;
 86+
 87+ if ($showMap) $this->setMapProperties($result, $className);
 88+
 89+ $this->errorList = $manager->getErrorList();
 90+
 91+ return $showMap;
 92+ }
 93+
 94+ /**
 95+ * Sets the map properties as class fields.
 96+ *
 97+ * @param array $mapProperties
 98+ * @param string $className
 99+ */
 100+ private function setMapProperties(array $mapProperties, $className) {
 101+ //var_dump($mapProperties); exit;
73102 foreach($mapProperties as $paramName => $paramValue) {
74103 if (! property_exists($className, $paramName)) {
75104 $this->{$paramName} = $paramValue;
76105 }
77 - }
78 -
79 - MapsMapper::enforceArrayValues($this->controls);
80 -
81 - MapsUtils::makeMapSizeValid($this->width, $this->height);
 106+ else {
 107+ throw new Exception('Attempt to override a class field during map propertie assignment. Field name: ' . $paramName);
 108+ }
 109+ }
82110 }
83111
84112 /**
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsUtils.php
@@ -1,120 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * A class that holds static helper functions for Yahoo! Maps
6 - *
7 - * @file Maps_YahooMapsUtils.php
8 - * @ingroup MapsYahooMaps
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -final class MapsYahooMapsUtils {
18 -
19 - const SERVICE_NAME = 'yahoomaps';
20 -
21 - // http://developer.yahoo.com/maps/ajax
22 - private static $mapTypes = array(
23 - 'normal' => 'YAHOO_MAP_REG',
24 - 'YAHOO_MAP_REG' => 'YAHOO_MAP_REG',
25 -
26 - 'satellite' => 'YAHOO_MAP_SAT',
27 - 'YAHOO_MAP_SAT' => 'YAHOO_MAP_SAT',
28 -
29 - 'hybrid' => 'YAHOO_MAP_HYB',
30 - 'YAHOO_MAP_HYB' => 'YAHOO_MAP_HYB'
31 - );
32 -
33 - /**
34 - * Returns the Yahoo Map type (defined in MapsYahooMaps::$mapTypes)
35 - * for the provided a general map type. When no match is found, the first
36 - * Google Map type will be returned as default.
37 - *
38 - * @param string $type
39 - * @param boolean $restoreAsDefault
40 - * @return string or false
41 - */
42 - public static function getYMapType($type, $restoreAsDefault = false) {
43 - global $egMapsYahooMapsType;
44 -
45 - $typeIsValid = array_key_exists($type, self::$mapTypes);
46 -
47 - if (!$typeIsValid && $restoreAsDefault) $type = $egMapsYahooMapsType;
48 -
49 - return $typeIsValid || $restoreAsDefault ? self::$mapTypes[ $type ] : false;
50 - }
51 -
52 - /**
53 - * Build up a csv string with the controls, to be outputted as a JS array
54 - *
55 - * @param array $controls
56 - * @return csv string
57 - */
58 - public static function createControlsString(array $controls) {
59 - global $egMapsYMapControls;
60 - return MapsMapper::createJSItemsString($controls, $egMapsYMapControls);
61 - }
62 -
63 - /**
64 - * Retuns an array holding the default parameters and their values.
65 - *
66 - * @return array
67 - */
68 - public static function getDefaultParams() {
69 - global $egMapsYahooAutozoom;
70 - return array
71 - (
72 - 'type' => '',
73 - 'types' => '',
74 - 'autozoom' => $egMapsYahooAutozoom ? 'on' : 'off',
75 - );
76 - }
77 -
78 - /**
79 - * Add references to the Yahoo! Maps API and required JS file to the provided output
80 - *
81 - * @param string $output
82 - */
83 - public static function addYMapDependencies(&$output) {
84 - global $wgJsMimeType;
85 - global $egYahooMapsKey, $egMapsScriptPath, $egYahooMapsOnThisPage, $egMapsStyleVersion;
86 -
87 - if (empty($egYahooMapsOnThisPage)) {
88 - $egYahooMapsOnThisPage = 0;
89 - $output .= "<script type='$wgJsMimeType' src='http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=$egYahooMapsKey'></script>
90 - <script type='$wgJsMimeType' src='$egMapsScriptPath/YahooMaps/YahooMapFunctions.js?$egMapsStyleVersion'></script>";
91 - }
92 - }
93 -
94 - /**
95 - * Retuns a boolean as string, true if $autozoom is on or yes.
96 - *
97 - * @param string $autozoom
98 - * @return string
99 - */
100 - public static function getAutozoomJSValue($autozoom) {
101 - return MapsMapper::getJSBoolValue(in_array($autozoom, array('on', 'yes')));
102 - }
103 -
104 - /**
105 - * Returns a JS items string with the provided types. The earth type will
106 - * be added to it when it's not present and $enableEarth is true. If there are
107 - * no types, the default will be used.
108 - *
109 - * @param array $types
110 - * @param boolean $enableEarth
111 - * @return string
112 - */
113 - public static function createTypesString(array &$types) {
114 - global $egMapsYahooMapsTypes, $egMapsYahooMapTypesValid;
115 -
116 - $types = MapsMapper::getValidTypes($types, $egMapsYahooMapsTypes, $egMapsYahooMapTypesValid, array(__CLASS__, 'getYMapType'));
117 -
118 - return MapsMapper::createJSItemsString($types, null, false, false);
119 - }
120 -
121 -}
\ No newline at end of file
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php
@@ -20,7 +20,7 @@
2121 */
2222 class MapsYahooMapsDispPoint extends MapsBasePointMap {
2323
24 - public $serviceName = MapsYahooMapsUtils::SERVICE_NAME;
 24+ public $serviceName = MapsYahooMaps::SERVICE_NAME;
2525
2626 /**
2727 * @see MapsBaseMap::setFormInputSettings()
@@ -29,22 +29,26 @@
3030 protected function setMapSettings() {
3131 global $egMapsYahooMapsZoom, $egMapsYahooMapsPrefix;
3232
33 - $this->defaultParams = MapsYahooMapsUtils::getDefaultParams();
34 -
3533 $this->elementNamePrefix = $egMapsYahooMapsPrefix;
3634 $this->defaultZoom = $egMapsYahooMapsZoom;
3735
3836 $this->markerStringFormat = 'getYMarkerData(lat, lon, "title", "label", "icon")';
 37+
 38+ $this->spesificParameters = array(
 39+ 'zoom' => array(
 40+ 'default' => '',
 41+ )
 42+ );
3943 }
4044
4145 /**
4246 * @see MapsBaseMap::doMapServiceLoad()
4347 *
44 - */
 48+ */
4549 protected function doMapServiceLoad() {
4650 global $egYahooMapsOnThisPage;
4751
48 - MapsYahooMapsUtils::addYMapDependencies($this->output);
 52+ MapsYahooMaps::addYMapDependencies($this->output);
4953 $egYahooMapsOnThisPage++;
5054
5155 $this->elementNr = $egYahooMapsOnThisPage;
@@ -57,15 +61,15 @@
5862 public function addSpecificMapHTML() {
5963 global $wgJsMimeType;
6064
61 - $this->type = MapsYahooMapsUtils::getYMapType($this->type, true);
 65+ $this->type = MapsYahooMaps::getYMapType($this->type, true);
6266
63 - $this->controls = MapsYahooMapsUtils::createControlsString($this->controls);
 67+ $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls));
6468
65 - $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom);
 69+ $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom);
6670
67 - $this->types = explode(",", $this->types);
 71+ $this->types = explode(',', $this->types);
6872
69 - $typesString = MapsYahooMapsUtils::createTypesString($this->types);
 73+ $typesString = MapsYahooMaps::createTypesString($this->types);
7074
7175 $this->output .= <<<END
7276 <div id="$this->mapName" style="width: {$this->width}px; height: {$this->height}px;"></div>
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php
@@ -15,7 +15,7 @@
1616
1717 class MapsYahooMapsDispMap extends MapsBaseMap {
1818
19 - public $serviceName = MapsYahooMapsUtils::SERVICE_NAME;
 19+ public $serviceName = MapsYahooMaps::SERVICE_NAME;
2020
2121 /**
2222 * @see MapsBaseMap::setFormInputSettings()
@@ -24,8 +24,6 @@
2525 protected function setMapSettings() {
2626 global $egMapsYahooMapsZoom, $egMapsYahooMapsPrefix;
2727
28 - $this->defaultParams = MapsYahooMapsUtils::getDefaultParams();
29 -
3028 $this->elementNamePrefix = $egMapsYahooMapsPrefix;
3129 $this->defaultZoom = $egMapsYahooMapsZoom;
3230 }
@@ -37,7 +35,7 @@
3836 protected function doMapServiceLoad() {
3937 global $egYahooMapsOnThisPage;
4038
41 - MapsYahooMapsUtils::addYMapDependencies($this->output);
 39+ MapsYahooMaps::addYMapDependencies($this->output);
4240 $egYahooMapsOnThisPage++;
4341
4442 $this->elementNr = $egYahooMapsOnThisPage;
@@ -50,15 +48,15 @@
5149 public function addSpecificMapHTML() {
5250 global $wgJsMimeType;
5351
54 - $this->type = MapsYahooMapsUtils::getYMapType($this->type, true);
 52+ $this->type = MapsYahooMaps::getYMapType($this->type, true);
5553
56 - $this->controls = MapsYahooMapsUtils::createControlsString($this->controls);
 54+ $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls));
5755
58 - $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom);
 56+ $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom);
5957
6058 $this->types = explode(",", $this->types);
6159
62 - $typesString = MapsYahooMapsUtils::createTypesString($this->types);
 60+ $typesString = MapsYahooMaps::createTypesString($this->types);
6361
6462 $this->output .= <<<END
6563 <div id="$this->mapName" style="width: {$this->width}px; height: {$this->height}px;"></div>
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php
@@ -26,7 +26,7 @@
2727 'display_map' => array('class' => 'MapsYahooMapsDispMap', 'file' => 'YahooMaps/Maps_YahooMapsDispMap.php', 'local' => true),
2828 ),
2929 'classes' => array(
30 - array('class' => 'MapsYahooMapsUtils', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true)
 30+ array('class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true)
3131 ),
3232 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps'),
3333 'parameters' => array(
@@ -34,4 +34,142 @@
3535 'types' => array('map-types', 'map types'),
3636 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom')
3737 )
38 - );
\ No newline at end of file
 38+ );
 39+
 40+/**
 41+ * Class for Yahoo! Maps initialization.
 42+ *
 43+ * @ingroup MapsYahooMaps
 44+ *
 45+ * @author Jeroen De Dauw
 46+ */
 47+class MapsYahooMaps {
 48+
 49+ const SERVICE_NAME = 'yahoomaps';
 50+
 51+ public static function initialize() {
 52+ self::initializeParams();
 53+ }
 54+
 55+ private static function initializeParams() {
 56+ global $egMapsServices, $egMapsYahooAutozoom, $egMapsYahooMapsType, $egMapsYahooMapsTypes, $egMapsYahooMapsZoom, $egMapsYMapControls;
 57+
 58+ $allowedTypes = MapsYahooMaps::getTypeNames();
 59+
 60+ $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
 61+ 'zoom' => array (
 62+ 'default' => $egMapsYahooMapsZoom
 63+ ),
 64+ 'controls' => array(
 65+ 'criteria' => array(), // TODO
 66+ 'default' => implode(',', $egMapsYMapControls)
 67+ ),
 68+ 'type' => array (
 69+ 'aliases' => array('map-type', 'map type'),
 70+ 'criteria' => array(
 71+ 'in_array' => array($allowedTypes)
 72+ ),
 73+ 'default' => $egMapsYahooMapsType
 74+ ),
 75+ 'types' => array (
 76+ 'aliases' => array('map-types', 'map types'),
 77+ 'criteria' => array(
 78+ 'all_in_array' => array($allowedTypes)
 79+ ),
 80+ 'default' => implode(',', $egMapsYahooMapsTypes)
 81+ ),
 82+ 'autozoom' => array(
 83+ 'aliases' => array('auto zoom', 'mouse zoom', 'mousezoom'),
 84+ 'criteria' => array(
 85+ 'in_array' => array('on', 'off', 'yes', 'no')
 86+ ),
 87+ 'default' => $egMapsYahooAutozoom ? 'on' : 'off'
 88+ ),
 89+ );
 90+ }
 91+
 92+ // http://developer.yahoo.com/maps/ajax
 93+ private static $mapTypes = array(
 94+ 'normal' => 'YAHOO_MAP_REG',
 95+ 'YAHOO_MAP_REG' => 'YAHOO_MAP_REG',
 96+
 97+ 'satellite' => 'YAHOO_MAP_SAT',
 98+ 'YAHOO_MAP_SAT' => 'YAHOO_MAP_SAT',
 99+
 100+ 'hybrid' => 'YAHOO_MAP_HYB',
 101+ 'YAHOO_MAP_HYB' => 'YAHOO_MAP_HYB'
 102+ );
 103+
 104+ /**
 105+ * Returns the names of all supported map types.
 106+ *
 107+ * @return array
 108+ */
 109+ public static function getTypeNames() {
 110+ return array_keys(self::$mapTypes);
 111+ }
 112+
 113+ /**
 114+ * Returns the Yahoo Map type (defined in MapsYahooMaps::$mapTypes)
 115+ * for the provided a general map type. When no match is found, the first
 116+ * Google Map type will be returned as default.
 117+ *
 118+ * @param string $type
 119+ * @param boolean $restoreAsDefault
 120+ *
 121+ * @return string or false
 122+ */
 123+ public static function getYMapType($type, $restoreAsDefault = false) {
 124+ global $egMapsYahooMapsType;
 125+
 126+ $typeIsValid = array_key_exists($type, self::$mapTypes);
 127+
 128+ if (!$typeIsValid && $restoreAsDefault) $type = $egMapsYahooMapsType;
 129+
 130+ return $typeIsValid || $restoreAsDefault ? self::$mapTypes[ $type ] : false;
 131+ }
 132+
 133+ /**
 134+ * Add references to the Yahoo! Maps API and required JS file to the provided output
 135+ *
 136+ * @param string $output
 137+ */
 138+ public static function addYMapDependencies(&$output) {
 139+ global $wgJsMimeType;
 140+ global $egYahooMapsKey, $egMapsScriptPath, $egYahooMapsOnThisPage, $egMapsStyleVersion;
 141+
 142+ if (empty($egYahooMapsOnThisPage)) {
 143+ $egYahooMapsOnThisPage = 0;
 144+ $output .= "<script type='$wgJsMimeType' src='http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=$egYahooMapsKey'></script>
 145+ <script type='$wgJsMimeType' src='$egMapsScriptPath/YahooMaps/YahooMapFunctions.js?$egMapsStyleVersion'></script>";
 146+ }
 147+ }
 148+
 149+ /**
 150+ * Retuns a boolean as string, true if $autozoom is on or yes.
 151+ *
 152+ * @param string $autozoom
 153+ * @return string
 154+ */
 155+ public static function getAutozoomJSValue($autozoom) {
 156+ return MapsMapper::getJSBoolValue(in_array($autozoom, array('on', 'yes')));
 157+ }
 158+
 159+ /**
 160+ * Returns a JS items string with the provided types. The earth type will
 161+ * be added to it when it's not present and $enableEarth is true. If there are
 162+ * no types, the default will be used.
 163+ *
 164+ * @param array $types
 165+ * @param boolean $enableEarth
 166+ * @return string
 167+ */
 168+ public static function createTypesString(array &$types) {
 169+ global $egMapsYahooMapsTypes, $egMapsYahooMapTypesValid;
 170+
 171+ $types = MapsMapper::getValidTypes($types, $egMapsYahooMapsTypes, $egMapsYahooMapTypesValid, array(__CLASS__, 'getYMapType'));
 172+
 173+ return MapsMapper::createJSItemsString($types, null, false, false);
 174+ }
 175+
 176+}
\ No newline at end of file
Index: trunk/extensions/Maps/Maps_ParamManager.php
@@ -0,0 +1,105 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the MapsParamManager class.
 6+ *
 7+ * @file Maps_ParamManager.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+ * Class for parameter handling.
 19+ *
 20+ * @ingroup Maps
 21+ *
 22+ * @author Jeroen De Dauw
 23+ */
 24+final class MapsParamManager {
 25+
 26+ private $errors = array();
 27+
 28+ /**
 29+ * Validates the provided parameters, and corrects them depedning on the error level.
 30+ *
 31+ * @param array $rawParameters
 32+ * @param array $parameterInfo
 33+ *
 34+ * @return boolean Indicates whether the regular output should be shown or not.
 35+ */
 36+ public function manageMapparameters(array $rawParameters, array $parameterInfo) {
 37+ global $egMapsErrorLevel;
 38+
 39+ $validator = new MapsParamValidator();
 40+
 41+ $validator->setParameterInfo($parameterInfo);
 42+ $validator->setParameters($rawParameters);
 43+
 44+ if (! $validator->validateParameters()) {
 45+ if ($egMapsErrorLevel != Maps_ERRORS_STRICT) $validator->correctInvalidParams();
 46+ if ($egMapsErrorLevel >= Maps_ERRORS_SHOW) $this->errors = $validator->getErrors();
 47+ }
 48+
 49+ $showOutput = ! ($egMapsErrorLevel == Maps_ERRORS_STRICT && count($this->errors) > 0);
 50+
 51+ return $showOutput ? $validator->getValidParams() : false;
 52+ }
 53+
 54+ /**
 55+ * Returns a string containing an HTML error list, or an empty string when there are no errors.
 56+ *
 57+ * @return string
 58+ */
 59+ public function getErrorList() {
 60+ global $wgLang;
 61+ global $egMapsErrorLevel;
 62+
 63+ if ($egMapsErrorLevel >= Maps_ERRORS_SHOW && count($this->errors) > 0) {
 64+ $errorList = '<b>' . wfMsg('maps_error_parameters') . ':</b><br /><i>';
 65+
 66+ $errors = array();
 67+
 68+ foreach($this->errors as $error) {
 69+ $error['name'] = '</i>' . $error['name'] . '<i>';
 70+ switch($error['error'][0]) {
 71+ // General errors
 72+ case 'unknown' :
 73+ $errors[] = wfMsgExt('maps_error_unknown_argument', array('parsemag'), $error['name']);
 74+ break;
 75+ case 'missing' :
 76+ $errors[] = wfMsgExt('maps_error_required_missing', array('parsemag'), $error['name']);
 77+ break;
 78+ // Spesific validation faliures
 79+ case 'not_empty' :
 80+ $errors[] = wfMsgExt('maps_error_empty_argument', array('parsemag'), $error['name']);
 81+ break;
 82+ case 'in_range' :
 83+ $errors[] = wfMsgExt('maps_error_ivalid_range', array('parsemag'), $error['name'], $error['error'][1][0], $error['error'][1][1]);
 84+ break;
 85+ case 'is_numeric' :
 86+ $errors[] = wfMsgExt('maps_error_must_be_number', array('parsemag'), $error['name']);
 87+ break;
 88+ case 'in_array' :
 89+ $items = $wgLang->listToText($error['error'][1]);
 90+ $errors[] = wfMsgExt('maps_error_accepts_only', array('parsemag'), $error['name'], $items);
 91+ break;
 92+ // Unspesified errors
 93+ case 'invalid' : default :
 94+ $errors[] = wfMsgExt('maps_error_invalid_argument', array('parsemag'), $error['error'][2], $error['name']);
 95+ break;
 96+ }
 97+ }
 98+
 99+ return $errorList. implode($errors, '<br />') . '</i>';
 100+ }
 101+ else {
 102+ return '';
 103+ }
 104+ }
 105+
 106+}
\ No newline at end of file
Index: trunk/extensions/Maps/Maps.i18n.php
@@ -33,11 +33,13 @@
3434
3535 // Parameter errors. Used when strict parameter validation is turned on.
3636 'maps_error_parameters' => 'The following errors have been detected in your syntax',
 37+ 'maps_error_unknown_argument' => '$1 is not a valid parameter.',
3738 'maps_error_invalid_argument' => 'The value $1 is not valid for parameter $2.',
3839 'maps_error_empty_argument' => 'Parameter $1 can not have an empty value.',
3940 'maps_error_required_missing' => 'The required parameter $1 is not provided.',
4041 'maps_error_must_be_number' => 'Parameter $1 can only be a number.',
4142 'maps_error_ivalid_range' => 'Parameter $1 must be between $2 and $3.',
 43+ 'maps_error_accepts_only' => 'Parameter $1 can only be $2.',
4244
4345 // Mapping services
4446 'maps_googlemaps' => 'Google Maps',
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -123,7 +123,7 @@
124124 # Maps_ERRORS_WARN : Maps will make the best of the imput it got, but will show warnings for omitted coordinates.
125125 # Maps_ERRORS_SHOW : Maps will make the best of the imput it got, but will show a list of all errors.
126126 # Maps_ERRORS_STRICT: Maps will only show a map when there are no errors, if there are, a list of them will be shown.
127 -$egMapsErrorLevel = Maps_ERRORS_WARN;
 127+$egMapsErrorLevel = Maps_ERRORS_SHOW;
128128
129129 # Integer. The default width and height of a map. These values will only be used when the user does not provide them.
130130 $egMapsMapWidth = 600;
@@ -136,14 +136,24 @@
137137 'height' => array( 100, 1000 ),
138138 );
139139
140 -# Strings. The default coordinates of the marker. This value will only be used when the user does not provide one.
 140+# Strings. The default coordinates for the map. Must be in floating point notation.
 141+# This value will only be used when the user does not provide one.
141142 $egMapsMapLat = '1';
142143 $egMapsMapLon = '1';
143144
 145+# String. The default centre for a map. Must be in floating point notation.
 146+# This value will override the smart behaviour when multiple markers are present when set.
 147+# This value will only be used when the user does not provide one.
 148+$egMapsDefaultCentre = '';
144149
 150+# Strings. The default content for all pop-ups. This value will only be used when the user does not provide one.
 151+$egMapsDefaultTitle = '';
 152+$egMapsDefaultLabel = '';
145153
146154
147155
 156+
 157+
148158 # Specific map properties configuration
149159
150160 # Google maps
Index: trunk/extensions/Maps/Maps_ParamValidator.php
@@ -22,11 +22,7 @@
2323 */
2424 final class MapsParamValidator {
2525
26 - /**
27 - * @var boolean Indicates whether parameters not found in the criteria list
28 - * should be accepted. The default is false.
29 - */
30 - public static $acceptUnknownParameters = false;
 26+ // TODO: add lower/upper case nullification
3127
3228 /**
3329 * @var boolean Indicates whether parameters not found in the criteria list
@@ -34,7 +30,25 @@
3531 */
3632 public static $storeUnknownParameters = false;
3733
38 - private $parameterCriteria;
 34+ /**
 35+ * @var boolean Indicates whether parameters not found in the criteria list
 36+ * should be stored in case they are not accepted. The default is false.
 37+ */
 38+ public static $accumulateParameterErrors = false;
 39+
 40+ /**
 41+ * @var array Holder for the validation functions.
 42+ */
 43+ private static $validationFunctions = array(
 44+ 'in_array' => 'in_array',
 45+ 'in_range' => array('MapsValidationFunctions', 'in_range'),
 46+ 'is_numeric' => 'is_numeric',
 47+ 'not_empty' => array('MapsValidationFunctions', 'not_empty'),
 48+ 'all_in_array' => array('MapsValidationFunctions', 'all_in_array'),
 49+ 'any_in_array' => array('MapsValidationFunctions', 'any_in_array'),
 50+ );
 51+
 52+ private $parameterInfo;
3953 private $rawParameters = array();
4054
4155 private $valid = array();
@@ -46,10 +60,10 @@
4761 /**
4862 * Sets the parameter criteria, used to valiate the parameters.
4963 *
50 - * @param array $parameterCriteria
 64+ * @param array $parameterInfo
5165 */
52 - public function setCriteria(array $parameterCriteria) {
53 - $this->parameterCriteria = $parameterCriteria;
 66+ public function setParameterInfo(array $parameterInfo) {
 67+ $this->parameterInfo = $parameterInfo;
5468 }
5569
5670 /**
@@ -65,59 +79,123 @@
6680 * Valides the raw parameters, and allocates them as valid, invalid or unknown.
6781 * Errors are collected, and can be retrieved via getErrors.
6882 *
69 - * @return boolean Indicates whether there where any errors.
 83+ * @return boolean Indicates whether there where no errors.
7084 */
7185 public function validateParameters() {
 86+
 87+ $parameters = array();
 88+
 89+ // Loop through all the user provided parameters, and destinguise between those that are allowed and those that are not.
7290 foreach($this->rawParameters as $paramName => $paramValue) {
73 - $paramName = MapsMapper::getMainParamName($paramName, $allowedParms); // TODO: get $allowedParms
74 - if(array_key_exists($paramName, $allowedParms)) {
 91+ // Attempt to get the main parameter name (takes care of aliases).
 92+ $mainName = MapsParamValidator::getMainParamName($paramName, $this->parameterInfo);
 93+ // If the parameter is found in the list of allowed ones, add it to the $parameters array.
 94+ if($mainName) {
 95+ $parameters[$mainName] = $paramValue;
 96+ }
 97+ else { // If the parameter is not found in the list of allowed ones, add an item to the $this->errors array.
 98+ if (MapsParamValidator::$storeUnknownParameters) $this->unknown[$paramName] = $paramValue;
 99+ $this->errors[] = array('error' => array('unknown'), 'name' => $paramName);
 100+ }
 101+ }
 102+
 103+ // Loop through the list of allowed parameters.
 104+ foreach($this->parameterInfo as $paramName => $paramInfo) {
 105+ // If the user provided a value for this parameter, validate and handle it.
 106+ if (array_key_exists($paramName, $this->rawParameters)) {
75107
76 - $validationResult = $this->validateParameter($paramName, $paramValue);
 108+ $paramValue = $this->rawParameters[$paramName];
 109+ $validationErrors = $this->validateParameter($paramName, $paramValue);
77110
78 - if ($validationResult === true) {
 111+ if (count($validationErrors) == 0) {
79112 $this->valid[$paramName] = $paramValue;
80113 }
81114 else {
82115 $this->invalid[$paramName] = $paramValue;
83 - $this->errors[] = array('type' => $validationResult, 'name' => $paramName);
 116+ foreach($validationErrors as $error) {
 117+ $this->errors[] = array('error' => $error, 'name' => $paramName);
 118+ }
 119+ }
 120+ }
 121+ else { // If the user did not provide a value for this parameter, set the default if there is one.
 122+ if (array_key_exists('default', $paramInfo)) {
 123+ $this->valid[$paramName] = $paramInfo['default'];
84124 }
 125+ else { // If there is no default, the parameter must be provided, so add an error.
 126+ $this->errors[] = array('error' => array('missing'), 'name' => $paramName);
 127+ }
85128 }
86 - else {
87 - if ($storeUnknownParameters) $this->unknown[$paramName] = $paramValue;
88 - $this->errors[] = array('type' => 'unknown', 'name' => $paramName);
89 - }
90129 }
91130
92 - return count($this->errors) > 0;
 131+ return count($this->errors) == 0;
93132 }
94133
95134 /**
 135+ * Returns the main parameter name for a given parameter or alias, or false
 136+ * when it is not recognized as main parameter or alias.
 137+ *
 138+ * @param string $paramName
 139+ * @param array $allowedParms
 140+ *
 141+ * @return string
 142+ */
 143+ private function getMainParamName($paramName, array $allowedParms) {
 144+ $result = false;
 145+
 146+ if (array_key_exists($paramName, $allowedParms)) {
 147+ $result = $paramName;
 148+ }
 149+ else {
 150+ foreach ($allowedParms as $name => $data) {
 151+ if (array_key_exists('aliases', $data)) {
 152+ if (in_array($paramName, $data['aliases'])) {
 153+ $result = $name;
 154+ break;
 155+ }
 156+ }
 157+ }
 158+ }
 159+
 160+ return $result;
 161+ }
 162+
 163+ /**
96164 * Valides the provided parameter by matching the value against the criteria for the name.
97165 *
98166 * @param string $name
99167 * @param string $value
100168 *
101 - * @return true or string
 169+ * @return array The errors that occured during validation.
102170 */
103171 private function validateParameter($name, $value) {
 172+ $errors = array();
104173
105 - // TODO: get criteria and validate
106 - // If valid: return true
107 - // If infalid: return error type
108 -
 174+ if (array_key_exists('criteria', $this->parameterInfo[$name])) {
 175+ foreach($this->parameterInfo[$name]['criteria'] as $criteriaName => $criteriaArgs) {
 176+ $validationFunction = MapsParamValidator::$validationFunctions[$criteriaName];
 177+ $arguments = array($value);
 178+ if (count($criteriaArgs) > 0) $arguments[] = $criteriaArgs;
 179+ $isValid = call_user_func_array($validationFunction, $arguments);
 180+
 181+ if (! $isValid) {
 182+ $errors[] = array($criteriaName, $criteriaArgs, $value);
 183+ if (! MapsParamValidator::$accumulateParameterErrors) break;
 184+ }
 185+ }
 186+ }
 187+
 188+ return $errors;
109189 }
110190
111191 /**
112192 * Changes the invalid parameters to their default values, and changes their state to valid.
113 - *
114 - * @param array $defaults
115193 */
116 - public function correctInvalidParams(array $defaults) {
 194+ public function correctInvalidParams() {
117195 foreach($this->invalid as $paramName => $paramValue) {
118196
119 - if(array_key_exists($paramName, $defaults)) {
 197+ if(array_key_exists('default', $this->parameterInfo[$paramName])) {
120198 unset($this->invalid[$paramName]);
121 - $this->valid[$paramName] = $defaults[$defaults];
 199+ $this->valid[$paramName] = $this->parameterInfo[$paramName]['default'];
122200 }
123201 else {
124202 throw new Exception('The default value for parameter ' . $paramName . ' is not set.');
@@ -131,16 +209,37 @@
132210 * @return array
133211 */
134212 public function getValidParams() {
135 - return $this->valid();
 213+ return $this->valid;
136214 }
137215
138216 /**
 217+ * Returns the unknown parameters.
 218+ *
 219+ * @return array
 220+ */
 221+ public static function getUnknownParams() {
 222+ return $this->unknown;
 223+ }
 224+
 225+ /**
139226 * Returns the errors.
140227 *
141228 * @return array
142229 */
143230 public function getErrors() {
144 - return $this->errors();
 231+ return $this->errors;
145232 }
146233
 234+ /**
 235+ * Adds a new criteria type and the validation function that should validate values of this type.
 236+ * You can use this function to override existing criteria type handlers.
 237+ *
 238+ * @param string $criteriaName The name of the cirteria.
 239+ * @param array $functionName The functions location. If it's a global function, only the name,
 240+ * if it's in a class, first the class name, then the method name.
 241+ */
 242+ public static function addValidationFunction($criteriaName, array $functionName) {
 243+ $this->validationFunctions[$criteriaName] = $functionName;
 244+ }
 245+
147246 }
\ No newline at end of file
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersUtils.php
@@ -1,122 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * A class that holds static helper functions for OpenLayers
6 - *
7 - * @file Maps_OpenLayersUtils.php
8 - * @ingroup MapsOpenLayers
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -final class MapsOpenLayersUtils {
18 -
19 - const SERVICE_NAME = 'openlayers';
20 -
21 - private static $loadedBing = false;
22 - private static $loadedYahoo = false;
23 - private static $loadedOL = false;
24 - private static $loadedOSM = false;
25 -
26 - /**
27 - * Load the dependencies of a layer if they are not loaded yet
28 - *
29 - * @param string $output The output to which the html to load the dependencies needs to be added
30 - * @param string $layer The layer to check (and load the dependencies for
31 - */
32 - public static function loadDependencyWhenNeeded(&$output, $layer) {
33 - global $wgJsMimeType;
34 - global $egGoogleMapsOnThisPage, $egMapsScriptPath, $egMapsStyleVersion;
35 -
36 - switch ($layer) {
37 - case 'google' : case 'google-normal' : case 'google-sattelite' : case 'google-hybrid' : case 'google-physical' :
38 - if (empty($egGoogleMapsOnThisPage)) {
39 - $egGoogleMapsOnThisPage = 0;
40 - MapsGoogleMapsUtils::addGMapDependencies($output);
41 - }
42 - break;
43 - case 'bing' : case 'virtual-earth' :
44 - if (!self::$loadedBing) { $output .= "<script type='$wgJsMimeType' src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1'></script>\n"; self::$loadedBing = true; }
45 - break;
46 - case 'yahoo' : case 'yahoo-maps' :
47 - if (!self::$loadedYahoo) { $output .= "<style type='text/css'> #controls {width: 512px;}</style><script src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers'></script>\n"; self::$loadedYahoo = true; }
48 - break;
49 - case 'openlayers' : case 'open-layers' :
50 - if (!self::$loadedOL) { $output .= "<script type='$wgJsMimeType' src='http://clients.multimap.com/API/maps/1.1/metacarta_04'></script>\n"; self::$loadedOL = true; }
51 - break;
52 - case 'osm' : case 'openstreetmap' :
53 - if (!self::$loadedOSM) { $output .= "<script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OSM/OpenStreetMap.js?$egMapsStyleVersion'></script>\n"; self::$loadedOSM = true; }
54 - break;
55 - }
56 - }
57 -
58 - /**
59 - * Retuns an array holding the default parameters and their values.
60 - *
61 - * @return array
62 - */
63 - public static function getDefaultParams() {
64 - return array
65 - (
66 - 'layers' => array(),
67 - 'baselayer' => ''
68 - );
69 - }
70 -
71 - /**
72 - * If this is the first open layers map on the page, load the API, styles and extra JS functions
73 - *
74 - * @param string $output
75 - */
76 - public static function addOLDependencies(&$output) {
77 - global $wgJsMimeType;
78 - global $egOpenLayersOnThisPage, $egMapsScriptPath;
79 -
80 - if (empty($egOpenLayersOnThisPage)) {
81 - $egOpenLayersOnThisPage = 0;
82 -
83 - $output .="<link rel='stylesheet' href='$egMapsScriptPath/OpenLayers/OpenLayers/theme/default/style.css' type='text/css' />
84 - <script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OpenLayers/OpenLayers.js'></script>
85 - <script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OpenLayerFunctions.js'></script>
86 - <script type='$wgJsMimeType'>initOLSettings(200, 100);</script>\n";
87 - }
88 - }
89 -
90 - /**
91 - * Build up a csv string with the layers, to be outputted as a JS array
92 - *
93 - * @param string $output
94 - * @param array $layers
95 - * @return csv string
96 - */
97 - public static function createLayersStringAndLoadDependencies(&$output, array $layers) {
98 - global $egMapsOLLayers;
99 -
100 - if (count($layers) < 1) $layers = $egMapsOLLayers;
101 -
102 - $layerItems = '';
103 - foreach ($layers as $layer) {
104 - $layer = strtolower($layer);
105 - $layerItems .= "'$layer'" . ',';
106 - self::loadDependencyWhenNeeded($output, $layer);
107 - }
108 -
109 - return rtrim($layerItems, ',');
110 - }
111 -
112 - /**
113 - * Build up a csv string with the controls, to be outputted as a JS array
114 - *
115 - * @param array $controls
116 - * @return csv string
117 - */
118 - public static function createControlsString(array $controls) {
119 - global $egMapsOLControls;
120 - return MapsMapper::createJSItemsString($controls, $egMapsOLControls);
121 - }
122 -
123 -}
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispPoint.php
@@ -21,7 +21,7 @@
2222 */
2323 class MapsOpenLayersDispPoint extends MapsBasePointMap {
2424
25 - public $serviceName = MapsOpenLayersUtils::SERVICE_NAME;
 25+ public $serviceName = MapsOpenLayers::SERVICE_NAME;
2626
2727 /**
2828 * @see MapsBaseMap::setMapSettings()
@@ -30,12 +30,16 @@
3131 protected function setMapSettings() {
3232 global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix;
3333
34 - $this->defaultParams = MapsOpenLayersUtils::getDefaultParams();
35 -
3634 $this->elementNamePrefix = $egMapsOpenLayersPrefix;
3735 $this->defaultZoom = $egMapsOpenLayersZoom;
3836
39 - $this->markerStringFormat = 'getOLMarkerData(lat, lon, "title", "label", "icon")';
 37+ $this->markerStringFormat = 'getOLMarkerData(lat, lon, "title", "label", "icon")';
 38+
 39+ $this->spesificParameters = array(
 40+ 'zoom' => array(
 41+ 'default' => '',
 42+ )
 43+ );
4044 }
4145
4246 /**
@@ -45,7 +49,7 @@
4650 protected function doMapServiceLoad() {
4751 global $egOpenLayersOnThisPage;
4852
49 - MapsOpenLayersUtils::addOLDependencies($this->output);
 53+ MapsOpenLayers::addOLDependencies($this->output);
5054 $egOpenLayersOnThisPage++;
5155
5256 $this->elementNr = $egOpenLayersOnThisPage;
@@ -58,10 +62,10 @@
5963 public function addSpecificMapHTML() {
6064 global $wgJsMimeType;
6165
62 - $controlItems = MapsOpenLayersUtils::createControlsString($this->controls);
 66+ $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls));
6367
64 - MapsMapper::enforceArrayValues($this->layers);
65 - $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers);
 68+ //var_dump($this->layers);die();
 69+ $layerItems = MapsOpenLayers::createLayersStringAndLoadDependencies($this->output, $this->layers);
6670
6771 $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div>
6872 <script type='$wgJsMimeType'> /*<![CDATA[*/
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php
@@ -15,7 +15,7 @@
1616
1717 class MapsOpenLayersDispMap extends MapsBaseMap {
1818
19 - public $serviceName = MapsOpenLayersUtils::SERVICE_NAME;
 19+ public $serviceName = MapsOpenLayers::SERVICE_NAME;
2020
2121 /**
2222 * @see MapsBaseMap::setMapSettings()
@@ -24,10 +24,8 @@
2525 protected function setMapSettings() {
2626 global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix;
2727
28 - $this->defaultParams = MapsOpenLayersUtils::getDefaultParams();
29 -
3028 $this->elementNamePrefix = $egMapsOpenLayersPrefix;
31 - $this->defaultZoom = $egMapsOpenLayersZoom;
 29+ $this->defaultZoom = $egMapsOpenLayersZoom;
3230 }
3331
3432 /**
@@ -37,7 +35,7 @@
3836 protected function doMapServiceLoad() {
3937 global $egOpenLayersOnThisPage;
4038
41 - MapsOpenLayersUtils::addOLDependencies($this->output);
 39+ MapsOpenLayers::addOLDependencies($this->output);
4240 $egOpenLayersOnThisPage++;
4341
4442 $this->elementNr = $egOpenLayersOnThisPage;
@@ -50,10 +48,9 @@
5149 public function addSpecificMapHTML() {
5250 global $wgJsMimeType;
5351
54 - $controlItems = MapsOpenLayersUtils::createControlsString($this->controls);
 52+ $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls));
5553
56 - MapsMapper::enforceArrayValues($this->layers);
57 - $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers);
 54+ $layerItems = MapsOpenLayers::createLayersStringAndLoadDependencies($this->output, $this->layers);
5855
5956 $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div>
6057 <script type='$wgJsMimeType'> /*<![CDATA[*/
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php
@@ -26,11 +26,124 @@
2727 'display_map' => array('class' => 'MapsOpenLayersDispMap', 'file' => 'OpenLayers/Maps_OpenLayersDispMap.php', 'local' => true),
2828 ),
2929 'classes' => array(
30 - array('class' => 'MapsOpenLayersUtils', 'file' => 'OpenLayers/Maps_OpenLayersUtils.php', 'local' => true)
 30+ array('class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true)
3131 ),
3232 'aliases' => array('layers', 'openlayer'),
33 - 'parameters' => array(
34 - 'layers' => array(),
35 - 'baselayer' => array()
36 - )
37 - );
\ No newline at end of file
 33+ );
 34+/**
 35+ * Class for OpenLayers initialization.
 36+ *
 37+ * @ingroup MapsOpenLayers
 38+ *
 39+ * @author Jeroen De Dauw
 40+ */
 41+class MapsOpenLayers {
 42+
 43+ const SERVICE_NAME = 'openlayers';
 44+
 45+ private static $loadedBing = false;
 46+ private static $loadedYahoo = false;
 47+ private static $loadedOL = false;
 48+ private static $loadedOSM = false;
 49+
 50+ public static function initialize() {
 51+ self::initializeParams();
 52+ }
 53+
 54+ private static function initializeParams() {
 55+ global $egMapsServices, $egMapsOLLayers, $egMapsOLControls, $egMapsOpenLayersZoom;
 56+
 57+ $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
 58+ 'zoom' => array(
 59+ 'default' => $egMapsOpenLayersZoom,
 60+ ),
 61+ 'controls' => array(
 62+ 'criteria' => array(), // TODO
 63+ 'default' => implode(',', $egMapsOLControls)
 64+ ),
 65+ 'layers' => array(
 66+ 'aliases' => array(),
 67+ 'criteria' => array(), // TODO
 68+ 'default' => implode(',', $egMapsOLLayers)
 69+ ),
 70+ 'baselayer' => array( // TODO
 71+ 'aliases' => array(),
 72+ 'criteria' => array(),
 73+ 'default' => ''
 74+ ),
 75+ );
 76+ }
 77+
 78+ /**
 79+ * Load the dependencies of a layer if they are not loaded yet
 80+ *
 81+ * @param string $output The output to which the html to load the dependencies needs to be added
 82+ * @param string $layer The layer to check (and load the dependencies for
 83+ */
 84+ public static function loadDependencyWhenNeeded(&$output, $layer) {
 85+ global $wgJsMimeType;
 86+ global $egGoogleMapsOnThisPage, $egMapsScriptPath, $egMapsStyleVersion;
 87+
 88+ switch ($layer) {
 89+ case 'google' : case 'google-normal' : case 'google-sattelite' : case 'google-hybrid' : case 'google-physical' :
 90+ if (empty($egGoogleMapsOnThisPage)) {
 91+ $egGoogleMapsOnThisPage = 0;
 92+ MapsGoogleMapsUtils::addGMapDependencies($output);
 93+ }
 94+ break;
 95+ case 'bing' : case 'virtual-earth' :
 96+ if (!self::$loadedBing) { $output .= "<script type='$wgJsMimeType' src='http://dev.virtualearth.net/mapcontrol/mapcontrol.ashx?v=6.1'></script>\n"; self::$loadedBing = true; }
 97+ break;
 98+ case 'yahoo' : case 'yahoo-maps' :
 99+ if (!self::$loadedYahoo) { $output .= "<style type='text/css'> #controls {width: 512px;}</style><script src='http://api.maps.yahoo.com/ajaxymap?v=3.0&appid=euzuro-openlayers'></script>\n"; self::$loadedYahoo = true; }
 100+ break;
 101+ case 'openlayers' : case 'open-layers' :
 102+ if (!self::$loadedOL) { $output .= "<script type='$wgJsMimeType' src='http://clients.multimap.com/API/maps/1.1/metacarta_04'></script>\n"; self::$loadedOL = true; }
 103+ break;
 104+ case 'osm' : case 'openstreetmap' :
 105+ if (!self::$loadedOSM) { $output .= "<script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OSM/OpenStreetMap.js?$egMapsStyleVersion'></script>\n"; self::$loadedOSM = true; }
 106+ break;
 107+ }
 108+ }
 109+
 110+ /**
 111+ * If this is the first open layers map on the page, load the API, styles and extra JS functions
 112+ *
 113+ * @param string $output
 114+ */
 115+ public static function addOLDependencies(&$output) {
 116+ global $wgJsMimeType;
 117+ global $egOpenLayersOnThisPage, $egMapsScriptPath;
 118+
 119+ if (empty($egOpenLayersOnThisPage)) {
 120+ $egOpenLayersOnThisPage = 0;
 121+
 122+ $output .="<link rel='stylesheet' href='$egMapsScriptPath/OpenLayers/OpenLayers/theme/default/style.css' type='text/css' />
 123+ <script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OpenLayers/OpenLayers.js'></script>
 124+ <script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OpenLayerFunctions.js'></script>
 125+ <script type='$wgJsMimeType'>initOLSettings(200, 100);</script>\n";
 126+ }
 127+ }
 128+
 129+ /**
 130+ * Build up a csv string with the layers, to be outputted as a JS array
 131+ *
 132+ * @param string $output
 133+ * @param string $layers
 134+ * @return csv string
 135+ */
 136+ public static function createLayersStringAndLoadDependencies(&$output, $layers) {
 137+ $layers = explode(',', $layers);
 138+
 139+ $layerItems = '';
 140+ foreach ($layers as $layer) {
 141+ $layer = strtolower($layer);
 142+ $layerItems .= "'$layer'" . ',';
 143+ self::loadDependencyWhenNeeded($output, $layer);
 144+ }
 145+
 146+ return rtrim($layerItems, ',');
 147+ }
 148+
 149+}
 150+
\ No newline at end of file
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
@@ -40,27 +40,29 @@
4141 public final function displayMap(&$parser, array $params) {
4242 $this->setMapSettings();
4343
44 - parent::manageMapProperties($params, __CLASS__);
 44+ $this->featureParameters = MapsDisplayPoint::$parameters;
4545
46 - $this->doMapServiceLoad();
47 -
48 - $this->setMapName();
 46+ if (parent::manageMapProperties($params, __CLASS__)) {
 47+ $this->doMapServiceLoad();
 48+
 49+ $this->setMapName();
 50+
 51+ $this->setCoordinates($parser);
 52+
 53+ $this->createMarkerString();
 54+
 55+ $this->setZoom();
 56+
 57+ $this->setCentre();
 58+
 59+ $this->doParsing($parser);
 60+
 61+ $this->doEscaping();
 62+
 63+ $this->addSpecificMapHTML();
 64+ }
4965
50 - $this->setCoordinates($parser);
51 -
52 - $this->createMarkerString();
53 -
54 - $this->setZoom();
55 -
56 - $this->setCentre();
57 -
58 - $this->doParsing($parser);
59 -
60 - $this->doEscaping();
61 -
62 - $this->addSpecificMapHTML();
63 -
64 - return $this->output;
 66+ return $this->output . $this->errorList;
6567 }
6668
6769 /**
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php
@@ -13,12 +13,14 @@
1414 die( 'Not an entry point.' );
1515 }
1616
17 -$wgAutoloadClasses['MapsDisplayPoint'] = $egMapsIP . '/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php';
18 -$wgAutoloadClasses['MapsBasePointMap'] = $egMapsIP . '/ParserFunctions/DisplayPoint/Maps_BasePointMap.php';
 17+$wgAutoloadClasses['MapsDisplayPoint'] = $egMapsIP . '/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php';
 18+$wgAutoloadClasses['MapsBasePointMap'] = $egMapsIP . '/ParserFunctions/DisplayPoint/Maps_BasePointMap.php';
1919
20 -$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic';
21 -$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint';
 20+$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic';
 21+$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint';
2222
 23+$egMapsAvailableFeatures['pf']['hooks'][] = 'MapsDisplayPoint';
 24+
2325 /**
2426 * Adds the magic words for the parser functions.
2527 */
@@ -47,10 +49,17 @@
4850 */
4951 final class MapsDisplayPoint {
5052
 53+ public static $parameters = array();
 54+
 55+ public static function initialize() {
 56+ self::initializeParams();
 57+ }
 58+
5159 /**
5260 * Returns the output for a display_point call.
5361 *
5462 * @param unknown_type $parser
 63+ *
5564 * @return array
5665 */
5766 public static function displayPointRender(&$parser) {
@@ -58,4 +67,26 @@
5968 return MapsParserFunctions::getMapHtml($parser, $args, 'display_point');
6069 }
6170
 71+ private static function initializeParams() {
 72+ global $egMapsDefaultCentre, $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsDefaultTitle, $egMapsDefaultLabel;
 73+
 74+ self::$parameters = array_merge(MapsParserFunctions::$parameters, array(
 75+ 'centre' => array(
 76+ 'aliases' => array('center'),
 77+ 'criteria' => array(),
 78+ 'default' => $egMapsDefaultCentre
 79+ ),
 80+ 'title' => array(
 81+ 'aliases' => array(),
 82+ 'criteria' => array(),
 83+ 'default' => $egMapsDefaultTitle
 84+ ),
 85+ 'label' => array(
 86+ 'aliases' => array(),
 87+ 'criteria' => array(),
 88+ 'default' => $egMapsDefaultLabel
 89+ ),
 90+ ));
 91+ }
 92+
6293 }
\ No newline at end of file
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
@@ -36,19 +36,21 @@
3737 public final function displayMap(&$parser, array $params) {
3838 $this->setMapSettings();
3939
40 - parent::manageMapProperties($params, __CLASS__);
 40+ $this->featureParameters = MapsDisplayMap::$parameters;
4141
42 - $this->doMapServiceLoad();
43 -
44 - $this->setMapName();
 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();
 52+ }
4553
46 - $this->setZoom();
47 -
48 - $this->setCentre();
49 -
50 - $this->addSpecificMapHTML();
51 -
52 - return $this->output;
 54+ return $this->output . $this->errorList;
5355 }
5456
5557 /**
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php
@@ -13,12 +13,14 @@
1414 die( 'Not an entry point.' );
1515 }
1616
17 -$wgAutoloadClasses['MapsDisplayMap'] = $egMapsIP . '/ParserFunctions/DisplayMap/Maps_DisplayMap.php';
18 -$wgAutoloadClasses['MapsBaseMap'] = $egMapsIP . '/ParserFunctions/DisplayMap/Maps_BaseMap.php';
 17+$wgAutoloadClasses['MapsDisplayMap'] = $egMapsIP . '/ParserFunctions/DisplayMap/Maps_DisplayMap.php';
 18+$wgAutoloadClasses['MapsBaseMap'] = $egMapsIP . '/ParserFunctions/DisplayMap/Maps_BaseMap.php';
1919
20 -$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic';
21 -$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap';
 20+$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic';
 21+$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap';
2222
 23+$egMapsAvailableFeatures['pf']['hooks'][] = 'MapsDisplayMap';
 24+
2325 /**
2426 * Adds the magic words for the parser functions.
2527 */
@@ -46,10 +48,17 @@
4749 */
4850 final class MapsDisplayMap {
4951
 52+ public static $parameters = array();
 53+
 54+ public static function initialize() {
 55+ self::initializeParams();
 56+ }
 57+
5058 /**
5159 * Returns the output for a display_map call.
5260 *
5361 * @param unknown_type $parser
 62+ *
5463 * @return array
5564 */
5665 public static function displayMapRender(&$parser) {
@@ -57,4 +66,11 @@
5867 return MapsParserFunctions::getMapHtml($parser, $args, 'display_map');
5968 }
6069
 70+ private static function initializeParams() {
 71+ global $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
 72+
 73+ self::$parameters = array_merge(MapsParserFunctions::$parameters, array(
 74+ ));
 75+ }
 76+
6177 }
\ No newline at end of file
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php
@@ -20,15 +20,19 @@
2121 */
2222 final class MapsParserFunctions {
2323
 24+ public static $parameters = array();
 25+
2426 /**
2527 * Initialize the parser functions feature. This function handles the parser function hook,
2628 * and will load the required classes.
2729 */
2830 public static function initialize() {
29 - global $egMapsIP, $IP, $wgAutoloadClasses, $egMapsServices;
 31+ global $egMapsIP, $IP, $wgAutoloadClasses, $egMapsAvailableFeatures, $egMapsServices;
3032
3133 include_once $egMapsIP . '/ParserFunctions/Maps_iDisplayFunction.php';
3234
 35+ self::initializeParams();
 36+
3337 foreach($egMapsServices as $serviceName => $serviceData) {
3438 // Check if the service has parser function support
3539 $hasPFs = array_key_exists('pf', $serviceData);
@@ -42,8 +46,33 @@
4347 $wgAutoloadClasses[$parser_data['class']] = $file;
4448 }
4549 }
 50+
 51+ // This runs a small hook that enables parser functions to run initialization code.
 52+ foreach($egMapsAvailableFeatures['pf']['hooks'] as $hook) {
 53+ if (method_exists($hook, 'initialize')) call_user_func(array($hook, 'initialize'));
 54+ }
4655 }
4756
 57+ private static function initializeParams() {
 58+ global $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
 59+
 60+ self::$parameters = array(
 61+ 'coordinates' => array(
 62+ 'aliases' => array('coords', 'location', 'locations'),
 63+ 'criteria' => array(
 64+ //'arecoords' => array()// TODO
 65+ ),
 66+ ),
 67+ 'geoservice' => array(
 68+ 'aliases' => array(),
 69+ 'criteria' => array(
 70+ 'in_array' => $egMapsAvailableGeoServices
 71+ ),
 72+ 'default' => array($egMapsDefaultGeoService)
 73+ ),
 74+ );
 75+ }
 76+
4877 /**
4978 * Returns the output for the call to the specified parser function.
5079 *
@@ -80,7 +109,8 @@
81110 }
82111 }
83112
84 - $coords = MapsMapper::getParamValue('coordinates', $map);
 113+ $paramInfo = array_merge(MapsMapper::getMainParams(), self::$parameters);
 114+ $coords = MapsMapper::getParamValue('coordinates', $map, $paramInfo);
85115
86116 if ($coords) {
87117 if (! MapsMapper::paramIsPresent('service', $map)) $map['service'] = '';
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMUtils.php
@@ -1,116 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * A class that holds static helper functions for OSM.
6 - *
7 - * @file Maps_OSMUtils.php
8 - * @ingroup MapsOpenStreetMap
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -final class MapsOSMUtils {
18 -
19 - const SERVICE_NAME = 'osm';
20 -
21 - private static $layers = array(
22 - 'osm-wm' => array(
23 - // First layer = default
24 - 'layers' => array( 'osm-like' ),
25 -
26 - // Default "zoom=" argument
27 - 'defaultZoomLevel' => 14,
28 -
29 - 'static_rendering' => array(
30 - 'type' => 'SlippyMapExportCgiBin',
31 - 'options' => array(
32 - 'base_url' => 'http://cassini.toolserver.org/cgi-bin/export',
33 -
34 - 'format' => 'png',
35 - 'numZoomLevels' => 19,
36 - 'maxResolution' => 156543.0339,
37 - 'unit' => 'm',
38 - 'sphericalMercator' => true,
39 -
40 - // More GET arguments
41 - 'get_args' => array(
42 - // Will use $wgContLang->getCode()
43 - 'locale' => true,
44 - 'maptype' => 'osm-like'
45 - ),
46 - ),
47 - ),
48 - ),
49 - 'osm' => array(
50 - // First layer = default
51 - 'layers' => array( 'mapnik', 'osmarender', 'maplint', 'cycle' ),
52 -
53 - // Default "zoom=" argument
54 - 'defaultZoomLevel' => 14,
55 -
56 - 'static_rendering' => array(
57 - 'type' => 'SlippyMapExportCgiBin',
58 - 'options' => array(
59 - 'base_url' => 'http://tile.openstreetmap.org/cgi-bin/export',
60 -
61 - 'format' => 'png',
62 - 'numZoomLevels' => 19,
63 - 'maxResolution' => 156543.0339,
64 - 'unit' => 'm',
65 - 'sphericalMercator' => true
66 - ),
67 - ),
68 - ),
69 - 'satellite' => array(
70 - 'layers' => array( 'urban', 'landsat', 'bluemarble' ),
71 - 'defaultZoomLevel' => 14,
72 - 'static_rendering' => null,
73 - ),
74 - );
75 -
76 - /**
77 - * Retuns an array holding the default parameters and their values.
78 - *
79 - * @return array
80 - */
81 - public static function getDefaultParams() {
82 - return array
83 - (
84 - );
85 - }
86 -
87 - /**
88 - * If this is the first OSM map on the page, load the OpenLayers API, OSM styles and extra JS functions
89 - *
90 - * @param string $output
91 - */
92 - public static function addOSMDependencies(&$output) {
93 - global $wgJsMimeType;
94 - global $egOSMMapsOnThisPage, $egMapsScriptPath, $egMapsStyleVersion;
95 -
96 - if (empty($egOSMMapsOnThisPage)) {
97 - $egOSMMapsOnThisPage = 0;
98 -
99 - $output .="<link rel='stylesheet' href='$egMapsScriptPath/OpenLayers/OpenLayers/theme/default/style.css' type='text/css' />
100 - <script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OpenLayers/OpenLayers.js'></script>
101 - <script type='$wgJsMimeType' src='$egMapsScriptPath/OpenStreetMap/OSMFunctions.js?$egMapsStyleVersion'></script>
102 - <script type='$wgJsMimeType'>slippymaps = Array();</script>\n";
103 - }
104 - }
105 -
106 - /**
107 - * Build up a csv string with the controls, to be outputted as a JS array
108 - *
109 - * @param array $controls
110 - * @return csv string
111 - */
112 - public static function createControlsString(array $controls) {
113 - global $egMapsOSMControls;
114 - return MapsMapper::createJSItemsString($controls, $egMapsOSMControls);
115 - }
116 -
117 -}
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispPoint.php
@@ -20,7 +20,7 @@
2121 */
2222 class MapsOSMDispPoint extends MapsBasePointMap {
2323
24 - public $serviceName = MapsOSMUtils::SERVICE_NAME;
 24+ public $serviceName = MapsOSM::SERVICE_NAME;
2525
2626 /**
2727 * @see MapsBaseMap::setMapSettings()
@@ -29,12 +29,16 @@
3030 protected function setMapSettings() {
3131 global $egMapsOSMZoom, $egMapsOSMPrefix;
3232
33 - $this->defaultParams = MapsOSMUtils::getDefaultParams();
34 -
3533 $this->elementNamePrefix = $egMapsOSMPrefix;
3634 $this->defaultZoom = $egMapsOSMZoom;
3735
3836 $this->markerStringFormat = 'getOSMMarkerData(lat, lon, "title", "label", "icon")';
 37+
 38+ $this->spesificParameters = array(
 39+ 'zoom' => array(
 40+ 'default' => '',
 41+ )
 42+ );
3943 }
4044
4145 /**
@@ -44,7 +48,7 @@
4549 protected function doMapServiceLoad() {
4650 global $egOSMMapsOnThisPage;
4751
48 - MapsOSMUtils::addOSMDependencies($this->output);
 52+ MapsOSM::addOSMDependencies($this->output);
4953 $egOSMMapsOnThisPage++;
5054
5155 $this->elementNr = $egOSMMapsOnThisPage;
@@ -57,7 +61,7 @@
5862 public function addSpecificMapHTML() {
5963 global $wgJsMimeType;
6064
61 - $controlItems = MapsOSMUtils::createControlsString($this->controls);
 65+ $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls));
6266
6367 $this->output .= <<<EOT
6468 <script type='$wgJsMimeType'>slippymaps['$this->mapName'] = new slippymap_map('$this->mapName', {
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispMap.php
@@ -15,7 +15,7 @@
1616
1717 class MapsOSMDispMap extends MapsBaseMap {
1818
19 - public $serviceName = MapsOSMUtils::SERVICE_NAME;
 19+ public $serviceName = MapsOSM::SERVICE_NAME;
2020
2121 /**
2222 * @see MapsBaseMap::setMapSettings()
@@ -24,8 +24,6 @@
2525 protected function setMapSettings() {
2626 global $egMapsOSMZoom, $egMapsOSMPrefix;
2727
28 - $this->defaultParams = MapsOSMUtils::getDefaultParams();
29 -
3028 $this->elementNamePrefix = $egMapsOSMPrefix;
3129 $this->defaultZoom = $egMapsOSMZoom;
3230 }
@@ -37,7 +35,7 @@
3836 protected function doMapServiceLoad() {
3937 global $egOSMMapsOnThisPage;
4038
41 - MapsOSMUtils::addOSMDependencies($this->output);
 39+ MapsOSM::addOSMDependencies($this->output);
4240 $egOSMMapsOnThisPage++;
4341
4442 $this->elementNr = $egOSMMapsOnThisPage;
@@ -50,7 +48,7 @@
5149 public function addSpecificMapHTML() {
5250 global $wgJsMimeType;
5351
54 - $controlItems = MapsOSMUtils::createControlsString($this->controls);
 52+ $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls));
5553
5654 $this->output .= <<<EOT
5755 <script type='$wgJsMimeType'>slippymaps['$this->mapName'] = new slippymap_map('$this->mapName', {
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSM.php
@@ -26,9 +26,114 @@
2727 'display_map' => array('class' => 'MapsOSMDispMap', 'file' => 'OpenStreetMap/Maps_OSMDispMap.php', 'local' => true),
2828 ),
2929 'classes' => array(
30 - array('class' => 'MapsOSMUtils', 'file' => 'OpenStreetMap/Maps_OSMUtils.php', 'local' => true)
 30+ array('class' => 'MapsOSM', 'file' => 'OpenStreetMap/Maps_OSM.php', 'local' => true)
3131 ),
3232 'aliases' => array('openstreetmap', 'openstreetmaps'),
33 - 'parameters' => array(
34 - )
35 - );
\ No newline at end of file
 33+ );
 34+
 35+/**
 36+ * Class for OpenStreetMap initialization.
 37+ *
 38+ * @ingroup MapsOpenStreetMap
 39+ *
 40+ * @author Jeroen De Dauw
 41+ */
 42+class MapsOSM {
 43+
 44+ const SERVICE_NAME = 'osm';
 45+
 46+ public static function initialize() {
 47+ self::initializeParams();
 48+ }
 49+
 50+ private static function initializeParams() {
 51+ global $egMapsServices, $egMapsOSMZoom, $egMapsOSMControls;
 52+
 53+ $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
 54+ 'zoom' => array(
 55+ 'default' => $egMapsOSMZoom,
 56+ ),
 57+ 'controls' => array(
 58+ 'criteria' => array(), // TODO
 59+ 'default' => implode(',', $egMapsOSMControls)
 60+ ),
 61+ );
 62+ }
 63+
 64+ // TODO: create a modular system for this SlippyMap code
 65+
 66+ private static $layers = array(
 67+ 'osm-wm' => array(
 68+ // First layer = default
 69+ 'layers' => array( 'osm-like' ),
 70+
 71+ // Default "zoom=" argument
 72+ 'defaultZoomLevel' => 14,
 73+
 74+ 'static_rendering' => array(
 75+ 'type' => 'SlippyMapExportCgiBin',
 76+ 'options' => array(
 77+ 'base_url' => 'http://cassini.toolserver.org/cgi-bin/export',
 78+
 79+ 'format' => 'png',
 80+ 'numZoomLevels' => 19,
 81+ 'maxResolution' => 156543.0339,
 82+ 'unit' => 'm',
 83+ 'sphericalMercator' => true,
 84+
 85+ // More GET arguments
 86+ 'get_args' => array(
 87+ // Will use $wgContLang->getCode()
 88+ 'locale' => true,
 89+ 'maptype' => 'osm-like'
 90+ ),
 91+ ),
 92+ ),
 93+ ),
 94+ 'osm' => array(
 95+ // First layer = default
 96+ 'layers' => array( 'mapnik', 'osmarender', 'maplint', 'cycle' ),
 97+
 98+ // Default "zoom=" argument
 99+ 'defaultZoomLevel' => 14,
 100+
 101+ 'static_rendering' => array(
 102+ 'type' => 'SlippyMapExportCgiBin',
 103+ 'options' => array(
 104+ 'base_url' => 'http://tile.openstreetmap.org/cgi-bin/export',
 105+
 106+ 'format' => 'png',
 107+ 'numZoomLevels' => 19,
 108+ 'maxResolution' => 156543.0339,
 109+ 'unit' => 'm',
 110+ 'sphericalMercator' => true
 111+ ),
 112+ ),
 113+ ),
 114+ 'satellite' => array(
 115+ 'layers' => array( 'urban', 'landsat', 'bluemarble' ),
 116+ 'defaultZoomLevel' => 14,
 117+ 'static_rendering' => null,
 118+ ),
 119+ );
 120+
 121+ /**
 122+ * If this is the first OSM map on the page, load the OpenLayers API, OSM styles and extra JS functions
 123+ *
 124+ * @param string $output
 125+ */
 126+ public static function addOSMDependencies(&$output) {
 127+ global $wgJsMimeType;
 128+ global $egOSMMapsOnThisPage, $egMapsScriptPath, $egMapsStyleVersion;
 129+
 130+ if (empty($egOSMMapsOnThisPage)) {
 131+ $egOSMMapsOnThisPage = 0;
 132+
 133+ $output .="<link rel='stylesheet' href='$egMapsScriptPath/OpenLayers/OpenLayers/theme/default/style.css' type='text/css' />
 134+ <script type='$wgJsMimeType' src='$egMapsScriptPath/OpenLayers/OpenLayers/OpenLayers.js'></script>
 135+ <script type='$wgJsMimeType' src='$egMapsScriptPath/OpenStreetMap/OSMFunctions.js?$egMapsStyleVersion'></script>
 136+ <script type='$wgJsMimeType'>slippymaps = Array();</script>\n";
 137+ }
 138+ }
 139+
 140+}
\ No newline at end of file
Index: trunk/extensions/Maps/Maps.php
@@ -23,7 +23,7 @@
2424 die( 'Not an entry point.' );
2525 }
2626
27 -define('Maps_VERSION', '0.5 a4');
 27+define('Maps_VERSION', '0.5 a6');
2828
2929 // Constants indicating the strictness of the parameter validation.
3030 define('Maps_ERRORS_NONE', 0);
@@ -46,10 +46,15 @@
4747 $wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks';
4848
4949 // Autoload the general classes
50 -$wgAutoloadClasses['MapsMapFeature'] = $egMapsIP . '/Maps_MapFeature.php';
51 -$wgAutoloadClasses['MapsMapper'] = $egMapsIP . '/Maps_Mapper.php';
52 -$wgAutoloadClasses['MapsUtils'] = $egMapsIP . '/Maps_Utils.php';
 50+$wgAutoloadClasses['MapsMapFeature'] = $egMapsIP . '/Maps_MapFeature.php';
 51+$wgAutoloadClasses['MapsMapper'] = $egMapsIP . '/Maps_Mapper.php';
 52+$wgAutoloadClasses['MapsUtils'] = $egMapsIP . '/Maps_Utils.php';
5353
 54+// TODO: seperate extension
 55+$wgAutoloadClasses['MapsParamValidator'] = $egMapsIP . '/Maps_ParamValidator.php';
 56+$wgAutoloadClasses['MapsValidationFunctions'] = $egMapsIP . '/Maps_ValidationFunctions.php';
 57+$wgAutoloadClasses['MapsParamManager'] = $egMapsIP . '/Maps_ParamManager.php';
 58+
5459 if (empty($egMapsServices)) $egMapsServices = array();
5560
5661 /**
@@ -57,7 +62,7 @@
5863 */
5964 function efMapsSetup() {
6065 global $wgExtensionCredits, $wgOut, $wgLang, $wgAutoloadClasses, $IP;
61 - global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsScriptPath, $egMapsDefaultGeoService, $egMapsAvailableGeoServices, $egMapsIP, $egMapsAvailableFeatures;
 66+ global $egMapsDefaultService, $egMapsAvailableServices, $egMapsServices, $egMapsScriptPath, $egMapsDefaultGeoService, $egMapsAvailableGeoServices, $egMapsIP, $egMapsAvailableFeatures, $egMapsErrorLevel;
6267
6368 // Enure that the default service and geoservice are one of the enabled ones.
6469 $egMapsDefaultService = in_array($egMapsDefaultService, $egMapsAvailableServices) ? $egMapsDefaultService : $egMapsAvailableServices[0];
@@ -77,11 +82,13 @@
7883 'path' => __FILE__,
7984 'name' => wfMsg('maps_name'),
8085 'version' => Maps_VERSION,
81 - 'author' => array('[http://bn2vs.com Jeroen De Dauw]', '[http://www.mediawiki.org/wiki/User:Yaron_Koren Yaron Koren]', 'Robert Buzink', 'Matt Williamson', '[http://www.sergeychernyshev.com Sergey Chernyshev]'),
 86+ 'author' => array('[http://bn2vs.com Jeroen De Dauw]', '[http://www.mediawiki.org/wiki/User:Yaron_Koren Yaron Koren]', 'others'),
8287 'url' => 'http://www.mediawiki.org/wiki/Extension:Maps',
8388 'description' => wfMsgExt( 'maps_desc', 'parsemag', $services_list ),
8489 'descriptionmsg' => wfMsgExt( 'maps_desc', 'parsemag', $services_list ),
8590 );
 91+
 92+ MapsMapper::initializeMainParams();
8693
8794 $wgOut->addScriptFile($egMapsScriptPath . '/MapUtilityFunctions.js');
8895
@@ -90,9 +97,7 @@
9198 // Load and optionally initizlize feature.
9299 if (array_key_exists('class', $values) && array_key_exists('file', $values) && array_key_exists('local', $values)) {
93100 $wgAutoloadClasses[$values['class']] = $values['local'] ? $egMapsIP . '/' . $values['file'] : $IP . '/extensions/' . $values['file'];
94 - if (method_exists($values['class'], 'initialize')) {
95 - call_user_func(array($values['class'], 'initialize'));
96 - }
 101+ if (method_exists($values['class'], 'initialize')) call_user_func(array($values['class'], 'initialize'));
97102 }
98103
99104 // Check for wich services there are handlers for the current fature, and load them
@@ -108,6 +113,7 @@
109114 foreach($serviceData['classes'] as $class) {
110115 $file = $class['local'] ? $egMapsIP . '/' . $class['file'] : $IP . '/extensions/' . $class['file'];
111116 $wgAutoloadClasses[$class['class']] = $file;
 117+ if (method_exists($class['class'], 'initialize')) call_user_func(array($class['class'], 'initialize'));
112118 }
113119 }
114120 }
Index: trunk/extensions/Maps/Maps_ValidationFunctions.php
@@ -0,0 +1,88 @@
 2+<?php
 3+
 4+/**
 5+ * File holding the MapsValidationFunctions class.
 6+ *
 7+ * @file Maps_ValidationFunctions.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+ * Class holding variouse static methods for the validation of parameters that have to comply to cetrain criteria.
 19+ *
 20+ * @ingroup Maps
 21+ *
 22+ * @author Jeroen De Dauw
 23+ */
 24+final class MapsValidationFunctions {
 25+
 26+ /**
 27+ * Returns whether the provided value, which must be a number, is within a certain range.
 28+ *
 29+ * @param string $value
 30+ * @param array $limits
 31+ *
 32+ * @return boolean
 33+ */
 34+ public static function in_range($value, array $limits) {
 35+ if (! is_numeric($value)) return false;
 36+ $value = (int)$value;
 37+ return ($value >= $limits[0] && $value <= $limits[1]) || ($value <= $limits[0] And $value >= $limits[1]);
 38+ }
 39+
 40+ /**
 41+ * Returns whether the string value is not empty. Not empty is defined as having at least one character after trimming.
 42+ *
 43+ * @param string $value
 44+ *
 45+ * @return boolean
 46+ */
 47+ public static function not_empty($value) {
 48+ return strlen(trim($value)) > 0;
 49+ }
 50+
 51+ /**
 52+ * Returns if all items of the first array are present in the second one.
 53+ *
 54+ * @param array $needles
 55+ * @param array $haystack
 56+ *
 57+ * @return boolean
 58+ */
 59+ public static function all_in_array(array $needles, array $haystack) {
 60+ $true = true;
 61+ foreach($needles as $needle) {
 62+ if (! in_array($needle, $haystack)) {
 63+ $true = false;
 64+ break;
 65+ }
 66+ }
 67+ return $true;
 68+ }
 69+
 70+ /**
 71+ * Returns if any items of the first array are present in the second one.
 72+ *
 73+ * @param array $needles
 74+ * @param array $haystack
 75+ *
 76+ * @return boolean
 77+ */
 78+ public static function any_in_array(array $needles, array $haystack) {
 79+ $true = false;
 80+ foreach($needles as $needle) {
 81+ if (in_array($needle, $haystack)) {
 82+ $true = true;
 83+ break;
 84+ }
 85+ }
 86+ return $true;
 87+ }
 88+
 89+}
\ No newline at end of file
Index: trunk/extensions/Maps/Maps_Mapper.php
@@ -16,27 +16,73 @@
1717 final class MapsMapper {
1818
1919 /**
20 - * Array holding the allowed main parameters and their alias.
21 - * The array keys hold the main name, and the values are arrays holding the aliases.
 20+ * Array holding the parameters that are not spesific to a mapping service,
 21+ * their aliases, criteria and default value.
2222 *
2323 * @var array
2424 */
25 - private static $mainParams = array
26 - (
27 - 'service' => array(),
28 - 'geoservice' => array(),
29 - 'coordinates' => array('coords', 'location', 'locations'),
30 - 'zoom' => array(),
31 - 'centre' => array('center'),
32 - 'width' => array(),
33 - 'height' => array(),
34 - 'controls' => array(),
35 - 'label' => array(),
36 - 'title' => array(),
37 - 'lang' => array('locale', 'language')
 25+ private static $mainParams;
 26+
 27+ public static function initializeMainParams() {
 28+ global $egMapsAvailableServices, $egMapsDefaultService, $egMapsAvailableGeoServices, $egMapsDefaultGeoService, $egMapsDefaultCentre;
 29+ global $egMapsSizeRestrictions, $egMapsMapWidth, $egMapsMapHeight, $egMapsDefaultTitle, $egMapsDefaultLabel;
 30+
 31+ self::$mainParams = array
 32+ (
 33+ 'service' => array(
 34+ 'aliases' => array(),
 35+ 'criteria' => array(
 36+ 'in_array' => $egMapsAvailableServices
 37+ ),
 38+ 'default' => $egMapsDefaultService
 39+ ),
 40+ 'zoom' => array(
 41+ 'aliases' => array(),
 42+ 'criteria' => array(
 43+ 'is_numeric' => array(),
 44+ 'in_range' => array(0, 15)
 45+ )
 46+ ),
 47+ 'width' => array(
 48+ 'aliases' => array(),
 49+ 'criteria' => array(
 50+ 'is_numeric' => array(),
 51+ 'in_range' => $egMapsSizeRestrictions['width']
 52+ ),
 53+ 'default' => $egMapsMapWidth
 54+ ),
 55+ 'height' => array(
 56+ 'aliases' => array(),
 57+ 'criteria' => array(
 58+ 'is_numeric' => array(),
 59+ 'in_range' => $egMapsSizeRestrictions['height']
 60+ ),
 61+ 'default' => $egMapsMapHeight
 62+ ),
 63+ 'controls' => array(
 64+ 'aliases' => array(),
 65+ 'criteria' => array(),
 66+ ),
 67+ 'lang' => array(
 68+ 'aliases' => array('locale', 'language'),
 69+ 'criteria' => array(
 70+ 'not_empty' => array()
 71+ ),
 72+ 'default' => ''
 73+ ),
3874 );
 75+ }
3976
4077 /**
 78+ * Returns the main parameters array.
 79+ *
 80+ * @return array
 81+ */
 82+ public static function getMainParams() {
 83+ return self::$mainParams;
 84+ }
 85+
 86+ /**
4187 * Gets if a provided name is present in the aliases array of a parameter
4288 * name in the $mainParams array.
4389 *
@@ -54,29 +100,32 @@
55101 }
56102
57103 return $equals;
58 - }
 104+ }
59105
60 - /**
61 - * Gets if a parameter is present as key in the $stack. Also checks for
62 - * the presence of aliases in the $mainParams array unless specified not to.
63 - *
64 - * @param string $paramName
65 - * @param array $stack
66 - * @param boolean $checkForAliases
67 - *
68 - * @return boolean
69 - */
70 - public static function paramIsPresent($paramName, array $stack, $checkForAliases = true) {
71 - $isPresent = array_key_exists($paramName, $stack);
72 -
73 - if ($checkForAliases) {
74 - foreach(self::$mainParams[$paramName] as $alias) {
75 - if (array_key_exists($alias, $stack)) $isPresent = true;
76 - }
77 - }
78 -
79 - return $isPresent;
80 - }
 106+ /**
 107+ * Gets if a parameter is present as key in the $stack. Also checks for
 108+ * the presence of aliases in the $mainParams array unless specified not to.
 109+ *
 110+ * @param string $paramName
 111+ * @param array $stack
 112+ * @param boolean $checkForAliases
 113+ *
 114+ * @return boolean
 115+ */
 116+ public static function paramIsPresent($paramName, array $stack, $checkForAliases = true) {
 117+ $isPresent = array_key_exists($paramName, $stack);
 118+
 119+ if ($checkForAliases) {
 120+ foreach(self::$mainParams[$paramName]['aliases'] as $alias) {
 121+ if (array_key_exists($alias, $stack)) {
 122+ $isPresent = true;
 123+ break;
 124+ }
 125+ }
 126+ }
 127+
 128+ return $isPresent;
 129+ }
81130
82131 /**
83132 * Returns the value of a parameter represented as key in the $stack.
@@ -85,61 +134,26 @@
86135 * no array key name match is found, false will be returned.
87136 *
88137 * @param string $paramName
89 - * @param array $stack
 138+ * @param array $stack The values to search through
 139+ * @param array $paramInfo Contains meta data, including aliases, of the possible parameters
90140 * @param boolean $checkForAliases
91141 *
92142 * @return the parameter value or false
93143 */
94 - public static function getParamValue($paramName, array $stack, $checkForAliases = true) {
 144+ public static function getParamValue($paramName, array $stack, array $paramInfo = array(), $checkForAliases = true) {
95145 $paramValue = false;
96146
97147 if (array_key_exists($paramName, $stack)) $paramValue = $stack[$paramName];
98148
99149 if ($checkForAliases) {
100 - foreach(self::$mainParams[$paramName] as $alias) {
 150+ foreach($paramInfo[$paramName]['aliases'] as $alias) {
101151 if (array_key_exists($alias, $stack)) $paramValue = $stack[$alias];
 152+ break;
102153 }
103154 }
104155
105156 return $paramValue;
106157 }
107 -
108 - /**
109 - * Sets the default map properties and returns the new array.
110 - * This function also ensures all the properties are present, even when being empty,
111 - * which is important for the weakly typed classes using them.
112 - *
113 - * @param array $params Array containing the current set of pareters.
114 - * @param array $serviceDefaults Array with the default parameters and their values for the used mapping service.
115 - * @param boolean $strict If set to false, values which a key that does not
116 - * exist in the $map array will be retained.
117 - *
118 - * @return array
119 - */
120 - public static function setDefaultParValues(array $params, array $serviceDefaults, $strict = true) {
121 - global $egMapsMapLat, $egMapsMapLon, $egMapsMapWidth, $egMapsMapHeight, $egMapsDefaultService;
122 -
123 - $mapDefaults = array(
124 - 'service' => $egMapsDefaultService,
125 - 'geoservice' => '',
126 - 'coordinates' => "$egMapsMapLat, $egMapsMapLon",
127 - 'zoom' => '',
128 - 'centre' => '',
129 - 'width' => $egMapsMapWidth,
130 - 'height' => $egMapsMapHeight,
131 - 'controls' => array(),
132 - 'title' => '',
133 - 'label' => ''
134 - );
135 -
136 - $map = array_merge($mapDefaults, $serviceDefaults);
137 -
138 - foreach($params as $paramName => $paramValue) {
139 - if(array_key_exists($paramName, $map) || !$strict) $map[$paramName] = $paramValue;
140 - }
141 -
142 - return $map;
143 - }
144158
145159 /**
146160 * Returns the JS version (true/false as string) of the provided boolean parameter.
@@ -159,7 +173,7 @@
160174 * @param string $delimeter
161175 */
162176 public static function enforceArrayValues(&$values, $delimeter = ',') {
163 - if (!is_array($values)) $values = explode($delimeter, $values); // If not an array yet, split the values
 177+ if (! is_array($values)) $values = explode($delimeter, $values); // If not an array yet, split the values
164178 for ($i = 0; $i < count($values); $i++) $values[$i] = trim($values[$i]); // Trim all values
165179 }
166180
@@ -174,76 +188,61 @@
175189 *
176190 * @return string
177191 */
178 - public static function createJSItemsString(array $items, array $defaultItems = null, $asStrings = true, $toLower = true) {
179 - if (count($items) < 1 && isset($defaultItems)) $items = $defaultItems;
 192+ public static function createJSItemsString(array $items, $asStrings = true, $toLower = true) {
180193 $itemString = $asStrings ? "'" . implode("','", $items) . "'" : implode(',', $items);
181194 if ($toLower) $itemString = strtolower($itemString);
182195 return $itemString;
183196 }
184197
185198 /**
186 - * Returns a valid version of the provided parameter array. Paramaters that are not allowed will
187 - * be ignored, and alias parameter names will be changed to main parameter names, using getMainParamName().
 199+ * Returns the main parameter name for a given parameter or alias, or false
 200+ * when it is not recognized as main parameter or alias.
188201 *
189 - * @param array $paramz
190 - * @param array $serviceParameters
191 - * @param boolean $strict
192 - *
193 - * @return array
194 - */
195 - public static function getValidParams(array $paramz, array $serviceParameters, $strict = true) {
196 - $validParams = array();
197 -
198 - $allowedParms = array_merge(self::$mainParams, $serviceParameters);
199 -
200 - foreach($paramz as $paramName => $paramValue) {
201 - $paramName = self::getMainParamName($paramName, $allowedParms);
202 - if(array_key_exists($paramName, $allowedParms) || !$strict) $validParams[$paramName] = $paramValue;
203 - }
204 -
205 - return $validParams;
206 - }
207 -
208 - /**
209 - * Checks if the patameter name is an alias for an actual parameter,
210 - * and changes it into the main paremeter name if this is the case.
211 - *
212202 * @param string $paramName
213203 * @param array $allowedParms
214204 *
215205 * @return string
216206 */
217 - private static function getMainParamName($paramName, array $allowedParms) {
218 - if (!array_key_exists($paramName, $allowedParms)) {
219 - foreach ($allowedParms as $name => $aliases) {
220 - if (in_array($paramName, $aliases)) {
221 - $paramName = $name;
222 - continue;
 207+ public static function getMainParamName($paramName, array $allowedParms) {
 208+ $result = false;
 209+
 210+ if (array_key_exists($paramName, $allowedParms)) {
 211+ $result = $paramName;
 212+ }
 213+ else {
 214+ foreach ($allowedParms as $name => $data) {
 215+ if (array_key_exists('aliases', $data)) {
 216+ if (in_array($paramName, $data['aliases'])) {
 217+ $result = $name;
 218+ break;
 219+ }
223220 }
224221 }
225222 }
226 - return $paramName;
227 - }
228223
 224+ return $result;
 225+ }
 226+
 227+
229228 /**
230229 * Returns a valid service. When an invalid service is provided, the default one will be returned.
231230 * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName().
232231 *
233232 * @param string $service
 233+ * @param string $feature
 234+ *
234235 * @return string
235236 */
236 - public static function getValidService($service, $feature = '') {
 237+ public static function getValidService($service, $feature) {
237238 global $egMapsAvailableServices, $egMapsDefaultService, $egMapsDefaultServices, $egMapsServices;
238239
239240 $service = self::getMainServiceName($service);
240241
241 - if ($feature != '') {
242 - $shouldChange = ! array_key_exists($service, $egMapsServices);
243 - if (! $shouldChange) $shouldChange = ! array_key_exists($feature, $egMapsServices[$service]);
244 -
245 - if ($shouldChange) {
246 - $service = array_key_exists($feature, $egMapsDefaultServices) ? $egMapsDefaultServices[$feature] : $egMapsDefaultService;
247 - }
 242+ $shouldChange = ! array_key_exists($service, $egMapsServices);
 243+ if (! $shouldChange) $shouldChange = ! array_key_exists($feature, $egMapsServices[$service]);
 244+
 245+ if ($shouldChange) {
 246+ $service = array_key_exists($feature, $egMapsDefaultServices) ? $egMapsDefaultServices[$feature] : $egMapsDefaultService;
248247 }
249248
250249 if(! in_array($service, $egMapsAvailableServices)) $service = $egMapsDefaultService;
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php
@@ -1,308 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * A class that holds static helper functions for Google Maps
6 - *
7 - * @file Maps_GooleMapsUtils.php
8 - * @ingroup MapsGoogleMaps
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -final class MapsGoogleMapsUtils {
18 -
19 - const SERVICE_NAME = 'googlemaps';
20 -
21 - // http://code.google.com/apis/maps/documentation/reference.html#GMapType.G_NORMAL_MAP
22 - // TODO: Add a true alliasing system? Might be overkill.
23 - private static $mapTypes = array(
24 - 'normal' => 'G_NORMAL_MAP',
25 - 'G_NORMAL_MAP' => 'G_NORMAL_MAP',
26 -
27 - 'satellite' => 'G_SATELLITE_MAP',
28 - 'G_SATELLITE_MAP' => 'G_SATELLITE_MAP',
29 -
30 - 'hybrid' => 'G_HYBRID_MAP',
31 - 'G_HYBRID_MAP' => 'G_HYBRID_MAP',
32 -
33 - 'terrain' => 'G_PHYSICAL_MAP',
34 - 'physical' => 'G_PHYSICAL_MAP',
35 - 'G_PHYSICAL_MAP' => 'G_PHYSICAL_MAP',
36 -
37 - 'earth' => 'G_SATELLITE_3D_MAP',
38 - 'G_SATELLITE_3D_MAP' => 'G_SATELLITE_3D_MAP',
39 -
40 - 'sky' => 'G_SKY_VISIBLE_MAP',
41 - 'G_SKY_VISIBLE_MAP' => 'G_SKY_VISIBLE_MAP',
42 -
43 - 'moon' => 'G_MOON_VISIBLE_MAP',
44 - 'G_MOON_VISIBLE_MAP' => 'G_MOON_VISIBLE_MAP',
45 -
46 - 'moon-elevation' => 'G_MOON_ELEVATION_MAP',
47 - 'G_MOON_ELEVATION_MAP' => 'G_MOON_ELEVATION_MAP',
48 -
49 - 'mars' => 'G_MARS_VISIBLE_MAP',
50 - 'G_MARS_VISIBLE_MAP' => 'G_MARS_VISIBLE_MAP',
51 -
52 - 'mars-elevation' => 'G_MARS_ELEVATION_MAP',
53 - 'G_MARS_ELEVATION_MAP' => 'G_MARS_ELEVATION_MAP',
54 -
55 - 'mars-infrared' => 'G_MARS_INFRARED_MAP',
56 - 'G_MARS_INFRARED_MAP' => 'G_MARS_INFRARED_MAP',
57 - );
58 -
59 - private static $overlayData = array(
60 - 'photos' => '0',
61 - 'videos' => '1',
62 - 'wikipedia' => '2',
63 - 'webcams' => '3'
64 - );
65 -
66 - /**
67 - * Returns the Google Map type (defined in MapsGoogleMaps::$mapTypes)
68 - * for the provided a general map type. When no match is found, false
69 - * will be returned.
70 - *
71 - * @param string $type
72 - * @param boolean $restoreAsDefault
73 - * @return string or false
74 - */
75 - public static function getGMapType($type, $restoreAsDefault = false) {
76 - global $egMapsGoogleMapsType;
77 - $typeIsValid = array_key_exists($type, self::$mapTypes);
78 -
79 - if ($typeIsValid) {
80 - return self::$mapTypes[ $type ];
81 - }
82 - else {
83 - if ($restoreAsDefault) {
84 - return self::$mapTypes[ $egMapsGoogleMapsType ];
85 - }
86 - else {
87 - return false;
88 - }
89 - }
90 - }
91 -
92 - /**
93 - * Build up a csv string with the controls, to be outputted as a JS array
94 - *
95 - * @param array $controls
96 - * @return csv string
97 - */
98 - public static function createControlsString(array $controls) {
99 - global $egMapsGMapControls;
100 - return MapsMapper::createJSItemsString($controls, $egMapsGMapControls);
101 - }
102 -
103 - /**
104 - * Retuns an array holding the default parameters and their values.
105 - *
106 - * @return array
107 - */
108 - public static function getDefaultParams() {
109 - global $egMapsGoogleAutozoom;
110 - return array
111 - (
112 - 'type' => '',
113 - 'types' => '',
114 - 'class' => 'pmap',
115 - 'autozoom' => $egMapsGoogleAutozoom ? 'on' : 'off',
116 - 'earth' => '',
117 - 'style' => '',
118 - 'overlays' => ''
119 - );
120 - }
121 -
122 - /**
123 - * Add references to the Google Maps API and required JS file to the provided output
124 - *
125 - * @param string $output
126 - */
127 - public static function addGMapDependencies(&$output) {
128 - global $wgJsMimeType, $wgLang;
129 - global $egGoogleMapsKey, $egMapsScriptPath, $egGoogleMapsOnThisPage, $egMapsStyleVersion;
130 -
131 - if (empty($egGoogleMapsOnThisPage)) {
132 - $egGoogleMapsOnThisPage = 0;
133 -
134 - MapsGoogleMapsUtils::validateGoogleMapsKey();
135 -
136 - // TODO: use strbuilder for performance gain?
137 - $output .= "<script src='http://maps.google.com/maps?file=api&v=2&key=$egGoogleMapsKey&hl={$wgLang->getCode()}' type='$wgJsMimeType'></script>
138 - <script type='$wgJsMimeType' src='$egMapsScriptPath/GoogleMaps/GoogleMapFunctions.js?$egMapsStyleVersion'></script>
139 - <script type='$wgJsMimeType'>window.unload = GUnload;</script>";
140 - }
141 - }
142 -
143 - /**
144 - * Retuns a boolean as string, true if $autozoom is on or yes.
145 - *
146 - * @param string $autozoom
147 - * @return string
148 - */
149 - public static function getAutozoomJSValue($autozoom) {
150 - return MapsMapper::getJSBoolValue(in_array($autozoom, array('on', 'yes')));
151 - }
152 -
153 - /**
154 - * Returns a JS items string with the provided types. The earth type will
155 - * be added to it when it's not present and $enableEarth is true. If there are
156 - * no types, the default will be used.
157 - *
158 - * @param array $types
159 - * @param boolean $enableEarth
160 - * @return string
161 - */
162 - public static function createTypesString(array &$types) {
163 - global $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid;
164 -
165 - $types = MapsMapper::getValidTypes($types, $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid, array(__CLASS__, 'getGMapType'));
166 -
167 - return MapsMapper::createJSItemsString($types, null, false, false);
168 - }
169 -
170 - /**
171 - * This function ensures backward compatibility with Semantic Google Maps and other extensions
172 - * using $wgGoogleMapsKey instead of $egGoogleMapsKey.
173 - */
174 - public static function validateGoogleMapsKey() {
175 - global $egGoogleMapsKey, $wgGoogleMapsKey;
176 -
177 - if (isset($wgGoogleMapsKey)){
178 - if (strlen(trim($egGoogleMapsKey)) < 1) $egGoogleMapsKey = $wgGoogleMapsKey;
179 - }
180 - }
181 -
182 - /**
183 - * Adds the needed output for the overlays control.
184 - *
185 - * @param string $output
186 - * @param string $mapName
187 - * @param string $overlays
188 - * @param string $controls
189 - */
190 - public static function addOverlayOutput(&$output, $mapName, $overlays, $controls) {
191 - global $egMapsGMapOverlays, $egMapsGoogleOverlLoaded, $wgJsMimeType;
192 -
193 - // Check to see if there is an overlays control.
194 - $hasOverlayControl = in_string('overlays', $controls);
195 -
196 - $overlayNames = array_keys(self::$overlayData);
197 -
198 - // Create the overlays array, and use the default in case no overlays have been provided.
199 - if (strlen(trim($overlays)) < 1) {
200 - $overlays = $egMapsGMapOverlays;
201 - } else {
202 - MapsMapper::enforceArrayValues($overlays);
203 - $validOverlays = array();
204 - foreach ($overlays as $overlay) {
205 - $segements = explode('-', $overlay);
206 - $name = $segements[0];
207 -
208 - if (in_array($name, $overlayNames)) {
209 - $isOn = count($segements) > 1 ? $segements[1] : '0';
210 - $validOverlays[$name] = $isOn == '1';
211 - }
212 - }
213 - $overlays = $validOverlays;
214 - }
215 -
216 - // If there are no overlays or there is no control to hold them, don't bother the rest.
217 - if(!$hasOverlayControl || count($overlays) < 1) return;
218 -
219 - // If the overlays JS and CSS has not yet loaded, do it.
220 - if (empty($egMapsGoogleOverlLoaded)) {
221 - $egMapsGoogleOverlLoaded = true;
222 - MapsGoogleMapsUtils::addOverlayCss($output);
223 - }
224 -
225 - // Add the inputs for the overlays.
226 - $addedOverlays = array();
227 - $overlayHtml = '';
228 - $onloadFunctions = '';
229 - foreach ($overlays as $overlay => $isOn) {
230 - $overlay = strtolower($overlay);
231 -
232 - if (in_array($overlay, $overlayNames)) {
233 - if (! in_array($overlay, $addedOverlays)) {
234 - $addedOverlays[] = $overlay;
235 - $label = wfMsg('maps_' . $overlay);
236 - $urlNr = self::$overlayData[$overlay];
237 - $overlayHtml .= "<input id='$mapName-overlay-box-$overlay' name='$mapName-overlay-box' type='checkbox' onclick='switchGLayer(GMaps[\"$mapName\"], this.checked, GOverlays[$urlNr])' /> $label <br />";
238 - if ($isOn) {
239 - $onloadFunctions .= "<script type='$wgJsMimeType'>addOnloadHook( initiateGOverlay('$mapName-overlay-box-$overlay', '$mapName', $urlNr) );</script>";
240 - }
241 - }
242 - }
243 - }
244 -
245 - $output .=<<<END
246 -<script type='$wgJsMimeType'>var timer_$mapName;</script>
247 -<div class='outer-more' id='$mapName-outer-more'><form action=''><div class='more-box' id='$mapName-more-box'>
248 -$overlayHtml
249 -</div></form></div>
250 -END;
251 -
252 - return $onloadFunctions;
253 - }
254 -
255 - /**
256 - *
257 - *
258 - * @param $output
259 - * @return unknown_type
260 - */
261 - private static function addOverlayCss(&$output) {
262 - $css =<<<END
263 -
264 -<style type="text/css">
265 -.inner-more {
266 - text-align:center;
267 - font-size:12px;
268 - background-color: #fff;
269 - color: #000;
270 - border: 1px solid #fff;
271 - border-right-color: #b0b0b0;
272 - border-bottom-color: #c0c0c0;
273 - width:7em;
274 - cursor: pointer;
275 -}
276 -
277 -.inner-more.highlight {
278 - font-weight: bold;
279 - border: 1px solid #483D8B;
280 - border-right-color: #6495ed;
281 - border-bottom-color: #6495ed;
282 -}
283 -
284 -.more-box { position:absolute;
285 - top:25px; left:0px;
286 - margin-top:-1px;
287 - font-size:12px;
288 - padding: 6px 4px;
289 - width:120px;
290 - background-color: #fff;
291 - color: #000;
292 - border: 1px solid gray;
293 - border-top:1px solid #e2e2e2;
294 - display: none;
295 - cursor:default;
296 -}
297 -
298 -.more-box.highlight {
299 - width:119px;
300 - border-width:2px;
301 -}
302 -</style>
303 -
304 -END;
305 -
306 - $output .= preg_replace('/\s+/m', ' ', $css);
307 - }
308 -
309 -}
\ No newline at end of file
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php
@@ -20,7 +20,7 @@
2121 */
2222 final class MapsGoogleMapsDispPoint extends MapsBasePointMap {
2323
24 - public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME;
 24+ public $serviceName = MapsGoogleMaps::SERVICE_NAME;
2525
2626 /**
2727 * @see MapsBaseMap::setMapSettings()
@@ -29,12 +29,21 @@
3030 protected function setMapSettings() {
3131 global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix;
3232
33 - $this->defaultParams = MapsGoogleMapsUtils::getDefaultParams();
34 -
3533 $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
3634 $this->defaultZoom = $egMapsGoogleMapsZoom;
3735
3836 $this->markerStringFormat = 'getGMarkerData(lat, lon, "title", "label", "icon")';
 37+
 38+ $this->spesificParameters = array(
 39+ 'overlays' => array(
 40+ 'aliases' => array(),
 41+ 'criteria' => array(),
 42+ 'default' => ''
 43+ ),
 44+ 'zoom' => array(
 45+ 'default' => '',
 46+ )
 47+ );
3948 }
4049
4150 /**
@@ -44,7 +53,7 @@
4554 protected function doMapServiceLoad() {
4655 global $egGoogleMapsOnThisPage;
4756
48 - MapsGoogleMapsUtils::addGMapDependencies($this->output);
 57+ MapsGoogleMaps::addGMapDependencies($this->output);
4958 $egGoogleMapsOnThisPage++;
5059
5160 $this->elementNr = $egGoogleMapsOnThisPage;
@@ -57,17 +66,17 @@
5867 public function addSpecificMapHTML() {
5968 global $wgJsMimeType;
6069
61 - $this->type = MapsGoogleMapsUtils::getGMapType($this->type, true);
 70+ $this->type = MapsGoogleMaps::getGMapType($this->type, true);
6271
63 - $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls);
 72+ $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls));
6473
65 - $onloadFunctions = MapsGoogleMapsUtils::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls);
 74+ $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls);
6675
67 - $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom);
 76+ $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom);
6877
6978 $this->types = explode(",", $this->types);
7079
71 - $typesString = MapsGoogleMapsUtils::createTypesString($this->types);
 80+ $typesString = MapsGoogleMaps::createTypesString($this->types);
7281
7382 $this->output .=<<<END
7483
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php
@@ -15,7 +15,7 @@
1616
1717 final class MapsGoogleMapsDispMap extends MapsBaseMap {
1818
19 - public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME;
 19+ public $serviceName = MapsGoogleMaps::SERVICE_NAME;
2020
2121 /**
2222 * @see MapsBaseMap::setMapSettings()
@@ -24,10 +24,16 @@
2525 protected function setMapSettings() {
2626 global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix;
2727
28 - $this->defaultParams = MapsGoogleMapsUtils::getDefaultParams();
29 -
3028 $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
3129 $this->defaultZoom = $egMapsGoogleMapsZoom;
 30+
 31+ $this->spesificParameters = array(
 32+ 'overlays' => array(
 33+ 'aliases' => array(),
 34+ 'criteria' => array(),
 35+ 'default' => ''
 36+ ),
 37+ );
3238 }
3339
3440 /**
@@ -37,7 +43,7 @@
3844 protected function doMapServiceLoad() {
3945 global $egGoogleMapsOnThisPage;
4046
41 - MapsGoogleMapsUtils::addGMapDependencies($this->output);
 47+ MapsGoogleMaps::addGMapDependencies($this->output);
4248 $egGoogleMapsOnThisPage++;
4349
4450 $this->elementNr = $egGoogleMapsOnThisPage;
@@ -50,17 +56,17 @@
5157 public function addSpecificMapHTML() {
5258 global $wgJsMimeType;
5359
54 - $this->type = MapsGoogleMapsUtils::getGMapType($this->type, true);
 60+ $this->type = MapsGoogleMaps::getGMapType($this->type, true);
 61+
 62+ $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls));
5563
56 - $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls);
 64+ $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls);
5765
58 - $onloadFunctions = MapsGoogleMapsUtils::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls);
 66+ $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom);
5967
60 - $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom);
61 -
6268 $this->types = explode(",", $this->types);
6369
64 - $typesString = MapsGoogleMapsUtils::createTypesString($this->types);
 70+ $typesString = MapsGoogleMaps::createTypesString($this->types);
6571
6672 $this->output .=<<<END
6773
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
@@ -26,16 +26,340 @@
2727 'display_map' => array('class' => 'MapsGoogleMapsDispMap', 'file' => 'GoogleMaps/Maps_GoogleMapsDispMap.php', 'local' => true),
2828 ),
2929 'classes' => array(
30 - array('class' => 'MapsGoogleMapsUtils', 'file' => 'GoogleMaps/Maps_GoogleMapsUtils.php', 'local' => true)
 30+ array('class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true)
3131 ),
3232 'aliases' => array('google', 'googlemap', 'gmap', 'gmaps'),
33 - 'parameters' => array(
34 - 'type' => array('map-type', 'map type'),
35 - 'types' => array('map-types', 'map types'),
36 - 'earth' => array(),
37 - 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom'),
38 - 'class' => array(),
39 - 'style' => array(),
40 - 'overlays' => array()
41 - )
42 - );
\ No newline at end of file
 33+ );
 34+
 35+/**
 36+ * Class for Google Maps initialization.
 37+ *
 38+ * @ingroup MapsGoogleMaps
 39+ *
 40+ * @author Jeroen De Dauw
 41+ */
 42+class MapsGoogleMaps {
 43+
 44+ const SERVICE_NAME = 'googlemaps';
 45+
 46+ public static function initialize() {
 47+ self::initializeParams();
 48+ }
 49+
 50+ private static function initializeParams() {
 51+ global $egMapsServices, $egMapsGoogleMapsType, $egMapsGoogleMapsTypes, $egMapsGoogleAutozoom, $egMapsGoogleMapsZoom, $egMapsGMapControls;
 52+
 53+ $allowedTypes = MapsGoogleMaps::getTypeNames();
 54+
 55+ $egMapsServices[self::SERVICE_NAME]['parameters'] = array(
 56+ 'zoom' => array(
 57+ 'default' => $egMapsGoogleMapsZoom,
 58+ ),
 59+ 'controls' => array(
 60+ 'criteria' => array(), // TODO
 61+ 'default' => implode(',', $egMapsGMapControls)
 62+ ),
 63+ 'type' => array (
 64+ 'aliases' => array('map-type', 'map type'),
 65+ 'criteria' => array(
 66+ 'in_array' => array($allowedTypes)
 67+ ),
 68+ 'default' => $egMapsGoogleMapsType
 69+ ),
 70+ 'types' => array (
 71+ 'aliases' => array('map-types', 'map types'),
 72+ 'criteria' => array(
 73+ 'all_in_array' => array($allowedTypes)
 74+ ),
 75+ 'default' => implode(',', $egMapsGoogleMapsTypes)
 76+ ),
 77+ 'autozoom' => array(
 78+ 'aliases' => array('auto zoom', 'mouse zoom', 'mousezoom'),
 79+ 'criteria' => array(
 80+ 'in_array' => array('on', 'off', 'yes', 'no')
 81+ ),
 82+ 'default' => $egMapsGoogleAutozoom ? 'on' : 'off'
 83+ ),
 84+ 'class' => array(
 85+ 'aliases' => array(),
 86+ 'criteria' => array(),
 87+ 'default' => ''
 88+ ),
 89+ 'style' => array(
 90+ 'aliases' => array(),
 91+ 'criteria' => array(),
 92+ 'default' => ''
 93+ ),
 94+ );
 95+ }
 96+
 97+ // http://code.google.com/apis/maps/documentation/reference.html#GMapType.G_NORMAL_MAP
 98+ // TODO: Add a true alliasing system? Might be overkill.
 99+ private static $mapTypes = array(
 100+ 'normal' => 'G_NORMAL_MAP',
 101+ 'G_NORMAL_MAP' => 'G_NORMAL_MAP',
 102+
 103+ 'satellite' => 'G_SATELLITE_MAP',
 104+ 'G_SATELLITE_MAP' => 'G_SATELLITE_MAP',
 105+
 106+ 'hybrid' => 'G_HYBRID_MAP',
 107+ 'G_HYBRID_MAP' => 'G_HYBRID_MAP',
 108+
 109+ 'terrain' => 'G_PHYSICAL_MAP',
 110+ 'physical' => 'G_PHYSICAL_MAP',
 111+ 'G_PHYSICAL_MAP' => 'G_PHYSICAL_MAP',
 112+
 113+ 'earth' => 'G_SATELLITE_3D_MAP',
 114+ 'G_SATELLITE_3D_MAP' => 'G_SATELLITE_3D_MAP',
 115+
 116+ 'sky' => 'G_SKY_VISIBLE_MAP',
 117+ 'G_SKY_VISIBLE_MAP' => 'G_SKY_VISIBLE_MAP',
 118+
 119+ 'moon' => 'G_MOON_VISIBLE_MAP',
 120+ 'G_MOON_VISIBLE_MAP' => 'G_MOON_VISIBLE_MAP',
 121+
 122+ 'moon-elevation' => 'G_MOON_ELEVATION_MAP',
 123+ 'G_MOON_ELEVATION_MAP' => 'G_MOON_ELEVATION_MAP',
 124+
 125+ 'mars' => 'G_MARS_VISIBLE_MAP',
 126+ 'G_MARS_VISIBLE_MAP' => 'G_MARS_VISIBLE_MAP',
 127+
 128+ 'mars-elevation' => 'G_MARS_ELEVATION_MAP',
 129+ 'G_MARS_ELEVATION_MAP' => 'G_MARS_ELEVATION_MAP',
 130+
 131+ 'mars-infrared' => 'G_MARS_INFRARED_MAP',
 132+ 'G_MARS_INFRARED_MAP' => 'G_MARS_INFRARED_MAP',
 133+ );
 134+
 135+ private static $overlayData = array(
 136+ 'photos' => '0',
 137+ 'videos' => '1',
 138+ 'wikipedia' => '2',
 139+ 'webcams' => '3'
 140+ );
 141+
 142+ /**
 143+ * Returns the names of all supported map types.
 144+ *
 145+ * @return array
 146+ */
 147+ public static function getTypeNames() {
 148+ return array_keys(self::$mapTypes);
 149+ }
 150+
 151+ /**
 152+ * Returns the Google Map type (defined in MapsGoogleMaps::$mapTypes)
 153+ * for the provided a general map type. When no match is found, false
 154+ * will be returned.
 155+ *
 156+ * @param string $type
 157+ * @param boolean $restoreAsDefault
 158+ *
 159+ * @return string or false
 160+ */
 161+ public static function getGMapType($type, $restoreAsDefault = false) {
 162+ global $egMapsGoogleMapsType;
 163+ $typeIsValid = array_key_exists($type, self::$mapTypes);
 164+
 165+ if ($typeIsValid) {
 166+ return self::$mapTypes[ $type ];
 167+ }
 168+ else {
 169+ if ($restoreAsDefault) {
 170+ return self::$mapTypes[ $egMapsGoogleMapsType ];
 171+ }
 172+ else {
 173+ return false;
 174+ }
 175+ }
 176+ }
 177+
 178+ /**
 179+ * Add references to the Google Maps API and required JS file to the provided output
 180+ *
 181+ * @param string $output
 182+ */
 183+ public static function addGMapDependencies(&$output) {
 184+ global $wgJsMimeType, $wgLang;
 185+ global $egGoogleMapsKey, $egMapsScriptPath, $egGoogleMapsOnThisPage, $egMapsStyleVersion;
 186+
 187+ if (empty($egGoogleMapsOnThisPage)) {
 188+ $egGoogleMapsOnThisPage = 0;
 189+
 190+ MapsGoogleMaps::validateGoogleMapsKey();
 191+
 192+ // TODO: use strbuilder for performance gain?
 193+ $output .= "<script src='http://maps.google.com/maps?file=api&v=2&key=$egGoogleMapsKey&hl={$wgLang->getCode()}' type='$wgJsMimeType'></script>
 194+ <script type='$wgJsMimeType' src='$egMapsScriptPath/GoogleMaps/GoogleMapFunctions.js?$egMapsStyleVersion'></script>
 195+ <script type='$wgJsMimeType'>window.unload = GUnload;</script>";
 196+ }
 197+ }
 198+
 199+ /**
 200+ * Retuns a boolean as string, true if $autozoom is on or yes.
 201+ *
 202+ * @param string $autozoom
 203+ * @return string
 204+ */
 205+ public static function getAutozoomJSValue($autozoom) {
 206+ return MapsMapper::getJSBoolValue(in_array($autozoom, array('on', 'yes')));
 207+ }
 208+
 209+ /**
 210+ * Returns a JS items string with the provided types. The earth type will
 211+ * be added to it when it's not present and $enableEarth is true. If there are
 212+ * no types, the default will be used.
 213+ *
 214+ * @param array $types
 215+ * @param boolean $enableEarth
 216+ * @return string
 217+ */
 218+ public static function createTypesString(array &$types) {
 219+ global $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid;
 220+
 221+ $types = MapsMapper::getValidTypes($types, $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid, array(__CLASS__, 'getGMapType'));
 222+
 223+ return MapsMapper::createJSItemsString($types, null, false, false);
 224+ }
 225+
 226+ /**
 227+ * This function ensures backward compatibility with Semantic Google Maps and other extensions
 228+ * using $wgGoogleMapsKey instead of $egGoogleMapsKey.
 229+ */
 230+ public static function validateGoogleMapsKey() {
 231+ global $egGoogleMapsKey, $wgGoogleMapsKey;
 232+
 233+ if (isset($wgGoogleMapsKey)){
 234+ if (strlen(trim($egGoogleMapsKey)) < 1) $egGoogleMapsKey = $wgGoogleMapsKey;
 235+ }
 236+ }
 237+
 238+ /**
 239+ * Adds the needed output for the overlays control.
 240+ *
 241+ * @param string $output
 242+ * @param string $mapName
 243+ * @param string $overlays
 244+ * @param string $controls
 245+ */
 246+ public static function addOverlayOutput(&$output, $mapName, $overlays, $controls) {
 247+ global $egMapsGMapOverlays, $egMapsGoogleOverlLoaded, $wgJsMimeType;
 248+
 249+ // Check to see if there is an overlays control.
 250+ $hasOverlayControl = in_string('overlays', $controls);
 251+
 252+ $overlayNames = array_keys(self::$overlayData);
 253+
 254+ // Create the overlays array, and use the default in case no overlays have been provided.
 255+ if (strlen(trim($overlays)) < 1) {
 256+ $overlays = $egMapsGMapOverlays;
 257+ } else {
 258+ MapsMapper::enforceArrayValues($overlays);
 259+ $validOverlays = array();
 260+ foreach ($overlays as $overlay) {
 261+ $segements = explode('-', $overlay);
 262+ $name = $segements[0];
 263+
 264+ if (in_array($name, $overlayNames)) {
 265+ $isOn = count($segements) > 1 ? $segements[1] : '0';
 266+ $validOverlays[$name] = $isOn == '1';
 267+ }
 268+ }
 269+ $overlays = $validOverlays;
 270+ }
 271+
 272+ // If there are no overlays or there is no control to hold them, don't bother the rest.
 273+ if(!$hasOverlayControl || count($overlays) < 1) return;
 274+
 275+ // If the overlays JS and CSS has not yet loaded, do it.
 276+ if (empty($egMapsGoogleOverlLoaded)) {
 277+ $egMapsGoogleOverlLoaded = true;
 278+ MapsGoogleMaps::addOverlayCss($output);
 279+ }
 280+
 281+ // Add the inputs for the overlays.
 282+ $addedOverlays = array();
 283+ $overlayHtml = '';
 284+ $onloadFunctions = '';
 285+ foreach ($overlays as $overlay => $isOn) {
 286+ $overlay = strtolower($overlay);
 287+
 288+ if (in_array($overlay, $overlayNames)) {
 289+ if (! in_array($overlay, $addedOverlays)) {
 290+ $addedOverlays[] = $overlay;
 291+ $label = wfMsg('maps_' . $overlay);
 292+ $urlNr = self::$overlayData[$overlay];
 293+ $overlayHtml .= "<input id='$mapName-overlay-box-$overlay' name='$mapName-overlay-box' type='checkbox' onclick='switchGLayer(GMaps[\"$mapName\"], this.checked, GOverlays[$urlNr])' /> $label <br />";
 294+ if ($isOn) {
 295+ $onloadFunctions .= "<script type='$wgJsMimeType'>addOnloadHook( initiateGOverlay('$mapName-overlay-box-$overlay', '$mapName', $urlNr) );</script>";
 296+ }
 297+ }
 298+ }
 299+ }
 300+
 301+ $output .=<<<END
 302+<script type='$wgJsMimeType'>var timer_$mapName;</script>
 303+<div class='outer-more' id='$mapName-outer-more'><form action=''><div class='more-box' id='$mapName-more-box'>
 304+$overlayHtml
 305+</div></form></div>
 306+END;
 307+
 308+ return $onloadFunctions;
 309+ }
 310+
 311+ /**
 312+ *
 313+ *
 314+ * @param $output
 315+ * @return unknown_type
 316+ */
 317+ private static function addOverlayCss(&$output) {
 318+ $css =<<<END
 319+
 320+<style type="text/css">
 321+.inner-more {
 322+ text-align:center;
 323+ font-size:12px;
 324+ background-color: #fff;
 325+ color: #000;
 326+ border: 1px solid #fff;
 327+ border-right-color: #b0b0b0;
 328+ border-bottom-color: #c0c0c0;
 329+ width:7em;
 330+ cursor: pointer;
 331+}
 332+
 333+.inner-more.highlight {
 334+ font-weight: bold;
 335+ border: 1px solid #483D8B;
 336+ border-right-color: #6495ed;
 337+ border-bottom-color: #6495ed;
 338+}
 339+
 340+.more-box { position:absolute;
 341+ top:25px; left:0px;
 342+ margin-top:-1px;
 343+ font-size:12px;
 344+ padding: 6px 4px;
 345+ width:120px;
 346+ background-color: #fff;
 347+ color: #000;
 348+ border: 1px solid gray;
 349+ border-top:1px solid #e2e2e2;
 350+ display: none;
 351+ cursor:default;
 352+}
 353+
 354+.more-box.highlight {
 355+ width:119px;
 356+ border-width:2px;
 357+}
 358+</style>
 359+
 360+END;
 361+
 362+ $output .= preg_replace('/\s+/m', ' ', $css);
 363+ }
 364+
 365+}
 366+
\ No newline at end of file

Comments

#Comment by Siebrand (talk | contribs)   11:58, 29 November 2009

No idea what you did, but on translatewiki.net all map displays are gone now - no backward compatibility handling? Examples:

#Comment by Siebrand (talk | contribs)   12:00, 29 November 2009

Hmm, ignore that - sorry. Someone had disabled the extension for some reason, and it took a while to load the OSM tiles.

#Comment by Jeroen De Dauw (talk | contribs)   15:21, 29 November 2009

Although I try to get every commit I make to be relativity stable, I advice against using the latest SVN code. That's asking for troubles IMO.

#Comment by Siebrand (talk | contribs)   15:23, 29 November 2009

Someone has to test it sometime - unless you would want us to rely on your statement that the release versions are bug free? :)

#Comment by Jeroen De Dauw (talk | contribs)   15:29, 29 November 2009

I really appreciate any feedback on commits I make, but I guess I'm a little uncomfortable with them being put onto wiki's the size of translatewiki right away (I wouldn't do it if it was my wiki). If you are willing to risk it though, great for me :)

Status & tagging log