http://www.mediawiki.org/wiki/Special:Code/MediaWiki/59532
Revision: 59532 Author: jeroendedauw Date: 2009-11-28 21:28:41 +0000 (Sat, 28 Nov 2009) Log Message: ----------- Changes for 0.5. Rewrote parameter handling and added strict validation. http://www.mediawiki.org/wiki/Extension:Maps/Future#Maps_0.5 Modified Paths: -------------- trunk/extensions/SemanticMaps/FormInputs/SM_FormInput.php trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsFormInput.php trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsQP.php trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFormInput.php trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersQP.php trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php trunk/extensions/SemanticMaps/SemanticMaps.php trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsFormInput.php trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsQP.php Added Paths: ----------- trunk/extensions/SemanticMaps/SM_GeoCoordsValue.php Modified: trunk/extensions/SemanticMaps/FormInputs/SM_FormInput.php =================================================================== --- trunk/extensions/SemanticMaps/FormInputs/SM_FormInput.php 2009-11-28 21:27:51 UTC (rev 59531) +++ trunk/extensions/SemanticMaps/FormInputs/SM_FormInput.php 2009-11-28 21:28:41 UTC (rev 59532) @@ -43,8 +43,8 @@ * the form to handle coordinate data. */ public final function formInputHTML($coordinates, $input_name, $is_mandatory, $is_disabled, $field_args) { + global $sfgTabIndex; // TODO: Use function args for sf stuffz - global $sfgTabIndex; $this->coordinates = $coordinates; @@ -54,43 +54,46 @@ $this->manageGeocoding(); - $this->manageMapProperties($field_args, __CLASS__); - - $this->setCoordinates(); - $this->setCentre(); - $this->setZoom(); - - // Create html element names - $this->setMapName(); - $this->mapName .= '_'.$sfgTabIndex; - $this->geocodeFieldName = $this->elementNamePrefix.'_geocode_'.$this->elementNr.'_'.$sfgTabIndex; - $this->coordsFieldName = $this->elementNamePrefix.'_coords_'.$this->elementNr.'_'.$sfgTabIndex; - $this->infoFieldName = $this->elementNamePrefix.'_info_'.$this->elementNr.'_'.$sfgTabIndex; - - // Create the non specific form HTML - $this->output .= " - <input id='".$this->coordsFieldName."' name='$input_name' type='text' value='$this->startingCoords' size='40' tabindex='$sfgTabIndex'> - <span id='".$this->infoFieldName."' class='error_message'></span>"; - - if ($this->enableGeocoding) { - $sfgTabIndex++; + if (parent::manageMapProperties($field_args, __CLASS__)) { + $this->setCoordinates(); + $this->setCentre(); + $this->setZoom(); - // Retrieve language valuess - $enter_address_here_text = wfMsg('semanticmaps_enteraddresshere'); - $lookup_coordinates_text = wfMsg('semanticmaps_lookupcoordinates'); - $not_found_text = wfMsg('semanticmaps_notfound'); + // Create html element names + $this->setMapName(); + $this->mapName .= '_'.$sfgTabIndex; + $this->geocodeFieldName = $this->elementNamePrefix.'_geocode_'.$this->elementNr.'_'.$sfgTabIndex; + $this->coordsFieldName = $this->elementNamePrefix.'_coords_'.$this->elementNr.'_'.$sfgTabIndex; + $this->infoFieldName = $this->elementNamePrefix.'_info_'.$this->elementNr.'_'.$sfgTabIndex; + + // Create the non specific form HTML + $this->output .= " + <input id='".$this->coordsFieldName."' name='$input_name' type='text' value='$this->startingCoords' size='40' tabindex='$sfgTabIndex'> + <span id='".$this->infoFieldName."' class='error_message'></span>"; - $adress_field = SMFormInput::getDynamicInput($this->geocodeFieldName, $enter_address_here_text, 'size="30" name="geocode" style="color: #707070" tabindex="'.$sfgTabIndex.'"'); - $this->output .= " - <p> - $adress_field - <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' /> - </p>"; + if ($this->enableGeocoding) $this->addGeocodingField(); + + $this->addSpecificMapHTML(); } - $this->addSpecificMapHTML(); + return array($this->output . $this->errorList, ''); + } + + private function addGeocodingField() { + global $sfgTabIndex; + $sfgTabIndex++; - return array($this->output, ''); + // Retrieve language valuess + $enter_address_here_text = wfMsg('semanticmaps_enteraddresshere'); + $lookup_coordinates_text = wfMsg('semanticmaps_lookupcoordinates'); + $not_found_text = wfMsg('semanticmaps_notfound'); + + $adress_field = SMFormInput::getDynamicInput($this->geocodeFieldName, $enter_address_here_text, 'size="30" name="geocode" style="color: #707070" tabindex="'.$sfgTabIndex.'"'); + $this->output .= " + <p> + $adress_field + <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' /> + </p>"; } /** Modified: trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsFormInput.php =================================================================== --- trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsFormInput.php 2009-11-28 21:27:51 UTC (rev 59531) +++ trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsFormInput.php 2009-11-28 21:28:41 UTC (rev 59532) @@ -17,7 +17,7 @@ final class SMGoogleMapsFormInput extends SMFormInput { - public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME; + public $serviceName = MapsGoogleMaps::SERVICE_NAME; /** * @see MapsMapFeature::setMapSettings() @@ -31,8 +31,15 @@ $this->earthZoom = 1; - $this->defaultParams = MapsGoogleMapsUtils::getDefaultParams(); - $this->defaultZoom = $egMapsGoogleMapsZoom; + $this->defaultZoom = $egMapsGoogleMapsZoom; + + $this->spesificParameters = array( + 'overlays' => array( + 'aliases' => array(), + 'criteria' => array(), + 'default' => '' + ), + ); } /** @@ -43,7 +50,7 @@ global $wgJsMimeType; global $smgScriptPath, $smgGoogleFormsOnThisPage, $smgStyleVersion; - MapsGoogleMapsUtils::addGMapDependencies($this->output); + MapsGoogleMaps::addGMapDependencies($this->output); if (empty($smgGoogleFormsOnThisPage)) { $smgGoogleFormsOnThisPage = 0; @@ -73,11 +80,11 @@ protected function addSpecificMapHTML() { global $wgJsMimeType; - $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom); + $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom); - $this->type = MapsGoogleMapsUtils::getGMapType($this->type, true); + $this->type = MapsGoogleMaps::getGMapType($this->type, true); - $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls); + $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls)); if (in_string('overlays', $this->controls)) { $this->controls = str_replace(",'overlays'", '', $this->controls); @@ -86,7 +93,7 @@ $this->types = explode(",", $this->types); - $typesString = MapsGoogleMapsUtils::createTypesString($this->types); + $typesString = MapsGoogleMaps::createTypesString($this->types); $this->output .= " <div id='".$this->mapName."' class='".$this->class."'></div> @@ -121,7 +128,7 @@ protected function manageGeocoding() { global $egGoogleMapsKey; $this->enableGeocoding = strlen(trim($egGoogleMapsKey)) > 0; - if ($this->enableGeocoding) MapsGoogleMapsUtils::addGMapDependencies($this->output); + if ($this->enableGeocoding) MapsGoogleMaps::addGMapDependencies($this->output); } } Modified: trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsQP.php =================================================================== --- trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsQP.php 2009-11-28 21:27:51 UTC (rev 59531) +++ trunk/extensions/SemanticMaps/GoogleMaps/SM_GoogleMapsQP.php 2009-11-28 21:28:41 UTC (rev 59532) @@ -16,7 +16,7 @@ final class SMGoogleMapsQP extends SMMapPrinter { - public $serviceName = MapsGoogleMapsUtils::SERVICE_NAME; + public $serviceName = MapsGoogleMaps::SERVICE_NAME; /** * @see SMMapPrinter::setQueryPrinterSettings() @@ -29,7 +29,11 @@ $this->defaultZoom = $egMapsGoogleMapsZoom; - $this->defaultParams = MapsGoogleMapsUtils::getDefaultParams(); + $this->spesificParameters = array( + 'zoom' => array( + 'default' => '', + ) + ); } /** @@ -41,7 +45,7 @@ if (empty($egGoogleMapsOnThisPage)) { $egGoogleMapsOnThisPage = 0; - MapsGoogleMapsUtils::addGMapDependencies($this->output); + MapsGoogleMaps::addGMapDependencies($this->output); } $egGoogleMapsOnThisPage++; @@ -57,13 +61,13 @@ global $wgJsMimeType; // Get the Google Maps names for the control and map types. - $this->type = MapsGoogleMapsUtils::getGMapType($this->type, true); + $this->type = MapsGoogleMaps::getGMapType($this->type, true); - $this->controls = MapsGoogleMapsUtils::createControlsString($this->controls); + $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls)); - $onloadFunctions = MapsGoogleMapsUtils::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls); + $onloadFunctions = MapsGoogleMaps::addOverlayOutput($this->output, $this->mapName, $this->overlays, $this->controls); - $this->autozoom = MapsGoogleMapsUtils::getAutozoomJSValue($this->autozoom); + $this->autozoom = MapsGoogleMaps::getAutozoomJSValue($this->autozoom); $markerItems = array(); @@ -81,7 +85,7 @@ $this->types = explode(",", $this->types); - $typesString = MapsGoogleMapsUtils::createTypesString($this->types); + $typesString = MapsGoogleMaps::createTypesString($this->types); $this->output .= <<<END <div id="$this->mapName" class="$this->class" style="$this->style" ></div> Modified: trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFormInput.php =================================================================== --- trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFormInput.php 2009-11-28 21:27:51 UTC (rev 59531) +++ trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersFormInput.php 2009-11-28 21:28:41 UTC (rev 59532) @@ -15,7 +15,7 @@ final class SMOpenLayersFormInput extends SMFormInput { - public $serviceName = MapsOpenLayersUtils::SERVICE_NAME; + public $serviceName = MapsOpenLayers::SERVICE_NAME; /** * @see MapsMapFeature::setMapSettings() @@ -29,8 +29,7 @@ $this->earthZoom = 1; - $this->defaultParams = MapsOpenLayersUtils::getDefaultParams(); - $this->defaultZoom = $egMapsOpenLayersZoom; + $this->defaultZoom = $egMapsOpenLayersZoom; } /** @@ -41,7 +40,7 @@ global $wgJsMimeType; global $smgScriptPath, $smgOLFormsOnThisPage, $smgStyleVersion; - MapsOpenLayersUtils::addOLDependencies($this->output); + MapsOpenLayers::addOLDependencies($this->output); if (empty($smgOLFormsOnThisPage)) { $smgOLFormsOnThisPage = 0; @@ -71,15 +70,15 @@ protected function addSpecificMapHTML() { global $wgJsMimeType; - $controlItems = MapsOpenLayersUtils::createControlsString($this->controls); + $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls)); - $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers); + $layerItems = MapsOpenLayers::createLayersStringAndLoadDependencies($this->output, $this->layers); $this->output .=" <div id='".$this->mapName."' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div> <script type='$wgJsMimeType'>/*<![CDATA[*/ - addOnloadHook(makeFormInputOpenLayer('".$this->mapName."', '".$this->coordsFieldName."', ".$this->centre_lat.", ".$this->centre_lon.", ".$this->zoom.", ".$this->marker_lat.", ".$this->marker_lon.", [$layerItems], [$controlItems], $this->height)); + addOnloadHook(makeFormInputOpenLayer('".$this->mapName."', '".$this->coordsFieldName."', ".$this->centre_lat.", ".$this->centre_lon.", ".$this->zoom.", ".$this->marker_lat.", ".$this->marker_lon.", [$layerItems], [$this->controls], $this->height)); /*]]>*/</script>"; } Modified: trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersQP.php =================================================================== --- trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersQP.php 2009-11-28 21:27:51 UTC (rev 59531) +++ trunk/extensions/SemanticMaps/OpenLayers/SM_OpenLayersQP.php 2009-11-28 21:28:41 UTC (rev 59532) @@ -15,7 +15,7 @@ final class SMOpenLayersQP extends SMMapPrinter { - public $serviceName = MapsOpenLayersUtils::SERVICE_NAME; + public $serviceName = MapsOpenLayers::SERVICE_NAME; /** * @see SMMapPrinter::setQueryPrinterSettings() @@ -25,9 +25,13 @@ global $egMapsOpenLayersZoom, $egMapsOpenLayersPrefix; $this->elementNamePrefix = $egMapsOpenLayersPrefix; - $this->defaultZoom = $egMapsOpenLayersZoom; - - $this->defaultParams = MapsOpenLayersUtils::getDefaultParams(); + $this->defaultZoom = $egMapsOpenLayersZoom; + + $this->spesificParameters = array( + 'zoom' => array( + 'default' => '', + ) + ); } /** @@ -37,7 +41,7 @@ protected function doMapServiceLoad() { global $egOpenLayersOnThisPage; - MapsOpenLayersUtils::addOLDependencies($this->output); + MapsOpenLayers::addOLDependencies($this->output); $egOpenLayersOnThisPage++; $this->elementNr = $egOpenLayersOnThisPage; @@ -49,30 +53,29 @@ */ protected function addSpecificMapHTML() { global $wgJsMimeType; - - $controlItems = MapsOpenLayersUtils::createControlsString($this->controls); - - MapsMapper::enforceArrayValues($this->layers); - $layerItems = MapsOpenLayersUtils::createLayersStringAndLoadDependencies($this->output, $this->layers); - + + $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls)); + + $layerItems = MapsOpenLayers::createLayersStringAndLoadDependencies($this->output, $this->layers); + $markerItems = array(); foreach ($this->m_locations as $location) { // Create a string containing the marker JS list($lat, $lon, $title, $label, $icon) = $location; - + $title = str_replace("'", "\'", $title); $label = str_replace("'", "\'", $label); - + $markerItems[] = "getOLMarkerData($lon, $lat, '$title', '$label', '$icon')"; } - + $markersString = implode(',', $markerItems); - + $this->output .= "<div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px; background-color: #cccccc;'></div> <script type='$wgJsMimeType'> /*<![CDATA[*/ addOnloadHook( - initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$controlItems], [$markersString], $this->height) + initOpenLayer('$this->mapName', $this->centre_lon, $this->centre_lat, $this->zoom, [$layerItems], [$this->controls], [$markersString], $this->height) ); /*]]>*/ </script>"; } Modified: trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php =================================================================== --- trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php 2009-11-28 21:27:51 UTC (rev 59531) +++ trunk/extensions/SemanticMaps/QueryPrinters/SM_MapPrinter.php 2009-11-28 21:28:41 UTC (rev 59532) @@ -17,6 +17,14 @@ abstract class SMMapPrinter extends SMWResultPrinter { + /* + * TODO: + * This class is borrowing an awefull lot code from MapsMapFeature, which + * ideally should be inherited. Since SMWResultPrinter already gets inherited, + * this is not possible. Finding a better solution to this code redundancy + * would be nice, cause now changes to MapsMapFeature need to be copied here. + */ + /** * Sets the map service specific element name */ @@ -34,8 +42,6 @@ public $serviceName; - protected $defaultParams = array(); - protected $m_locations = array(); protected $defaultZoom; @@ -48,9 +54,13 @@ protected $centre_lon; protected $output = ''; + protected $errorList; protected $mapFeature; + protected $featureParameters = array(); + protected $spesificParameters = array(); + /** * Builds up and returns the HTML for the map, with the queried coordinate data on it. * @@ -63,24 +73,80 @@ $this->setQueryPrinterSettings(); - $this->manageMapProperties($this->m_params); + if (self::manageMapProperties($this->m_params, __CLASS__)) { + // Only create a map when there is at least one result. + if (count($this->m_locations) > 0) { + $this->doMapServiceLoad(); - // Only create a map when there is at least one result. - if (count($this->m_locations) > 0) { - $this->doMapServiceLoad(); - - $this->setMapName(); - - $this->setZoom(); - - $this->setCentre(); - - $this->addSpecificMapHTML(); + $this->setMapName(); + + $this->setZoom(); + + $this->setCentre(); + + $this->addSpecificMapHTML(); + } + else { + // TODO: add warning when level high enough and append to erro list. + } } - return array($this->output, 'noparse' => 'true', 'isHTML' => 'true'); + return array($this->output . $this->errorList, 'noparse' => 'true', 'isHTML' => 'true'); } + /** + * Validates and corrects the provided map properties, and the sets them as class fields. + * + * @param array $mapProperties + * @param string $className + * + * @return boolean Indicates whether the map should be shown or not. + */ + protected final function manageMapProperties(array $mapProperties, $className) { + global $egMapsServices, $egMapsErrorLevel; + + /* + * Assembliy of the allowed parameters and their information. + * The main parameters (the ones that are shared by everything) are overidden + * by the feature parameters (the ones spesific to a feature). The result is then + * again overidden by the service parameters (the ones spesific to the service), + * and finally by the spesific parameters (the ones spesific to a service-feature combination). + */ + $parameterInfo = array_merge(MapsMapper::getMainParams(), $this->featureParameters); + $parameterInfo = array_merge($parameterInfo, $egMapsServices[$this->serviceName]['parameters']); + $parameterInfo = array_merge($parameterInfo, $this->spesificParameters); + + $manager = new MapsParamManager(); + + $result = $manager->manageMapparameters($mapProperties, $parameterInfo); + + $showMap = $result !== false; + + if ($showMap) $this->setMapProperties($result, $className); + + $this->errorList = $manager->getErrorList(); + + return $showMap; + } + + /** + * Sets the map properties as class fields. + * + * @param array $mapProperties + * @param string $className + */ + private function setMapProperties(array $mapProperties, $className) { + //var_dump($mapProperties); exit; + foreach($mapProperties as $paramName => $paramValue) { + if (! property_exists($className, $paramName)) { + $this->{$paramName} = $paramValue; + } + else { + throw new Exception('Attempt to override a class field during map propertie assignment. Field name: ' . $paramName); + } + } + } + public final function getResult($results, $params, $outputmode) { // Skip checks, results with 0 entries are normal $this->readParameters($params, $outputmode); @@ -186,25 +252,6 @@ return $icon; } - private function manageMapProperties($mapProperties) { - global $egMapsServices; - - $mapProperties = MapsMapper::getValidParams($mapProperties, $egMapsServices[$this->serviceName]['parameters']); - $mapProperties = MapsMapper::setDefaultParValues($mapProperties, $this->defaultParams); - - if (isset($this->serviceName)) $mapProperties['service'] = $this->serviceName; - - // Go through the array with map parameters and create new variables - // with the name of the key and value of the item if they don't exist on class level yet. - foreach($mapProperties as $paramName => $paramValue) { - if (!property_exists(__CLASS__, $paramName)) { - $this->{$paramName} = $paramValue; - } - } - - MapsMapper::enforceArrayValues($this->controls); - } - /** * Sets the zoom level to the provided value, or when not set, to the default. * Added: trunk/extensions/SemanticMaps/SM_GeoCoordsValue.php =================================================================== --- trunk/extensions/SemanticMaps/SM_GeoCoordsValue.php (rev 0) +++ trunk/extensions/SemanticMaps/SM_GeoCoordsValue.php 2009-11-28 21:28:41 UTC (rev 59532) @@ -0,0 +1,339 @@ +<?php +/** + * File holding the SMGeoCoordsValue class. + * + * @file SM_GeoCoordsValue.php + * @ingroup SMWDataValues + * + * @author Markus Krötzsch + * @author Jeroen De Dauw + */ + +/// Unicode symbols for coordinate minutes and seconds; +/// may not display in every font ... +define('SM_GEO_MIN','′'); +define('SM_GEO_SEC','″'); + +/** + * Implementation of datavalues that are geographic coordinates. + * + * @author Markus Krötzsch + * @author Jeroen De Dauw + * + * @ingroup SemanticMaps + */ +class SMGeoCoordsValue extends SMWDataValue { + + protected $m_N = false; // cache for localised direction labels + protected $m_E = false; // cache for localised direction labels + protected $m_W = false; // cache for localised direction labels + protected $m_S = false; // cache for localised direction labels + + protected $m_wikivalue; + protected $m_lat; // decimal latitude of current value + protected $m_long; // decimal longitude of current value + protected $m_latparts; // latitude array of four entries: degrees, minutes, seconds, direction + protected $m_longparts; // longitude array of four entries: degrees, minutes, seconds, direction + // Note: signs are used as e.g. on Google maps, i.e. S and W are negative numbers. + + protected function parseUserValue($value) { + wfLoadExtensionMessages('SemanticMediaWiki'); + $this->m_lat = false; + $this->m_long = false; + $this->m_latparts = false; + $this->m_longparts = false; + $this->m_wikivalue = $value; + + // first normalise some typical symbols + $this->initDirectionLabels(); + $value = str_replace(array(' ', $this->m_N, $this->m_E, $this->m_W, $this->m_S, ), + array(' ','N','E','W','S'),$value); + $value = str_replace(array('°', '°'), '°', $value); + $value = str_replace(array('´', '´'),'´',$value); + $value = str_replace(array('″', '″', "''", '"', '´´', SM_GEO_MIN . SM_GEO_MIN),SM_GEO_SEC,$value); + $value = str_replace(array('′', '′', "'", '´'),SM_GEO_MIN,$value); + // now split the string + $parts = preg_split('/\s*(°|' . SM_GEO_MIN . '|' . SM_GEO_SEC . '|N|E|W|S|;)\s*/u',str_replace(', ', ';', $value) . ';', -1, PREG_SPLIT_DELIM_CAPTURE); + $curnum = false; + $angles = array(false, false, false); // temporary values for deg, min, sec + foreach ($parts as $part) { + switch ($part) { + case '°': + if ( ($angles[0] !== false) && ($this->m_lat === false) ) { // work off values found earlier + $this->setAngleValues('N',$angles); + } // else: we do not accept interchange of order (lat must be first), so there are just too many °s + if ( $curnum !== false ) { + $angles[0] = $curnum; + $curnum = false; + } else { + $this->addError(wfMsgForContent('smw_lonely_unit', $part)); + } + break; + case SM_GEO_MIN: + if ( ($curnum !== false) && ($angles[1] === false) ) { + $angles[1] = $curnum; + if ($angles[0] === false) $angles[0] = 0; + $curnum = false; + } else { + $this->addError(wfMsgForContent('smw_lonely_unit', $part)); + } + break; + case SM_GEO_SEC: + if ( ($curnum !== false) && ($angles[2] === false) ) { + $angles[2] = $curnum; + if ($angles[0] === false) $angles[0] = 0; + if ($angles[1] === false) $angles[1] = 0; + $curnum = false; + } else { + $this->addError(wfMsgForContent('smw_lonely_unit', $part)); + } + break; + case 'N': case 'S': // interpret findings as latitude + if ( $curnum !== false ) { // work off number without ° + if ($angles[0] !== false) { // "12° 34" as coordinate, complain + $this->addError(wfMsgForContent('smw_bad_latlong')); + break; + } else { + $angles[0] = $curnum; + $curnum = false; + } + } + if (($this->m_lat === false) && ($angles[0] !== false)) { + $this->setAngleValues($part,$angles); + } else { + $this->addError(wfMsgForContent('smw_bad_latlong')); + } + break; + case 'E': case 'W': // interpret findings as longitude + if ( $curnum !== false ) { // work off number without ° + if ($angles[0] !== false) { // "12° 34" as coordinate, complain + $this->addError(wfMsgForContent('smw_bad_latlong')); + break; + } else { + $angles[0] = $curnum; + $curnum = false; + } + } + if (($this->m_long === false) && ($angles[0] !== false)) { + $this->setAngleValues($part,$angles); + } else { + $this->addError(wfMsgForContent('smw_bad_latlong')); + } + break; + case ';': // interpret findings as latitude + if ( $curnum !== false ) { // work off number without ° + if ($angles[0] !== false) { // "12° 34" as coordinate, complain + $this->addError(wfMsgForContent('smw_bad_latlong')); + break; + } else { + $angles[0] = $curnum; + $curnum = false; + } + } + if (($this->m_lat === false) && ($angles[0] !== false)) { + $this->setAngleValues('N',$angles); + } // else: ignore ";" without complaining + break; + case '': break; // ignore + default: // should be a number (if not, errors appear elsewhere) + // no kiloseps in coordinates, use as decsep as a convenience to some users (Bug 11808): + $curnum = str_replace(wfMsgForContent('smw_kiloseparator'), wfMsgForContent('smw_decseparator'), $part); + break; + } + } + + if ( ($this->m_lat !== false) && ($this->m_long === false) && ($angles[0] !== false) ) { // no final E or W? + $this->setAngleValues('E',$angles); + } + if ( ($angles[0] !== false)||($curnum !== false)) { // unprocessed chunk, error + + } + + if ($this->m_caption === false) { + $this->m_caption = $value; + } + return true; + } + + protected function parseDBkeys($args) { + $this->m_lat = false; + $this->m_long = false; + $this->m_latparts = false; + $this->m_longparts = false; + + list($this->m_lat, $this->m_long) = explode(',', $args[0]); + $this->m_caption = $this->formatAngleValues(true) . ', ' . $this->formatAngleValues(false); // this is our output text + $this->m_wikivalue = $this->m_caption; + } + + public function getShortWikiText($linked = NULL) { + if ($this->isValid() && ($linked !== NULL) && ($linked !== false)) { + wfLoadExtensionMessages('SemanticMediaWiki'); + SMWOutputs::requireHeadItem(SMW_HEADER_TOOLTIP); + return '<span class="smwttinline">' . $this->m_caption . '<span class="smwttcontent">' . + wfMsgForContent('smw_label_latitude') . ' ' . $this->formatAngleValues(true) . '<br />' . + wfMsgForContent('smw_label_longitude') . ' ' . $this->formatAngleValues(false) . + '</span></span>'; + } else { + return $this->m_caption; + } + } + + public function getShortHTMLText($linker = NULL) { + return $this->getShortWikiText($linker); // should be save (based on xsdvalue) + } + + public function getLongWikiText($linked = NULL) { + if (!$this->isValid()) { + return $this->getErrorText(); + } else { + return $this->formatAngleValues(true) . ', ' . $this->formatAngleValues(false); + } + } + + public function getLongHTMLText($linker = NULL) { + return $this->getLongWikiText($linker); + } + + public function getDBkeys() { + $this->unstub(); + return array($this->m_lat . ',' . $this->m_long); + } + + public function getWikiValue(){ + $this->unstub(); + return $this->m_wikivalue; + } + + public function getExportData() { + if ($this->isValid()) { + $lit = new SMWExpLiteral($this->formatAngleValues(true, false) . ', ' . $this->formatAngleValues(false, false), $this, 'http://www.w3.org/2001/XMLSchema#string'); + return new SMWExpData($lit); + } else { + return NULL; + } + } + + /** + * Get and cache localised direction labels. Just for convenience. + */ + protected function initDirectionLabels() { + wfLoadExtensionMessages('SemanticMediaWiki'); + $this->m_N = wfMsgForContent('smw_abb_north'); + $this->m_E = wfMsgForContent('smw_abb_east'); + $this->m_W = wfMsgForContent('smw_abb_west'); + $this->m_S = wfMsgForContent('smw_abb_south'); + } + + /** + * Helper function: read a possibly incomplete array of angles for one coordinate. + * The direction is one of N, E, W, S, and $angles is an array of three values, + * each possibly false if unset. + */ + protected function setAngleValues($direction, &$angles) { + wfLoadExtensionMessages('SemanticMediaWiki'); + $numvalue = SMWDataValueFactory::newTypeIDValue('_num'); + $res = 0; + $factor = 1; + for ($i=0; $i<3; $i++) { + if ($angles[$i] !== false) { + $numvalue->setUserValue($angles[$i]); + if ($numvalue->isValid() && ($numvalue->getUnit() == '')) { + $res += $numvalue->getNumericValue() / $factor; + } else { + $this->addError(wfMsgForContent('smw_nofloat', $angles[$i])); + } + } + $factor = $factor * 60; + } + switch ($direction) { + case 'N': $this->m_lat = $res; break; + case 'S': $this->m_lat = -1 * $res; break; + case 'E': $this->m_long = $res; break; + case 'W': $this->m_long = -1 * $res; break; + } + if ( (($direction == 'E') || ($direction == 'W')) && + (($this->m_long > 180) || ($this->m_long <= -180)) ) { // bring values back into [180, -180) + $this->m_long += ($this->m_long<0)?(round(abs($this->m_long)/360)*360):(round($this->m_long/360)*-360); + } + ///TODO: also make such a normalisation for lat ... + $angles = array(false, false, false); + } + + /** + * Return array with four entries for deg, min, sec, direction, + * that corresponds to the current latitude or longitude. + */ + protected function getAngleValues($lat = true) { + if ($lat) { + if ($this->m_latparts !== false) { + return $this->m_latparts; + } + $num = abs($this->m_lat); + $d = ($this->m_lat<0)?'S':'N'; + } else { + if ($this->m_longparts !== false) { + return $this->m_longparts; + } + $num = abs($this->m_long); + $d = ($this->m_long<0)?'W':'E'; + } + $result = array(0,0,0,$d); + $result[0] = floor($num); + $num = ($num-$result[0]) * 60; + $result[1] = floor($num); + $result[2] = ($num-$result[1]) * 60; + if ( abs($result[2]) < 0.001 ) { // limit precission, avoid conversion generated junk and EXP notation in coords + $result[2] = 0; + } + if ($lat) { + $this->m_latparts = $result; + } else { + $this->m_longparts = $result; + } + return $result; + } + + /** + * Format the current latitude or longitude. The parameter $content states + * whether the result is for content printout. Alternatively, a language- + * independent result is generated. + */ + protected function formatAngleValues($lat = true, $content = true) { + $values = $this->getAngleValues($lat); + if ($content) { + $this->initDirectionLabels(); + $result = smwfNumberFormat($values[0]) . '°' . smwfNumberFormat($values[1]) . SM_GEO_MIN . + smwfNumberFormat($values[2]) . SM_GEO_SEC; + switch ($values[3]) { + case 'N': return $result . $this->m_N; + case 'E': return $result . $this->m_E; + case 'W': return $result . $this->m_W; + case 'S': return $result . $this->m_S; + } + } else { + return smwfNumberFormat($values[0]) . '°' . smwfNumberFormat($values[1]) . SM_GEO_MIN . + smwfNumberFormat($values[2]) . SM_GEO_SEC . $values[3]; + } + } + + protected function getServiceLinkParams() { + // Create links to mapping services based on a wiki-editable message. The parameters + // available to the message are: + // $1: latitude integer degrees, $2: longitude integer degrees + // $3: latitude integer minutes, $4: longitude integer minutes + // $5: latitude integer seconds, $6: longitude integer seconds, + // $7: latitude direction string (N or S), $8: longitude direction string (W or E) + // $9: latitude in decimal degrees, $10: longitude in decimal degrees + // $11: sign (- if south) for latitude, $12: sign (- if west) for longitude + $latvals = $this->getAngleValues(true); + $longvals = $this->getAngleValues(false); + return array($latvals[0], $longvals[0], + $latvals[1], $longvals[1], + round($latvals[2]), round($longvals[2]), + $latvals[3], $longvals[3], + abs($this->m_lat), abs($this->m_long), + $latvals[3]=='S'?'-':'', $longvals[3]=='W'?'-':''); + } + +} Modified: trunk/extensions/SemanticMaps/SemanticMaps.php =================================================================== --- trunk/extensions/SemanticMaps/SemanticMaps.php 2009-11-28 21:27:51 UTC (rev 59531) +++ trunk/extensions/SemanticMaps/SemanticMaps.php 2009-11-28 21:28:41 UTC (rev 59532) @@ -23,20 +23,23 @@ die( 'Not an entry point.' ); } -define('SM_VERSION', '0.5 a4'); +define('SM_VERSION', '0.5 a6'); $smgScriptPath = $wgScriptPath . '/extensions/SemanticMaps'; $smgIP = $IP . '/extensions/SemanticMaps'; $smgStyleVersion = $wgStyleVersion . '-' . SM_VERSION; -// Include the settings file +// Include the settings file. require_once($smgIP . '/SM_Settings.php'); $wgExtensionFunctions[] = 'smfSetup'; $wgHooks['AdminLinks'][] = 'smfAddToAdminLinks'; +$wgAutoloadClasses['SMGeoCoordsValue'] = $smgIP . '/SM_GeoCoordsValue.php'; +$wgHooks['smwInitDatatypes'][] = 'smfInitGeoCoordsType'; + $wgExtensionMessagesFiles['SemanticMaps'] = $smgIP . '/SemanticMaps.i18n.php'; /** @@ -47,7 +50,7 @@ function smfSetup() { global $wgExtensionCredits, $wgLang, $egMapsServices; - // Creation of a list of internationalized service names + // Creation of a list of internationalized service names. $services = array(); foreach (array_keys($egMapsServices) as $name) $services[] = wfMsg('maps_'.$name); $services_list = $wgLang->listToText($services); @@ -58,7 +61,7 @@ 'path' => __FILE__, 'name' => wfMsg('semanticmaps_name'), 'version' => SM_VERSION, - 'author' => array('[http://bn2vs.com Jeroen De Dauw]', 'Yaron Koren', 'Robert Buzink'), + 'author' => array('[http://bn2vs.com Jeroen De Dauw]', '[http://www.mediawiki.org/wiki/User:Yaron_Koren Yaron Koren]', 'others'), 'url' => 'http://www.mediawiki.org/wiki/Extension:Semantic_Maps', 'description' => wfMsgExt( 'semanticmaps_desc', 'parsemag', $services_list ), 'descriptionmsg' => wfMsgExt( 'semanticmaps_desc', 'parsemag', $services_list ), @@ -68,12 +71,20 @@ } /** - * Adds a link to Admin Links page + * Adds support for the geographical coordinate data type to Semantic MediaWiki. */ +function smfInitGeoCoordsType() { + SMWDataValueFactory::registerDatatype('_geo', 'SMWGeoCoordsValue'); + return true; +} + +/** + * Adds a link to Admin Links page. + */ function smfAddToAdminLinks(&$admin_links_tree) { $displaying_data_section = $admin_links_tree->getSection(wfMsg('smw_adminlinks_displayingdata')); - // Escape if SMW hasn't added links + // Escape if SMW hasn't added links. if (is_null($displaying_data_section)) return true; $smw_docu_row = $displaying_data_section->getRow('smw'); Modified: trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsFormInput.php =================================================================== --- trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsFormInput.php 2009-11-28 21:27:51 UTC (rev 59531) +++ trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsFormInput.php 2009-11-28 21:28:41 UTC (rev 59532) @@ -15,7 +15,7 @@ final class SMYahooMapsFormInput extends SMFormInput { - public $serviceName = MapsYahooMapsUtils::SERVICE_NAME; + public $serviceName = MapsYahooMaps::SERVICE_NAME; /** * @see MapsMapFeature::setMapSettings() @@ -29,7 +29,6 @@ $this->earthZoom = 17; - $this->defaultParams = MapsYahooMapsUtils::getDefaultParams(); $this->defaultZoom = $egMapsYahooMapsZoom; } @@ -41,7 +40,7 @@ global $wgJsMimeType; global $smgScriptPath, $smgYahooFormsOnThisPage, $smgStyleVersion; - MapsYahooMapsUtils::addYMapDependencies($this->output); + MapsYahooMaps::addYMapDependencies($this->output); if (empty($smgYahooFormsOnThisPage)) { $smgYahooFormsOnThisPage = 0; @@ -71,21 +70,21 @@ protected function addSpecificMapHTML() { global $wgJsMimeType; - $type = MapsYahooMapsUtils::getYMapType($this->type, true); + $type = MapsYahooMaps::getYMapType($this->type, true); - $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom); + $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); - $controlItems = MapsYahooMapsUtils::createControlsString($this->controls); + $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls)); $this->types = explode(",", $this->types); - $typesString = MapsYahooMapsUtils::createTypesString($this->types); + $typesString = MapsYahooMaps::createTypesString($this->types); $this->output .=" <div id='".$this->mapName."' style='width: {$this->width}px; height: {$this->height}px;'></div> <script type='$wgJsMimeType'>/*<![CDATA[*/ - addOnloadHook(makeFormInputYahooMap('$this->mapName', '$this->coordsFieldName', $this->centre_lat, $this->centre_lon, $this->zoom, $type, [$typesString], [$controlItems], $this->autozoom, $this->marker_lat, $this->centre_lon)); + addOnloadHook(makeFormInputYahooMap('$this->mapName', '$this->coordsFieldName', $this->centre_lat, $this->centre_lon, $this->zoom, $type, [$typesString], [$this->controls], $this->autozoom, $this->marker_lat, $this->centre_lon)); /*]]>*/</script>"; } @@ -96,7 +95,7 @@ protected function manageGeocoding() { global $egYahooMapsKey; $this->enableGeocoding = strlen(trim($egYahooMapsKey)) > 0; - if ($this->enableGeocoding) MapsYahooMapsUtils::addYMapDependencies($this->output); + if ($this->enableGeocoding) MapsYahooMaps::addYMapDependencies($this->output); } Modified: trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsQP.php =================================================================== --- trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsQP.php 2009-11-28 21:27:51 UTC (rev 59531) +++ trunk/extensions/SemanticMaps/YahooMaps/SM_YahooMapsQP.php 2009-11-28 21:28:41 UTC (rev 59532) @@ -14,7 +14,7 @@ final class SMYahooMapsQP extends SMMapPrinter { - public $serviceName = MapsYahooMapsUtils::SERVICE_NAME; + public $serviceName = MapsYahooMaps::SERVICE_NAME; /** * @see SMMapPrinter::setQueryPrinterSettings() @@ -26,8 +26,12 @@ $this->elementNamePrefix = $egMapsYahooMapsPrefix; $this->defaultZoom = $egMapsYahooMapsZoom; - - $this->defaultParams = MapsYahooMapsUtils::getDefaultParams(); + + $this->spesificParameters = array( + 'zoom' => array( + 'default' => '', + ) + ); } /** @@ -37,7 +41,7 @@ protected function doMapServiceLoad() { global $egYahooMapsOnThisPage; - MapsYahooMapsUtils::addYMapDependencies($this->output); + MapsYahooMaps::addYMapDependencies($this->output); $egYahooMapsOnThisPage++; $this->elementNr = $egYahooMapsOnThisPage; @@ -50,10 +54,10 @@ protected function addSpecificMapHTML() { global $wgJsMimeType; - $this->type = MapsYahooMapsUtils::getYMapType($this->type, true); - $this->controls = MapsYahooMapsUtils::createControlsString($this->controls); + $this->type = MapsYahooMaps::getYMapType($this->type, true); + $this->controls = MapsMapper::createJSItemsString(explode(',', $this->controls)); - $this->autozoom = MapsYahooMapsUtils::getAutozoomJSValue($this->autozoom); + $this->autozoom = MapsYahooMaps::getAutozoomJSValue($this->autozoom); $markerItems = array(); @@ -71,7 +75,7 @@ $this->types = explode(",", $this->types); - $typesString = MapsYahooMapsUtils::createTypesString($this->types); + $typesString = MapsYahooMaps::createTypesString($this->types); $this->output .= " <div id='$this->mapName' style='width: {$this->width}px; height: {$this->height}px;'></div> _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs