Index: trunk/extensions/Maps/Maps_MapFeature.php |
— | — | @@ -37,9 +37,7 @@ |
38 | 38 | */ |
39 | 39 | protected abstract function addSpecificMapHTML(); |
40 | 40 | |
41 | | - public $serviceName; |
42 | | - |
43 | | - protected $defaultParams = array(); |
| 41 | + public $serviceName; |
44 | 42 | |
45 | 43 | protected $defaultZoom; |
46 | 44 | |
— | — | @@ -52,32 +50,62 @@ |
53 | 51 | protected $centre_lon; |
54 | 52 | |
55 | 53 | protected $output = ''; |
56 | | - protected $errors = array(); |
| 54 | + protected $errorList; |
57 | 55 | |
| 56 | + protected $featureParameters = array(); |
| 57 | + protected $spesificParameters = array(); |
| 58 | + |
58 | 59 | /** |
59 | 60 | * Validates and corrects the provided map properties, and the sets them as class fields. |
60 | 61 | * |
61 | 62 | * @param array $mapProperties |
62 | 63 | * @param string $className |
| 64 | + * |
| 65 | + * @return boolean Indicates whether the map should be shown or not. |
63 | 66 | */ |
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; |
70 | 69 | |
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; |
73 | 102 | foreach($mapProperties as $paramName => $paramValue) { |
74 | 103 | if (! property_exists($className, $paramName)) { |
75 | 104 | $this->{$paramName} = $paramValue; |
76 | 105 | } |
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 | + } |
82 | 110 | } |
83 | 111 | |
84 | 112 | /** |
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 @@ |
21 | 21 | */ |
22 | 22 | class MapsYahooMapsDispPoint extends MapsBasePointMap { |
23 | 23 | |
24 | | - public $serviceName = MapsYahooMapsUtils::SERVICE_NAME; |
| 24 | + public $serviceName = MapsYahooMaps::SERVICE_NAME; |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @see MapsBaseMap::setFormInputSettings() |
— | — | @@ -29,22 +29,26 @@ |
30 | 30 | protected function setMapSettings() { |
31 | 31 | global $egMapsYahooMapsZoom, $egMapsYahooMapsPrefix; |
32 | 32 | |
33 | | - $this->defaultParams = MapsYahooMapsUtils::getDefaultParams(); |
34 | | - |
35 | 33 | $this->elementNamePrefix = $egMapsYahooMapsPrefix; |
36 | 34 | $this->defaultZoom = $egMapsYahooMapsZoom; |
37 | 35 | |
38 | 36 | $this->markerStringFormat = 'getYMarkerData(lat, lon, "title", "label", "icon")'; |
| 37 | + |
| 38 | + $this->spesificParameters = array( |
| 39 | + 'zoom' => array( |
| 40 | + 'default' => '', |
| 41 | + ) |
| 42 | + ); |
39 | 43 | } |
40 | 44 | |
41 | 45 | /** |
42 | 46 | * @see MapsBaseMap::doMapServiceLoad() |
43 | 47 | * |
44 | | - */ |
| 48 | + */ |
45 | 49 | protected function doMapServiceLoad() { |
46 | 50 | global $egYahooMapsOnThisPage; |
47 | 51 | |
48 | | - MapsYahooMapsUtils::addYMapDependencies($this->output); |
| 52 | + MapsYahooMaps::addYMapDependencies($this->output); |
49 | 53 | $egYahooMapsOnThisPage++; |
50 | 54 | |
51 | 55 | $this->elementNr = $egYahooMapsOnThisPage; |
— | — | @@ -57,15 +61,15 @@ |
58 | 62 | public function addSpecificMapHTML() { |
59 | 63 | global $wgJsMimeType; |
60 | 64 | |
61 | | - $this->type = MapsYahooMapsUtils::getYMapType($this->type, true); |
| 65 | + $this->type = MapsYahooMaps::getYMapType($this->type, true); |
62 | 66 | |
63 | | - $this->controls = MapsYahooMapsUtils::createControlsString($this->controls); |
| 67 | + $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls)); |
64 | 68 | |
65 | | - $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom); |
| 69 | + $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); |
66 | 70 | |
67 | | - $this->types = explode(",", $this->types); |
| 71 | + $this->types = explode(',', $this->types); |
68 | 72 | |
69 | | - $typesString = MapsYahooMapsUtils::createTypesString($this->types); |
| 73 | + $typesString = MapsYahooMaps::createTypesString($this->types); |
70 | 74 | |
71 | 75 | $this->output .= <<<END |
72 | 76 | <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 @@ |
16 | 16 | |
17 | 17 | class MapsYahooMapsDispMap extends MapsBaseMap { |
18 | 18 | |
19 | | - public $serviceName = MapsYahooMapsUtils::SERVICE_NAME; |
| 19 | + public $serviceName = MapsYahooMaps::SERVICE_NAME; |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @see MapsBaseMap::setFormInputSettings() |
— | — | @@ -24,8 +24,6 @@ |
25 | 25 | protected function setMapSettings() { |
26 | 26 | global $egMapsYahooMapsZoom, $egMapsYahooMapsPrefix; |
27 | 27 | |
28 | | - $this->defaultParams = MapsYahooMapsUtils::getDefaultParams(); |
29 | | - |
30 | 28 | $this->elementNamePrefix = $egMapsYahooMapsPrefix; |
31 | 29 | $this->defaultZoom = $egMapsYahooMapsZoom; |
32 | 30 | } |
— | — | @@ -37,7 +35,7 @@ |
38 | 36 | protected function doMapServiceLoad() { |
39 | 37 | global $egYahooMapsOnThisPage; |
40 | 38 | |
41 | | - MapsYahooMapsUtils::addYMapDependencies($this->output); |
| 39 | + MapsYahooMaps::addYMapDependencies($this->output); |
42 | 40 | $egYahooMapsOnThisPage++; |
43 | 41 | |
44 | 42 | $this->elementNr = $egYahooMapsOnThisPage; |
— | — | @@ -50,15 +48,15 @@ |
51 | 49 | public function addSpecificMapHTML() { |
52 | 50 | global $wgJsMimeType; |
53 | 51 | |
54 | | - $this->type = MapsYahooMapsUtils::getYMapType($this->type, true); |
| 52 | + $this->type = MapsYahooMaps::getYMapType($this->type, true); |
55 | 53 | |
56 | | - $this->controls = MapsYahooMapsUtils::createControlsString($this->controls); |
| 54 | + $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls)); |
57 | 55 | |
58 | | - $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom); |
| 56 | + $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); |
59 | 57 | |
60 | 58 | $this->types = explode(",", $this->types); |
61 | 59 | |
62 | | - $typesString = MapsYahooMapsUtils::createTypesString($this->types); |
| 60 | + $typesString = MapsYahooMaps::createTypesString($this->types); |
63 | 61 | |
64 | 62 | $this->output .= <<<END |
65 | 63 | <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 @@ |
27 | 27 | 'display_map' => array('class' => 'MapsYahooMapsDispMap', 'file' => 'YahooMaps/Maps_YahooMapsDispMap.php', 'local' => true), |
28 | 28 | ), |
29 | 29 | 'classes' => array( |
30 | | - array('class' => 'MapsYahooMapsUtils', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true) |
| 30 | + array('class' => 'MapsYahooMaps', 'file' => 'YahooMaps/Maps_YahooMapsUtils.php', 'local' => true) |
31 | 31 | ), |
32 | 32 | 'aliases' => array('yahoo', 'yahoomap', 'ymap', 'ymaps'), |
33 | 33 | 'parameters' => array( |
— | — | @@ -34,4 +34,142 @@ |
35 | 35 | 'types' => array('map-types', 'map types'), |
36 | 36 | 'autozoom' => array('auto zoom', 'mouse zoom', 'mousezoom') |
37 | 37 | ) |
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 @@ |
34 | 34 | |
35 | 35 | // Parameter errors. Used when strict parameter validation is turned on. |
36 | 36 | 'maps_error_parameters' => 'The following errors have been detected in your syntax', |
| 37 | + 'maps_error_unknown_argument' => '$1 is not a valid parameter.', |
37 | 38 | 'maps_error_invalid_argument' => 'The value $1 is not valid for parameter $2.', |
38 | 39 | 'maps_error_empty_argument' => 'Parameter $1 can not have an empty value.', |
39 | 40 | 'maps_error_required_missing' => 'The required parameter $1 is not provided.', |
40 | 41 | 'maps_error_must_be_number' => 'Parameter $1 can only be a number.', |
41 | 42 | 'maps_error_ivalid_range' => 'Parameter $1 must be between $2 and $3.', |
| 43 | + 'maps_error_accepts_only' => 'Parameter $1 can only be $2.', |
42 | 44 | |
43 | 45 | // Mapping services |
44 | 46 | 'maps_googlemaps' => 'Google Maps', |
Index: trunk/extensions/Maps/Maps_Settings.php |
— | — | @@ -123,7 +123,7 @@ |
124 | 124 | # Maps_ERRORS_WARN : Maps will make the best of the imput it got, but will show warnings for omitted coordinates. |
125 | 125 | # Maps_ERRORS_SHOW : Maps will make the best of the imput it got, but will show a list of all errors. |
126 | 126 | # 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; |
128 | 128 | |
129 | 129 | # Integer. The default width and height of a map. These values will only be used when the user does not provide them. |
130 | 130 | $egMapsMapWidth = 600; |
— | — | @@ -136,14 +136,24 @@ |
137 | 137 | 'height' => array( 100, 1000 ), |
138 | 138 | ); |
139 | 139 | |
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. |
141 | 142 | $egMapsMapLat = '1'; |
142 | 143 | $egMapsMapLon = '1'; |
143 | 144 | |
| 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 = ''; |
144 | 149 | |
| 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 = ''; |
145 | 153 | |
146 | 154 | |
147 | 155 | |
| 156 | + |
| 157 | + |
148 | 158 | # Specific map properties configuration |
149 | 159 | |
150 | 160 | # Google maps |
Index: trunk/extensions/Maps/Maps_ParamValidator.php |
— | — | @@ -22,11 +22,7 @@ |
23 | 23 | */ |
24 | 24 | final class MapsParamValidator { |
25 | 25 | |
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 |
31 | 27 | |
32 | 28 | /** |
33 | 29 | * @var boolean Indicates whether parameters not found in the criteria list |
— | — | @@ -34,7 +30,25 @@ |
35 | 31 | */ |
36 | 32 | public static $storeUnknownParameters = false; |
37 | 33 | |
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; |
39 | 53 | private $rawParameters = array(); |
40 | 54 | |
41 | 55 | private $valid = array(); |
— | — | @@ -46,10 +60,10 @@ |
47 | 61 | /** |
48 | 62 | * Sets the parameter criteria, used to valiate the parameters. |
49 | 63 | * |
50 | | - * @param array $parameterCriteria |
| 64 | + * @param array $parameterInfo |
51 | 65 | */ |
52 | | - public function setCriteria(array $parameterCriteria) { |
53 | | - $this->parameterCriteria = $parameterCriteria; |
| 66 | + public function setParameterInfo(array $parameterInfo) { |
| 67 | + $this->parameterInfo = $parameterInfo; |
54 | 68 | } |
55 | 69 | |
56 | 70 | /** |
— | — | @@ -65,59 +79,123 @@ |
66 | 80 | * Valides the raw parameters, and allocates them as valid, invalid or unknown. |
67 | 81 | * Errors are collected, and can be retrieved via getErrors. |
68 | 82 | * |
69 | | - * @return boolean Indicates whether there where any errors. |
| 83 | + * @return boolean Indicates whether there where no errors. |
70 | 84 | */ |
71 | 85 | 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. |
72 | 90 | 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)) { |
75 | 107 | |
76 | | - $validationResult = $this->validateParameter($paramName, $paramValue); |
| 108 | + $paramValue = $this->rawParameters[$paramName]; |
| 109 | + $validationErrors = $this->validateParameter($paramName, $paramValue); |
77 | 110 | |
78 | | - if ($validationResult === true) { |
| 111 | + if (count($validationErrors) == 0) { |
79 | 112 | $this->valid[$paramName] = $paramValue; |
80 | 113 | } |
81 | 114 | else { |
82 | 115 | $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']; |
84 | 124 | } |
| 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 | + } |
85 | 128 | } |
86 | | - else { |
87 | | - if ($storeUnknownParameters) $this->unknown[$paramName] = $paramValue; |
88 | | - $this->errors[] = array('type' => 'unknown', 'name' => $paramName); |
89 | | - } |
90 | 129 | } |
91 | 130 | |
92 | | - return count($this->errors) > 0; |
| 131 | + return count($this->errors) == 0; |
93 | 132 | } |
94 | 133 | |
95 | 134 | /** |
| 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 | + /** |
96 | 164 | * Valides the provided parameter by matching the value against the criteria for the name. |
97 | 165 | * |
98 | 166 | * @param string $name |
99 | 167 | * @param string $value |
100 | 168 | * |
101 | | - * @return true or string |
| 169 | + * @return array The errors that occured during validation. |
102 | 170 | */ |
103 | 171 | private function validateParameter($name, $value) { |
| 172 | + $errors = array(); |
104 | 173 | |
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; |
109 | 189 | } |
110 | 190 | |
111 | 191 | /** |
112 | 192 | * Changes the invalid parameters to their default values, and changes their state to valid. |
113 | | - * |
114 | | - * @param array $defaults |
115 | 193 | */ |
116 | | - public function correctInvalidParams(array $defaults) { |
| 194 | + public function correctInvalidParams() { |
117 | 195 | foreach($this->invalid as $paramName => $paramValue) { |
118 | 196 | |
119 | | - if(array_key_exists($paramName, $defaults)) { |
| 197 | + if(array_key_exists('default', $this->parameterInfo[$paramName])) { |
120 | 198 | unset($this->invalid[$paramName]); |
121 | | - $this->valid[$paramName] = $defaults[$defaults]; |
| 199 | + $this->valid[$paramName] = $this->parameterInfo[$paramName]['default']; |
122 | 200 | } |
123 | 201 | else { |
124 | 202 | throw new Exception('The default value for parameter ' . $paramName . ' is not set.'); |
— | — | @@ -131,16 +209,37 @@ |
132 | 210 | * @return array |
133 | 211 | */ |
134 | 212 | public function getValidParams() { |
135 | | - return $this->valid(); |
| 213 | + return $this->valid; |
136 | 214 | } |
137 | 215 | |
138 | 216 | /** |
| 217 | + * Returns the unknown parameters. |
| 218 | + * |
| 219 | + * @return array |
| 220 | + */ |
| 221 | + public static function getUnknownParams() { |
| 222 | + return $this->unknown; |
| 223 | + } |
| 224 | + |
| 225 | + /** |
139 | 226 | * Returns the errors. |
140 | 227 | * |
141 | 228 | * @return array |
142 | 229 | */ |
143 | 230 | public function getErrors() { |
144 | | - return $this->errors(); |
| 231 | + return $this->errors; |
145 | 232 | } |
146 | 233 | |
| 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 | + |
147 | 246 | } |
\ 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 @@ |
22 | 22 | */ |
23 | 23 | class MapsOpenLayersDispPoint extends MapsBasePointMap { |
24 | 24 | |
25 | | - public $serviceName = MapsOpenLayersUtils::SERVICE_NAME; |
| 25 | + public $serviceName = MapsOpenLayers::SERVICE_NAME; |
26 | 26 | |
27 | 27 | /** |
28 | 28 | * @see MapsBaseMap::setMapSettings() |
— | — | @@ -30,12 +30,16 @@ |
31 | 31 | protected function setMapSettings() { |
32 | 32 | global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix; |
33 | 33 | |
34 | | - $this->defaultParams = MapsOpenLayersUtils::getDefaultParams(); |
35 | | - |
36 | 34 | $this->elementNamePrefix = $egMapsOpenLayersPrefix; |
37 | 35 | $this->defaultZoom = $egMapsOpenLayersZoom; |
38 | 36 | |
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 | + ); |
40 | 44 | } |
41 | 45 | |
42 | 46 | /** |
— | — | @@ -45,7 +49,7 @@ |
46 | 50 | protected function doMapServiceLoad() { |
47 | 51 | global $egOpenLayersOnThisPage; |
48 | 52 | |
49 | | - MapsOpenLayersUtils::addOLDependencies($this->output); |
| 53 | + MapsOpenLayers::addOLDependencies($this->output); |
50 | 54 | $egOpenLayersOnThisPage++; |
51 | 55 | |
52 | 56 | $this->elementNr = $egOpenLayersOnThisPage; |
— | — | @@ -58,10 +62,10 @@ |
59 | 63 | public function addSpecificMapHTML() { |
60 | 64 | global $wgJsMimeType; |
61 | 65 | |
62 | | - $controlItems = MapsOpenLayersUtils::createControlsString($this->controls); |
| 66 | + $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls)); |
63 | 67 | |
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); |
66 | 70 | |
67 | 71 | $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div> |
68 | 72 | <script type='$wgJsMimeType'> /*<![CDATA[*/ |
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayersDispMap.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | |
17 | 17 | class MapsOpenLayersDispMap extends MapsBaseMap { |
18 | 18 | |
19 | | - public $serviceName = MapsOpenLayersUtils::SERVICE_NAME; |
| 19 | + public $serviceName = MapsOpenLayers::SERVICE_NAME; |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @see MapsBaseMap::setMapSettings() |
— | — | @@ -24,10 +24,8 @@ |
25 | 25 | protected function setMapSettings() { |
26 | 26 | global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix; |
27 | 27 | |
28 | | - $this->defaultParams = MapsOpenLayersUtils::getDefaultParams(); |
29 | | - |
30 | 28 | $this->elementNamePrefix = $egMapsOpenLayersPrefix; |
31 | | - $this->defaultZoom = $egMapsOpenLayersZoom; |
| 29 | + $this->defaultZoom = $egMapsOpenLayersZoom; |
32 | 30 | } |
33 | 31 | |
34 | 32 | /** |
— | — | @@ -37,7 +35,7 @@ |
38 | 36 | protected function doMapServiceLoad() { |
39 | 37 | global $egOpenLayersOnThisPage; |
40 | 38 | |
41 | | - MapsOpenLayersUtils::addOLDependencies($this->output); |
| 39 | + MapsOpenLayers::addOLDependencies($this->output); |
42 | 40 | $egOpenLayersOnThisPage++; |
43 | 41 | |
44 | 42 | $this->elementNr = $egOpenLayersOnThisPage; |
— | — | @@ -50,10 +48,9 @@ |
51 | 49 | public function addSpecificMapHTML() { |
52 | 50 | global $wgJsMimeType; |
53 | 51 | |
54 | | - $controlItems = MapsOpenLayersUtils::createControlsString($this->controls); |
| 52 | + $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls)); |
55 | 53 | |
56 | | - MapsMapper::enforceArrayValues($this->layers); |
57 | | - $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers); |
| 54 | + $layerItems = MapsOpenLayers::createLayersStringAndLoadDependencies($this->output, $this->layers); |
58 | 55 | |
59 | 56 | $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div> |
60 | 57 | <script type='$wgJsMimeType'> /*<![CDATA[*/ |
Index: trunk/extensions/Maps/OpenLayers/Maps_OpenLayers.php |
— | — | @@ -26,11 +26,124 @@ |
27 | 27 | 'display_map' => array('class' => 'MapsOpenLayersDispMap', 'file' => 'OpenLayers/Maps_OpenLayersDispMap.php', 'local' => true), |
28 | 28 | ), |
29 | 29 | 'classes' => array( |
30 | | - array('class' => 'MapsOpenLayersUtils', 'file' => 'OpenLayers/Maps_OpenLayersUtils.php', 'local' => true) |
| 30 | + array('class' => 'MapsOpenLayers', 'file' => 'OpenLayers/Maps_OpenLayers.php', 'local' => true) |
31 | 31 | ), |
32 | 32 | '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 @@ |
41 | 41 | public final function displayMap(&$parser, array $params) { |
42 | 42 | $this->setMapSettings(); |
43 | 43 | |
44 | | - parent::manageMapProperties($params, __CLASS__); |
| 44 | + $this->featureParameters = MapsDisplayPoint::$parameters; |
45 | 45 | |
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 | + } |
49 | 65 | |
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; |
65 | 67 | } |
66 | 68 | |
67 | 69 | /** |
Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_DisplayPoint.php |
— | — | @@ -13,12 +13,14 @@ |
14 | 14 | die( 'Not an entry point.' ); |
15 | 15 | } |
16 | 16 | |
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'; |
19 | 19 | |
20 | | -$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic'; |
21 | | -$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint'; |
| 20 | +$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayPointMagic'; |
| 21 | +$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayPoint'; |
22 | 22 | |
| 23 | +$egMapsAvailableFeatures['pf']['hooks'][] = 'MapsDisplayPoint'; |
| 24 | + |
23 | 25 | /** |
24 | 26 | * Adds the magic words for the parser functions. |
25 | 27 | */ |
— | — | @@ -47,10 +49,17 @@ |
48 | 50 | */ |
49 | 51 | final class MapsDisplayPoint { |
50 | 52 | |
| 53 | + public static $parameters = array(); |
| 54 | + |
| 55 | + public static function initialize() { |
| 56 | + self::initializeParams(); |
| 57 | + } |
| 58 | + |
51 | 59 | /** |
52 | 60 | * Returns the output for a display_point call. |
53 | 61 | * |
54 | 62 | * @param unknown_type $parser |
| 63 | + * |
55 | 64 | * @return array |
56 | 65 | */ |
57 | 66 | public static function displayPointRender(&$parser) { |
— | — | @@ -58,4 +67,26 @@ |
59 | 68 | return MapsParserFunctions::getMapHtml($parser, $args, 'display_point'); |
60 | 69 | } |
61 | 70 | |
| 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 | + |
62 | 93 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php |
— | — | @@ -36,19 +36,21 @@ |
37 | 37 | public final function displayMap(&$parser, array $params) { |
38 | 38 | $this->setMapSettings(); |
39 | 39 | |
40 | | - parent::manageMapProperties($params, __CLASS__); |
| 40 | + $this->featureParameters = MapsDisplayMap::$parameters; |
41 | 41 | |
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 | + } |
45 | 53 | |
46 | | - $this->setZoom(); |
47 | | - |
48 | | - $this->setCentre(); |
49 | | - |
50 | | - $this->addSpecificMapHTML(); |
51 | | - |
52 | | - return $this->output; |
| 54 | + return $this->output . $this->errorList; |
53 | 55 | } |
54 | 56 | |
55 | 57 | /** |
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_DisplayMap.php |
— | — | @@ -13,12 +13,14 @@ |
14 | 14 | die( 'Not an entry point.' ); |
15 | 15 | } |
16 | 16 | |
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'; |
19 | 19 | |
20 | | -$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic'; |
21 | | -$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap'; |
| 20 | +$wgHooks['LanguageGetMagic'][] = 'efMapsDisplayMapMagic'; |
| 21 | +$wgHooks['ParserFirstCallInit'][] = 'efMapsRegisterDisplayMap'; |
22 | 22 | |
| 23 | +$egMapsAvailableFeatures['pf']['hooks'][] = 'MapsDisplayMap'; |
| 24 | + |
23 | 25 | /** |
24 | 26 | * Adds the magic words for the parser functions. |
25 | 27 | */ |
— | — | @@ -46,10 +48,17 @@ |
47 | 49 | */ |
48 | 50 | final class MapsDisplayMap { |
49 | 51 | |
| 52 | + public static $parameters = array(); |
| 53 | + |
| 54 | + public static function initialize() { |
| 55 | + self::initializeParams(); |
| 56 | + } |
| 57 | + |
50 | 58 | /** |
51 | 59 | * Returns the output for a display_map call. |
52 | 60 | * |
53 | 61 | * @param unknown_type $parser |
| 62 | + * |
54 | 63 | * @return array |
55 | 64 | */ |
56 | 65 | public static function displayMapRender(&$parser) { |
— | — | @@ -57,4 +66,11 @@ |
58 | 67 | return MapsParserFunctions::getMapHtml($parser, $args, 'display_map'); |
59 | 68 | } |
60 | 69 | |
| 70 | + private static function initializeParams() { |
| 71 | + global $egMapsAvailableGeoServices, $egMapsDefaultGeoService; |
| 72 | + |
| 73 | + self::$parameters = array_merge(MapsParserFunctions::$parameters, array( |
| 74 | + )); |
| 75 | + } |
| 76 | + |
61 | 77 | } |
\ No newline at end of file |
Index: trunk/extensions/Maps/ParserFunctions/Maps_ParserFunctions.php |
— | — | @@ -20,15 +20,19 @@ |
21 | 21 | */ |
22 | 22 | final class MapsParserFunctions { |
23 | 23 | |
| 24 | + public static $parameters = array(); |
| 25 | + |
24 | 26 | /** |
25 | 27 | * Initialize the parser functions feature. This function handles the parser function hook, |
26 | 28 | * and will load the required classes. |
27 | 29 | */ |
28 | 30 | public static function initialize() { |
29 | | - global $egMapsIP, $IP, $wgAutoloadClasses, $egMapsServices; |
| 31 | + global $egMapsIP, $IP, $wgAutoloadClasses, $egMapsAvailableFeatures, $egMapsServices; |
30 | 32 | |
31 | 33 | include_once $egMapsIP . '/ParserFunctions/Maps_iDisplayFunction.php'; |
32 | 34 | |
| 35 | + self::initializeParams(); |
| 36 | + |
33 | 37 | foreach($egMapsServices as $serviceName => $serviceData) { |
34 | 38 | // Check if the service has parser function support |
35 | 39 | $hasPFs = array_key_exists('pf', $serviceData); |
— | — | @@ -42,8 +46,33 @@ |
43 | 47 | $wgAutoloadClasses[$parser_data['class']] = $file; |
44 | 48 | } |
45 | 49 | } |
| 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 | + } |
46 | 55 | } |
47 | 56 | |
| 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 | + |
48 | 77 | /** |
49 | 78 | * Returns the output for the call to the specified parser function. |
50 | 79 | * |
— | — | @@ -80,7 +109,8 @@ |
81 | 110 | } |
82 | 111 | } |
83 | 112 | |
84 | | - $coords = MapsMapper::getParamValue('coordinates', $map); |
| 113 | + $paramInfo = array_merge(MapsMapper::getMainParams(), self::$parameters); |
| 114 | + $coords = MapsMapper::getParamValue('coordinates', $map, $paramInfo); |
85 | 115 | |
86 | 116 | if ($coords) { |
87 | 117 | 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 @@ |
21 | 21 | */ |
22 | 22 | class MapsOSMDispPoint extends MapsBasePointMap { |
23 | 23 | |
24 | | - public $serviceName = MapsOSMUtils::SERVICE_NAME; |
| 24 | + public $serviceName = MapsOSM::SERVICE_NAME; |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @see MapsBaseMap::setMapSettings() |
— | — | @@ -29,12 +29,16 @@ |
30 | 30 | protected function setMapSettings() { |
31 | 31 | global $egMapsOSMZoom, $egMapsOSMPrefix; |
32 | 32 | |
33 | | - $this->defaultParams = MapsOSMUtils::getDefaultParams(); |
34 | | - |
35 | 33 | $this->elementNamePrefix = $egMapsOSMPrefix; |
36 | 34 | $this->defaultZoom = $egMapsOSMZoom; |
37 | 35 | |
38 | 36 | $this->markerStringFormat = 'getOSMMarkerData(lat, lon, "title", "label", "icon")'; |
| 37 | + |
| 38 | + $this->spesificParameters = array( |
| 39 | + 'zoom' => array( |
| 40 | + 'default' => '', |
| 41 | + ) |
| 42 | + ); |
39 | 43 | } |
40 | 44 | |
41 | 45 | /** |
— | — | @@ -44,7 +48,7 @@ |
45 | 49 | protected function doMapServiceLoad() { |
46 | 50 | global $egOSMMapsOnThisPage; |
47 | 51 | |
48 | | - MapsOSMUtils::addOSMDependencies($this->output); |
| 52 | + MapsOSM::addOSMDependencies($this->output); |
49 | 53 | $egOSMMapsOnThisPage++; |
50 | 54 | |
51 | 55 | $this->elementNr = $egOSMMapsOnThisPage; |
— | — | @@ -57,7 +61,7 @@ |
58 | 62 | public function addSpecificMapHTML() { |
59 | 63 | global $wgJsMimeType; |
60 | 64 | |
61 | | - $controlItems = MapsOSMUtils::createControlsString($this->controls); |
| 65 | + $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls)); |
62 | 66 | |
63 | 67 | $this->output .= <<<EOT |
64 | 68 | <script type='$wgJsMimeType'>slippymaps['$this->mapName'] = new slippymap_map('$this->mapName', { |
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSMDispMap.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | |
17 | 17 | class MapsOSMDispMap extends MapsBaseMap { |
18 | 18 | |
19 | | - public $serviceName = MapsOSMUtils::SERVICE_NAME; |
| 19 | + public $serviceName = MapsOSM::SERVICE_NAME; |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @see MapsBaseMap::setMapSettings() |
— | — | @@ -24,8 +24,6 @@ |
25 | 25 | protected function setMapSettings() { |
26 | 26 | global $egMapsOSMZoom, $egMapsOSMPrefix; |
27 | 27 | |
28 | | - $this->defaultParams = MapsOSMUtils::getDefaultParams(); |
29 | | - |
30 | 28 | $this->elementNamePrefix = $egMapsOSMPrefix; |
31 | 29 | $this->defaultZoom = $egMapsOSMZoom; |
32 | 30 | } |
— | — | @@ -37,7 +35,7 @@ |
38 | 36 | protected function doMapServiceLoad() { |
39 | 37 | global $egOSMMapsOnThisPage; |
40 | 38 | |
41 | | - MapsOSMUtils::addOSMDependencies($this->output); |
| 39 | + MapsOSM::addOSMDependencies($this->output); |
42 | 40 | $egOSMMapsOnThisPage++; |
43 | 41 | |
44 | 42 | $this->elementNr = $egOSMMapsOnThisPage; |
— | — | @@ -50,7 +48,7 @@ |
51 | 49 | public function addSpecificMapHTML() { |
52 | 50 | global $wgJsMimeType; |
53 | 51 | |
54 | | - $controlItems = MapsOSMUtils::createControlsString($this->controls); |
| 52 | + $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls)); |
55 | 53 | |
56 | 54 | $this->output .= <<<EOT |
57 | 55 | <script type='$wgJsMimeType'>slippymaps['$this->mapName'] = new slippymap_map('$this->mapName', { |
Index: trunk/extensions/Maps/OpenStreetMap/Maps_OSM.php |
— | — | @@ -26,9 +26,114 @@ |
27 | 27 | 'display_map' => array('class' => 'MapsOSMDispMap', 'file' => 'OpenStreetMap/Maps_OSMDispMap.php', 'local' => true), |
28 | 28 | ), |
29 | 29 | 'classes' => array( |
30 | | - array('class' => 'MapsOSMUtils', 'file' => 'OpenStreetMap/Maps_OSMUtils.php', 'local' => true) |
| 30 | + array('class' => 'MapsOSM', 'file' => 'OpenStreetMap/Maps_OSM.php', 'local' => true) |
31 | 31 | ), |
32 | 32 | '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 @@ |
24 | 24 | die( 'Not an entry point.' ); |
25 | 25 | } |
26 | 26 | |
27 | | -define('Maps_VERSION', '0.5 a4'); |
| 27 | +define('Maps_VERSION', '0.5 a6'); |
28 | 28 | |
29 | 29 | // Constants indicating the strictness of the parameter validation. |
30 | 30 | define('Maps_ERRORS_NONE', 0); |
— | — | @@ -46,10 +46,15 @@ |
47 | 47 | $wgHooks['AdminLinks'][] = 'efMapsAddToAdminLinks'; |
48 | 48 | |
49 | 49 | // 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'; |
53 | 53 | |
| 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 | + |
54 | 59 | if (empty($egMapsServices)) $egMapsServices = array(); |
55 | 60 | |
56 | 61 | /** |
— | — | @@ -57,7 +62,7 @@ |
58 | 63 | */ |
59 | 64 | function efMapsSetup() { |
60 | 65 | 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; |
62 | 67 | |
63 | 68 | // Enure that the default service and geoservice are one of the enabled ones. |
64 | 69 | $egMapsDefaultService = in_array($egMapsDefaultService, $egMapsAvailableServices) ? $egMapsDefaultService : $egMapsAvailableServices[0]; |
— | — | @@ -77,11 +82,13 @@ |
78 | 83 | 'path' => __FILE__, |
79 | 84 | 'name' => wfMsg('maps_name'), |
80 | 85 | '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'), |
82 | 87 | 'url' => 'http://www.mediawiki.org/wiki/Extension:Maps', |
83 | 88 | 'description' => wfMsgExt( 'maps_desc', 'parsemag', $services_list ), |
84 | 89 | 'descriptionmsg' => wfMsgExt( 'maps_desc', 'parsemag', $services_list ), |
85 | 90 | ); |
| 91 | + |
| 92 | + MapsMapper::initializeMainParams(); |
86 | 93 | |
87 | 94 | $wgOut->addScriptFile($egMapsScriptPath . '/MapUtilityFunctions.js'); |
88 | 95 | |
— | — | @@ -90,9 +97,7 @@ |
91 | 98 | // Load and optionally initizlize feature. |
92 | 99 | if (array_key_exists('class', $values) && array_key_exists('file', $values) && array_key_exists('local', $values)) { |
93 | 100 | $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')); |
97 | 102 | } |
98 | 103 | |
99 | 104 | // Check for wich services there are handlers for the current fature, and load them |
— | — | @@ -108,6 +113,7 @@ |
109 | 114 | foreach($serviceData['classes'] as $class) { |
110 | 115 | $file = $class['local'] ? $egMapsIP . '/' . $class['file'] : $IP . '/extensions/' . $class['file']; |
111 | 116 | $wgAutoloadClasses[$class['class']] = $file; |
| 117 | + if (method_exists($class['class'], 'initialize')) call_user_func(array($class['class'], 'initialize')); |
112 | 118 | } |
113 | 119 | } |
114 | 120 | } |
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 @@ |
17 | 17 | final class MapsMapper { |
18 | 18 | |
19 | 19 | /** |
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. |
22 | 22 | * |
23 | 23 | * @var array |
24 | 24 | */ |
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 | + ), |
38 | 74 | ); |
| 75 | + } |
39 | 76 | |
40 | 77 | /** |
| 78 | + * Returns the main parameters array. |
| 79 | + * |
| 80 | + * @return array |
| 81 | + */ |
| 82 | + public static function getMainParams() { |
| 83 | + return self::$mainParams; |
| 84 | + } |
| 85 | + |
| 86 | + /** |
41 | 87 | * Gets if a provided name is present in the aliases array of a parameter |
42 | 88 | * name in the $mainParams array. |
43 | 89 | * |
— | — | @@ -54,29 +100,32 @@ |
55 | 101 | } |
56 | 102 | |
57 | 103 | return $equals; |
58 | | - } |
| 104 | + } |
59 | 105 | |
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 | + } |
81 | 130 | |
82 | 131 | /** |
83 | 132 | * Returns the value of a parameter represented as key in the $stack. |
— | — | @@ -85,61 +134,26 @@ |
86 | 135 | * no array key name match is found, false will be returned. |
87 | 136 | * |
88 | 137 | * @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 |
90 | 140 | * @param boolean $checkForAliases |
91 | 141 | * |
92 | 142 | * @return the parameter value or false |
93 | 143 | */ |
94 | | - public static function getParamValue($paramName, array $stack, $checkForAliases = true) { |
| 144 | + public static function getParamValue($paramName, array $stack, array $paramInfo = array(), $checkForAliases = true) { |
95 | 145 | $paramValue = false; |
96 | 146 | |
97 | 147 | if (array_key_exists($paramName, $stack)) $paramValue = $stack[$paramName]; |
98 | 148 | |
99 | 149 | if ($checkForAliases) { |
100 | | - foreach(self::$mainParams[$paramName] as $alias) { |
| 150 | + foreach($paramInfo[$paramName]['aliases'] as $alias) { |
101 | 151 | if (array_key_exists($alias, $stack)) $paramValue = $stack[$alias]; |
| 152 | + break; |
102 | 153 | } |
103 | 154 | } |
104 | 155 | |
105 | 156 | return $paramValue; |
106 | 157 | } |
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 | | - } |
144 | 158 | |
145 | 159 | /** |
146 | 160 | * Returns the JS version (true/false as string) of the provided boolean parameter. |
— | — | @@ -159,7 +173,7 @@ |
160 | 174 | * @param string $delimeter |
161 | 175 | */ |
162 | 176 | 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 |
164 | 178 | for ($i = 0; $i < count($values); $i++) $values[$i] = trim($values[$i]); // Trim all values |
165 | 179 | } |
166 | 180 | |
— | — | @@ -174,76 +188,61 @@ |
175 | 189 | * |
176 | 190 | * @return string |
177 | 191 | */ |
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) { |
180 | 193 | $itemString = $asStrings ? "'" . implode("','", $items) . "'" : implode(',', $items); |
181 | 194 | if ($toLower) $itemString = strtolower($itemString); |
182 | 195 | return $itemString; |
183 | 196 | } |
184 | 197 | |
185 | 198 | /** |
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. |
188 | 201 | * |
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 | | - * |
212 | 202 | * @param string $paramName |
213 | 203 | * @param array $allowedParms |
214 | 204 | * |
215 | 205 | * @return string |
216 | 206 | */ |
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 | + } |
223 | 220 | } |
224 | 221 | } |
225 | 222 | } |
226 | | - return $paramName; |
227 | | - } |
228 | 223 | |
| 224 | + return $result; |
| 225 | + } |
| 226 | + |
| 227 | + |
229 | 228 | /** |
230 | 229 | * Returns a valid service. When an invalid service is provided, the default one will be returned. |
231 | 230 | * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName(). |
232 | 231 | * |
233 | 232 | * @param string $service |
| 233 | + * @param string $feature |
| 234 | + * |
234 | 235 | * @return string |
235 | 236 | */ |
236 | | - public static function getValidService($service, $feature = '') { |
| 237 | + public static function getValidService($service, $feature) { |
237 | 238 | global $egMapsAvailableServices, $egMapsDefaultService, $egMapsDefaultServices, $egMapsServices; |
238 | 239 | |
239 | 240 | $service = self::getMainServiceName($service); |
240 | 241 | |
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; |
248 | 247 | } |
249 | 248 | |
250 | 249 | 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 @@ |
21 | 21 | */ |
22 | 22 | final class MapsGoogleMapsDispPoint extends MapsBasePointMap { |
23 | 23 | |
24 | | - public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME; |
| 24 | + public $serviceName = MapsGoogleMaps::SERVICE_NAME; |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * @see MapsBaseMap::setMapSettings() |
— | — | @@ -29,12 +29,21 @@ |
30 | 30 | protected function setMapSettings() { |
31 | 31 | global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix; |
32 | 32 | |
33 | | - $this->defaultParams = MapsGoogleMapsUtils::getDefaultParams(); |
34 | | - |
35 | 33 | $this->elementNamePrefix = $egMapsGoogleMapsPrefix; |
36 | 34 | $this->defaultZoom = $egMapsGoogleMapsZoom; |
37 | 35 | |
38 | 36 | $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 | + ); |
39 | 48 | } |
40 | 49 | |
41 | 50 | /** |
— | — | @@ -44,7 +53,7 @@ |
45 | 54 | protected function doMapServiceLoad() { |
46 | 55 | global $egGoogleMapsOnThisPage; |
47 | 56 | |
48 | | - MapsGoogleMapsUtils::addGMapDependencies($this->output); |
| 57 | + MapsGoogleMaps::addGMapDependencies($this->output); |
49 | 58 | $egGoogleMapsOnThisPage++; |
50 | 59 | |
51 | 60 | $this->elementNr = $egGoogleMapsOnThisPage; |
— | — | @@ -57,17 +66,17 @@ |
58 | 67 | public function addSpecificMapHTML() { |
59 | 68 | global $wgJsMimeType; |
60 | 69 | |
61 | | - $this->type = MapsGoogleMapsUtils::getGMapType($this->type, true); |
| 70 | + $this->type = MapsGoogleMaps::getGMapType($this->type, true); |
62 | 71 | |
63 | | - $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls); |
| 72 | + $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls)); |
64 | 73 | |
65 | | - $onloadFunctions = MapsGoogleMapsUtils::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls); |
| 74 | + $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls); |
66 | 75 | |
67 | | - $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom); |
| 76 | + $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom); |
68 | 77 | |
69 | 78 | $this->types = explode(",", $this->types); |
70 | 79 | |
71 | | - $typesString = MapsGoogleMapsUtils::createTypesString($this->types); |
| 80 | + $typesString = MapsGoogleMaps::createTypesString($this->types); |
72 | 81 | |
73 | 82 | $this->output .=<<<END |
74 | 83 | |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php |
— | — | @@ -15,7 +15,7 @@ |
16 | 16 | |
17 | 17 | final class MapsGoogleMapsDispMap extends MapsBaseMap { |
18 | 18 | |
19 | | - public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME; |
| 19 | + public $serviceName = MapsGoogleMaps::SERVICE_NAME; |
20 | 20 | |
21 | 21 | /** |
22 | 22 | * @see MapsBaseMap::setMapSettings() |
— | — | @@ -24,10 +24,16 @@ |
25 | 25 | protected function setMapSettings() { |
26 | 26 | global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix; |
27 | 27 | |
28 | | - $this->defaultParams = MapsGoogleMapsUtils::getDefaultParams(); |
29 | | - |
30 | 28 | $this->elementNamePrefix = $egMapsGoogleMapsPrefix; |
31 | 29 | $this->defaultZoom = $egMapsGoogleMapsZoom; |
| 30 | + |
| 31 | + $this->spesificParameters = array( |
| 32 | + 'overlays' => array( |
| 33 | + 'aliases' => array(), |
| 34 | + 'criteria' => array(), |
| 35 | + 'default' => '' |
| 36 | + ), |
| 37 | + ); |
32 | 38 | } |
33 | 39 | |
34 | 40 | /** |
— | — | @@ -37,7 +43,7 @@ |
38 | 44 | protected function doMapServiceLoad() { |
39 | 45 | global $egGoogleMapsOnThisPage; |
40 | 46 | |
41 | | - MapsGoogleMapsUtils::addGMapDependencies($this->output); |
| 47 | + MapsGoogleMaps::addGMapDependencies($this->output); |
42 | 48 | $egGoogleMapsOnThisPage++; |
43 | 49 | |
44 | 50 | $this->elementNr = $egGoogleMapsOnThisPage; |
— | — | @@ -50,17 +56,17 @@ |
51 | 57 | public function addSpecificMapHTML() { |
52 | 58 | global $wgJsMimeType; |
53 | 59 | |
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)); |
55 | 63 | |
56 | | - $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls); |
| 64 | + $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls); |
57 | 65 | |
58 | | - $onloadFunctions = MapsGoogleMapsUtils::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls); |
| 66 | + $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom); |
59 | 67 | |
60 | | - $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom); |
61 | | - |
62 | 68 | $this->types = explode(",", $this->types); |
63 | 69 | |
64 | | - $typesString = MapsGoogleMapsUtils::createTypesString($this->types); |
| 70 | + $typesString = MapsGoogleMaps::createTypesString($this->types); |
65 | 71 | |
66 | 72 | $this->output .=<<<END |
67 | 73 | |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php |
— | — | @@ -26,16 +26,340 @@ |
27 | 27 | 'display_map' => array('class' => 'MapsGoogleMapsDispMap', 'file' => 'GoogleMaps/Maps_GoogleMapsDispMap.php', 'local' => true), |
28 | 28 | ), |
29 | 29 | 'classes' => array( |
30 | | - array('class' => 'MapsGoogleMapsUtils', 'file' => 'GoogleMaps/Maps_GoogleMapsUtils.php', 'local' => true) |
| 30 | + array('class' => 'MapsGoogleMaps', 'file' => 'GoogleMaps/Maps_GoogleMaps.php', 'local' => true) |
31 | 31 | ), |
32 | 32 | '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 |