r59745 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r59744‎ | r59745 | r59746 >
Date:21:01, 4 December 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Modified paths:
  • /trunk/extensions/SemanticMaps/FormInputs/SM_FormInputFactory.php (deleted) (history)
  • /trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php (modified) (history)
  • /trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFunctions.js (modified) (history)
  • /trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSM.php (modified) (history)
  • /trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFunctions.js (modified) (history)
  • /trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SM_Settings.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFunctions.js
@@ -87,7 +87,7 @@
8888 }
8989
9090 /**
91 - * Remove all markers from an OL map (that's in window.OLMaps), and pplace a new one.
 91+ * Remove all markers from an OL map (that's in window.OLMaps), and place a new one.
9292 *
9393 * @param mapName Name of the map as in OLMaps[mapName].
9494 * @param newLocation The location for the new marker.
Index: trunk/extensions/SemanticMaps/SM_Settings.php
@@ -53,3 +53,11 @@
5454 include_once $smgIP . '/OpenStreetMap/SM_OSM.php'; // OpenLayers optimized for OSM
5555
5656
 57+
 58+
 59+
 60+# Array of String. The default mapping service for each feature, which will be used when no valid service is provided by the user.
 61+# Each service needs to be enabled, if not, the first one from the available services will be taken.
 62+# Note: The default service needs to be available for the feature you set it for, since it's used as a fallback mechanism.
 63+$egMapsDefaultServices['qp'] = 'googlemaps';
 64+$egMapsDefaultServices['fi'] = 'googlemaps';
Index: trunk/extensions/SemanticMaps/FormInputs/SM_FormInputFactory.php
@@ -1,61 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Factory method for form input handling classes
6 - *
7 - * @file SM_FormInputFactory.php
8 - * @ingroup SemanticMaps
9 - *
10 - * @author Jeroen De Dauw
11 - */
12 -
13 -if( !defined( 'MEDIAWIKI' ) ) {
14 - die( 'Not an entry point.' );
15 -}
16 -
17 -class SMFormInputFactory {
18 -
19 - public static function getFormInputHtml() {
20 - global $egMapsServices;
21 -
22 - // If service_name is set, use this value, and ignore any given
23 - // service parameters
24 - // This will prevent ..input type=googlemaps|service=yahoo.. from
25 - // showing up as a Yahoo! Maps map
26 - if (array_key_exists('service_name', $field_args)) {
27 - $service_name = $field_args['service_name'];
28 - }
29 - elseif (array_key_exists('service', $field_args)) {
30 - $service_name = $field_args['service'];
31 - }
32 - else{
33 - $service_name = null;
34 - }
35 -
36 - $service_name = MapsMapper::getValidService($service_name, 'fi');
37 -
38 - $formInput = self::getFormInputInstance();
39 -
40 - // Get and return the form input HTML from the hook corresponding with the provided service
41 - return $formInput->formInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args);
42 - }
43 -
44 - private static function getFormInputInstance($serviceName) {
45 - return new $egMapsServices[$service_name]['fi']['class']();
46 - }
47 -
48 -}
49 -
50 -/**
51 - * Class for the form input type 'map'. The relevant form input class is called depending on the provided service.
52 - *
53 - * @param unknown_type $coordinates
54 - * @param unknown_type $input_name
55 - * @param unknown_type $is_mandatory
56 - * @param unknown_type $is_disabled
57 - * @param array $field_args
58 - * @return unknown
59 - */
60 -function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, array $field_args) {
61 -
62 -}
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php
@@ -39,7 +39,7 @@
4040 $hasFormInputs = true;
4141
4242 // Add the result form input type for the service name.
43 - self::initFormHook($serviceName, $serviceData['fi']);
 43+ self::initFormHook($serviceName, $serviceData['fi'], $serviceName);
4444
4545 // Loop through the service alliases, and add them as form input types.
4646 foreach ($serviceData['aliases'] as $alias) self::initFormHook($alias, $serviceData['fi'], $serviceName);
@@ -52,8 +52,8 @@
5353 }
5454
5555 private static function initializeParams() {
56 - global $egMapsAvailableServices, $egMapsDefaultService, $egMapsDefaultCentre, $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
57 -
 56+ global $egMapsAvailableServices, $egMapsDefaultServices, $egMapsDefaultCentre, $egMapsAvailableGeoServices, $egMapsDefaultGeoService;
 57+
5858 self::$parameters = array(
5959 'centre' => array(
6060 'aliases' => array('center'),
@@ -65,7 +65,7 @@
6666 'criteria' => array(
6767 'in_array' => $egMapsAvailableServices
6868 ),
69 - 'default' => $egMapsDefaultService
 69+ 'default' => $egMapsDefaultServices['fi']
7070 ),
7171 'geoservice' => array(
7272 'aliases' => array(),
@@ -73,7 +73,7 @@
7474 'in_array' => array_keys($egMapsAvailableGeoServices)
7575 ),
7676 'default' => $egMapsDefaultGeoService
77 - ),
 77+ ),
7878 'service_name' => array('default' => ''),
7979 'part_of_multiple' => array('default' => ''),
8080 'possible_values' => array('default' => ''),
@@ -84,13 +84,13 @@
8585 }
8686
8787 /**
88 - * Adds a mapping service's form hook
 88+ * Adds a mapping service's form hook.
8989 *
90 - * @param string $service
 90+ * @param string $inputName The name of the form input.
9191 * @param array $fi
9292 * @param strig $mainName
9393 */
94 - private static function initFormHook($service, array $fi = null, $mainName = '') {
 94+ private static function initFormHook($inputName, array $fi = null, $mainName = '') {
9595 global $wgAutoloadClasses, $sfgFormPrinter, $smgIP;
9696
9797 if (isset($fi)) {
@@ -103,13 +103,13 @@
104104 // Add the form input hook for the service
105105 $field_args = array();
106106 if (strlen($mainName) > 0) $field_args['service_name'] = $mainName;
107 - $sfgFormPrinter->setInputTypeHook($service, 'smfSelectFormInputHTML', $field_args);
 107+ $sfgFormPrinter->setInputTypeHook($inputName, 'smfSelectFormInputHTML', $field_args);
108108 }
109109
110110 }
111111
112112 /**
113 - * Class for the form input type 'map'. The relevant form input class is called depending on the provided service.
 113+ * Calls the relevant form input class depending on the provided service.
114114 *
115115 * @param unknown_type $coordinates
116116 * @param unknown_type $input_name
@@ -122,10 +122,8 @@
123123 function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, array $field_args) {
124124 global $egMapsServices;
125125
126 - // If service_name is set, use this value, and ignore any given
127 - // service parameters
128 - // This will prevent ..input type=googlemaps|service=yahoo.. from
129 - // showing up as a Yahoo! Maps map
 126+ // If service_name is set, use this value, and ignore any given service parameters.
 127+ // This will prevent ..input type=googlemaps|service=yahoo.. from showing up as a Yahoo! Maps map.
130128 if (array_key_exists('service_name', $field_args)) {
131129 $service_name = $field_args['service_name'];
132130 }
@@ -137,7 +135,6 @@
138136 }
139137
140138 $service_name = MapsMapper::getValidService($service_name, 'fi');
141 -
142139 $formInput = new $egMapsServices[$service_name]['fi']['class']();
143140
144141 // Get and return the form input HTML from the hook corresponding with the provided service
Index: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFunctions.js
@@ -0,0 +1,118 @@
 2+ /**
 3+ * Javascript functions for OpenStreetMap functionallity in Semantic Maps
 4+ *
 5+ * @file SM_OSMFunctions.js
 6+ * @ingroup SMOSM
 7+ *
 8+ * @author Jeroen De Dauw
 9+ */
 10+
 11+/**
 12+ * This function holds spesific functionallity for the OpenStreetMap form input of Semantic Maps
 13+ * TODO: Refactor as much code as possible to non specific functions
 14+ */
 15+function makeOSMFormInput(mapName, locationFieldName, lat, lon, zoom, marker_lat, marker_lon, layers, controls, height) {
 16+ var markers = Array();
 17+
 18+ // Show a starting marker only if marker coordinates are provided
 19+ if (marker_lat != null && marker_lon != null) {
 20+ markers.push(getOSMMarkerData(marker_lon, marker_lat, '', ''));
 21+ }
 22+
 23+ // Click event handler for updating the location of the marker
 24+ // TODO / FIXME: This will probably cause problems when used for multiple maps on one page.
 25+ OpenLayers.Control.Click = OpenLayers.Class(OpenLayers.Control, {
 26+ defaultHandlerOptions: {
 27+ 'single': true,
 28+ 'double': false,
 29+ 'pixelTolerance': 0,
 30+ 'stopSingle': false,
 31+ 'stopDouble': false
 32+ },
 33+
 34+ initialize: function(options) {
 35+ this.handlerOptions = OpenLayers.Util.extend(
 36+ {}, this.defaultHandlerOptions
 37+ );
 38+ OpenLayers.Control.prototype.initialize.apply(
 39+ this, arguments
 40+ );
 41+ this.handler = new OpenLayers.Handler.Click(
 42+ this, {
 43+ 'click': this.trigger
 44+ }, this.handlerOptions
 45+ );
 46+ },
 47+
 48+ trigger: function(e) {
 49+ replaceMarker(mapName, map.getLonLatFromViewPortPx(e.xy));
 50+ document.getElementById(locationFieldName).value = convertLatToDMS(map.getLonLatFromViewPortPx(e.xy).lat)+', '+convertLngToDMS(map.getLonLatFromViewPortPx(e.xy).lon);
 51+ }
 52+
 53+ });
 54+
 55+ var clickHanler = new OpenLayers.Control.Click();
 56+ controls.push(clickHanler);
 57+
 58+ var map = initOpenLayer(mapName, lon, lat, zoom, layers, controls, markers, height);
 59+
 60+ // Make the map variable available for other functions
 61+ if (!window.OSMMaps) window.OSMMaps = new Object;
 62+ eval("window.OSMMaps." + mapName + " = map;");
 63+}
 64+
 65+
 66+/**
 67+ * This function holds spesific functionallity for the OpenStreetMap form input of Semantic Maps
 68+ * TODO: Refactor as much code as possible to non specific functions
 69+ */
 70+function showOSMAddress(address, mapName, outputElementName, notFoundFormat) {
 71+
 72+ var map = OSMMaps[mapName];
 73+ var geocoder = new GClientGeocoder();
 74+
 75+ geocoder.getLatLng(address,
 76+ function(point) {
 77+ if (!point) {
 78+ window.alert(address + ' ' + notFoundFormat);
 79+ } else {
 80+ var loc = new OpenLayers.LonLat(point.x, point.y);
 81+
 82+ replaceMarker(mapName, loc);
 83+ document.getElementById(outputElementName).value = convertLatToDMS(point.y) + ', ' + convertLngToDMS(point.x);
 84+ }
 85+ }
 86+ );
 87+
 88+}
 89+
 90+/**
 91+ * Remove all markers from an OSM map (that's in window.OSMMaps), and place a new one.
 92+ *
 93+ * @param mapName Name of the map as in OSMMaps[mapName].
 94+ * @param newLocation The location for the new marker.
 95+ * @return
 96+ */
 97+function replaceMarker(mapName, newLocation) {
 98+ var map = OSMMaps[mapName];
 99+ var markerLayer = map.getLayer('markerLayer');
 100+
 101+ removeOSMMarkers(markerLayer);
 102+ markerLayer.addMarker(getOSMMarker(markerLayer, getOSMMarkerData(newLocation.lon, newLocation.lat, '', ''), map.getProjectionObject()));
 103+
 104+ map.panTo(newLocation);
 105+}
 106+
 107+/**
 108+ * Removes all markers from a marker layer.
 109+ *
 110+ * @param markerLayer The layer to remove all markers from.
 111+ * @return
 112+ */
 113+function removeOSMMarkers(markerLayer) {
 114+ var markerCollection = markerLayer.markers;
 115+
 116+ for (i in markerCollection) {
 117+ markerLayer.removeMarker(markerCollection[i]);
 118+ }
 119+}
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSM.php
@@ -3,15 +3,15 @@
44 /**
55 * This groupe contains all OpenStreetMap related files of the Semantic Maps extension.
66 *
7 - * @defgroup SMOpenStreetMap OpenStreetMap
 7+ * @defgroup SMOSM OpenStreetMap
88 * @ingroup SemanticMaps
99 */
1010
1111 /**
1212 * This file holds the general information for the OpenStreetMap service.
1313 *
14 - * @file SM_OpenStreetMap.php
15 - * @ingroup SMOpenStreetMap
 14+ * @file SM_OSM.php
 15+ * @ingroup SMOSM
1616 *
1717 * @author Jeroen De Dauw
1818 */
@@ -21,4 +21,4 @@
2222 }
2323
2424 $egMapsServices['osm']['qp'] = array('class' => 'SMOSMQP', 'file' => 'SemanticMaps/OpenStreetMap/SM_OSMQP.php', 'local' => false);
25 -// $egMapsServices['osm']['fi'] = array('class' => 'SMOSMFormInput', 'file' => 'SemanticMaps/OpenStreetMap/SM_OSMFormInput.php', 'local' => false);
\ No newline at end of file
 25+//$egMapsServices['osm']['fi'] = array('class' => 'SMOSMFormInput', 'file' => 'SemanticMaps/OpenStreetMap/SM_OSMFormInput.php', 'local' => false);
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/OpenStreetMap/SM_OSMFormInput.php
@@ -40,7 +40,7 @@
4141 global $wgJsMimeType;
4242 global $smgScriptPath, $smgOSMFormsOnThisPage, $smgStyleVersion;
4343
44 - MapsOSM::addOLDependencies($this->output);
 44+ MapsOSM::addOSMDependencies($this->output);
4545
4646 if (empty($smgOSMFormsOnThisPage)) {
4747 $smgOSMFormsOnThisPage = 0;
@@ -73,9 +73,9 @@
7474 $controlItems = MapsMapper::createJSItemsString(explode(',', $this->controls));
7575
7676 $this->output .= <<<EOT
77 - addOnloadHook(makeOSMFormInput(
 77+ <script type='$wgJsMimeType'>
 78+ slippymaps['$this->mapName'] = new slippymap_map(
7879 '$this->mapName',
79 - '$this->coordsFieldName',
8080 {
8181 mode: 'osm-wm',
8282 layer: 'osm-like',
@@ -85,9 +85,11 @@
8686 zoom: $this->zoom,
8787 width: $this->width,
8888 height: $this->height,
89 - controls: [$controlItems]
 89+ controls: [$controlItems],
 90+ coordField: '$this->coordsFieldName'
9091 }
91 - ));
 92+ );
 93+ </script>
9294
9395 <div id='$this->mapName' class='map' style='width:{$this->width}px; height:{$this->height}px;'>
9496 <script type='$wgJsMimeType'>slippymaps['$this->mapName'].init();</script>
Index: trunk/extensions/SemanticMaps/SemanticMaps.php
@@ -23,26 +23,29 @@
2424 die( 'Not an entry point.' );
2525 }
2626
27 -define('SM_VERSION', '0.5 a15');
28 -
29 -$smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps';
30 -$smgIP = $IP . '/extensions/SemanticMaps';
31 -
32 -$smgStyleVersion = $wgStyleVersion . '-' . SM_VERSION;
33 -
34 -// Include the settings file.
35 -require_once($smgIP . '/SM_Settings.php');
36 -
37 -$wgExtensionFunctions[] = 'smfSetup';
38 -
39 -$wgHooks['AdminLinks'][] = 'smfAddToAdminLinks';
40 -
41 -$wgExtensionMessagesFiles['SemanticMaps'] = $smgIP . '/SemanticMaps.i18n.php';
42 -
43 -// Registration of the Geographical Coordinate type.
44 -$wgAutoloadClasses['SMGeoCoordsValue'] = $smgIP . '/SM_GeoCoordsValue.php';
45 -$wgHooks['smwInitDatatypes'][] = 'smfInitGeoCoordsType';
46 -
 27+// Only initialize the extension when all dependencies are present.
 28+if (defined( 'Maps_VERSION' ) && defined( 'SMW_VERSION' )) {
 29+ define('SM_VERSION', '0.5 a18');
 30+
 31+ $smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps';
 32+ $smgIP = $IP . '/extensions/SemanticMaps';
 33+
 34+ $smgStyleVersion = $wgStyleVersion . '-' . SM_VERSION;
 35+
 36+ // Include the settings file.
 37+ require_once($smgIP . '/SM_Settings.php');
 38+
 39+ $wgExtensionFunctions[] = 'smfSetup';
 40+
 41+ $wgHooks['AdminLinks'][] = 'smfAddToAdminLinks';
 42+
 43+ $wgExtensionMessagesFiles['SemanticMaps'] = $smgIP . '/SemanticMaps.i18n.php';
 44+
 45+ // Registration of the Geographical Coordinate type.
 46+ $wgAutoloadClasses['SMGeoCoordsValue'] = $smgIP . '/SM_GeoCoordsValue.php';
 47+ $wgHooks['smwInitDatatypes'][] = 'smfInitGeoCoordsType';
 48+}
 49+
4750 /**
4851 * 'Initialization' function for the Semantic Maps extension.
4952 * The only work done here is creating the extension credits for
Index: trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php
@@ -48,13 +48,13 @@
4949 }
5050
5151 private static function initializeParams() {
52 - global $egMapsDefaultService, $egMapsDefaultCentre;
 52+ global $egMapsDefaultServices, $egMapsDefaultCentre;
5353
5454 self::$parameters = array(
5555 'format' => array(
5656 'aliases' => array(),
5757 'criteria' => array(),
58 - 'default' => $egMapsDefaultService
 58+ 'default' => $egMapsDefaultServices['qp']
5959 ),
6060 'centre' => array(
6161 'aliases' => array('center'),

Status & tagging log