Index: trunk/extensions/Maps/Maps.php |
— | — | @@ -33,7 +33,7 @@ |
34 | 34 | echo '<b>Warning:</b> You need to have <a href="http://www.mediawiki.org/wiki/Extension:Validator">Validator</a> installed in order to use <a href="http://www.mediawiki.org/wiki/Extension:Maps">Maps</a>.'; |
35 | 35 | } |
36 | 36 | else { |
37 | | - define('Maps_VERSION', '0.5.1 a4'); |
| 37 | + define('Maps_VERSION', '0.5.1 a5'); |
38 | 38 | |
39 | 39 | $egMapsScriptPath = $wgScriptPath . '/extensions/Maps'; |
40 | 40 | $egMapsIP = $IP . '/extensions/Maps'; |
Index: trunk/extensions/Maps/Maps_Mapper.php |
— | — | @@ -62,6 +62,8 @@ |
63 | 63 | } |
64 | 64 | |
65 | 65 | /** |
| 66 | + * TODO: remove |
| 67 | + * |
66 | 68 | * Returns the JS version (true/false as string) of the provided boolean parameter. |
67 | 69 | * |
68 | 70 | * @param boolean $bool |
— | — | @@ -72,6 +74,8 @@ |
73 | 75 | } |
74 | 76 | |
75 | 77 | /** |
| 78 | + * TODO: remove |
| 79 | + * |
76 | 80 | * Turns the provided values into an array by splitting it on comma's if |
77 | 81 | * it's not an array yet. |
78 | 82 | * |
— | — | @@ -84,67 +88,6 @@ |
85 | 89 | } |
86 | 90 | |
87 | 91 | /** |
88 | | - * Checks if the items array has members, and sets it to the default when this is not the case. |
89 | | - * Then returns an imploded/joined, comma seperated, version of the array as string. |
90 | | - * |
91 | | - * @param array $items |
92 | | - * @param array $defaultItems |
93 | | - * @param boolean $asStrings |
94 | | - * @param boolean $toLower |
95 | | - * |
96 | | - * @return string |
97 | | - */ |
98 | | - public static function createJSItemsString(array $items, $asStrings = true, $toLower = true) { |
99 | | - $itemString = $asStrings ? "'" . implode("','", $items) . "'" : implode(',', $items); |
100 | | - if ($toLower) $itemString = strtolower($itemString); |
101 | | - return $itemString; |
102 | | - } |
103 | | - |
104 | | - /** |
105 | | - * Returns a valid version of the types. |
106 | | - * |
107 | | - * @param array $types |
108 | | - * @param array $defaults |
109 | | - * @param boolean $defaultsAreValid |
110 | | - * @param function $validationFunction |
111 | | - * |
112 | | - * @return array |
113 | | - */ |
114 | | - public static function getValidTypes(array $types, array &$defaults, &$defaultsAreValid, $validationFunction) { |
115 | | - $validTypes = array(); |
116 | | - $phpAtLeast523 = MapsUtils::phpVersionIsEqualOrBigger('5.2.3'); |
117 | | - |
118 | | - // Ensure every type is valid and uses the relevant map API's name. |
119 | | - for($i = 0 ; $i < count($types); $i++) { |
120 | | - $type = call_user_func($validationFunction, $phpAtLeast523 ? $types[$i] : array($types[$i])); |
121 | | - if ($type) $validTypes[] = $type; |
122 | | - } |
123 | | - |
124 | | - $types = $validTypes; |
125 | | - |
126 | | - // If there are no valid types, add the default ones. |
127 | | - if (count($types) < 1) { |
128 | | - $validTypes = array(); |
129 | | - |
130 | | - // If the default ones have not been checked, |
131 | | - // ensure every type is valid and uses the relevant map API's name. |
132 | | - if (empty($defaultsAreValid)) { |
133 | | - for($i = 0 ; $i < count($defaults); $i++) { |
134 | | - $type = call_user_func($validationFunction, $phpAtLeast523 ? $defaults[$i] : array($defaults[$i])); |
135 | | - if ($type) $validTypes[] = $type; |
136 | | - } |
137 | | - |
138 | | - $defaults = $validTypes; |
139 | | - $defaultsAreValid = true; |
140 | | - } |
141 | | - |
142 | | - $types = $defaults; |
143 | | - } |
144 | | - |
145 | | - return $types; |
146 | | - } |
147 | | - |
148 | | - /** |
149 | 92 | * Returns a valid service. When an invalid service is provided, the default one will be returned. |
150 | 93 | * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName(). |
151 | 94 | * |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php |
— | — | @@ -57,14 +57,10 @@ |
58 | 58 | public function addSpecificMapHTML() { |
59 | 59 | global $wgJsMimeType; |
60 | 60 | |
61 | | - $this->type = MapsGoogleMaps::getGMapType($this->type, true); |
62 | | - |
63 | 61 | $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls); |
64 | 62 | |
65 | 63 | $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom); |
66 | 64 | |
67 | | - $typesString = MapsGoogleMaps::createTypesString($this->types); |
68 | | - |
69 | 65 | $this->output .=<<<END |
70 | 66 | |
71 | 67 | <div id="$this->mapName" class="$this->class" style="$this->style" ></div> |
— | — | @@ -78,7 +74,7 @@ |
79 | 75 | lon: $this->centre_lon, |
80 | 76 | zoom: $this->zoom, |
81 | 77 | type: $this->type, |
82 | | - types: [$typesString], |
| 78 | + types: [$this->types], |
83 | 79 | controls: [$this->controls], |
84 | 80 | scrollWheelZoom: $this->autozoom |
85 | 81 | }, []) |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php |
— | — | @@ -44,6 +44,8 @@ |
45 | 45 | |
46 | 46 | public static function initialize() { |
47 | 47 | self::initializeParams(); |
| 48 | + Validator::addOutputFormat('gmaptype', array('MapsGoogleMaps', 'setGMapType')); |
| 49 | + Validator::addOutputFormat('gmaptypes', array('MapsGoogleMaps', 'setGMapTypes')); |
48 | 50 | } |
49 | 51 | |
50 | 52 | private static function initializeParams() { |
— | — | @@ -52,43 +54,45 @@ |
53 | 55 | $allowedTypes = self::getTypeNames(); |
54 | 56 | |
55 | 57 | $egMapsServices[self::SERVICE_NAME]['parameters'] = array( |
56 | | - 'zoom' => array( |
57 | | - 'default' => $egMapsGoogleMapsZoom, |
58 | | - ), |
59 | | - 'controls' => array( |
60 | | - 'type' => array('string', 'list'), |
61 | | - 'criteria' => array( |
62 | | - 'in_array' => self::getControlNames() |
63 | | - ), |
64 | | - 'default' => $egMapsGMapControls, |
65 | | - 'output-type' => array('list', ',', '\'') |
66 | | - ), |
67 | | - 'type' => array( |
68 | | - 'aliases' => array('map-type', 'map type'), |
69 | | - 'criteria' => array( |
70 | | - 'in_array' => $allowedTypes |
71 | | - ), |
72 | | - 'default' => $egMapsGoogleMapsType |
73 | | - ), |
74 | | - 'types' => array( |
75 | | - 'type' => array('string', 'list'), |
76 | | - 'aliases' => array('map-types', 'map types'), |
77 | | - 'criteria' => array( |
78 | | - 'in_array' => $allowedTypes |
79 | | - ), |
80 | | - 'default' => $egMapsGoogleMapsTypes |
81 | | - ), |
82 | | - 'autozoom' => array( |
83 | | - 'type' => 'boolean', |
84 | | - 'aliases' => array('auto zoom', 'mouse zoom', 'mousezoom'), |
85 | | - 'criteria' => array( |
86 | | - 'in_array' => array('on', 'off', 'yes', 'no') |
87 | | - ), |
88 | | - 'default' => $egMapsGoogleAutozoom |
89 | | - ), |
90 | | - 'class' => array(), |
91 | | - 'style' => array(), |
92 | | - ); |
| 58 | + 'zoom' => array( |
| 59 | + 'default' => $egMapsGoogleMapsZoom, |
| 60 | + ), |
| 61 | + 'controls' => array( |
| 62 | + 'type' => array('string', 'list'), |
| 63 | + 'criteria' => array( |
| 64 | + 'in_array' => self::getControlNames() |
| 65 | + ), |
| 66 | + 'default' => $egMapsGMapControls, |
| 67 | + 'output-type' => array('list', ',', '\'') |
| 68 | + ), |
| 69 | + 'type' => array( |
| 70 | + 'aliases' => array('map-type', 'map type'), |
| 71 | + 'criteria' => array( |
| 72 | + 'in_array' => $allowedTypes |
| 73 | + ), |
| 74 | + 'default' => $egMapsGoogleMapsType, |
| 75 | + 'output-type' => array('gmaptype') |
| 76 | + ), |
| 77 | + 'types' => array( |
| 78 | + 'type' => array('string', 'list'), |
| 79 | + 'aliases' => array('map-types', 'map types'), |
| 80 | + 'criteria' => array( |
| 81 | + 'in_array' => $allowedTypes |
| 82 | + ), |
| 83 | + 'default' => $egMapsGoogleMapsTypes, |
| 84 | + 'output-types' => array('gmaptypes', 'list') |
| 85 | + ), |
| 86 | + 'autozoom' => array( |
| 87 | + 'type' => 'boolean', |
| 88 | + 'aliases' => array('auto zoom', 'mouse zoom', 'mousezoom'), |
| 89 | + 'criteria' => array( |
| 90 | + 'in_array' => array('on', 'off', 'yes', 'no') |
| 91 | + ), |
| 92 | + 'default' => $egMapsGoogleAutozoom |
| 93 | + ), |
| 94 | + 'class' => array(), |
| 95 | + 'style' => array(), |
| 96 | + ); |
93 | 97 | } |
94 | 98 | |
95 | 99 | // http://code.google.com/apis/maps/documentation/reference.html#GMapType.G_NORMAL_MAP |
— | — | @@ -147,31 +151,28 @@ |
148 | 152 | } |
149 | 153 | |
150 | 154 | /** |
151 | | - * Returns the Google Map type (defined in MapsGoogleMaps::$mapTypes) |
152 | | - * for the provided a general map type. When no match is found, false |
153 | | - * will be returned. |
| 155 | + * Changes the map type name into the corresponding Google Maps API identifier. |
154 | 156 | * |
155 | 157 | * @param string $type |
156 | | - * @param boolean $restoreAsDefault |
157 | 158 | * |
158 | | - * @return string or false |
| 159 | + * @return string |
159 | 160 | */ |
160 | | - public static function getGMapType($type, $restoreAsDefault = false) { |
161 | | - global $egMapsGoogleMapsType; |
162 | | - $typeIsValid = array_key_exists($type, self::$mapTypes); |
163 | | - |
164 | | - if ($typeIsValid) { |
165 | | - return self::$mapTypes[ $type ]; |
| 161 | + public static function setGMapType(&$type) { |
| 162 | + $type = self::$mapTypes[ $type ]; |
| 163 | + } |
| 164 | + |
| 165 | + /** |
| 166 | + * Changes the map type names into the corresponding Google Maps API identifiers. |
| 167 | + * |
| 168 | + * @param array $types |
| 169 | + * |
| 170 | + * @return array |
| 171 | + */ |
| 172 | + public static function setGMapTypes(array &$types) { |
| 173 | + for($i = count($types) - 1; $i >= 0; $i--) { |
| 174 | + $types[$i] = self::$mapTypes[ $types[$i] ]; |
166 | 175 | } |
167 | | - else { |
168 | | - if ($restoreAsDefault) { |
169 | | - return self::$mapTypes[ $egMapsGoogleMapsType ]; |
170 | | - } |
171 | | - else { |
172 | | - return false; |
173 | | - } |
174 | | - } |
175 | | - } |
| 176 | + } |
176 | 177 | |
177 | 178 | /** |
178 | 179 | * Add references to the Google Maps API and required JS file to the provided output |
— | — | @@ -192,6 +193,8 @@ |
193 | 194 | } |
194 | 195 | |
195 | 196 | /** |
| 197 | + * TODO: remove |
| 198 | + * |
196 | 199 | * Retuns a boolean as string, true if $autozoom is on or yes. |
197 | 200 | * |
198 | 201 | * @param string $autozoom |
— | — | @@ -202,23 +205,6 @@ |
203 | 206 | } |
204 | 207 | |
205 | 208 | /** |
206 | | - * Returns a JS items string with the provided types. The earth type will |
207 | | - * be added to it when it's not present and $enableEarth is true. If there are |
208 | | - * no types, the default will be used. |
209 | | - * |
210 | | - * @param array $types |
211 | | - * |
212 | | - * @return string |
213 | | - */ |
214 | | - public static function createTypesString(array &$types) { |
215 | | - global $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid; |
216 | | - |
217 | | - $types = MapsMapper::getValidTypes($types, $egMapsGoogleMapsTypes, $egMapsGoogleMapTypesValid, array(__CLASS__, 'getGMapType')); |
218 | | - |
219 | | - return MapsMapper::createJSItemsString($types, null, false, false); |
220 | | - } |
221 | | - |
222 | | - /** |
223 | 209 | * This function ensures backward compatibility with Semantic Google Maps and other extensions |
224 | 210 | * using $wgGoogleMapsKey instead of $egGoogleMapsKey. |
225 | 211 | */ |
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php |
— | — | @@ -67,16 +67,10 @@ |
68 | 68 | public function addSpecificMapHTML() { |
69 | 69 | global $wgJsMimeType; |
70 | 70 | |
71 | | - $this->type = MapsGoogleMaps::getGMapType($this->type, true); |
72 | | - |
73 | 71 | $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls); |
74 | 72 | |
75 | 73 | $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom); |
76 | 74 | |
77 | | - $this->types = $this->types; |
78 | | - |
79 | | - $typesString = MapsGoogleMaps::createTypesString($this->types); |
80 | | - |
81 | 75 | $this->output .=<<<END |
82 | 76 | |
83 | 77 | <div id="$this->mapName" class="$this->class" style="$this->style" ></div> |
— | — | @@ -90,7 +84,7 @@ |
91 | 85 | lon: $this->centre_lon, |
92 | 86 | zoom: $this->zoom, |
93 | 87 | type: $this->type, |
94 | | - types: [$typesString], |
| 88 | + types: [$this->types], |
95 | 89 | controls: [$this->controls], |
96 | 90 | scrollWheelZoom: $this->autozoom |
97 | 91 | }, |
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php |
— | — | @@ -57,22 +57,18 @@ |
58 | 58 | /** |
59 | 59 | * @see MapsBaseMap::addSpecificMapHTML() |
60 | 60 | * |
61 | | - */ |
| 61 | + */ |
62 | 62 | public function addSpecificMapHTML() { |
63 | 63 | global $wgJsMimeType; |
64 | 64 | |
65 | | - $this->type = MapsYahooMaps::getYMapType($this->type, true); |
66 | | - |
67 | | - $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); |
| 65 | + $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); |
68 | 66 | |
69 | | - $typesString = MapsYahooMaps::createTypesString($this->types); |
70 | | - |
71 | 67 | $this->output .= <<<END |
72 | 68 | <div id="$this->mapName" style="width: {$this->width}px; height: {$this->height}px;"></div> |
73 | 69 | |
74 | 70 | <script type="$wgJsMimeType">/*<![CDATA[*/ |
75 | 71 | addOnloadHook( |
76 | | - initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$this->markerString], $this->height) |
| 72 | + initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$this->types], [$this->controls], $this->autozoom, [$this->markerString], $this->height) |
77 | 73 | ); |
78 | 74 | /*]]>*/</script> |
79 | 75 | END; |
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php |
— | — | @@ -47,19 +47,15 @@ |
48 | 48 | */ |
49 | 49 | public function addSpecificMapHTML() { |
50 | 50 | global $wgJsMimeType; |
51 | | - |
52 | | - $this->type = MapsYahooMaps::getYMapType($this->type, true); |
53 | 51 | |
54 | | - $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); |
| 52 | + $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); |
55 | 53 | |
56 | | - $typesString = MapsYahooMaps::createTypesString($this->types); |
57 | | - |
58 | 54 | $this->output .= <<<END |
59 | 55 | <div id="$this->mapName" style="width: {$this->width}px; height: {$this->height}px;"></div> |
60 | 56 | |
61 | 57 | <script type="$wgJsMimeType">/*<![CDATA[*/ |
62 | 58 | addOnloadHook( |
63 | | - initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [], $this->height) |
| 59 | + initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$this->types], [$this->controls], $this->autozoom, [], $this->height) |
64 | 60 | ); |
65 | 61 | /*]]>*/</script> |
66 | 62 | END; |
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php |
— | — | @@ -44,6 +44,8 @@ |
45 | 45 | |
46 | 46 | public static function initialize() { |
47 | 47 | self::initializeParams(); |
| 48 | + Validator::addOutputFormat('ymaptype', array('MapsYahooMaps', 'setYMapType')); |
| 49 | + Validator::addOutputFormat('ymaptypes', array('MapsYahooMaps', 'setYMapTypes')); |
48 | 50 | } |
49 | 51 | |
50 | 52 | private static function initializeParams() { |
— | — | @@ -68,7 +70,8 @@ |
69 | 71 | 'criteria' => array( |
70 | 72 | 'in_array' => $allowedTypes |
71 | 73 | ), |
72 | | - 'default' => $egMapsYahooMapsType |
| 74 | + 'default' => $egMapsYahooMapsType, |
| 75 | + 'output-type' => array('ymaptype') |
73 | 76 | ), |
74 | 77 | 'types' => array ( |
75 | 78 | 'type' => array('string', 'list'), |
— | — | @@ -76,7 +79,8 @@ |
77 | 80 | 'criteria' => array( |
78 | 81 | 'in_array' => $allowedTypes |
79 | 82 | ), |
80 | | - 'default' => $egMapsYahooMapsTypes |
| 83 | + 'default' => $egMapsYahooMapsTypes, |
| 84 | + 'output-types' => array('ymaptypes', 'list') |
81 | 85 | ), |
82 | 86 | 'autozoom' => array( |
83 | 87 | 'aliases' => array('auto zoom', 'mouse zoom', 'mousezoom'), |
— | — | @@ -114,26 +118,30 @@ |
115 | 119 | public static function getControlNames() { |
116 | 120 | return array('scale', 'type', 'pan', 'zoom', 'zoom-short', 'auto-zoom'); |
117 | 121 | } |
118 | | - |
| 122 | + |
119 | 123 | /** |
120 | | - * Returns the Yahoo Map type (defined in MapsYahooMaps::$mapTypes) |
121 | | - * for the provided a general map type. When no match is found, the first |
122 | | - * Google Map type will be returned as default. |
| 124 | + * Changes the map type name into the corresponding Yahoo! Maps API identifier. |
123 | 125 | * |
124 | 126 | * @param string $type |
125 | | - * @param boolean $restoreAsDefault |
126 | 127 | * |
127 | | - * @return string or false |
| 128 | + * @return string |
128 | 129 | */ |
129 | | - public static function getYMapType($type, $restoreAsDefault = false) { |
130 | | - global $egMapsYahooMapsType; |
131 | | - |
132 | | - $typeIsValid = array_key_exists($type, self::$mapTypes); |
133 | | - |
134 | | - if (!$typeIsValid && $restoreAsDefault) $type = $egMapsYahooMapsType; |
135 | | - |
136 | | - return $typeIsValid || $restoreAsDefault ? self::$mapTypes[ $type ] : false; |
137 | | - } |
| 130 | + public static function setYMapType(&$type) { |
| 131 | + $type = self::$mapTypes[ $type ]; |
| 132 | + } |
| 133 | + |
| 134 | + /** |
| 135 | + * Changes the map type names into the corresponding Yahoo! Maps API identifiers. |
| 136 | + * |
| 137 | + * @param array $types |
| 138 | + * |
| 139 | + * @return array |
| 140 | + */ |
| 141 | + public static function setYMapTypes(array &$types) { |
| 142 | + for($i = count($types) - 1; $i >= 0; $i--) { |
| 143 | + $types[$i] = self::$mapTypes[ $types[$i] ]; |
| 144 | + } |
| 145 | + } |
138 | 146 | |
139 | 147 | /** |
140 | 148 | * Add references to the Yahoo! Maps API and required JS file to the provided output |