r58935 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r58934‎ | r58935 | r58936 >
Date:03:23, 12 November 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Modified paths:
  • /trunk/extensions/Maps/GoogleMaps/GoogleMapFunctions.js (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php (modified) (history)
  • /trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php (modified) (history)
  • /trunk/extensions/Maps/Maps.i18n.php (modified) (history)
  • /trunk/extensions/Maps/Maps.php (modified) (history)
  • /trunk/extensions/Maps/Maps_Settings.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php (modified) (history)
  • /trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Maps/ParserFunctions/DisplayPoint/Maps_BasePointMap.php
@@ -31,7 +31,7 @@
3232 public final function displayMap(&$parser, array $params) {
3333 $this->setMapSettings();
3434
35 - $coords = $this->manageMapProperties($params);
 35+ $coords = $this->manageMapProperties($params, __CLASS__);
3636
3737 $this->doMapServiceLoad();
3838
@@ -56,8 +56,8 @@
5757 * (non-PHPdoc)
5858 * @see smw/extensions/Maps/MapsMapFeature#manageMapProperties($mapProperties, $className)
5959 */
60 - protected function manageMapProperties($params) {
61 - parent::manageMapProperties($params, __CLASS__);
 60+ protected function manageMapProperties($params, $className) {
 61+ parent::manageMapProperties($params, $className);
6262 }
6363
6464 /**
Index: trunk/extensions/Maps/ParserFunctions/DisplayMap/Maps_BaseMap.php
@@ -29,7 +29,7 @@
3030 public final function displayMap(&$parser, array $params) {
3131 $this->setMapSettings();
3232
33 - $coords = $this->manageMapProperties($params);
 33+ $coords = $this->manageMapProperties($params, __CLASS__);
3434
3535 $this->doMapServiceLoad();
3636
@@ -48,8 +48,8 @@
4949 * (non-PHPdoc)
5050 * @see smw/extensions/Maps/MapsMapFeature#manageMapProperties($mapProperties, $className)
5151 */
52 - protected function manageMapProperties($params) {
53 - parent::manageMapProperties($params, __CLASS__);
 52+ protected function manageMapProperties($params, $className) {
 53+ parent::manageMapProperties($params, $className);
5454 }
5555
5656 /**
Index: trunk/extensions/Maps/Maps.php
@@ -23,7 +23,7 @@
2424 die( 'Not an entry point.' );
2525 }
2626
27 -define('Maps_VERSION', '0.4.2 a1');
 27+define('Maps_VERSION', '0.4.2 a2');
2828
2929 $egMapsScriptPath = $wgScriptPath . '/extensions/Maps';
3030 $egMapsIP = $IP . '/extensions/Maps';
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispMap.php
@@ -54,6 +54,8 @@
5555
5656 $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls);
5757
 58+ $onloadFunctions = MapsGoogleMapsUtils::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls);
 59+
5860 $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom);
5961
6062 $this->types = explode(",", $this->types);
@@ -82,6 +84,8 @@
8385
8486 END;
8587
 88+ $this->output .= $onloadFunctions;
 89+
8690 }
8791
8892 }
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsUtils.php
@@ -54,7 +54,14 @@
5555 'mars-infrared' => 'G_MARS_INFRARED_MAP',
5656 'G_MARS_INFRARED_MAP' => 'G_MARS_INFRARED_MAP',
5757 );
58 -
 58+
 59+ private static $overlayData = array(
 60+ 'photos' => '0',
 61+ 'videos' => '1',
 62+ 'wikipedia' => '2',
 63+ 'webcams' => '3'
 64+ );
 65+
5966 /**
6067 * Returns the Google Map type (defined in MapsGoogleMaps::$mapTypes)
6168 * for the provided a general map type. When no match is found, false
@@ -117,7 +124,7 @@
118125 * @param string $output
119126 */
120127 public static function addGMapDependencies(&$output) {
121 - global $wgJsMimeType, $wgLang;
 128+ global $wgJsMimeType, $wgLang, $wgOut;
122129 global $egGoogleMapsKey, $egMapsScriptPath, $egGoogleMapsOnThisPage, $egMapsStyleVersion;
123130
124131 if (empty($egGoogleMapsOnThisPage)) {
@@ -194,4 +201,130 @@
195202 }
196203 }
197204
 205+ /**
 206+ *
 207+ *
 208+ * @param string $output
 209+ * @param string $mapName
 210+ * @return unknown_type
 211+ */
 212+ public static function addOverlayOutput(&$output, $mapName, $overlays, $controls) {
 213+ global $egMapsGMapOverlays, $egMapsGoogleOverlLoaded, $wgJsMimeType;
 214+
 215+ // Check to see if there is an overlays control.
 216+ $hasOverlayControl = in_string('overlays', $controls);
 217+
 218+ $overlayNames = array_keys(self::$overlayData);
 219+
 220+ // Create the overlays array, and use the default in case no overlays have been provided.
 221+ if (strlen(trim($overlays)) < 1) {
 222+ $overlays = $egMapsGMapOverlays;
 223+ } else {
 224+ MapsMapper::enforceArrayValues($overlays);
 225+ $validOverlays = array();
 226+ foreach ($overlays as $overlay) {
 227+ $segements = split('-', $overlay);
 228+ $name = $segements[0];
 229+
 230+ if (in_array($name, $overlayNames)) {
 231+ $isOn = count($segements) > 1 ? $segements[1] : '0';
 232+ $validOverlays[$name] = $isOn == '1';
 233+ }
 234+ }
 235+ $overlays = $validOverlays;
 236+ }
 237+
 238+ // If there are no overlays or there is no control to hold them, don't bother the rest.
 239+ if(!$hasOverlayControl || count($overlays) < 1) return;
 240+
 241+ // If the overlays JS and CSS has not yet loaded, do it.
 242+ if (empty($egMapsGoogleOverlLoaded)) {
 243+ $egMapsGoogleOverlLoaded = true;
 244+ MapsGoogleMapsUtils::addOverlayCss($output);
 245+ }
 246+
 247+ // Add the inputs for the overlays.
 248+ $addedOverlays = array();
 249+ $overlayHtml = '';
 250+ $onloadFunctions = '';
 251+ foreach ($overlays as $overlay => $isOn) {
 252+ $overlay = strtolower($overlay);
 253+
 254+ if (in_array($overlay, $overlayNames)) {
 255+ if (! in_array($overlay, $addedOverlays)) {
 256+ $addedOverlays[] = $overlay;
 257+ $label = wfMsg('maps_' . $overlay);
 258+ $urlNr = self::$overlayData[$overlay];
 259+ $overlayHtml .= "<input id='$mapName-overlay-box-$overlay' name='$mapName-overlay-box' type='checkbox' onclick='switchGLayer(GMaps[\"$mapName\"], this.checked, GOverlays[$urlNr])' /> $label <br />";
 260+ if ($isOn) {
 261+ $onloadFunctions .= "<script type='$wgJsMimeType'>addOnloadHook( initiateGOverlay('$mapName-overlay-box-$overlay', '$mapName', $urlNr) );</script>";
 262+ }
 263+ }
 264+ }
 265+ }
 266+
 267+ $output .=<<<END
 268+<script type='$wgJsMimeType'>var timer_$mapName;</script>
 269+<div class='outer-more' id='$mapName-outer-more'><form action=''><div class='more-box' id='$mapName-more-box'>
 270+$overlayHtml
 271+</div></form></div>
 272+END;
 273+
 274+ return $onloadFunctions;
 275+ }
 276+
 277+ /**
 278+ *
 279+ *
 280+ * @param $output
 281+ * @return unknown_type
 282+ */
 283+ private static function addOverlayCss(&$output) {
 284+ $css =<<<END
 285+
 286+<style type="text/css">
 287+.inner-more {
 288+ text-align:center;
 289+ font-size:12px;
 290+ background-color: #fff;
 291+ color: #000;
 292+ border: 1px solid #fff;
 293+ border-right-color: #b0b0b0;
 294+ border-bottom-color: #c0c0c0;
 295+ width:7em;
 296+ cursor: pointer;
 297+}
 298+
 299+.inner-more.highlight {
 300+ font-weight: bold;
 301+ border: 1px solid #483D8B;
 302+ border-right-color: #6495ed;
 303+ border-bottom-color: #6495ed;
 304+}
 305+
 306+.more-box { position:absolute;
 307+ top:25px; left:0px;
 308+ margin-top:-1px;
 309+ font-size:12px;
 310+ padding: 6px 4px;
 311+ width:120px;
 312+ background-color: #fff;
 313+ color: #000;
 314+ border: 1px solid gray;
 315+ border-top:1px solid #e2e2e2;
 316+ display: none;
 317+ cursor:default;
 318+}
 319+
 320+.more-box.highlight {
 321+ width:119px;
 322+ border-width:2px;
 323+}
 324+</style>
 325+
 326+END;
 327+
 328+ $output .= preg_replace('/\s+/m', ' ', $css);
 329+ }
 330+
198331 }
\ No newline at end of file
Index: trunk/extensions/Maps/GoogleMaps/Maps_GoogleMapsDispPoint.php
@@ -48,7 +48,7 @@
4949 *
5050 */
5151 public function addSpecificMapHTML() {
52 - global $wgJsMimeType;
 52+ global $wgJsMimeType, $wgOut;
5353
5454 $enableEarth = MapsGoogleMapsUtils::getEarthValue($this->earth);
5555
@@ -56,6 +56,8 @@
5757
5858 $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls);
5959
 60+ $onloadFunctions = MapsGoogleMapsUtils::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls);
 61+
6062 $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom);
6163
6264 $markerItems = array();
@@ -67,10 +69,10 @@
6870
6971 $title = array_key_exists('title', $markerData) ? $markerData['title'] : $this->title;
7072 $label = array_key_exists('label', $markerData) ? $markerData['label'] : $this->label;
71 -
 73+
7274 $title = str_replace("'", "\'", $title);
7375 $label = str_replace("'", "\'", $label);
74 -
 76+
7577 $icon = array_key_exists('icon', $markerData) ? $markerData['icon'] : '';
7678 $markerItems[] = "getGMarkerData($lat, $lon, '$title', '$label', '$icon')";
7779 }
@@ -82,7 +84,7 @@
8385 $typesString = MapsGoogleMapsUtils::createTypesString($this->types, $enableEarth);
8486
8587 $this->output .=<<<END
86 -
 88+
8789 <div id="$this->mapName" class="$this->class" style="$this->style" ></div>
8890 <script type="$wgJsMimeType"> /*<![CDATA[*/
8991 addOnloadHook(
@@ -105,6 +107,8 @@
106108
107109 END;
108110
 111+ $this->output .= $onloadFunctions;
 112+
109113 }
110114
111115 }
Index: trunk/extensions/Maps/GoogleMaps/GoogleMapFunctions.js
@@ -9,7 +9,14 @@
1010 * @author Jeroen De Dauw
1111 */
1212
 13+var GOverlays = [
 14+ new GLayer("com.panoramio.all"),
 15+ new GLayer("com.youtube.all"),
 16+ new GLayer("org.wikipedia.en"),
 17+ new GLayer("com.google.webcams")
 18+];
1319
 20+
1421 /**
1522 * Returns GMarker object on the provided location. It will show a popup baloon
1623 * with title and label when clicked, if either of these is set.
@@ -48,7 +55,7 @@
4956 if (GBrowserIsCompatible()) {
5057 mapOptions.centre = (mapOptions.lat != null && mapOptions.lon != null) ? new GLatLng(mapOptions.lat, mapOptions.lon) : null;
5158 mapOptions.size = new GSize(mapOptions.width, mapOptions.height);
52 - return createGoogleMap(document.getElementById(mapName), mapOptions, markers);
 59+ return createGoogleMap(mapName, mapOptions, markers);
5360 }
5461 else {
5562 return false;
@@ -58,20 +65,22 @@
5966 /**
6067 * Returns GMap2 object with the provided properties.
6168 */
62 -function createGoogleMap(mapElement, mapOptions, markers) {
 69+function createGoogleMap(mapName, mapOptions, markers) {
 70+ var mapElement = document.getElementById(mapName);
6371 var typesContainType = false;
6472
6573 // TODO: Change labels of the moon/mars map types?
6674 for (var i = 0; i < mapOptions.types.length; i++) {
6775 if (mapOptions.types[i] == mapOptions.type) typesContainType = true;
6876 }
69 -
 77+
7078 if (! typesContainType) mapOptions.types.push(mapOptions.type);
7179
7280 var map = new GMap2(mapElement, {size: mapOptions.size, mapTypes: mapOptions.types});
73 -
 81+ map.name = mapName;
 82+
7483 map.setMapType(mapOptions.type);
75 -
 84+
7685 // List of GControls: http://code.google.com/apis/maps/documentation/reference.html#GControl
7786 for (i in mapOptions.controls){
7887 switch (mapOptions.controls[i]) {
@@ -92,10 +101,13 @@
93102 break;
94103 case 'type' :
95104 map.addControl(new GMapTypeControl());
96 - break;
 105+ break;
97106 case 'type-menu' :
98107 map.addControl(new GMenuMapTypeControl());
99108 break;
 109+ case 'overlays' :
 110+ map.addControl(new MoreControl());
 111+ break;
100112 case 'overview' : case 'overview-map' :
101113 map.addControl(new GOverviewMapControl());
102114 break;
@@ -107,29 +119,121 @@
108120 break;
109121 }
110122 }
111 -
 123+
112124 var bounds = ((mapOptions.zoom == null || mapOptions.centre == null) && markers.length > 1) ? new GLatLngBounds() : null;
113 -
 125+
114126 for (i in markers) {
115127 var marker = markers[i];
116128 map.addOverlay(createGMarker(marker.point, marker.title, marker.label, marker.icon));
117129 if (bounds != null) bounds.extend(marker.point);
118130 }
119 -
 131+
120132 if (bounds != null) {
121133 map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel(bounds));
122134 }
123 -
 135+
124136 if (mapOptions.centre != null) map.setCenter(mapOptions.centre);
125137 if (mapOptions.zoom != null) map.setZoom(mapOptions.zoom);
126138
127139 if (mapOptions.scrollWheelZoom) map.enableScrollWheelZoom();
128 -
 140+
129141 map.enableContinuousZoom();
130142
 143+ // Make the map variable available for other functions
 144+ if (!window.GMaps) window.GMaps = new Object;
 145+ eval("window.GMaps." + mapName + " = map;");
 146+
131147 return map;
132148 }
133149
134150 function getGMarkerData(lat, lon, title, label, icon) {
135151 return {point: new GLatLng(lat, lon), title: title, label: label, icon: icon};
136152 }
 153+
 154+function setupCheckboxShiftClick() { return true; }
 155+
 156+
 157+function MoreControl() {};
 158+MoreControl.prototype = new GControl();
 159+
 160+MoreControl.prototype.initialize = function(map) {
 161+ alert('ur doin it wron');
 162+ this.map = map;
 163+
 164+ var more = document.getElementById(map.name + "-outer-more");
 165+
 166+ var buttonDiv = document.createElement("div");
 167+ buttonDiv.id = map.name + "-more-button";
 168+ buttonDiv.title = "Show/Hide Overlays";
 169+ buttonDiv.style.border = "1px solid black";
 170+ buttonDiv.style.width = "86px";
 171+
 172+ var textDiv = document.createElement("div");
 173+ textDiv.id = map.name + "-inner-more";
 174+ textDiv.setAttribute('class', 'inner-more');
 175+ textDiv.appendChild(document.createTextNode("Overlays"));
 176+
 177+ buttonDiv.appendChild(textDiv);
 178+
 179+ // Register Event handlers
 180+ more.onmouseover = showGLayerbox;
 181+ more.onmouseout = setGLayerboxClose;
 182+
 183+ // Insert the button just after outer_more div.
 184+ more.insertBefore(buttonDiv, document.getElementById(map.name + "-more-box").parentNode);
 185+
 186+ // Remove the whole div from its location and reinsert it to the map.
 187+ map.getContainer().appendChild(more);
 188+
 189+ return more;
 190+};
 191+
 192+MoreControl.prototype.getDefaultPosition = function() {
 193+ return new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(7, 35));
 194+};
 195+
 196+function checkGChecked(mapName) {
 197+ // Returns true if a checkbox is still checked otherwise false.
 198+ var boxes = document.getElementsByName(mapName + "-overlay-box");
 199+ for(var i = 0; i < boxes.length; i++) {
 200+ if(boxes[i].checked) return true;
 201+ }
 202+ return false;
 203+}
 204+
 205+function showGLayerbox() {
 206+ var mapName = this.id.split('-')[0];
 207+ eval("if(window.timer_" + mapName + ") clearTimeout(timer_" + mapName + ");");
 208+ document.getElementById(mapName + "-more-box").style.display = "block";
 209+ var button = document.getElementById(mapName + "-inner-more");
 210+ button.style.borderBottomWidth = "4px";
 211+ button.style.borderBottomColor = "white";
 212+}
 213+
 214+
 215+function setGLayerboxClose() {
 216+ var mapName = this.id.split('-')[0];
 217+ var layerbox = document.getElementById(mapName + "-more-box");
 218+ var button = document.getElementById(mapName + "-inner-more");
 219+ var bottomColor = checkGChecked(mapName) ? "#6495ed" : "#c0c0c0";
 220+ eval("timer_" + mapName + " = window.setTimeout(function() { layerbox.style.display = 'none'; button.style.borderBottomWidth = '1px'; button.style.borderBottomColor = bottomColor; }, 400);");
 221+}
 222+
 223+function switchGLayer(map, checked, layer) {
 224+ // Function borrowed from Esa: http://esa.ilmari.googlepages.com/dropdownmenu.htm
 225+ var layerbox = document.getElementById(map.name + "-more-box");
 226+ var button = document.getElementById(map.name + "-inner-more");
 227+
 228+ if(checked) {
 229+ map.addOverlay(layer);
 230+ }
 231+ else {
 232+ map.removeOverlay(layer);
 233+ }
 234+
 235+}
 236+
 237+function initiateGOverlay(elementId, mapName, urlNr) {
 238+ document.getElementById(elementId).checked = true;
 239+ switchGLayer(GMaps[mapName], true, GOverlays[urlNr]);
 240+}
Index: trunk/extensions/Maps/Maps.i18n.php
@@ -15,16 +15,20 @@
1616 * @author Jeroen De Dauw
1717 */
1818 $messages['en'] = array(
 19+ // General
1920 'maps_name' => 'Maps',
2021 'maps_desc' => "Provides the ability to display coordinate data in maps, and geocode addresses ([http://wiki.bn2vs.com/wiki/Maps demo]).
2122 Available mapping services: $1",
 23+ 'maps_map' => 'Map',
2224
 25+ // Geocoding errors
2326 'maps_coordinates_missing' => 'No coordinates provided for the map.',
2427 'maps_geocoding_failed' => 'The following {{PLURAL:$2|address|addresses}} could not be geocoded: $1.
2528 The map cannot be displayed.',
2629 'maps_geocoding_failed_for' => 'The following {{PLURAL:$2|address|addresses}} could not be geocoded and {{PLURAL:$2|has|have}} been omitted from the map:
2730 $1',
2831
 32+ // Parameter errors. Used when strict parameter validation is turned on.
2933 'maps_error_parameters' => 'The following errors have been detected in your syntaxis',
3034 'maps_error_invalid_argument' => 'The value $1 is not valid for parameter $2.',
3135 'maps_error_empty_argument' => 'Parameter $1 can not have an empty value.',
@@ -32,12 +36,18 @@
3337 'maps_error_must_be_number' => 'Parameter $1 can only be a number.',
3438 'maps_error_ivalid_range' => 'Parameter $1 must be between $2 and $3.',
3539
36 - 'maps_map' => 'Map',
37 -
 40+ // Mapping services
3841 'maps_googlemaps' => 'Google Maps',
3942 'maps_yahoomaps' => 'Yahoo! Maps',
4043 'maps_openlayers' => 'OpenLayers',
4144 'maps_osm' => 'OpenStreetMaps',
 45+
 46+ // Google Maps overlays
 47+ 'maps_overlays' => 'Overlays',
 48+ 'maps_photos' => 'Photos',
 49+ 'maps_videos' => 'Videos',
 50+ 'maps_wikipedia' => 'Wikipedia',
 51+ 'maps_webcams' => 'Webcams'
4252 );
4353
4454 /** Message documentation (Message documentation)
Index: trunk/extensions/Maps/Maps_Settings.php
@@ -162,10 +162,15 @@
163163
164164 # Array of String. The default controls for Google Maps. This value will only be used when the user does not provide one.
165165 # Available values: large, small, large-original, small-original, zoom, type, type-menu, overview-map, scale, nav-label
166 -$egMapsGMapControls = array('large', 'scale', 'type');
 166+$egMapsGMapControls = array('large', 'scale', 'type', 'overlays');
167167
 168+# Array. The default overlays for the Google Maps overlays control, and wether they should be shown at pageload.
 169+# This value will only be used when the user does not provide one.
 170+# Available values: photos, videos, wikipedia, webcams
 171+$egMapsGMapOverlays = array('photos' => false, 'videos' => true, 'wikipedia' => true, 'webcams' => false);
168172
169173
 174+
170175 # Yahoo maps
171176
172177 # Your Yahoo! Maps API key. Required for displaying Yahoo! Maps.

Status & tagging log