r56190 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r56189‎ | r56190 | r56191 >
Date:17:24, 11 September 2009
Author:jeroendedauw
Status:deferred
Tags:
Comment:
Changes for 0.3.4
Modified paths:
  • /trunk/extensions/SemanticMaps/FormInputs (added) (history)
  • /trunk/extensions/SemanticMaps/FormInputs/SM_FormInput.php (added) (history)
  • /trunk/extensions/SemanticMaps/FormInputs/SM_FormInputFactory.php (added) (history)
  • /trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php (added) (history)
  • /trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsFormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsQP.php (added) (history)
  • /trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersQP.php (added) (history)
  • /trunk/extensions/SemanticMaps/QueryPrinters (added) (history)
  • /trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php (added) (history)
  • /trunk/extensions/SemanticMaps/QueryPrinters/SM_Mapper.php (added) (history)
  • /trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php (added) (history)
  • /trunk/extensions/SemanticMaps/SM_FormInput.php (deleted) (history)
  • /trunk/extensions/SemanticMaps/SM_MapPrinter.php (deleted) (history)
  • /trunk/extensions/SemanticMaps/SM_Mapper.php (deleted) (history)
  • /trunk/extensions/SemanticMaps/SM_Settings.php (modified) (history)
  • /trunk/extensions/SemanticMaps/SemanticMaps.php (modified) (history)
  • /trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsFormInput.php (modified) (history)
  • /trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsQP.php (added) (history)

Diff [purge]

Index: trunk/extensions/SemanticMaps/SM_MapPrinter.php
@@ -1,254 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Abstract class that provides the common functionallity for all map query printers
6 - *
7 - * @file SM_MapPrinter.php
8 - * @ingroup SemanticMaps
9 - *
10 - * @author Jeroen De Dauw
11 - * @author Robert Buzink
12 - * @author Yaron Koren
13 - */
14 -
15 -if( !defined( 'MEDIAWIKI' ) ) {
16 - die( 'Not an entry point.' );
17 -}
18 -
19 -abstract class SMMapPrinter extends SMWResultPrinter {
20 -
21 - /**
22 - * Sets the map service specific element name
23 - */
24 - protected abstract function setQueryPrinterSettings();
25 -
26 - /**
27 - * Map service spesific map count and loading of dependencies
28 - */
29 - protected abstract function doMapServiceLoad();
30 -
31 - /**
32 - * Gets the query result
33 - */
34 - protected abstract function addSpecificMapHTML();
35 -
36 - public $serviceName;
37 -
38 - protected $defaultParams = array();
39 -
40 - protected $m_locations = array();
41 -
42 - protected $defaultZoom;
43 - protected $elementNr;
44 - protected $elementNamePrefix;
45 -
46 - protected $mapName;
47 -
48 - protected $centre_lat;
49 - protected $centre_lon;
50 -
51 - protected $output = '';
52 -
53 - protected $mapFeature;
54 -
55 - /**
56 - * Builds up and returns the HTML for the map, with the queried coordinate data on it.
57 - *
58 - * @param unknown_type $res
59 - * @param unknown_type $outputmode
60 - * @return array
61 - */
62 - public final function getResultText($res, $outputmode) {
63 - $this->formatResultData($res, $outputmode);
64 -
65 - $this->setQueryPrinterSettings();
66 -
67 - $this->manageMapProperties($this->m_params);
68 -
69 - // Only create a map when there is at least one result.
70 - if (count($this->m_locations) > 0) {
71 - $this->doMapServiceLoad();
72 -
73 - $this->setMapName();
74 -
75 - $this->setZoom();
76 -
77 - $this->setCentre();
78 -
79 - $this->addSpecificMapHTML();
80 - }
81 -
82 - return array($this->output, 'noparse' => 'true', 'isHTML' => 'true');
83 - }
84 -
85 - public final function getResult($results, $params, $outputmode) {
86 - // Skip checks, results with 0 entries are normal
87 - $this->readParameters($params, $outputmode);
88 - return $this->getResultText($results, SMW_OUTPUT_HTML);
89 - }
90 -
91 - private function formatResultData($res, $outputmode) {
92 - while ( ($row = $res->getNext()) !== false ) {
93 - $this->addResultRow($outputmode, $row);
94 - }
95 - }
96 -
97 - /**
98 - * This function will loop through all properties (fields) of one record (row),
99 - * and add the location data, title, label and icon to the m_locations array.
100 - *
101 - * @param unknown_type $outputmode
102 - * @param unknown_type $row The record you want to add data from
103 - */
104 - private function addResultRow($outputmode, $row) {
105 - global $wgUser;
106 - $skin = $wgUser->getSkin();
107 -
108 - $title = '';
109 - $text = '';
110 - $lat = '';
111 - $lon = '';
112 -
113 - $coords = array();
114 -
115 - // Loop throught all fields of the record
116 - foreach ($row as $i => $field) {
117 - $pr = $field->getPrintRequest();
118 -
119 - // Loop throught all the parts of the field value
120 - while ( ($object = $field->getNextObject()) !== false ) {
121 - if ($object->getTypeID() == '_wpg' && $i == 0) {
122 - $title = $object->getLongText($outputmode, $skin);
123 - }
124 -
125 - if ($object->getTypeID() != '_geo' && $i != 0) {
126 - $text .= $pr->getHTMLText($skin) . ': ' . $object->getLongText($outputmode, $skin) . '<br />';
127 - }
128 -
129 - if ($pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_geo') {
130 - $coords[] = explode(',', $object->getXSDValue());
131 - }
132 - }
133 - }
134 -
135 - foreach ($coords as $coord) {
136 - if (count($coord) == 2) {
137 - list($lat, $lon) = $coord;
138 -
139 - if (strlen($lat) > 0 && strlen($lon) > 0) {
140 - $icon = $this->getLocationIcon($row);
141 - $this->m_locations[] = array($lat, $lon, $title, $text, $icon);
142 - }
143 -
144 - }
145 - }
146 -
147 - }
148 -
149 - /**
150 - * Get the icon for a row
151 - *
152 - * @param unknown_type $row
153 - * @return unknown
154 - */
155 - private function getLocationIcon($row) {
156 - $icon = '';
157 - $legend_labels = array();
158 -
159 - // Look for display_options field, which can be set by Semantic Compound Queries
160 - if (property_exists($row[0], 'display_options')) {
161 - if (array_key_exists('icon', $row[0]->display_options)) {
162 - $icon = $row[0]->display_options['icon'];
163 -
164 - // This is somewhat of a hack - if a legend label has been set, we're getting it for every point, instead of just once per icon
165 - if (array_key_exists('legend label', $row[0]->display_options)) {
166 -
167 - $legend_label = $row[0]->display_options['legend label'];
168 -
169 - if (! array_key_exists($icon, $legend_labels)) {
170 - $legend_labels[$icon] = $legend_label;
171 - }
172 - }
173 - }
174 - // Icon can be set even for regular, non-compound queries If it is, though, we have to translate the name into a URL here
175 - } elseif (array_key_exists('icon', $this->m_params)) {
176 -
177 - $icon_title = Title::newFromText($this->m_params['icon']);
178 - $icon_image_page = new ImagePage($icon_title);
179 - $icon = $icon_image_page->getDisplayedFile()->getURL();
180 - }
181 -
182 - return $icon;
183 - }
184 -
185 - private function manageMapProperties($mapProperties) {
186 - global $egMapsServices;
187 -
188 - $mapProperties = MapsMapper::getValidParams($mapProperties, $egMapsServices[$this->serviceName]['parameters']);
189 - $mapProperties = MapsMapper::setDefaultParValues($mapProperties, $this->defaultParams);
190 -
191 - if (isset($this->serviceName)) $mapProperties['service'] = $this->serviceName;
192 -
193 - // Go through the array with map parameters and create new variables
194 - // with the name of the key and value of the item if they don't exist on class level yet.
195 - foreach($mapProperties as $paramName => $paramValue) {
196 - if (!property_exists(__CLASS__, $paramName)) {
197 - $this->{$paramName} = $paramValue;
198 - }
199 - }
200 -
201 - MapsMapper::enforceArrayValues($this->controls);
202 - }
203 -
204 - /**
205 - * Sets the zoom level to the provided value, or when not set, to the default.
206 - *
207 - */
208 - private function setZoom() {
209 - if (strlen($this->zoom) < 1) {
210 - if (count($this->m_locations) > 1) {
211 - $this->zoom = 'null';
212 - }
213 - else {
214 - $this->zoom = $this->defaultZoom;
215 - }
216 - }
217 - }
218 -
219 - /**
220 - * Sets the $centre_lat and $centre_lon fields.
221 - * Note: this needs to be done AFTRE the maker coordinates are set.
222 - *
223 - */
224 - private function setCentre() {
225 - if (strlen($this->centre) > 0) {
226 - // If a centre value is set, use it.
227 - $centre = MapsUtils::getLatLon($this->centre);
228 - $this->centre_lat = $centre['lat'];
229 - $this->centre_lon = $centre['lon'];
230 - }
231 - elseif (count($this->m_locations) > 1) {
232 - // If centre is not set, and there are multiple points, set the values to null, to be auto determined by the JS of the mapping API.
233 - $this->centre_lat = 'null';
234 - $this->centre_lon = 'null';
235 - }
236 - else {
237 - // If centre is not set and there is exactelly one marker, use it's coordinates.
238 - $this->centre_lat = $this->m_locations[0][0];
239 - $this->centre_lon = $this->m_locations[0][1];
240 - }
241 - }
242 -
243 - /**
244 - * Sets the $mapName field, using the $elementNamePrefix and $elementNr.
245 - *
246 - */
247 - protected function setMapName() {
248 - $this->mapName = $this->elementNamePrefix.'_'.$this->elementNr;
249 - }
250 -
251 - public final function getName() {
252 - return wfMsg('maps_' . $this->serviceName);
253 - }
254 -
255 -}
Index: trunk/extensions/SemanticMaps/SM_FormInput.php
@@ -1,150 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * Abstract class that provides the common functionallity for all map form inputs
6 - *
7 - * @file SM_FormInput.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 -abstract class SMFormInput extends MapsMapFeature {
18 -
19 - /**
20 - * Determine if geocoding will be enabled and load the required dependencies.
21 - */
22 - protected abstract function manageGeocoding();
23 -
24 - /**
25 - * Ensures all dependencies for the used map are loaded, and increases that map service's count
26 - */
27 - protected abstract function addFormDependencies();
28 -
29 - protected $marker_lat;
30 - protected $marker_lon;
31 -
32 - protected $earthZoom;
33 -
34 - protected $showAddresFunction;
35 -
36 - protected $enableGeocoding = false;
37 -
38 - private $startingCoords ='';
39 -
40 - private $coordinates;
41 -
42 - /**
43 - * This function is a hook for Semantic Forms, and returns the HTML needed in
44 - * the form to handle coordinate data.
45 - */
46 - public final function formInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args) {
47 - // TODO: Use function args for sf stuffz
48 - global $sfgTabIndex;
49 -
50 - $this->coordinates = $coordinates;
51 -
52 - $this->manageGeocoding();
53 -
54 - $this->setMapSettings();
55 -
56 - $this->doMapServiceLoad();
57 -
58 - $this->manageMapProperties($field_args, __CLASS__);
59 -
60 - $this->setCoordinates();
61 - $this->setCentre();
62 - $this->setZoom();
63 -
64 - // Create html element names
65 - $this->setMapName();
66 - $this->mapName .= '_'.$sfgTabIndex;
67 - $this->geocodeFieldName = $this->elementNamePrefix.'_geocode_'.$this->elementNr.'_'.$sfgTabIndex;
68 - $this->coordsFieldName = $this->elementNamePrefix.'_coords_'.$this->elementNr.'_'.$sfgTabIndex;
69 - $this->infoFieldName = $this->elementNamePrefix.'_info_'.$this->elementNr.'_'.$sfgTabIndex;
70 -
71 - // Create the non specific form HTML
72 - $this->output .= "
73 - <input id='".$this->coordsFieldName."' name='$input_name' type='text' value='$this->startingCoords' size='40' tabindex='$sfgTabIndex'>
74 - <span id='".$this->infoFieldName."' class='error_message'></span>";
75 -
76 - if ($this->enableGeocoding) {
77 - $sfgTabIndex++;
78 -
79 - // Retrieve language values
80 - // wfLoadExtensionMessages( 'SemanticMaps' ); // TODO: remove?
81 - $enter_address_here_text = wfMsg('semanticmaps_enteraddresshere');
82 - $lookup_coordinates_text = wfMsg('semanticmaps_lookupcoordinates');
83 - $not_found_text = wfMsg('semanticmaps_notfound');
84 -
85 - $adress_field = smfGetDynamicInput($this->geocodeFieldName, $enter_address_here_text, 'size="30" name="geocode" style="color: #707070" tabindex="'.$sfgTabIndex.'"');
86 - $this->output .= "
87 - <p>
88 - $adress_field
89 - <input type='submit' onClick=\"$this->showAddresFunction(document.forms['createbox'].$this->geocodeFieldName.value, '$this->mapName', '$this->coordsFieldName', '$not_found_text'); return false\" value='$lookup_coordinates_text' />
90 - </p>";
91 - }
92 -
93 - $this->addSpecificMapHTML();
94 -
95 - return array($this->output, '');
96 - }
97 -
98 - /**
99 - * Sets the zoom so the whole map is visible in case there is no maker yet,
100 - * and sets it to the default when there is a marker but no zoom parameter.
101 - */
102 - private function setZoom() {
103 - if (empty($this->coordinates)) {
104 - $this->zoom = $this->earthZoom;
105 - } else if (strlen($this->zoom) < 1) {
106 - $this->zoom = $this->defaultZoom;
107 - }
108 - }
109 -
110 - /**
111 - * Sets the $marler_lon and $marler_lat fields and when set, the starting coordinates
112 - *
113 - */
114 - private function setCoordinates() {
115 - if (empty($this->coordinates)) {
116 - // If no coordinates exist yet, no marker should be displayed
117 - $this->marker_lat = 'null';
118 - $this->marker_lon = 'null';
119 - }
120 - else {
121 - $marker = MapsUtils::getLatLon($this->coordinates);
122 - $this->marker_lat = $marker['lat'];
123 - $this->marker_lon = $marker['lon'];
124 - $this->startingCoords = MapsUtils::latDecimal2Degree($this->marker_lat) . ', ' . MapsUtils::lonDecimal2Degree($this->marker_lon);
125 - }
126 - }
127 -
128 - /**
129 - * Sets the $centre_lat and $centre_lon fields.
130 - * Note: this needs to be done AFTRE the maker coordinates are set.
131 - *
132 - */
133 - private function setCentre() {
134 - if (empty($this->centre)) {
135 - if (isset($this->coordinates)) {
136 - $this->centre_lat = $this->marker_lat;
137 - $this->centre_lon = $this->marker_lon;
138 - }
139 - else {
140 - $this->centre_lat = '0';
141 - $this->centre_lon = '0';
142 - }
143 - }
144 - else {
145 - $centre = MapsUtils::getLatLon($this->centre);
146 - $this->centre_lat = $centre['lat'];
147 - $this->centre_lon = $centre['lon'];
148 - }
149 - }
150 -}
151 -
Index: trunk/extensions/SemanticMaps/SM_Mapper.php
@@ -1,47 +0,0 @@
2 -<?php
3 -
4 -/**
5 - * General map query printer class
6 - *
7 - * @file SM_Mapper.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 -final class SMMapper {
18 -
19 - private $queryPrinter;
20 -
21 - public function __construct($format, $inline) {
22 - global $egMapsDefaultServices, $egMapsServices;
23 -
24 - // TODO: allow service parameter to override the default
25 - if ($format == 'map') $format = $egMapsDefaultServices['qp'];
26 -
27 - $service = MapsMapper::getValidService($format, 'qp');
28 -
29 - $this->queryPrinter = new $egMapsServices[$service]['qp']['class']($format, $inline);
30 - }
31 -
32 - public function getName() {
33 - return $this->queryPrinter->getName();
34 - }
35 -
36 - public function getQueryMode($context) {
37 - return $this->queryPrinter->getQueryMode($context);
38 - }
39 -
40 - public function getResult($results, $params, $outputmode) {
41 - return $this->queryPrinter->getResult($results, $params, $outputmode);
42 - }
43 -
44 - protected function getResultText($res, $outputmode) {
45 - return $this->queryPrinter->getResultText($res, $outputmode);
46 - }
47 -
48 -}
Index: trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsQP.php
@@ -0,0 +1,90 @@
 2+<?php
 3+/**
 4+ * A query printer for maps using the Yahoo Maps API
 5+ *
 6+ * @file SM_YahooMaps.php
 7+ * @ingroup SemanticMaps
 8+ *
 9+ * @author Jeroen De Dauw
 10+ */
 11+
 12+if( !defined( 'MEDIAWIKI' ) ) {
 13+ die( 'Not an entry point.' );
 14+}
 15+
 16+final class SMYahooMapsQP extends SMMapPrinter {
 17+
 18+ public $serviceName = MapsYahooMapsUtils::SERVICE_NAME;
 19+
 20+ /**
 21+ * @see SMMapPrinter::setQueryPrinterSettings()
 22+ *
 23+ */
 24+ protected function setQueryPrinterSettings() {
 25+ global $egMapsYahooMapsZoom, $egMapsYahooMapsPrefix;
 26+
 27+ $this->elementNamePrefix = $egMapsYahooMapsPrefix;
 28+
 29+ $this->defaultZoom = $egMapsYahooMapsZoom;
 30+
 31+ $this->defaultParams = MapsYahooMapsUtils::getDefaultParams();
 32+ }
 33+
 34+ /**
 35+ * @see SMMapPrinter::doMapServiceLoad()
 36+ *
 37+ */
 38+ protected function doMapServiceLoad() {
 39+ global $egYahooMapsOnThisPage;
 40+
 41+ MapsYahooMapsUtils::addYMapDependencies($this->output);
 42+ $egYahooMapsOnThisPage++;
 43+
 44+ $this->elementNr = $egYahooMapsOnThisPage;
 45+ }
 46+
 47+ /**
 48+ * @see SMMapPrinter::addSpecificMapHTML()
 49+ *
 50+ */
 51+ protected function addSpecificMapHTML() {
 52+ global $wgJsMimeType;
 53+
 54+ $this->type = MapsYahooMapsUtils::getYMapType($this->type, true);
 55+ $this->controls = MapsYahooMapsUtils::createControlsString($this->controls);
 56+
 57+ MapsUtils::makePxValue($this->width);
 58+ MapsUtils::makePxValue($this->height);
 59+
 60+ $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom);
 61+
 62+ $markerItems = array();
 63+
 64+ foreach ($this->m_locations as $location) {
 65+ // Create a string containing the marker JS
 66+ list($lat, $lon, $title, $label, $icon) = $location;
 67+
 68+ $title = str_replace("'", "\'", $title);
 69+ $label = str_replace("'", "\'", $label);
 70+
 71+ $markerItems[] = "getYMarkerData($lat, $lon, '$title', '$label', '$icon')";
 72+ }
 73+
 74+ $markersString = implode(',', $markerItems);
 75+
 76+ $this->types = explode(",", $this->types);
 77+
 78+ $typesString = MapsYahooMapsUtils::createTypesString($this->types);
 79+
 80+ $this->output .= "
 81+ <div id='$this->mapName' style='width: $this->width; height: $this->height;'></div>
 82+
 83+ <script type='$wgJsMimeType'>/*<![CDATA[*/
 84+ addLoadEvent(
 85+ initializeYahooMap('$this->mapName', $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$markersString])
 86+ );
 87+ /*]]>*/</script>";
 88+
 89+ }
 90+
 91+}
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsFormInput.php
@@ -15,7 +15,7 @@
1616
1717 final class SMYahooMapsFormInput extends SMFormInput {
1818
19 - public $serviceName = MapsYahooMaps::SERVICE_NAME;
 19+ public $serviceName = MapsYahooMapsUtils::SERVICE_NAME;
2020
2121 /**
2222 * @see MapsMapFeature::setMapSettings()
Index: trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersQP.php
@@ -0,0 +1,83 @@
 2+<?php
 3+
 4+/**
 5+ * A query printer for maps using the Open Layers API
 6+ *
 7+ * @file SM_OpenLayers.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+final class SMOpenLayersQP extends SMMapPrinter {
 18+
 19+ public $serviceName = MapsOpenLayersUtils::SERVICE_NAME;
 20+
 21+ /**
 22+ * @see SMMapPrinter::setQueryPrinterSettings()
 23+ *
 24+ */
 25+ protected function setQueryPrinterSettings() {
 26+ global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix;
 27+
 28+ $this->elementNamePrefix = $egMapsOpenLayersPrefix;
 29+ $this->defaultZoom = $egMapsOpenLayersZoom;
 30+
 31+ $this->defaultParams = MapsOpenLayersUtils::getDefaultParams();
 32+ }
 33+
 34+ /**
 35+ * @see SMMapPrinter::doMapServiceLoad()
 36+ *
 37+ */
 38+ protected function doMapServiceLoad() {
 39+ global $egOpenLayersOnThisPage;
 40+
 41+ MapsOpenLayersUtils::addOLDependencies($this->output);
 42+ $egOpenLayersOnThisPage++;
 43+
 44+ $this->elementNr = $egOpenLayersOnThisPage;
 45+ }
 46+
 47+ /**
 48+ * @see SMMapPrinter::addSpecificMapHTML()
 49+ *
 50+ */
 51+ protected function addSpecificMapHTML() {
 52+ global $wgJsMimeType;
 53+
 54+ $controlItems = MapsOpenLayersUtils::createControlsString($this->controls);
 55+
 56+ MapsMapper::enforceArrayValues($this->layers);
 57+ $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers);
 58+
 59+ MapsUtils::makePxValue($this->width);
 60+ MapsUtils::makePxValue($this->height);
 61+
 62+ $markerItems = array();
 63+
 64+ foreach ($this->m_locations as $location) {
 65+ // Create a string containing the marker JS
 66+ list($lat, $lon, $title, $label, $icon) = $location;
 67+
 68+ $title = str_replace("'", "\'", $title);
 69+ $label = str_replace("'", "\'", $label);
 70+
 71+ $markerItems[] = "getOLMarkerData($lon, $lat, '$title', '$label', '$icon')";
 72+ }
 73+
 74+ $markersString = implode(',', $markerItems);
 75+
 76+ $this->output .= "<div id='$this->mapName' style='width: $this->width; height: $this->height; background-color: #cccccc;'></div>
 77+ <script type='$wgJsMimeType'> /*<![CDATA[*/
 78+ addLoadEvent(
 79+ initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems], [$markersString])
 80+ );
 81+ /*]]>*/ </script>";
 82+ }
 83+
 84+}
Index: trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFormInput.php
@@ -15,7 +15,7 @@
1616
1717 final class SMOpenLayersFormInput extends SMFormInput {
1818
19 - public $serviceName = MapsOpenLayers::SERVICE_NAME;
 19+ public $serviceName = MapsOpenLayersUtils::SERVICE_NAME;
2020
2121 /**
2222 * @see MapsMapFeature::setMapSettings()
Index: trunk/extensions/SemanticMaps/SM_Settings.php
@@ -2,7 +2,7 @@
33
44 /**
55 * File defining the settings for the Semantic Maps extension
6 - * More info can be found at http://www.mediawiki.org/wiki/Extension:Semantic Maps#Settings
 6+ * More info can be found at http://www.mediawiki.org/wiki/Extension:Semantic_Maps#Settings
77 *
88 * NOTICE:
99 * Changing one of these settings can be done by copieng or cutting it,
@@ -25,7 +25,18 @@
2626 # (named) Array of String. This array contains the available features for Maps.
2727 # The array element name contains an abbriviation, used for code references,
2828 # and in the service data arrays, the value is the human readible version for displaying purpouses.
29 -$egMapsAvailableFeatures['qp'] = 'Query Printer';
30 -$egMapsAvailableFeatures['fi'] = 'Form input';
 29+$egMapsAvailableFeatures['qp'] = array(
 30+ 'name' => 'Query Printer',
 31+ 'class' => 'SMQueryPrinters',
 32+ 'file' => 'SemanticMaps/QueryPrinters/SM_QueryPrinters.php',
 33+ 'local' => false
 34+ );
3135
 36+$egMapsAvailableFeatures['fi'] = array(
 37+ 'name' => 'Form input',
 38+ 'class' => 'SMFormInputs',
 39+ 'file' => 'SemanticMaps/FormInputs/SM_FormInputs.php',
 40+ 'local' => false
 41+ );
3242
 43+
Index: trunk/extensions/SemanticMaps/FormInputs/SM_FormInputFactory.php
@@ -0,0 +1,61 @@
 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_FormInput.php
@@ -0,0 +1,150 @@
 2+<?php
 3+
 4+/**
 5+ * Abstract class that provides the common functionallity for all map form inputs
 6+ *
 7+ * @file SM_FormInput.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+abstract class SMFormInput extends MapsMapFeature {
 18+
 19+ /**
 20+ * Determine if geocoding will be enabled and load the required dependencies.
 21+ */
 22+ protected abstract function manageGeocoding();
 23+
 24+ /**
 25+ * Ensures all dependencies for the used map are loaded, and increases that map service's count
 26+ */
 27+ protected abstract function addFormDependencies();
 28+
 29+ protected $marker_lat;
 30+ protected $marker_lon;
 31+
 32+ protected $earthZoom;
 33+
 34+ protected $showAddresFunction;
 35+
 36+ protected $enableGeocoding = false;
 37+
 38+ private $startingCoords ='';
 39+
 40+ private $coordinates;
 41+
 42+ /**
 43+ * This function is a hook for Semantic Forms, and returns the HTML needed in
 44+ * the form to handle coordinate data.
 45+ */
 46+ public final function formInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args) {
 47+ // TODO: Use function args for sf stuffz
 48+ global $sfgTabIndex;
 49+
 50+ $this->coordinates = $coordinates;
 51+
 52+ $this->manageGeocoding();
 53+
 54+ $this->setMapSettings();
 55+
 56+ $this->doMapServiceLoad();
 57+
 58+ $this->manageMapProperties($field_args, __CLASS__);
 59+
 60+ $this->setCoordinates();
 61+ $this->setCentre();
 62+ $this->setZoom();
 63+
 64+ // Create html element names
 65+ $this->setMapName();
 66+ $this->mapName .= '_'.$sfgTabIndex;
 67+ $this->geocodeFieldName = $this->elementNamePrefix.'_geocode_'.$this->elementNr.'_'.$sfgTabIndex;
 68+ $this->coordsFieldName = $this->elementNamePrefix.'_coords_'.$this->elementNr.'_'.$sfgTabIndex;
 69+ $this->infoFieldName = $this->elementNamePrefix.'_info_'.$this->elementNr.'_'.$sfgTabIndex;
 70+
 71+ // Create the non specific form HTML
 72+ $this->output .= "
 73+ <input id='".$this->coordsFieldName."' name='$input_name' type='text' value='$this->startingCoords' size='40' tabindex='$sfgTabIndex'>
 74+ <span id='".$this->infoFieldName."' class='error_message'></span>";
 75+
 76+ if ($this->enableGeocoding) {
 77+ $sfgTabIndex++;
 78+
 79+ // Retrieve language values
 80+ // wfLoadExtensionMessages( 'SemanticMaps' ); // TODO: remove?
 81+ $enter_address_here_text = wfMsg('semanticmaps_enteraddresshere');
 82+ $lookup_coordinates_text = wfMsg('semanticmaps_lookupcoordinates');
 83+ $not_found_text = wfMsg('semanticmaps_notfound');
 84+
 85+ $adress_field = smfGetDynamicInput($this->geocodeFieldName, $enter_address_here_text, 'size="30" name="geocode" style="color: #707070" tabindex="'.$sfgTabIndex.'"');
 86+ $this->output .= "
 87+ <p>
 88+ $adress_field
 89+ <input type='submit' onClick=\"$this->showAddresFunction(document.forms['createbox'].$this->geocodeFieldName.value, '$this->mapName', '$this->coordsFieldName', '$not_found_text'); return false\" value='$lookup_coordinates_text' />
 90+ </p>";
 91+ }
 92+
 93+ $this->addSpecificMapHTML();
 94+
 95+ return array($this->output, '');
 96+ }
 97+
 98+ /**
 99+ * Sets the zoom so the whole map is visible in case there is no maker yet,
 100+ * and sets it to the default when there is a marker but no zoom parameter.
 101+ */
 102+ private function setZoom() {
 103+ if (empty($this->coordinates)) {
 104+ $this->zoom = $this->earthZoom;
 105+ } else if (strlen($this->zoom) < 1) {
 106+ $this->zoom = $this->defaultZoom;
 107+ }
 108+ }
 109+
 110+ /**
 111+ * Sets the $marler_lon and $marler_lat fields and when set, the starting coordinates
 112+ *
 113+ */
 114+ private function setCoordinates() {
 115+ if (empty($this->coordinates)) {
 116+ // If no coordinates exist yet, no marker should be displayed
 117+ $this->marker_lat = 'null';
 118+ $this->marker_lon = 'null';
 119+ }
 120+ else {
 121+ $marker = MapsUtils::getLatLon($this->coordinates);
 122+ $this->marker_lat = $marker['lat'];
 123+ $this->marker_lon = $marker['lon'];
 124+ $this->startingCoords = MapsUtils::latDecimal2Degree($this->marker_lat) . ', ' . MapsUtils::lonDecimal2Degree($this->marker_lon);
 125+ }
 126+ }
 127+
 128+ /**
 129+ * Sets the $centre_lat and $centre_lon fields.
 130+ * Note: this needs to be done AFTRE the maker coordinates are set.
 131+ *
 132+ */
 133+ private function setCentre() {
 134+ if (empty($this->centre)) {
 135+ if (isset($this->coordinates)) {
 136+ $this->centre_lat = $this->marker_lat;
 137+ $this->centre_lon = $this->marker_lon;
 138+ }
 139+ else {
 140+ $this->centre_lat = '0';
 141+ $this->centre_lon = '0';
 142+ }
 143+ }
 144+ else {
 145+ $centre = MapsUtils::getLatLon($this->centre);
 146+ $this->centre_lat = $centre['lat'];
 147+ $this->centre_lon = $centre['lon'];
 148+ }
 149+ }
 150+}
 151+
Index: trunk/extensions/SemanticMaps/FormInputs/SM_FormInputs.php
@@ -0,0 +1,110 @@
 2+<?php
 3+
 4+/**
 5+ * Initialization file for form input functionality in the Maps extension
 6+ *
 7+ * @file SM_FormInputs.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+final class SMFormInputs {
 18+
 19+ public static function initialize() {
 20+ global $smgIP, $wgAutoloadClasses, $egMapsServices, $sfgFormPrinter;
 21+
 22+ $wgAutoloadClasses['SMFormInput'] = $smgIP . '/FormInputs/SM_FormInput.php';
 23+
 24+ // This feature can only be enbled when Semantic Forms is loaded.
 25+ if (isset($sfgFormPrinter)) {
 26+ $hasFormInputs = false;
 27+
 28+ foreach($egMapsServices as $serviceName => $serviceData) {
 29+ // Check if the service has a form input
 30+ $hasFI = array_key_exists('fi', $serviceData);
 31+
 32+ // If the service has no FI, skipt it and continue with the next one.
 33+ if (!$hasFI) continue;
 34+
 35+ // At least one form input will be enabled when this point is reached.
 36+ $hasFormInputs = true;
 37+
 38+ // Add the result form input type for the service name.
 39+ self::initFormHook($serviceName, $serviceData['fi']);
 40+
 41+ // Loop through the service alliases, and add them as form input types.
 42+ foreach ($serviceData['aliases'] as $alias) self::initFormHook($alias, $serviceData['fi'], $serviceName);
 43+ }
 44+
 45+ // Add the 'map' form input type if there are mapping services that have FI's loaded.
 46+ if ($hasFormInputs) self::initFormHook('map');
 47+
 48+ }
 49+
 50+ }
 51+
 52+ /**
 53+ * Adds a mapping service's form hook
 54+ *
 55+ * @param string $service
 56+ * @param array $fi
 57+ * @param strig $mainName
 58+ */
 59+ private static function initFormHook($service, array $fi = null, $mainName = '') {
 60+ global $wgAutoloadClasses, $sfgFormPrinter, $smgIP;
 61+
 62+ if (isset($fi)) {
 63+ if (! array_key_exists($fi['class'], $wgAutoloadClasses)) {
 64+ $file = $fi['local'] ? $smgIP . '/' . $fi['file'] : $fi['file'];
 65+ $wgAutoloadClasses[$fi['class']] = $file;
 66+ }
 67+ }
 68+
 69+ // Add the form input hook for the service
 70+ $field_args = array();
 71+ if (strlen($mainName) > 0) $field_args['service_name'] = $mainName;
 72+ $sfgFormPrinter->setInputTypeHook($service, 'smfSelectFormInputHTML', $field_args);
 73+ }
 74+
 75+}
 76+
 77+/**
 78+ * Class for the form input type 'map'. The relevant form input class is called depending on the provided service.
 79+ *
 80+ * @param unknown_type $coordinates
 81+ * @param unknown_type $input_name
 82+ * @param unknown_type $is_mandatory
 83+ * @param unknown_type $is_disabled
 84+ * @param array $field_args
 85+ * @return unknown
 86+ */
 87+function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, array $field_args) {
 88+ global $egMapsServices;
 89+
 90+ // If service_name is set, use this value, and ignore any given
 91+ // service parameters
 92+ // This will prevent ..input type=googlemaps|service=yahoo.. from
 93+ // showing up as a Yahoo! Maps map
 94+ if (array_key_exists('service_name', $field_args)) {
 95+ $service_name = $field_args['service_name'];
 96+ }
 97+ elseif (array_key_exists('service', $field_args)) {
 98+ $service_name = $field_args['service'];
 99+ }
 100+ else{
 101+ $service_name = null;
 102+ }
 103+
 104+ $service_name = MapsMapper::getValidService($service_name, 'fi');
 105+
 106+ $formInput = new $egMapsServices[$service_name]['fi']['class']();
 107+
 108+ // Get and return the form input HTML from the hook corresponding with the provided service
 109+ return $formInput->formInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args);
 110+
 111+}
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/SemanticMaps.php
@@ -43,33 +43,29 @@
4444
4545 $wgExtensionMessagesFiles['SemanticMaps'] = $smgIP . '/SemanticMaps.i18n.php';
4646
47 -// Autoload the general classes
48 -$wgAutoloadClasses['SMMapPrinter'] = $smgIP . '/SM_MapPrinter.php';
49 -$wgAutoloadClasses['SMMapper'] = $smgIP . '/SM_Mapper.php';
50 -$wgAutoloadClasses['SMFormInput'] = $smgIP . '/SM_FormInput.php';
51 -
5247 // Add the services
53 -$egMapsServices['googlemaps']['qp'] = array('class' => 'SMGoogleMaps', 'file' => 'GoogleMaps/SM_GoogleMaps.php', 'local' => true);
54 -$egMapsServices['googlemaps']['fi'] = array('class' => 'SMGoogleMapsFormInput', 'file' => 'GoogleMaps/SM_GoogleMapsFormInput.php', 'local' => true);
 48+$egMapsServices['googlemaps']['qp'] = array('class' => 'SMGoogleMapsQP', 'file' => 'SemanticMaps/GoogleMaps/SM_GoogleMapsQP.php', 'local' => false);
 49+$egMapsServices['googlemaps']['fi'] = array('class' => 'SMGoogleMapsFormInput', 'file' => 'SemanticMaps/GoogleMaps/SM_GoogleMapsFormInput.php', 'local' => false);
5550
56 -$egMapsServices['yahoomaps']['qp'] = array('class' => 'SMYahooMaps', 'file' => 'YahooMaps/SM_YahooMaps.php', 'local' => true);
57 -$egMapsServices['yahoomaps']['fi'] = array('class' => 'SMYahooMapsFormInput', 'file' => 'YahooMaps/SM_YahooMapsFormInput.php', 'local' => true);
 51+$egMapsServices['yahoomaps']['qp'] = array('class' => 'SMYahooMapsQP', 'file' => 'SemanticMaps/YahooMaps/SM_YahooMapsQP.php', 'local' => false);
 52+$egMapsServices['yahoomaps']['fi'] = array('class' => 'SMYahooMapsFormInput', 'file' => 'SemanticMaps/YahooMaps/SM_YahooMapsFormInput.php', 'local' => false);
5853
59 -$egMapsServices['openlayers']['qp'] = array('class' => 'SMOpenLayers', 'file' => 'OpenLayers/SM_OpenLayers.php', 'local' => true);
60 -$egMapsServices['openlayers']['fi'] = array('class' => 'SMOpenLayersFormInput', 'file' => 'OpenLayers/SM_OpenLayersFormInput.php', 'local' => true);
 54+$egMapsServices['openlayers']['qp'] = array('class' => 'SMOpenLayersQP', 'file' => 'SemanticMaps/OpenLayers/SM_OpenLayersQP.php', 'local' => false);
 55+$egMapsServices['openlayers']['fi'] = array('class' => 'SMOpenLayersFormInput', 'file' => 'SemanticMaps/OpenLayers/SM_OpenLayersFormInput.php', 'local' => false);
6156
6257 /**
6358 * Initialization function for the Semantic Maps extension
6459 *
6560 */
6661 function smfSetup() {
67 - global $wgExtensionCredits, $wgLang, $egMapsServices, $sfgFormPrinter;
 62+ global $wgExtensionCredits, $wgLang, $egMapsServices;
6863
6964 // Creation of a list of internationalized service names
7065 $services = array();
7166 foreach (array_keys($egMapsServices) as $name) $services[] = wfMsg('maps_'.$name);
7267 $services_list = $wgLang->listToText($services);
7368
 69+ // TODO: split for feature hook system?
7470 wfLoadExtensionMessages( 'SemanticMaps' );
7571
7672 $wgExtensionCredits['other'][]= array(
@@ -81,113 +77,11 @@
8278 'description' => wfMsgExt( 'semanticmaps_desc', 'parsemag', $services_list ),
8379 'descriptionmsg' => wfMsgExt( 'semanticmaps_desc', 'parsemag', $services_list ),
8480 );
85 -
86 - if (isset($sfgFormPrinter)) smfInitFormHook('map');
87 - smfInitFormat('map', array('class' => 'SMMapper', 'file' => 'SM_Mapper.php', 'local' => true));
8881
89 - foreach($egMapsServices as $serviceName => $serviceData) {
90 - $hasQP = array_key_exists('qp', $serviceData);
91 - $hasFI = array_key_exists('fi', $serviceData) && isset($sfgFormPrinter);
92 -
93 - // If the service has no QP and no FI, skipt it and continue with the next one.
94 - if (!$hasQP && !$hasFI) continue;
95 -
96 - // Add the result format and form input type for the service name when needed.
97 - if ($hasQP) smfInitFormat($serviceName, $serviceData['qp']);
98 - if ($hasFI) smfInitFormHook($serviceName, $serviceData['fi']);
99 -
100 - // Loop through the service alliases, and add them as result formats and form input types when needed.
101 - foreach ($serviceData['aliases'] as $alias) {
102 - if ($hasQP) smfInitFormat($alias, $serviceData['qp']);
103 - if ($hasFI) smfInitFormHook($alias, $serviceData['fi'], $serviceName);
104 - }
105 - }
106 -
10782 return true;
10883 }
10984
11085 /**
111 - * Add the result format for a mapping service or alias
112 - *
113 - * @param string $format
114 - * @param array $qp
115 - */
116 -function smfInitFormat($format, array $qp) {
117 - global $wgAutoloadClasses, $smwgResultFormats, $smgIP;
118 -
119 - if (! array_key_exists($qp['class'], $wgAutoloadClasses)) {
120 - $file = $qp['local'] ? $smgIP . '/' . $qp['file'] : $qp['file'];
121 - $wgAutoloadClasses[$qp['class']] = $file;
122 - }
123 -
124 - if (isset($smwgResultFormats)) {
125 - $smwgResultFormats[$format] = $qp['class'];
126 - }
127 - else {
128 - SMWQueryProcessor::$formats[$format] = $qp['class'];
129 - }
130 -}
131 -
132 -/**
133 - * Adds a mapping service's form hook
134 - *
135 - * @param string $service
136 - * @param array $fi
137 - * @param strig $mainName
138 - */
139 -function smfInitFormHook($service, array $fi = null, $mainName = '') {
140 - global $wgAutoloadClasses, $sfgFormPrinter, $smgIP;
141 -
142 - if (isset($fi)) {
143 - if (! array_key_exists($fi['class'], $wgAutoloadClasses)) {
144 - $file = $fi['local'] ? $smgIP . '/' . $fi['file'] : $fi['file'];
145 - $wgAutoloadClasses[$fi['class']] = $file;
146 - }
147 - }
148 -
149 - // Add the form input hook for the service
150 - $field_args = array();
151 - if (strlen($mainName) > 0) $field_args['service_name'] = $mainName;
152 - $sfgFormPrinter->setInputTypeHook($service, 'smfSelectFormInputHTML', $field_args);
153 -}
154 -
155 -/**
156 - * Class for the form input type 'map'. The relevant form input class is called depending on the provided service.
157 - *
158 - * @param unknown_type $coordinates
159 - * @param unknown_type $input_name
160 - * @param unknown_type $is_mandatory
161 - * @param unknown_type $is_disabled
162 - * @param array $field_args
163 - * @return unknown
164 - */
165 -function smfSelectFormInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, array $field_args) {
166 - global $egMapsServices;
167 -
168 - // If service_name is set, use this value, and ignore any given
169 - // service parameters
170 - // This will prevent ..input type=googlemaps|service=yahoo.. from
171 - // showing up as a Yahoo! Maps map
172 - if (array_key_exists('service_name', $field_args)) {
173 - $service_name = $field_args['service_name'];
174 - }
175 - elseif (array_key_exists('service', $field_args)) {
176 - $service_name = $field_args['service'];
177 - }
178 - else{
179 - $service_name = null;
180 - }
181 -
182 - $service_name = MapsMapper::getValidService($service_name, 'fi');
183 -
184 - $formInput = new $egMapsServices[$service_name]['fi']['class']();
185 -
186 - // Get and return the form input HTML from the hook corresponding with the provided service
187 - return $formInput->formInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args);
188 -
189 -}
190 -
191 -/**
19286 * Returns html for an html input field with a default value that will automatically dissapear when
19387 * the user clicks in it, and reappers when the focus on the field is lost and it's still empty.
19488 *
Index: trunk/extensions/SemanticMaps/QueryPrinters/SM_QueryPrinters.php
@@ -0,0 +1,70 @@
 2+<?php
 3+
 4+/**
 5+ * Initialization file for query printer functionality in the Maps extension
 6+ *
 7+ * @file SM_FormInputs.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+final class SMQueryPrinters {
 18+
 19+ public static function initialize() {
 20+ global $smgIP, $wgAutoloadClasses, $egMapsServices;
 21+
 22+ $wgAutoloadClasses['SMMapPrinter'] = $smgIP . '/QueryPrinters/SM_MapPrinter.php';
 23+
 24+ global $egMapsServices;
 25+
 26+ $hasQueryPrinters = false;
 27+
 28+ foreach($egMapsServices as $serviceName => $serviceData) {
 29+ // Check if the service has a query printer
 30+ $hasQP = array_key_exists('qp', $serviceData);
 31+
 32+ // If the service has no QP, skipt it and continue with the next one.
 33+ if (!$hasQP) continue;
 34+
 35+ // At least one query printer will be enabled when this point is reached.
 36+ $hasQueryPrinters = true;
 37+
 38+ // Add the result format for the service name.
 39+ self::initFormat($serviceName, $serviceData['qp']);
 40+
 41+ // Loop through the service alliases, and add them as result formats to the query printer.
 42+ foreach ($serviceData['aliases'] as $alias) self::initFormat($alias, $serviceData['qp']);
 43+ }
 44+
 45+ // Add the 'map' result format if there are mapping services that have QP's loaded.
 46+ if ($hasQueryPrinters) self::initFormat('map', array('class' => 'SMMapper', 'file' => 'QueryPrinters/SM_Mapper.php', 'local' => true));
 47+ }
 48+
 49+ /**
 50+ * Add the result format for a mapping service or alias
 51+ *
 52+ * @param string $format
 53+ * @param array $qp
 54+ */
 55+ private static function initFormat($format, array $qp) {
 56+ global $wgAutoloadClasses, $smwgResultFormats, $smgIP;
 57+
 58+ if (! array_key_exists($qp['class'], $wgAutoloadClasses)) {
 59+ $file = $qp['local'] ? $smgIP . '/' . $qp['file'] : $qp['file'];
 60+ $wgAutoloadClasses[$qp['class']] = $file;
 61+ }
 62+
 63+ if (isset($smwgResultFormats)) {
 64+ $smwgResultFormats[$format] = $qp['class'];
 65+ }
 66+ else {
 67+ SMWQueryProcessor::$formats[$format] = $qp['class'];
 68+ }
 69+ }
 70+
 71+}
\ No newline at end of file
Index: trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php
@@ -0,0 +1,254 @@
 2+<?php
 3+
 4+/**
 5+ * Abstract class that provides the common functionallity for all map query printers
 6+ *
 7+ * @file SM_MapPrinter.php
 8+ * @ingroup SemanticMaps
 9+ *
 10+ * @author Jeroen De Dauw
 11+ * @author Robert Buzink
 12+ * @author Yaron Koren
 13+ */
 14+
 15+if( !defined( 'MEDIAWIKI' ) ) {
 16+ die( 'Not an entry point.' );
 17+}
 18+
 19+abstract class SMMapPrinter extends SMWResultPrinter {
 20+
 21+ /**
 22+ * Sets the map service specific element name
 23+ */
 24+ protected abstract function setQueryPrinterSettings();
 25+
 26+ /**
 27+ * Map service spesific map count and loading of dependencies
 28+ */
 29+ protected abstract function doMapServiceLoad();
 30+
 31+ /**
 32+ * Gets the query result
 33+ */
 34+ protected abstract function addSpecificMapHTML();
 35+
 36+ public $serviceName;
 37+
 38+ protected $defaultParams = array();
 39+
 40+ protected $m_locations = array();
 41+
 42+ protected $defaultZoom;
 43+ protected $elementNr;
 44+ protected $elementNamePrefix;
 45+
 46+ protected $mapName;
 47+
 48+ protected $centre_lat;
 49+ protected $centre_lon;
 50+
 51+ protected $output = '';
 52+
 53+ protected $mapFeature;
 54+
 55+ /**
 56+ * Builds up and returns the HTML for the map, with the queried coordinate data on it.
 57+ *
 58+ * @param unknown_type $res
 59+ * @param unknown_type $outputmode
 60+ * @return array
 61+ */
 62+ public final function getResultText($res, $outputmode) {
 63+ $this->formatResultData($res, $outputmode);
 64+
 65+ $this->setQueryPrinterSettings();
 66+
 67+ $this->manageMapProperties($this->m_params);
 68+
 69+ // Only create a map when there is at least one result.
 70+ if (count($this->m_locations) > 0) {
 71+ $this->doMapServiceLoad();
 72+
 73+ $this->setMapName();
 74+
 75+ $this->setZoom();
 76+
 77+ $this->setCentre();
 78+
 79+ $this->addSpecificMapHTML();
 80+ }
 81+
 82+ return array($this->output, 'noparse' => 'true', 'isHTML' => 'true');
 83+ }
 84+
 85+ public final function getResult($results, $params, $outputmode) {
 86+ // Skip checks, results with 0 entries are normal
 87+ $this->readParameters($params, $outputmode);
 88+ return $this->getResultText($results, SMW_OUTPUT_HTML);
 89+ }
 90+
 91+ private function formatResultData($res, $outputmode) {
 92+ while ( ($row = $res->getNext()) !== false ) {
 93+ $this->addResultRow($outputmode, $row);
 94+ }
 95+ }
 96+
 97+ /**
 98+ * This function will loop through all properties (fields) of one record (row),
 99+ * and add the location data, title, label and icon to the m_locations array.
 100+ *
 101+ * @param unknown_type $outputmode
 102+ * @param unknown_type $row The record you want to add data from
 103+ */
 104+ private function addResultRow($outputmode, $row) {
 105+ global $wgUser;
 106+ $skin = $wgUser->getSkin();
 107+
 108+ $title = '';
 109+ $text = '';
 110+ $lat = '';
 111+ $lon = '';
 112+
 113+ $coords = array();
 114+
 115+ // Loop throught all fields of the record
 116+ foreach ($row as $i => $field) {
 117+ $pr = $field->getPrintRequest();
 118+
 119+ // Loop throught all the parts of the field value
 120+ while ( ($object = $field->getNextObject()) !== false ) {
 121+ if ($object->getTypeID() == '_wpg' && $i == 0) {
 122+ $title = $object->getLongText($outputmode, $skin);
 123+ }
 124+
 125+ if ($object->getTypeID() != '_geo' && $i != 0) {
 126+ $text .= $pr->getHTMLText($skin) . ': ' . $object->getLongText($outputmode, $skin) . '<br />';
 127+ }
 128+
 129+ if ($pr->getMode() == SMWPrintRequest::PRINT_PROP && $pr->getTypeID() == '_geo') {
 130+ $coords[] = explode(',', $object->getXSDValue());
 131+ }
 132+ }
 133+ }
 134+
 135+ foreach ($coords as $coord) {
 136+ if (count($coord) == 2) {
 137+ list($lat, $lon) = $coord;
 138+
 139+ if (strlen($lat) > 0 && strlen($lon) > 0) {
 140+ $icon = $this->getLocationIcon($row);
 141+ $this->m_locations[] = array($lat, $lon, $title, $text, $icon);
 142+ }
 143+
 144+ }
 145+ }
 146+
 147+ }
 148+
 149+ /**
 150+ * Get the icon for a row
 151+ *
 152+ * @param unknown_type $row
 153+ * @return unknown
 154+ */
 155+ private function getLocationIcon($row) {
 156+ $icon = '';
 157+ $legend_labels = array();
 158+
 159+ // Look for display_options field, which can be set by Semantic Compound Queries
 160+ if (property_exists($row[0], 'display_options')) {
 161+ if (array_key_exists('icon', $row[0]->display_options)) {
 162+ $icon = $row[0]->display_options['icon'];
 163+
 164+ // This is somewhat of a hack - if a legend label has been set, we're getting it for every point, instead of just once per icon
 165+ if (array_key_exists('legend label', $row[0]->display_options)) {
 166+
 167+ $legend_label = $row[0]->display_options['legend label'];
 168+
 169+ if (! array_key_exists($icon, $legend_labels)) {
 170+ $legend_labels[$icon] = $legend_label;
 171+ }
 172+ }
 173+ }
 174+ // Icon can be set even for regular, non-compound queries If it is, though, we have to translate the name into a URL here
 175+ } elseif (array_key_exists('icon', $this->m_params)) {
 176+
 177+ $icon_title = Title::newFromText($this->m_params['icon']);
 178+ $icon_image_page = new ImagePage($icon_title);
 179+ $icon = $icon_image_page->getDisplayedFile()->getURL();
 180+ }
 181+
 182+ return $icon;
 183+ }
 184+
 185+ private function manageMapProperties($mapProperties) {
 186+ global $egMapsServices;
 187+
 188+ $mapProperties = MapsMapper::getValidParams($mapProperties, $egMapsServices[$this->serviceName]['parameters']);
 189+ $mapProperties = MapsMapper::setDefaultParValues($mapProperties, $this->defaultParams);
 190+
 191+ if (isset($this->serviceName)) $mapProperties['service'] = $this->serviceName;
 192+
 193+ // Go through the array with map parameters and create new variables
 194+ // with the name of the key and value of the item if they don't exist on class level yet.
 195+ foreach($mapProperties as $paramName => $paramValue) {
 196+ if (!property_exists(__CLASS__, $paramName)) {
 197+ $this->{$paramName} = $paramValue;
 198+ }
 199+ }
 200+
 201+ MapsMapper::enforceArrayValues($this->controls);
 202+ }
 203+
 204+ /**
 205+ * Sets the zoom level to the provided value, or when not set, to the default.
 206+ *
 207+ */
 208+ private function setZoom() {
 209+ if (strlen($this->zoom) < 1) {
 210+ if (count($this->m_locations) > 1) {
 211+ $this->zoom = 'null';
 212+ }
 213+ else {
 214+ $this->zoom = $this->defaultZoom;
 215+ }
 216+ }
 217+ }
 218+
 219+ /**
 220+ * Sets the $centre_lat and $centre_lon fields.
 221+ * Note: this needs to be done AFTRE the maker coordinates are set.
 222+ *
 223+ */
 224+ private function setCentre() {
 225+ if (strlen($this->centre) > 0) {
 226+ // If a centre value is set, use it.
 227+ $centre = MapsUtils::getLatLon($this->centre);
 228+ $this->centre_lat = $centre['lat'];
 229+ $this->centre_lon = $centre['lon'];
 230+ }
 231+ elseif (count($this->m_locations) > 1) {
 232+ // If centre is not set, and there are multiple points, set the values to null, to be auto determined by the JS of the mapping API.
 233+ $this->centre_lat = 'null';
 234+ $this->centre_lon = 'null';
 235+ }
 236+ else {
 237+ // If centre is not set and there is exactelly one marker, use it's coordinates.
 238+ $this->centre_lat = $this->m_locations[0][0];
 239+ $this->centre_lon = $this->m_locations[0][1];
 240+ }
 241+ }
 242+
 243+ /**
 244+ * Sets the $mapName field, using the $elementNamePrefix and $elementNr.
 245+ *
 246+ */
 247+ protected function setMapName() {
 248+ $this->mapName = $this->elementNamePrefix.'_'.$this->elementNr;
 249+ }
 250+
 251+ public final function getName() {
 252+ return wfMsg('maps_' . $this->serviceName);
 253+ }
 254+
 255+}
Index: trunk/extensions/SemanticMaps/QueryPrinters/SM_Mapper.php
@@ -0,0 +1,47 @@
 2+<?php
 3+
 4+/**
 5+ * General map query printer class
 6+ *
 7+ * @file SM_Mapper.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+final class SMMapper {
 18+
 19+ private $queryPrinter;
 20+
 21+ public function __construct($format, $inline) {
 22+ global $egMapsDefaultServices, $egMapsServices;
 23+
 24+ // TODO: allow service parameter to override the default
 25+ if ($format == 'map') $format = $egMapsDefaultServices['qp'];
 26+
 27+ $service = MapsMapper::getValidService($format, 'qp');
 28+
 29+ $this->queryPrinter = new $egMapsServices[$service]['qp']['class']($format, $inline);
 30+ }
 31+
 32+ public function getName() {
 33+ return $this->queryPrinter->getName();
 34+ }
 35+
 36+ public function getQueryMode($context) {
 37+ return $this->queryPrinter->getQueryMode($context);
 38+ }
 39+
 40+ public function getResult($results, $params, $outputmode) {
 41+ return $this->queryPrinter->getResult($results, $params, $outputmode);
 42+ }
 43+
 44+ protected function getResultText($res, $outputmode) {
 45+ return $this->queryPrinter->getResultText($res, $outputmode);
 46+ }
 47+
 48+}
Index: trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsQP.php
@@ -0,0 +1,100 @@
 2+<?php
 3+/**
 4+ * A query printer for maps using the Google Maps API
 5+ *
 6+ * @file SM_GoogleMaps.php
 7+ * @ingroup SemanticMaps
 8+ *
 9+ * @author Robert Buzink
 10+ * @author Yaron Koren
 11+ * @author Jeroen De Dauw
 12+ */
 13+
 14+if( !defined( 'MEDIAWIKI' ) ) {
 15+ die( 'Not an entry point.' );
 16+}
 17+
 18+final class SMGoogleMapsQP extends SMMapPrinter {
 19+
 20+ public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME;
 21+
 22+ /**
 23+ * @see SMMapPrinter::setQueryPrinterSettings()
 24+ *
 25+ */
 26+ protected function setQueryPrinterSettings() {
 27+ global $egMapsGoogleMapsZoom, $egMapsGoogleMapsPrefix;
 28+
 29+ $this->elementNamePrefix = $egMapsGoogleMapsPrefix;
 30+
 31+ $this->defaultZoom = $egMapsGoogleMapsZoom;
 32+
 33+ $this->defaultParams = MapsGoogleMapsUtils::getDefaultParams();
 34+ }
 35+
 36+ /**
 37+ * @see SMMapPrinter::doMapServiceLoad()
 38+ *
 39+ */
 40+ protected function doMapServiceLoad() {
 41+ global $egGoogleMapsOnThisPage;
 42+
 43+ if (empty($egGoogleMapsOnThisPage)) {
 44+ $egGoogleMapsOnThisPage = 0;
 45+ MapsGoogleMapsUtils::addGMapDependencies($this->output);
 46+ }
 47+
 48+ $egGoogleMapsOnThisPage++;
 49+
 50+ $this->elementNr = $egGoogleMapsOnThisPage;
 51+ }
 52+
 53+ /**
 54+ * @see SMMapPrinter::getQueryResult()
 55+ *
 56+ */
 57+ protected function addSpecificMapHTML() {
 58+ global $wgJsMimeType;
 59+
 60+ $enableEarth = MapsGoogleMapsUtils::getEarthValue($this->earth);
 61+
 62+ // Get the Google Maps names for the control and map types
 63+ $this->type = MapsGoogleMapsUtils::getGMapType($this->type, true);
 64+
 65+ $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls);
 66+
 67+ $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom);
 68+
 69+ $markerItems = array();
 70+
 71+ foreach ($this->m_locations as $location) {
 72+ list($lat, $lon, $title, $label, $icon) = $location;
 73+
 74+ $title = str_replace("'", "\'", $title);
 75+ $label = str_replace("'", "\'", $label);
 76+
 77+ $markerItems[] = "getGMarkerData($lat, $lon, '$title', '$label', '$icon')";
 78+ }
 79+
 80+ // Create a string containing the marker JS
 81+ $markersString = implode(',', $markerItems);
 82+
 83+ $this->types = explode(",", $this->types);
 84+
 85+ $typesString = MapsGoogleMapsUtils::createTypesString($this->types, $enableEarth);
 86+
 87+ $this->output .= <<<END
 88+<div id="$this->mapName" class="$this->class" style="$this->style" ></div>
 89+<script type="$wgJsMimeType"> /*<![CDATA[*/
 90+addLoadEvent(
 91+ initializeGoogleMap('$this->mapName', $this->width, $this->height, $this->centre_lat, $this->centre_lon, $this->zoom, $this->type, [$typesString], [$this->controls], $this->autozoom, [$markersString])
 92+);
 93+/*]]>*/ </script>
 94+
 95+END;
 96+
 97+ }
 98+
 99+
 100+}
 101+
Index: trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsFormInput.php
@@ -17,7 +17,7 @@
1818
1919 final class SMGoogleMapsFormInput extends SMFormInput {
2020
21 - public $serviceName = MapsGoogleMaps::SERVICE_NAME;
 21+ public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME;
2222
2323 /**
2424 * @see MapsMapFeature::setMapSettings()

Status & tagging log