r60372 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r60371‎ | r60372 | r60373 >
Date:22:16, 24 December 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.5.1. Changes for 0.5.1. Modified parameter definitions to work Validator 0.2.
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Mapper.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php (modified) (history)
  • /trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/Maps.php
@@ -33,7 +33,7 @@
3434 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>.';
3535 }
3636 else {
37 - define('Maps_VERSION', '0.5.1 a4');
 37+ define('Maps_VERSION', '0.5.1 a5');
3838
3939 $egMapsScriptPath = $wgScriptPath . '/extensions/Maps';
4040 $egMapsIP = $IP . '/extensions/Maps';
Index: trunk/extensions/Maps/Maps_Mapper.php
@@ -62,6 +62,8 @@
6363 }
6464
6565 /**
 66+ * TODO: remove
 67+ *
6668 * Returns the JS version (true/false as string) of the provided boolean parameter.
6769 *
6870 * @param boolean $bool
@@ -72,6 +74,8 @@
7375 }
7476
7577 /**
 78+ * TODO: remove
 79+ *
7680 * Turns the provided values into an array by splitting it on comma's if
7781 * it's not an array yet.
7882 *
@@ -84,67 +88,6 @@
8589 }
8690
8791 /**
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 - /**
14992 * Returns a valid service. When an invalid service is provided, the default one will be returned.
15093 * Aliases are also chancged into the main service names @see MapsMapper::getMainServiceName().
15194 *
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php
@@ -57,14 +57,10 @@
5858 public function addSpecificMapHTML() {
5959 global $wgJsMimeType;
6060
61 - $this->type = MapsGoogleMaps::getGMapType($this->type, true);
62 -
6361 $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls);
6462
6563 $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom);
6664
67 - $typesString = MapsGoogleMaps::createTypesString($this->types);
68 -
6965 $this->output .=<<<END
7066
7167 <div id="$this->mapName" class="$this->class" style="$this->style" ></div>
@@ -78,7 +74,7 @@
7975 lon: $this->centre_lon,
8076 zoom: $this->zoom,
8177 type: $this->type,
82 - types: [$typesString],
 78+ types: [$this->types],
8379 controls: [$this->controls],
8480 scrollWheelZoom: $this->autozoom
8581 }, [])
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMaps.php
@@ -44,6 +44,8 @@
4545
4646 public static function initialize() {
4747 self::initializeParams();
 48+ Validator::addOutputFormat('gmaptype', array('MapsGoogleMaps', 'setGMapType'));
 49+ Validator::addOutputFormat('gmaptypes', array('MapsGoogleMaps', 'setGMapTypes'));
4850 }
4951
5052 private static function initializeParams() {
@@ -52,43 +54,45 @@
5355 $allowedTypes = self::getTypeNames();
5456
5557 $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+ );
9397 }
9498
9599 // http://code.google.com/apis/maps/documentation/reference.html#GMapType.G_NORMAL_MAP
@@ -147,31 +151,28 @@
148152 }
149153
150154 /**
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.
154156 *
155157 * @param string $type
156 - * @param boolean $restoreAsDefault
157158 *
158 - * @return string or false
 159+ * @return string
159160 */
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] ];
166175 }
167 - else {
168 - if ($restoreAsDefault) {
169 - return self::$mapTypes[ $egMapsGoogleMapsType ];
170 - }
171 - else {
172 - return false;
173 - }
174 - }
175 - }
 176+ }
176177
177178 /**
178179 * Add references to the Google Maps API and required JS file to the provided output
@@ -192,6 +193,8 @@
193194 }
194195
195196 /**
 197+ * TODO: remove
 198+ *
196199 * Retuns a boolean as string, true if $autozoom is on or yes.
197200 *
198201 * @param string $autozoom
@@ -202,23 +205,6 @@
203206 }
204207
205208 /**
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 - /**
223209 * This function ensures backward compatibility with Semantic Google Maps and other extensions
224210 * using $wgGoogleMapsKey instead of $egGoogleMapsKey.
225211 */
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php
@@ -67,16 +67,10 @@
6868 public function addSpecificMapHTML() {
6969 global $wgJsMimeType;
7070
71 - $this->type = MapsGoogleMaps::getGMapType($this->type, true);
72 -
7371 $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls);
7472
7573 $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom);
7674
77 - $this->types = $this->types;
78 -
79 - $typesString = MapsGoogleMaps::createTypesString($this->types);
80 -
8175 $this->output .=<<<END
8276
8377 <div id="$this->mapName" class="$this->class" style="$this->style" ></div>
@@ -90,7 +84,7 @@
9185 lon: $this->centre_lon,
9286 zoom: $this->zoom,
9387 type: $this->type,
94 - types: [$typesString],
 88+ types: [$this->types],
9589 controls: [$this->controls],
9690 scrollWheelZoom: $this->autozoom
9791 },
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispPoint.php
@@ -57,22 +57,18 @@
5858 /**
5959 * @see MapsBaseMap::addSpecificMapHTML()
6060 *
61 - */
 61+ */
6262 public function addSpecificMapHTML() {
6363 global $wgJsMimeType;
6464
65 - $this->type = MapsYahooMaps::getYMapType($this->type, true);
66 -
67 - $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom);
 65+ $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom);
6866
69 - $typesString = MapsYahooMaps::createTypesString($this->types);
70 -
7167 $this->output .= <<<END
7268 <div id="$this->mapName" style="width: {$this->width}px; height: {$this->height}px;"></div>
7369
7470 <script type="$wgJsMimeType">/*<![CDATA[*/
7571 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)
7773 );
7874 /*]]>*/</script>
7975 END;
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMapsDispMap.php
@@ -47,19 +47,15 @@
4848 */
4949 public function addSpecificMapHTML() {
5050 global $wgJsMimeType;
51 -
52 - $this->type = MapsYahooMaps::getYMapType($this->type, true);
5351
54 - $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom);
 52+ $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom);
5553
56 - $typesString = MapsYahooMaps::createTypesString($this->types);
57 -
5854 $this->output .= <<<END
5955 <div id="$this->mapName" style="width: {$this->width}px; height: {$this->height}px;"></div>
6056
6157 <script type="$wgJsMimeType">/*<![CDATA[*/
6258 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)
6460 );
6561 /*]]>*/</script>
6662 END;
Index: trunk/extensions/Maps/YahooMaps/Maps_YahooMaps.php
@@ -44,6 +44,8 @@
4545
4646 public static function initialize() {
4747 self::initializeParams();
 48+ Validator::addOutputFormat('ymaptype', array('MapsYahooMaps', 'setYMapType'));
 49+ Validator::addOutputFormat('ymaptypes', array('MapsYahooMaps', 'setYMapTypes'));
4850 }
4951
5052 private static function initializeParams() {
@@ -68,7 +70,8 @@
6971 'criteria' => array(
7072 'in_array' => $allowedTypes
7173 ),
72 - 'default' => $egMapsYahooMapsType
 74+ 'default' => $egMapsYahooMapsType,
 75+ 'output-type' => array('ymaptype')
7376 ),
7477 'types' => array (
7578 'type' => array('string', 'list'),
@@ -76,7 +79,8 @@
7780 'criteria' => array(
7881 'in_array' => $allowedTypes
7982 ),
80 - 'default' => $egMapsYahooMapsTypes
 83+ 'default' => $egMapsYahooMapsTypes,
 84+ 'output-types' => array('ymaptypes', 'list')
8185 ),
8286 'autozoom' => array(
8387 'aliases' => array('auto zoom', 'mouse zoom', 'mousezoom'),
@@ -114,26 +118,30 @@
115119 public static function getControlNames() {
116120 return array('scale', 'type', 'pan', 'zoom', 'zoom-short', 'auto-zoom');
117121 }
118 -
 122+
119123 /**
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.
123125 *
124126 * @param string $type
125 - * @param boolean $restoreAsDefault
126127 *
127 - * @return string or false
 128+ * @return string
128129 */
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+ }
138146
139147 /**
140148 * Add references to the Yahoo! Maps API and required JS file to the provided output

Status & tagging log